Question Answer Plugin

some minor issues with the QA plugin-test:

  • answers are not sorted based on their votes in our Persian forum. in fact they become randomly sorted after activation of QA tag. and won’t go back to the previous time-based sorting if I deactivate the tag from the topic :frowning:

  • people can vote to their own reply.

2 Likes

Hey dude, sorry for being unresponsive here. Will take a look soon.

1 Like

@angus did you manage to solve this?

On my forum this is also an issue, posts are not sorted based on their votes, this is an example:

1 Like

Ok, previously I was trying to be clever and use the existing sort_order property on posts, however it seems that that breaks down when the topic gets longer than a handful of posts. I’ve just directly overridden the sort order of topics which are in a QA enabled category. So it’ll work for topics of any length.

https://github.com/angusmcleod/discourse-qa/commit/0a5521c3e0322ae1de99b05c287ba076990d8f1d

cc @Pad_Pors @TomekB

2 Likes

I tried to move a Q&A topic from the QA category to a different category, and all the votes and voting functionality disappeared. So I added a “question” tag to the topic, and all the votes came back on again. So the tag actually works.

The bug that I encountered is that, you can “like” any and all replies as long as you haven’t voted yet. However, if you vote first, then you can’t like anymore, you will get this error – “You are not permitted to view the requested resource”. So you should first undo your vote, then like some of the replies, then cast your precious one vote again.

Thanks for sharing :slight_smile:

@angus After installing your plugin I cannot read any private messages.

I get an error and this log message:

NoMethodError (undefined method custom_fields for nil:NilClass)
/var/www/discourse/plugins/discourse-qa/plugin.rb:66:in qa_enabled
1 Like

I have the same issue. Strangely it persists when entering discourse’s safe mode.

Found the reason: “Safe mode currently only disable the JavaScript portions of plugins”

3 Likes

Yup, looks like my last update didn’t handle the case of uncategorized topics. Please give it another shot.

https://github.com/angusmcleod/discourse-qa/commit/a64544c6682639eff413333de129f137d9994e23

cc @DiscourseMetrics.com

1 Like

This bug is now fixed as well.

https://github.com/angusmcleod/discourse-qa/commit/99fbb0fbcad909073294e4ba25d4c31125b99939

2 Likes

Hi @angus, thank you for a great plugin.

However, I’m curious how this plugin works with built-in posts timeline. If “this plugin re-arranges the posts in the topic based on those that have been supported” then this timeline is messed up, isn’t it? Posts with the most votes will be on top no matter when they were posted.

Or this plugin turns off the timeline and default chronological posts order?

Your example topic https://dev.civll.com/t/testing-the-qa-plugin/187 does not work.

Sorry for the slow reply, I’ve been on holiday :sun_with_face: :bear:

Yes indeed. The timeline no longer ‘works’ if you use this plugin. I haven’t explicitly addressed that yet. But you’re right that this needs it. I’ll add something in the next few days to deal with it properly. You could always hide it with CSS if need be.

I haven’t needed to address this for my own purposes, as I’m using this in conjunction with my layouts plugin (and others).

Basically, how this plugin works is that it:

  1. Uses the latent vote post action in the core Discourse code and stores the votes in the latent vote_count property of posts. These properties both already exist in the core code, but are not used in the client at the moment (see e.g. here). There’s even core logic to re-arrange the sort_order of the topic based on the vote_count, but it doesn’t work anymore (or maybe I don’t understand it). Previously I had tried to use that, but that led to the issues discussed above, so I added 2…

  2. Overrides the default topic view ordering logic for topics in categories with the appropriate flag, to order posts by vote_count instead of by post_number (the normal way topic views are ordered) (see here). If you want to understand the post ordering logic for topics, most of it is in lib/topic_view.rb. Tantalizingly, there’s a reference in the code to allowing custom post orders in the future

Basically, this ordering logic boils down to this SQL statement:

case when post_number = 1 then 0 else 1 end, vote_count DESC

i.e. if the post is the first post in the topic, then put it at the top, otherwise order the topic by post vote count.

I’ve made another Q/A topic on my dev instance if you want to take a look. Or you could sign up an account and create your own.

2 Likes

Thank you so much for such a detailed answer!

  1. Do you think this plugin could possibly significantly slow down page load speed? if there are lot’s of posts in a topic.

  2. Also, is there any possibility that this plugin will conflict with future discourse developments and updates. For example, if t hey decided to roll out their own “posts up-voting” feature.

  3. And the last one, is there any was to turn your plugin active site-wide in all categories? I have about 100 categories, and going to each category settings to turn on the plugin is PITA :slight_smile:

  4. As far as I understood, vote counts of each post are saved in a database and remain there even if I remove this plugin, is this correct? And if yes, could it possibly cause some issues in future discourse updates?

Thank you so much again for this plugin.

1 Like

No, it won’t affect page load speed.

Yes, this is a possibility with any plugin. If Discourse releases a core mechanism for up-voting posts then I will discontinue work on this and use that instead of this.

No, there isn’t yet. I could add this, but I strongly suggest you test this in a single category first, for at least a few weeks. This is a new plugin. I don’t use it in production myself yet.

[quote=“stantyan, post:37, topic:56032”]
As far as I understood, vote counts of each post are saved in a database and remain there even if I remove this plugin, is this correct?[/quote]

Correct.

The main question here is whether a future Discourse version will use the existing vote_count property of posts. If it does, then all votes made with this plugin will be picked up by the new core functionality.

Remember that vote_count is a property in the core Discourse code itself. It’s been there since the initial release of Discourse, i.e. 2013.

The alternative way of handling the storage of votes would have been to create a post custom field, i.e. post.custom_fields['vote_count']. The reason I chose not to do this was because it seemed redundant given there was an existing post property, and it would also make it harder to migrate the data created by this plugin if the core vote_count field were used in the future for a similar purpose. Also, I would have to re-create the front-end post-action UI and translations that already exist for voting.

I suppose there is a risk that vote_count could be used in the future in a such a way that does not conceptually relate to the way I am using it here, however I doubt it. Something called vote_count on a post object could only really be used for storing the count of how many people have voted for that post.

If you’re wondering whether this plugin conflicts with the poll plugin or the topic voting plugin, it doesn’t. Those plugins use different fields. All are about voting, but different kinds of voting…

image

3 Likes

@angus I can not rebuild Discourse when using your plugin. I get this error:

NoMethodError: undefined method attributes' for PostSerializer:Class /var/www/discourse/plugins/discourse-qa/plugin.rb:33:in class:PostSerializer

1 Like

Thanks for the bug report. Fixed.

https://github.com/angusmcleod/discourse-qa/commit/3410a6fd784f0163dd0466730d0e90185ad73bdd

4 Likes

Works great! Thanks so much.

2 Likes

Trying to view your Q&A plugin in action but getting a “This site can’t be reached” message

Yeah, I just took that sandbox down. I’m making a new one.

1 Like