How to find to the people have liked me?


(SMHassanAlavi) #1

I want to show my users that you have received some likes from a specific user.
I have explored the discourse site but I don’t find like’s owener of my likes.
I just find the most_liked_by_users but I want all users not most_liked because each like from that specific user is very valuable and we want to show the number to user to try to get like from him.
I ddn’t find anything here:
https://padpors.com/u/{username}/summary.json


(Andrew Waugh) #2

https://meta.discourse.org/u/{username}/notifications/likes-received.json


(SMHassanAlavi) #3

Thank You but:
It didn’t show me all likes,
It just shoewed me latest likes.
I want to see all a user’s like’s owenrs, all of them.


(cpradio) #4

You will want to use
https://meta.discourse.org/user_actions.json?offset=0&username=username&filter=2

That will get you page one (30 entries) then you can call page 2 using
https://meta.discourse.org/user_actions.json?offset=30&username=username&filter=2

and so forth.


(SMHassanAlavi) #5

Does doing this reduce the site’s speed?
How is the effect on the speed for each ajax?


(cpradio) #6

If you are asking if you could theoretically DDOS a site by requesting that information for each user, then the answer is, it depends. There are ratelimits setup by default in Discourse, however, if you tweaked those or are bypassing them, then well, you’re on your own. :slight_smile:


(SMHassanAlavi) #7

No I didn’t mean that :joy:
The js code run on the user’s browsers may reduce the speed for him and annoy him.
I am asking about the transfer size. Our site’s transfer size is about 2.8 MB and I don’t want to increase the size by inefficient ajax.
I want to reduce the ajax numbers to the lowest number possible


(cpradio) #8

Your best bet is a plugin. As it is incredibly inefficient to approach it using the existing endpoints. As they are meant for lazy loading and not for statistic gathering, which is what you are attempting.

It would be far wiser to create a new response that can be cached that returns the data you need. But that is just my opinion.

I’m also not 100% clear as to what the data is to represent or how it is to be displayed, so without mockups it is hard for me to steer you in a more descriptive direction.


(SMHassanAlavi) #9

I have a plugin that shows some data beside the page, the plugin is profile widget.
What is your opinion about ajaxing these data in the .js file?
Does it reduce the site speed?


(cpradio) #10

You will need to add Ruby code. You will want to create a new route that can cache its data by user requested and return a response from a custom SQL query to get the data on who liked them.

Then you would call that route via an Ajax call to load into your widget.


(Mittineague) #11

This query might be close to what you want, tweak to suit eg. add a WHERE user_id = an id for a single user

SELECT 
 user_actions.user_id 
 , array_agg(DISTINCT user_actions.acting_user_id) 
FROM user_actions 
WHERE 
 user_actions.action_type = 2 
GROUP BY user_actions.user_id

“2” is “liked” and “acting_user_id” is the “giver”

You may prefer to use AR pluck, but it would be the same table


(SMHassanAlavi) #12

How can I do this in plugin.rb file?
Can you tell me a simple plugin That have done this?


(cpradio) #13

The Staff Notes could be a good starting place. It integrates with users and posts, so you’d want to ignore the posts part and likely integrate with the user only.

You should also look at the Who’s Online plugin. That also deals with Users. However, the big difference is the Who’s Online is a global view, not specific to the user who is logged in, so you’d need to take that into account. But it also has several advantages for you, it is utilizing the message bus to send updates and that could be useful for you.