Who's Online Plugin (discourse-whos-online)


(Lee Strickland) #122

I love this plugin! I would have to have the opt-out feature to use this in the community I admin, but it’s great for community building. We have lots of lurkers and sometimes if they just saw how many others were lurking they might post?


(B Iggy) #123

Hey,

wow, what a journey. I just liked your work @david and thought “why not”, integrated it to my forum and after one guy complained about being “exposed” I started to investigate quite deep into this whole topic.

GDPR was just one little obstacle in general regarding “user must control their stuff”. I see it’s hot discussed in Discourse already (anonymizing user, downloading data via CSV etc.).

Anyways I checked the philosophy of “Who’s online” in general here and there and saw for example why it isn’t in one of the biggest mobile game (Clash of Clans).

So I started to code my own version of “User control” and achieved it - more or less.
I’m still not sure if I will keep it since it might hinder people even to login to the forum if they feel “exposed” but for everyone who wants my version so far or use it as a starting point I’ll share.

1. Implement a User Field

Set it up as Dropdown and configure as you wish (Required at signup for example)

Access it in your Preferences > Profile page

2. Implement some JS magic

<script type="text/discourse-plugin" version="0.8">

api.onPageChange(() =>{
    onlineStatus();
});

function onlineStatus() {
    $.ajax("/session/current").then(function (json) { 
       var userName = json.current_user.username; 
       
        $("#whos-online a[data-user-card]").each(function() {
            var userData = $(this).data("user-card"),
                userIcon = $('#whos-online').find("[data-user-card='" + userData + "']");
            
            $.ajax("https://YOUR_FORUM_URL/u/" + userData + ".json").then(function (json) { 
               if(json.user.user_fields[1] === "Yes") {
                  userIcon.show(); 
                  $('html').addClass('whos-online-flair');
               } else if(json.user.user_fields[1] === "No" || json.user.user_fields[1] === null) {
                  userIcon.hide(); 
                  $('html').removeClass('whos-online-flair');
               }
            });
        });
        
    });
    
}
  • Replace YOUR_FORUM_URL
  • We are using the Discourse API helper to execute our code on each change (not only on reload)
  • We are iterating over all online user given from the DOM
  • We fetching then each of these users JSON and grabbing the User Field value we created in step 1
  • Since the existent user don’t opt-in for the online status they have “null” in their json which means we handle them as “offline”
  • In the end we either hide or show the icon and in my case the “flair” on the user avatar

3. Little CSS magic

@keyframes showOnlineDelay {
0% {
    opacity: 0;
}
90% {
    opacity: 0;
}
100% {
    opacity: 1;
}
}

#whos-online {
    animation-name: showOnlineDelay;
    animation-duration: 3s;
}

html.whos-online-flair .latest-topic-list .latest-topic-list-item.last-poster-online .topic-poster::before {
    animation-name: showOnlineDelay;
    animation-duration: 3s;
}
  • Since the inital load of onPageChange takes a bit until our code is executed I hide the widget “until it is ready”. This is very inaccurate because 3 seconds can vary. For my forum (10 users) it was just about right that I only saw the end result (everyone who have set their User Field Online Status to “Yes”)

Limitation & Result

Everyone who have Show Online = Yes in their Preferences > Profile > Show Online Status are then listed like this:

grafik

@david after some thoughts maybe you can integrate an easy setting “Don’t show icon” or so?
The little fact that the forum has “10” active user at the moment is already quite helpful to measure the “activity” on the first sight. Like it’s nice to check how many people are playing a game on steam at the moment. Taking away all the “privacy” gurus.
However best would be a combination with “Trust Level” to give it the max. flexibility :wink:
Example: Trust Level 4 = always show user icon. Trust Level 0 = don’t show user icon.

Limits with my hacky approach are:

  • as written the 3 seconds in the CSS might need to be adjusted and is just a workaround
  • If the other user icons are hidden and one new user logs in, he is visible. I couldn’t find an API call like “onPageCheck” or so (?)
  • I used flair as indicator. Adjust to your needs
  • Sorry for my probably poor attempt in that :pensive:

Have a nice day


(Lee Strickland) #124

It may be a little hacky of an approach but it looks like it lays a decent foundation for opt on this plugin. Many kudos!


(Tobias Eigen) #125

I had an idea today for this plugin, while showing discourse to someone. Probably not easy to do, but it would be helpful to filter the list of people online by those who have access to a private category I am currently in.

And/or in the future, when group messaging functionality is on parity with private category functionality, seeing the list of people online who are in the group, on the group message inbox, would be nifty.


#126

The green dot seems to be buggy for us when switching to RTL (Arabic/hebrew).

Here’s an example of a far off green dot:
IMG_1269


(AppyBuilder) #127

@david seems like when in mobile, tapping on individual online user, doesn’t work anymore. Could be effect of discourse update. The list expands, but you can’t get user info. This works in desktop mode:

Great plug in


(AppyBuilder) #128

Hello @david do you know how to fix this issue? Thanks


(David Taylor) #129

Hi @Hossein_Amerkashi, thanks for reporting the issue.

I’m seeing the problem on my sites as well. I should have time to get it fixed next week.


(Jay Pfaffman) #130

On a site I manage we’ve seen lots of users listed who are not logged in (e.g.,suspended users). If anyone else seeing this problem?


(David Taylor) #131

In theory the logic here is exactly the same as the core ‘last seen’ logic. If you visit those users’ profiles, do they show up as having been ‘seen’ recently?


(Driver Geo) #132

This plugin is not working for several days now, please update.


#133

It works for me and I upgraded it this weekend. It might be coming from another plugin


(David Taylor) #134

This should now be fixed:

If you are referring to the avatar tapping problem, it should now be fixed. If not, what issue are you seeing?


(Driver Geo) #135

This are my plugins and settings.

Screenshot_2

And as you can see, the list of people online is not showing, nor green light on users.


(David Taylor) #136

It looks like there is a Javascript error on your site https://gaming-club.ro, caused by discourse-formatting-toolbar. Uninstall it and try again.

(note that disabling plugins in the admin interface does not prevent them causing errors)


#137

You shouldn’t use formatting with bbcode, I included bbcodes in the formatting toolbar. So you should use only one of the two


(Driver Geo) #138

Done, removed the bbcode toolbar and other plugins that i dint use. I can see who is online now but i cant select the format (glow, ring, flare), whatever format i chose, only ring it shows.


(David Taylor) #139

On your site at the moment I see ‘glow’:

36

You will need to refresh the page after you change the settings.


(AppyBuilder) #140

@david what do i need to do for your change to take effect?


(David Taylor) #141

Just update the plugin to the latest version. If you’re using a standard discourse installation go to /admin/upgrade.