I am looking for a simple way for a CSS selector to match posts made by the current user (but not posts by other users). As far as I can tell, there is no CSS class added to such posts which I can use. But perhaps I am missing something?
If there is no such class at the moment, I would greatly appreciate if one was added!
My suggestion would be to add a class to the topic-post element, similar to the currently existing classes relating to the posting user, e.g. topic-owner. The new class could be current-user or my-post or whatever fits with existing Discourse nomenclature.
Click here for an explanation of why I want to do this...
Some time ago users of my forum complained about getting addicted to checking how many likes their posts have received. They went back to posts repeatedly just to check their likes and this behavior reminded them of the more toxic aspects of the mainstream social media platforms.
My solution was to create a theme for them to use where I simply added a CSS rule to hide the like counter on their posts. The like button on posts created by the current user has a class called .my-likes, so it is easy to select with CSS. This worked well and the users were happy with the solution.
However, earlier today it was pointed out to me that if you click the “…”-button, i.e. “show more” on a post, the users who have liked that post are listed. One user reported that he was back in his “dopamine junkie” ways because of this, repeatedly clicking “…” to circumvent the special theme and check his likes.
But unlike the above mentioned case of the like button, I can not find a CSS selector which lets me do this. The only solution I have found is to hide the list of likers for all posts, i.e. making it so that the users of the theme can not see that list for any post.
One thing you could to is find the topics in topic list which have current user are the poster, that could be done with jQuery. If true, then apply style to that row. Downside could be that user can be found as poster to the OP topic.
Other way is to override topic list component completely and do the magic there. More info on overriding templates can be found here:
Sorry, are you saying to want to decorate user posts in topic list or in the actual topic?
You could hook to the avatar of the current user in that case and find the parent post root element and add a class with jQuery to it.
I am well aware that I can do this with Javascript. I should have mentioned that from the start. However, the point of my post is that I would like to do it in a much simpler way, with a tiny bit of CSS (see the expandable part of my original post).
Besides being a simpler and more natural solution, it would let me manage things with the excellent built-in system for Themes and Theme Components.
And it is not like this would be some weird exotic thing. As I mentioned initially, Discourse already has class attributes on the very same element (post on topic page) for indicating properties of the posting user (topic-owner, trust level, group memberships etc). And in a sub-element of this element (the like button), there is already a class attribute indicating that the post is made by the user who is currently accessing the page.
For these reasons, I think adding that single attribute on the topic-post element is a much better solution than some Javascript hack.