Question Answer Plugin


(Angus McLeod) #64

Not sure what you mean here. If by question you mean the first post in a topic, the vote button doesn’t appear on the first post. See e.g.: What has cities, but no houses; forests, but no trees; and water, but no fish? - QnA - Angus’ Sandbox

Not sure I agree :slight_smile: I think there’s a difference between liking an answer and thinking it’s the correct answer. For example you could like an answer because it’s funny, but not think it’s the best answer to the question.

No doubt, there will be further issues this plugin needs to overcome. As Jeff says in that topic you linked, there are indeed a number of parts of the app that assume the posts are in chronological order. I’ve dealt with some of the key ones in this plugin. But there will probably be more.

Personally, I still consider this plugin to be speculative. I’m planning to use Discourse Solved for questions on my own site, at least for now.

That said, it does actually work. Try it out on your own test instance and it will work as described. If you’re sure you need this style of QnA to work in Discourse, you could hire a dev (or do it yourself) to test all the edge cases and related functionality that the changes to the topic order might affect. Things like: topic entry (i.e. where does the topic scroll to), topic tracking time (i.e. reading time), or how it handles long threads. If after extensive testing you’re satisfied, then use it by all means.

In terms of future compatibility, core Discourse may well introduce new logic that assumes a topic’s posts are in chronological order, in which case this plugin will have to be updated to handle that as well.

That said, there is actually a sort_order property for Posts in core Discourse which is seperate from post_number. Currently there are two sort orders in Core Discourse (see models/post.rb - I don’t think reverse_order is actually used though):

def self.regular_order
 order(:sort_order, :post_number)
end

def self.reverse_order
  order('sort_order desc, post_number desc')
end

The way this plugin works is to introduce a new (slightly more complex) sort order:

answers = posts.where(reply_to_post_number: [nil, ''])
          .where.not(post_number: 1)
          .order("vote_count DESC, post_number ASC")

count = 1
answers.each do |a|
   a.update(sort_order: count)
   comments = posts.where(reply_to_post_number: a.post_number)
      .order("post_number ASC")
   if comments.any?
      comments.each do |c|
        count += 1
        c.update(sort_order: count)
      end
   else
      count += 1
   end
end

The sort_order column is not going away any time soon. It’s existence anticipates that there can be other orders apart from the chronological order (i.e. post number).


(Daler) #65

Sorry I misstated, in this case I meant an answer (not Question) for which people can vote, but also “Like”.

Valid point. For my use case I believe it is better to “disable” likes for posts which have a voting button. Sure, we could hide the “Like” button and the list of Likers with CSS, but that would not prevent abuse with the browser console.

So, perhaps it would it be possible to add an optional global setting to e.g.:
qa disable likes on answers - prevents rendering of “Like” button and the list of Likers


(Angus McLeod) #66

Sure, why not :). Here you go:


(Daler) #67

Thank you once again!
To make UX & styling customizations easier, would it be possible to do the following:

  1. Wrap the text nodes in a span tag? (e.g. “voted for this”, “N persons voted for this post” etc.)

  2. Change “N persons voted for this…” to a simpler: “Show/Hide voters” button?

Even better, let the Vote count become a button in charge of showing/hiding the list of voters?
(similar to how “Likes” counter works)

  1. Not duplicate the voters count (as the vote count already reflects this)?

UPDATE:
4. Toggle “.active” class on “.qa-post button” (if user voted/unvoted), so we can give a better visual feedback (again, similar to the Like :heart: button).


#68

Excellent info, thanks for writing up a detailed description @angus I feel much more comfortable utilizing the plugin after understanding sort_order.

Plugin-builder newbie question - is there a significant time implication to altering the UI for this plugin (moddifying core, etc.)? Happy to help contribute, I just wanted to understand the complexity in altering the UI to look something like this:


(Daler) #69

I really need to let my users vote more than once per topic (e.g. for different responses).
Would it be possible to allow for this? e.g. with an opt-in setting like:

qa number of votes per user per topic e.g. “5” - (default “1”, “0”- unlimited) - how many responses a user can vote for.


(Angus McLeod) #70

It’s possible :slight_smile: I won’t have the time to do this till next week though.


(Guy Fawkes) #71

Angus McLeod
May I please have some few screenshots for the plugin
Does it support anonymous answer ? if not , can it be customisable ?
Thanks


(Angus McLeod) #72

Sorry, I missed a few questions here.

Overall, I have to give my apologies in terms of doing new work on this plugin. I’m happy to fix bugs with the existing functionality (I just fixed an issue with time-gaps), but for new features this plugin is near the bottom of my priority list.

If you want to add more features / customisations here your best bet is to get someone with some standard frontend skills. If that someone gets stuck with the logic of the plugin itself I’m happy to help them out understanding it.


@dalerka Those changes the voter list are possible, but are slightly harder than they may first seem as this plugin uses an existing structure in Discourse called “Post Actions” to display the voter list. So it would require some JS changes as well.

@supernaturally The UI part of the change to the vote buttons would not be that hard to do, but down-voting would be a new feature.

You can see it in action, and try it out, on my sandbox in the QA category, e.g.

It should support anonymous answers (I haven’t tested it with anonymous users extensively though), as it has all the features of a normal Discourse topic, which allows a user to post anonymously if the “allow anonymous posting” site setting is turned on.


(Blu McCormick) #73

Does this plugin’s vote count carry over to comments embedded into a wordpress site via the WP Discourse plugin? Does the resorting of comments based on votes impact order of comments embedded in wordpress site? I am thinking not. I imagine once comments are resorted per votes in the forum, the comments could be manually reimported to wordpress.

Has anyone tried these two plugins together?

Thanks in advance.


(Angus McLeod) #74

I’ve never used the WP plugin before, but in theory the only thing you’d need to do to get a ‘read only’ version within Wordpress (i.e. you can’t vote, or clicking a ‘vote button’ would send you to the discourse topic itself) would be to customise the WP comment template to support the QA styles.

The key bits would be:

1 - If a topic has qa enabled and the post is not the first post, it’s a ‘comment’ if it’s a reply to a post and it’s an ‘answer’ if its not. This is the version of this logic in the Discourse client customisations in this plugin:

api.addPostClassesCallback((attrs) => {
  if (attrs.topic.qa_enabled && !attrs.firstPost) {
    return attrs.reply_to_post_number ? ["comment"] : ["answer"];
  };
});

2 - Display the property topic.vote_count alongside answers.

The posts should already be in the right order as this plugin changes the sort_order of posts in a topic, which should be respected regardless of what client is consuming the server endpoints (i.e. the Discourse client, or the Wordpress plugin).


(Blu McCormick) #75

This is a great plugin, Angus. Thanks. :pray:

Sounds like you are onto other things now. Good for you. Have you ever considered programming the plugin so members can change their vote to another answer if a better answer comes along as the discussion on a topic grows over time? Kinda like how you can unlike content by clicking on the heart icon a second time?

Actually, this might work too:

P.S. I will be using wp discourse and the q/a plugin together and will report in here to let you know how it goes. I imagine the prioritization of order of content based on membership consensus would be a nice complement to the settings in the wp discourse plugin where you can set the criteria in a number of ways for what gets embedded from the topic into wordpress blogs.


(Joshua) #76

Um, could you please give screenshots of the plugin? I am thinking of suggesting it to a forum that I am on, but I want to know how it looks first.


(Blu McCormick) #77

Try this, @Yusamac205


(Angus McLeod) #78

Great! Let me know how it goes.

You can change your vote by clicking ‘Undo vote’ on a post you’ve voted for

Screenshot%20at%20Feb%2026%2021-58-28|289x150,100%.

This behaviour is actually part of core Discourse itself, it’s just not currently used. This plugin uses the latent voting logic in core Discourse where it can, this being one instance.

As @McBlu noted, you can see this plugin in action on my sandbox, e.g

If you’re considering using this, please note that I’m not currently devoting much time to this plugin, and:


(Blu McCormick) #79

Thanks, @angus. I see this line.

56%20AM

And when I click on it the line changes to this:

05%20AM

And there is no option to undo vote. ie. This doesn’t come up:

22%20AM

Here are what I have checked in settings:

I have verstion 0.2 installed by discoursehosting.com.


(Angus McLeod) #80

Ah yes, there’s a time limit to undoing post actions (‘voting’ is a type of ‘post action’, like ‘liking’). I can’t check the code right now (it may be something like 5 minutes). Increasing this limit won’t be too hard, so if it helps I’ll add this in as a setting tomorrow.


(Blu McCormick) #81

Thanks, Angus, I’ll keep testing the undo function to see what happens.

Which setting are you adding tomorrow?

This plugin is awesome, btw.


(Angus McLeod) #82

Sorry, I mean I’ll add a setting for increasing the time limit on changing your vote (including making it always possible).


(Blu McCormick) #83

Awesome, Angus. Thanks. That would be great. In my scenario, I accidentally deleted a post when I went to try and undo a vote so I can imagine people accidentally voting and just wanting to undo it in the moment for which, being able to immediately undo it would be great.

I saw in an earlier post that you were toying with having a setting that lets you set how many votes per topic a member can do (sorry if I misunderstood). Is that right?


I get the impression you are done working on this plugin and moving onto other things. Of all the plugins, this is the one I’d fund changes to if I had the dinero. It’s fantastic and a great complement to the WP Discourse plugin that embeds comments in blogs per the criteria you set. With your plugin, members get to weigh in on what gets to the top of the comments in an impactful way.

P.S. The undo function isn’t working for votes that happened yesterday. I have a message into discoursehosting.com to see what version of the q/a plugin is installed. It says 2.0 in my settings and was very recently installed so likely we are up to date.