Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+16 votes
in Plugins by
retagged by

Hi, I discovered last month Q2A and installed the latest version 1.8.6 locally. I have to confess that I am really impressed and i cant stop playing around with the code !!
Now to my question. I found the plugin onsite notifications and installed it successfully. However i would like to ask how can i display inside the notifications popup the username in each notification/event.. For example:

Now displays:
Upvote for "Question Title..."

I want:
Upvote by "Username" for "Question Title"

I checked the code of the plugin and tried to get the username with

$event['handle'] = qa_post_userid_to_handle($event['userid']);

  but i get my user name (admin) inside each notification instead of the user who upvoted, commented etc the question!! What am I doing wrong?? $event['userid'] should get the user id of the event and not my id !!

Any help would be very much appreciated.

Q2A version: 1.8.6
I need this too. Hopefully Gabriel will answer.

2 Answers

+3 votes

Even though it is not the intention, this "question" ends up being a "please, code this new feature for me as an answer" :) What you request goes beyond the time/length of just an answer. But I can guide you in how to make that work step by step. After step 1 you will be able to ask more concrete questions, if anything is unclear.

So, in short, what you're attempting makes no sense, because you will always get your own username if you check for events that belong for your username. What you need to check is actually the parameters of the event as those are the ones that store the information related to the event.

However, if you do so, you will find out that the parameters also hold your user ID. This is actually a bug :(. It is located in this line (although it might affect some other lines that have been copy-pasted in that file as well). The explanation is that from the user sending the event, the parameters of the receiver user should be stored. When storing them, the plugin will create its "in_*" event which should be a mirror: it should use the main user as the receiver of the original event (this is working fine) but it should also use the sending user of the original event as the user ID stored in the parameters (this is not working fine).

Currently, the parameters are being copied in both events so, the user receiving the vote is the one that will show up in both events (the original and the "in_*" one).

Once you fix this, you will be able to work on the next step.

Hi Pupi85. First I would like to thank you for your answer. I had no intention of making you or anyone else build a new feature exclusively for me!!  Nowhere in my question I mention anything like that. I just kindly asked  for help  ;) if you took it that way, then accept my sincere apologies.
Anyway i will try to fix this issue according to your instructions above!
Once again thank you for your time.
I know, that's why I started my answer by saying it was not the intention :)
Damn i missed that :) Anyway i started the coding of my first plugin.... Wish me good luck community :)
That's great
0 votes
edited by

This is now easier to do with the latest versions of the plugin. Although this would defy the purpose of hiding Up/Down votes to regular users, as this would result in toxic behaviors like returning downvotes. "User X downvoted your post".

That's why only Admins and Mods can see who casted votes in questions, answers and comments, when you hover over the Vote Counter.

This idea also popped in my head while I was updating the latest versions of the plugin, because of the new structure for Message notifications:

 Username  +  sent you a private message:  +  The message...  

(Which you can study it to recreate that for the upvotes btw. Line 189 and line 397.)

but then I didn't go forward with it because of that reason.