Good extension! A suggestion: it would be nice, as it's not always possible to show all online users, to be able to click on "more user" (or "+# user") to display the full list of online users on a page or in the main window.

6 months later

I haven't installed this yet but I want the widget to be visible only for the admins and mods, is that possible? Actually I don't even need this to be a widget, something in the admin dashboard would suffice. Are there any plans for that?

a year later

@SychO I've installed this widget. It works fine.

But I need to refresh the page to update the list of online users..... It's normal ? The list doesn't update automatically?

    @SychO , I just noticed that on my forum when I open it in an incognito window (hence not even logged and no cookies), I can see the online widget and what users are online.

    However in the permissions settings I have:

    Always view user last seen time - admins and mods
    Search users - admins, mods and members

    This is really surprising since I wanted to limit this functionality to admins and mods only. Or even if it's to registered members but not to anybody.

    Is that by design or is it a bug?

      CyberGene the "Always view user last seen time" means that a user A can see the last seen time of another user B even if user B has it set to invisible, it's not an absolute permission about being able to see visibility. So it doesn't factor into whether this widget shows or not.

      Only the search members permission is taken into consideration here. I might add a new unique permission for the widget in the future.

        SychO I see, that makes sense.

        However I still think there's some discrepancy here, because:

        SychO Only the search members permission is taken into consideration here.

        However in my case the search is not public but is limited to members only, while the online users widget is visible even for non-registered users browsing the forum. Could that be a bug?

          SychO OK, thank !

          It would be nice if it updated in real time.... If it's possible, of course 🙂

          SychO there’s only one setting:
          “Prefer loading all widgets data with initial page response.” which is enabled. I don’t remember exactly why I enabled it but maybe the widget was slow to load or didn’t always load or something and then I enabled it and all started working OK. Is that option the reason for restrictions not applying?

          P.S. I disabled it and now I see that there are no online users which is suspicious since I always have at least 1-2 users that are online and I remembered that without that option the online users widget actually never worked even though I explicitly logged in with a test user. I think I’m seeing the same problem now.

            CyberGene checked the code again, when disabled, make sure the two permissions you mentioned earlier are given to members

              2 months later

              I am giving this a second chance but I think something is not working as expected. I am an admin on my forum and I have all permissions. So, for instance I see 1-2 users online, then I see no users online for some time and in that time a new post appears by a user. He was not shown as online neither before, nor during, nor after his post.

              I have the following option disabled:
              “Prefer loading all widgets data with initial page response”

              As I said, I’m admin and have permissions:
              Always view user last seen time - admins and mods
              Search users - admins, mods and members

              Is there anything else that needs to be set? Is there any caching? Maybe the extension checks for online users each 10 minutes and will cache that for the next 10 minutes and will not refresh and miss members going on and off in the meantime?

              @SychO , I did some investigation and I can now confirm the following: those users that have chosen not to show their online status are not visible in the widget, however they are shown as online in the User Directory to me since I am an admin and I have the permission to see their online status.

              Is that a bug or the intended behavior of this widget? I see that previously you said this:

              SychO checked the code again, when disabled, make sure the two permissions you mentioned earlier are given to members

              Do you mean that for the widget to work, all members should be given the permission to always see the online status of all members? If that's true, this defeats the purpose of the permission because members can't hide their online status anymore. I think the widget should show different online users, according to the permissions that are given to the user who is viewing the widget, e.g. the admin should be able too see all online users, even those who are hiding their online status, whereas a regular member (that should naturally not be given the permission to see everybody's online status) should only see those that are not hiding their status.

              Can you confirm what is the actual behavior of this widget?

                CyberGene Can you confirm what is the actual behavior of this widget?

                sorry, I really don't remember, it's very likely a bug.

                  SychO , sure, no problem, I know you are busy with the 2.0, this is not really important. When you have time after the new release, it would be good to see if it's an easy fix though 🙂

                  Looking at the code (but I'm a Java developer and haven't worked with web frameworks and PHP, so might be missing something):

                             return User::query()
                                  ->select('id', 'preferences')
                                  ->whereVisibleTo($actor)
                                  ->where('last_seen_at', '>', $time)
                                  ->limit($limit + 1)
                                  ->get()
                                  ->filter(function ($user) {
                                      return (bool)$user->getPreference('discloseOnline');
                                  })
                                  ->pluck('id')
                                  ->toArray();

                  Seems that we filter only those users that disclose their online status. I think this filter should be kept but with another OR-ed condition checking if the actor has the permission to always see online status of other members.

                  @SychO , do you think the following code will fix the issue:

                         return $this->cache->remember('afrux-online-users-widget.users', 40, function () use ($actor, $time, $limit) {
                              return User::query()
                                  ->select('id', 'preferences')
                                  ->whereVisibleTo($actor)
                                  ->where('last_seen_at', '>', $time)
                                  ->limit($limit + 1)
                                  ->get()
                                  ->filter(function ($user, $actor) {
                                      return (bool)$actor->hasPermission('user.viewLastSeenAt') or (bool)$user->getPreference('discloseOnline');
                                  })
                                  ->pluck('id')
                                  ->toArray();
                          }) ?: [];
                      }

                  How can I test it easily? I checked out your code and put that change in a branch but I can't push it to the remote repository, I guess I have to be granted permissions. What's the easiest way for me to test that change without installing PHP, etc. on my computer? If I directly find that PHP file on my hosting server and edit it to include that change, will it work?

                    CyberGene If I directly find that PHP file on my hosting server and edit it to include that change, will it work?

                    yes, then you can fork the github repo, change the name in composer.json, make a release on the github repo, go to packagist.org and publish it

                      SychO I made it working with the following change of the filter:

                      ->filter(function ($user) use ($actor) {
                        return ($actor->hasPermission('user.viewLastSeenAt') or $user->getPreference('discloseOnline'))
                          and ($actor->id !== $user->id);
                      })

                      Tested on a copy of my Prod forum and now as an admin I can see users that are hiding their online status. Thanks for all the hints about how to clone the repo and make a release, that's what I'm going to try next.

                      @SychO , I forked your repository, made the filter update, changed the name in the composer.json to ekumanov/online-users-widget, here's the repository:
                      https://github.com/ekumanov/online-users-widget

                      I then created a new v.1.0.0 release and published it on packagist.org. I then managed to install it on my forum, however what's odd is I don't see the setting for the max users on the extension page. And the core widgets doesn't detect the extension, so I can't place it visually on the screen. I don't see any errors in the logs and the forum works otherwise. Should something else be done? Are settings somehow linked to the original name of the extension in the DB, maybe I should also update some other place?

                      Apologies if taking your time too much, I know you're busy with the release 🙁