-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[IMPROVE] Change user presence events to streams and new REST endpoint to retrieve them #12800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
95836b4
3cb073f
1f3d5e9
b3a94d1
445da32
d259895
b5d6c83
7da3bf4
5813df6
bc5232b
763ddc7
8cddec2
3362d75
28c1877
c3fc29f
3be1d35
55856be
9de8b69
e03ce36
c8fa471
a2e62b5
30d94d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| import '../../message-read-receipt/client'; | ||
| import '../../personal-access-tokens/client'; | ||
| import './listenActiveUsers'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import { Tracker } from 'meteor/tracker'; | ||
| import _ from 'underscore'; | ||
|
|
||
| const saveUser = (user, force = false) => { | ||
| // do not update my own user, my user's status will come from a subscription | ||
| if (user._id === Meteor.userId()) { | ||
| return; | ||
| } | ||
| if (force) { | ||
| return Meteor.users._collection.upsert({ _id: user._id }, { | ||
| $set: { | ||
| username: user.username, | ||
| name: user.name, | ||
| utcOffset: user.utcOffset, | ||
| status: user.status, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const found = Meteor.users.findOne(user._id, { fields: { _id: 1 } }); | ||
| if (found) { | ||
| return; | ||
| } | ||
|
|
||
| Meteor.users._collection.insert(user); | ||
| }; | ||
|
|
||
| let retry = 0; | ||
| const getActiveUsers = _.debounce(() => { | ||
| RocketChat.API.v1.get('users.active') | ||
| .then((result) => { | ||
| result.users.forEach((user) => { | ||
| saveUser(user); | ||
| }); | ||
| }) | ||
| .catch(() => setTimeout(getActiveUsers, retry++ * 2000)); | ||
| }, 1000); | ||
|
|
||
| Tracker.autorun(() => { | ||
| if (!Meteor.userId() || !Meteor.status().connected) { | ||
| return; | ||
| } | ||
| getActiveUsers(); | ||
| }); | ||
|
|
||
| Meteor.startup(function() { | ||
| RocketChat.Notifications.onLogged('user-status', (user) => { | ||
| saveUser(user, true); | ||
| }); | ||
|
|
||
| RocketChat.Notifications.onLogged('Users:NameChanged', ({ _id, username }) => { | ||
| if (!username) { | ||
| return; | ||
| } | ||
| Meteor.users._collection.upsert({ _id }, { | ||
| $set: { | ||
| username, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| import '../../message-read-receipt/server'; | ||
| import '../../personal-access-tokens/server'; | ||
| import '../../users-presence/server'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { UserPresenceEvents } from 'meteor/konecty:user-presence'; | ||
|
|
||
| UserPresenceEvents.on('setUserStatus', (user, status/* , statusConnection*/) => { | ||
| const { | ||
| _id, | ||
| username, | ||
| name, | ||
| utcOffset, | ||
| } = user; | ||
|
|
||
| // since this callback can be called by only one instance in the cluster | ||
| // we need to brodcast the change to all instances | ||
| RocketChat.Notifications.notifyLogged('user-status', { | ||
| _id, | ||
| username, | ||
| name, | ||
| status, | ||
| utcOffset, | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './activeUsers'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| RocketChat.models.FullUser = new class extends RocketChat.models._Base { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this separation, I didn't understand the idea.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the issue is since I'm updating/inserting records on so I had to change the fullUserData publication to publish on this new virtual collection. |
||
| constructor() { | ||
| super(); | ||
| this._initModel('full_user'); | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.