Topic Ratings Plugin

A Discourse plugin that lets you use topics to rate things!

Features

  • Rate topics by a star rating system in the composer.
  • Enable different rating types on a per-category or per-tag basis.
  • Toggle rating count and average rating per rating type.
  • Toggle visibility of ratings, counts and averages based on user roles.
  • Bulk actions including rating type migration

:page_facing_up: Get the code

:bug: Report a bug

Lost?

  • Not sure how to install a plugin? Follow the steps here.

  • Make sure you check out all the site settings for this plugin by searching for ā€œRatingā€ in your admin settings.

:wave: Before you post in this topic, bug reports or feature requests over at thepavilion.io are much appreciated (itā€™s easier to manage than one big topic!). If you just have a quick question, itā€™s fine to post that here.

59 Likes

Ok Iā€™ve made a simple frontend exclusion of the ratings stars for users that have already posted in a ratings topic.

Ideally, Iā€™d like to modify the topic and/or post guardians on the server to prevent a user from posting in a ratings topic twice. However, with my limited ruby skills, I canā€™t see an easy way to do this without just overriding the existing methods (assuming thatā€™s possible this isnā€™t a very sustainable thing to do)ā€¦ any ideas/tips? @sam

Relevant topic guardian method

Relevant post guardian method

2 Likes

We need to add plugin hooks here.

4 Likes

Where is the button in the composer UI or for the finished post to rate the thread?
I have installed the plugin, given the thread the ā€œratingā€ tag, and can see the empty stars at the top. But no button to actually rate it. :frowning: (Or must I use a non-admin account for that?)

EDIT: looked closely at the screenshots, and see that there is supposed to be a ā€œYour ratingā€ line there. Well, itā€™s missing in my instance.
Thought of a second reason this might not work: My instance is German. If the translation is missingā€¦

Will create a test user and set his user interface to English. If it still does not work then something is broken.

OK, mystery solved. As a normal user, I can answer even though my user interface is still in German.

Warn a guy about stuff like that, will ya! :wink:

(An option to allow admins to vote too would be honestly appreciated, though.)

Edit: Celebrated too early, its still broken.
I had the option to select stars on posting the initial reply. That did not affect the overall rating, though. And on editing the reply, the ā€œYour ratingā€ line is missing again. :frowning:
Switched the user interface of the test user to English - no change.

Help!?

1 Like

@fackelwind Thanks for the feedback! I appreciate it. This precipitated a significant refactor to get it working as expected. In retrospect Iā€™m surprised it worked before at allā€¦

https://github.com/angusmcleod/discourse-ratings/commit/2b766fae0e730f63d83a3c7c42c51fa7c0df8827

https://github.com/angusmcleod/discourse-ratings/commit/94ad34bc8423db0e592dd596e806a8357178c0e5

The only thing that doesnā€™t work now is the topic average will not get automatically updated for other users when a new user publishes a post with a rating or edits a rating in a post. Other users will see the updated rating on the new or updated post itself, but the topic average rating wonā€™t update until those other users refresh. I will fix that soon.

Hereā€™s a screencast demonstrating the functionality: http://quick.as/b1wbSOa9g

@zogstrip @riking Hey guys, could you give me some advice on the best way to push topic updates to other clients from the server? Iā€™m pushing the post updates using the aptly named post method publish_change_to_clients which uses the MessageBus. But Iā€™m not sure of the best way to do the same for the average_rating custom field Iā€™ve created for topics. I can send it to back to the current userā€™s client easily enough, but other clients? Iā€™m sure itā€™s relatively straight forward, but with my basic ruby skills the answer isnā€™t jumping out at meā€¦

1 Like

You want to use MessageBus.publish(channel, msg, group_ids: topic.secure_group_ids) with the same channel and a different message.

Iā€™m not quite sure how to hook into the MessageBus.subscribe() call on the client, thoughā€¦

2 Likes

Alright, installed and quickly tested.
Rating now works (great!). However, I can rate all threads, whether or not they have a rating Tag attached. I also see stars under each Thread title (again, no rating Tag). Not idealā€¦
Klicking on the stars on the published post does not work (I think having to edit the post is fine, but since you advertised it, I am telling you about it).
Is there a way for the user to remove a rating again? (Not necessary, but nice to have.)

I will test more later today.

Just one more request: When you implement your restriction to one post per user in any rating thread, can you make that a setting? I think for my use case having a proper back and forth discussion might be better (of course with a limit of one rating per user :wink: ).

Thanks, Iā€™ve got it working now. I was getting confused by the last parameter, i.e. the user or group ids, on the publish function; it made me think it wasnā€™t apposite for this case.

The topic controller subscribes to the message bus here. The ā€˜revisedā€™ type case already handles the post update, so all I needed to do was set the bus message type to ā€˜revisedā€™ and then add extra logic to save the average to the clientā€™s topic model for the ā€˜revisedā€™ case, i.e.

then

@fackelwind topic averages now update automatically for all clients when any rating is changed.

2 Likes

Yes, I see the issue, Iā€™ll fix it tomorrow morning.

Klicking on the stars on the published post does not work (I think having to edit the post is fine, but since you advertised it, I am telling you about it).

Yes I should have mentioned, I removed that functionality (updated the description accordingly now). So you can only rate in the composer itself.

Just one more request: When you implement your restriction to one post per user in any rating thread, can you make that a setting? I think for my use case having a proper back and forth discussion might be better (of course with a limit of one rating per user :wink: ).

Yes, I think Iā€™ll make it a setting.

Thanks!

Thanks a bunch for your fast response!
I did not have a lot of time this morning, so I just sent of a very quick response. I want to really thank you for this plugin, it matches perfectly with what I want to make possible for our community! (completely new site, so I am free to play around with a still maturing plugin. :wink: )

Another Bug Report from me:

  • Right now, every post can vote, even when that user has already replied and voted in the thread.

  • If you do not vote, it counts as 0 stars. I donā€™t think this is the correct way to handle it: A non-vote should not influence the average at all. And just posting into a thread which can rate should not lower the average opinion about the topic. Besides, once you have klicked onto 1-5 stars, you can never go back to 0 stars, so even if there just had to be a default vote, it would not be correct.

And a wishlist item: Some way to see the precise average, and how many people have rated the topic how highly. Kinda obvious if you look at amazon or wherever. Just making sure. :wink:

EDIT: Since it might not be obvious: Even though I report everything that looks wrong to me, and even write down whishlist items, the most important thing is that the plugin does not influence threads which it shouldnā€™t (no rating Tag, category not marked for rating). People are starting to use my discourse instance. Whether this plugin does or doesnā€™t work correctly is not a big deal as long as only the rating trial topic is influenced. When every single thread is modified, that is a much bigger problem. (All topics created today show starsā€¦)

I have deinstalled the plugin again for now (rebuild the docker instance without it), to get rid of the visual clutter on threads that were not supposed to be rated.

I will happily retry it once that bug is fixed (though having to rebuild the instance for that, with the associated downtime, is unfortunate).

I have made sure the topic averages will not be applied to new topics in a non-ratings category or without the ratings tag. Unfortunately this wonā€™t fix existing topics with empty ratings youā€™ve made in your instance. If that is a significant issue, Iā€™ll see if I can figure out how to fix it.

https://github.com/angusmcleod/discourse-ratings/commit/22444911758280e519f5908cacf259da53df2a57

Right now, every post can vote, even when that user has already replied and voted in the thread.

I canā€™t reproduce this one. Could you check again if you re-install the plugin. Thanks.

If you do not vote, it counts as 0 stars. I donā€™t think this is the correct way to handle it: A non-vote should not influence the average at all. And just posting into a thread which can rate should not lower the average opinion about the topic. Besides, once you have klicked onto 1-5 stars, you can never go back to 0 stars, so even if there just had to be a default vote, it would not be correct.

Yes this is an issue. I think the way to handle it is if the user does not select a rating in a post, that post does not get a rating included. That user could still post on that topic with a rating in another post. Of course, once I add the setting to prevent a user posting in a ratings topic more than once, I will have to require that the user adds a rating to their single post. I will fix this one within the next two days.

And a wishlist item: Some way to see the precise average, and how many people have rated the topic how highly. Kinda obvious if you look at amazon or wherever. Just making sure. :wink:

Yes this is possible. I think Iā€™ll add it next to the topic stars and add later a setting to show/hide it. I will do this one on the weekend.

1 Like

This is a significant issue, but not in the way you think. Having an SQL query to run against the DB (to remove the empty ratings) would not really help.
Think about this: How do you intend to handle the case where someone removes the ā€œratingā€ tag from a topic? Or in any other way removes a topic from being a rated one?
I would argue that the only sane way for you to handle that case is to treat it as a vanilla topic: No stars, no possibility to rate, no restrictions in the amount of posts. So you donā€™t only look whether there are ratings when deciding on whether to draw stars or not, you always check whether the topic fulfills the criteria of being a rated one. (I have honestly no idea what you intend to do when someone tags an existing topic with ā€œratingā€, the setting to restrict it to one post per user is active, and users have already posted more than onceā€¦)

And if you have implement that, I wonā€™t have any problems with stale ratings either. :wink:

Iā€™ve got a discourse docker instance lying around on my desktop. Tell me when you have a version which you think should work, and Iā€™ll test it there. :smiley:

Sure, Iā€™ll play around with the ā€˜removalā€™ case tomorrow morning.

This morning I migrated this to the new plugin api.

https://github.com/angusmcleod/discourse-ratings/commit/31e49b955a0d9711d1275200d4e9d660a754ebef

1 Like

Ok! Finally had some time to work on this. Made various bugfixes and updates. Inter alia, I changed the category property that signified whether the category had ratings enabled, so existing categories with ratings enabled will have to be re-enabled to work.

The ratings tag and category toggle is now handled within the composer. If the creator of a topic removes/adds a ratings tag or changes from a ratings category in the first post of a topic the topic will refresh after they post and the ratings will show/hide depending on whether their action was to turn ratings on or off. If ratings are turned ā€˜offā€™ on a topic they are still there in the DB. If ratings are turned back on the same ratings will appear again.

Tomorrow or the next day, Iā€™ll apply the same logic to the topic title edit (i.e. if the creator of the topic changes the category or tags by editing the topic title).

Then Iā€™ll add the exact numeric rating to topics title sections and add a setting to toggle it. Then Iā€™ll add an indication that a topic has ratings if those ratings are hidden (i.e. if the category or tags were changed) and a setting to toggle this too.

4 Likes

That sounds really good!
Iā€™ll play around with your plugin this weekend, see whether I have any more bug reports for you. :smiley:

1 Like

Tomorrow or the next day, Iā€™ll apply the same logic to the topic title edit (i.e. if the creator of the topic changes the category or tags by editing the topic title).

This is done.

1 Like

Thanks @DavidGNavas for the Spanish translation!

https://github.com/angusmcleod/discourse-ratings/pull/2

3 Likes

It seems that the ratings plugin makes messages unavailable. Here are some logs. It looks like somehow messages donā€™t know that they donā€™t have ratings.

Logs.txt (43.7 KB)

When I disabled the ratings plugins my messages worked again.

Version	v1.5.0.beta11 +267	1.5.0.beta11