[FIX] Not properly fetching users presence on some startup situations (#3967)
This commit is contained in:
parent
f4538635b8
commit
2af88a5544
|
@ -32,9 +32,9 @@ export function subscribeUsersPresence(this: IRocketChat) {
|
||||||
sdk.subscribe('stream-notify-logged', 'Users:NameChanged');
|
sdk.subscribe('stream-notify-logged', 'Users:NameChanged');
|
||||||
}
|
}
|
||||||
|
|
||||||
let ids: string[] = [];
|
let usersBatch: string[] = [];
|
||||||
|
|
||||||
export default async function getUsersPresence() {
|
export default async function getUsersPresence(usersParams: string[]) {
|
||||||
const serverVersion = reduxStore.getState().server.version as string;
|
const serverVersion = reduxStore.getState().server.version as string;
|
||||||
const { user: loggedUser } = reduxStore.getState().login;
|
const { user: loggedUser } = reduxStore.getState().login;
|
||||||
|
|
||||||
|
@ -45,11 +45,11 @@ export default async function getUsersPresence() {
|
||||||
// if server is greather than or equal 3.0.0
|
// if server is greather than or equal 3.0.0
|
||||||
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.0.0')) {
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.0.0')) {
|
||||||
// if not have any id
|
// if not have any id
|
||||||
if (!ids.length) {
|
if (!usersParams.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Request userPresence on demand
|
// Request userPresence on demand
|
||||||
params = { ids: ids.join(',') };
|
params = { ids: usersParams.join(',') };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -57,13 +57,13 @@ export default async function getUsersPresence() {
|
||||||
const result = (await sdk.get('users.presence' as any, params as any)) as any;
|
const result = (await sdk.get('users.presence' as any, params as any)) as any;
|
||||||
|
|
||||||
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.1.0')) {
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.1.0')) {
|
||||||
sdk.subscribeRaw('stream-user-presence', ['', { added: ids }]);
|
sdk.subscribeRaw('stream-user-presence', ['', { added: usersParams }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const { users } = result;
|
const { users } = result;
|
||||||
|
|
||||||
const activeUsers = ids.reduce((ret: IActiveUsers, id) => {
|
const activeUsers = usersParams.reduce((ret: IActiveUsers, id) => {
|
||||||
const user = users.find((u: IUser) => u._id === id) ?? { _id: id, status: 'offline' };
|
const user = users.find((u: IUser) => u._id === id) ?? { _id: id, status: 'offline' };
|
||||||
const { _id, status, statusText } = user;
|
const { _id, status, statusText } = user;
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ export default async function getUsersPresence() {
|
||||||
InteractionManager.runAfterInteractions(() => {
|
InteractionManager.runAfterInteractions(() => {
|
||||||
reduxStore.dispatch(setActiveUsers(activeUsers));
|
reduxStore.dispatch(setActiveUsers(activeUsers));
|
||||||
});
|
});
|
||||||
ids = [];
|
|
||||||
|
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const userCollection = db.get('users');
|
const userCollection = db.get('users');
|
||||||
|
@ -110,12 +109,13 @@ let usersTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
export function getUserPresence(uid: string) {
|
export function getUserPresence(uid: string) {
|
||||||
if (!usersTimer) {
|
if (!usersTimer) {
|
||||||
usersTimer = setTimeout(() => {
|
usersTimer = setTimeout(() => {
|
||||||
getUsersPresence();
|
getUsersPresence(usersBatch);
|
||||||
|
usersBatch = [];
|
||||||
usersTimer = null;
|
usersTimer = null;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
ids.push(uid);
|
usersBatch.push(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue