Finding out how many users are watching or tracking?


(SMHassanAlavi) #1

Where Can we find how many users are watching or tracking a topic or a category? Does it save any where in discourse?


(Mittineague) #2

There are “_user” tables.
category_users, topic_users, group_users and tag_users
Each has a notification_level field where the integer indicates a members preference - 0 Muted, 1 Normal, 2 Tracked, 3 Watched

So a query something like this should work

SELECT COUNT(id) 
FROM category_users 
WHERE notification_level = 3 
GROUP BY category_id 

to give you how many are Watching each category.


(SMHassanAlavi) #3

How can I define a function in plugin.rb for using this code?
I want to use a function in my JavaScript code to get the tracking but I don’t know how to configure the plugin.rb file to create a function like that?
Can any body tell me what should I add to plugin.rb to access a function like trakingNumbers(categoryID) in my widget’s javascript code?


(Mittineague) #4

If you post a link to your GitHub repo others could look and offer suggestions / PRs


(SMHassanAlavi) #5

Here is my repo on github.
It is a widget for @angus sidebar widget plugin. but I have stock in finding tracking number. I want to use this number in This file.


(Mittineague) #6

I think others will know better than I as to what the best approach might be. My take is that certain values are already available by making an XHR to get the JSON and when they aren’t a controller can be put together to return JSON eg.


I have seen plugins that use custom queries involving JOINs etc. but I have not experimented doing similar yet.