Trying to show self replies in color

Hi,
I’m trying to add a new class to topic-post for users, seeing self replies. In fact, I am trying to show self messages with different looks in topics.
This feature is good when a template is designed like a messenger app.

Is this feature already defined anywhere?

This is already possible with the .topic-owner CSS class. You can use below CSS to highlight the self replies

.topic-owner .topic-body {
  background: #fffaaa;
}
8개의 좋아요

But topic-owner class just assigned to replies of the topic creator. I need a class for example named my-own for adding to other replies if logged in user wrote them.

Like a messenger app, shows my replies right side and others on the left side balloon.

1개의 좋아요

You can do this by adding the following code to the Header of your theme (or to the header of a theme component):

<script type="text/discourse-plugin" version="0.8">
    const currentUser = api.getCurrentUser();
    api.addPostClassesCallback((attrs) => {
        if (currentUser && currentUser.id === attrs.user_id) {
            return ["post-by-current-user"];
        } else {
            return [];
        }
    });
</script>

You can then use the post-by-current-user class in your stylesheet.

11개의 좋아요

Woooow, I thought that doing so would require a lot of changes.
Discourse is really exciting …

Thanks a million!

5개의 좋아요