Skip to content

Commit

Permalink
fix: revert status websocket payload changes (#31823)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Feb 28, 2024
1 parent 329ae41 commit 5abac60
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/strange-lamps-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/ddp-client': patch
'@rocket.chat/meteor': patch
---

Revert unintentional changes real time presence data payload
9 changes: 7 additions & 2 deletions apps/meteor/app/notifications/client/lib/Presence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserStatus } from '@rocket.chat/core-typings';
import { UserStatus } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { Presence } from '../../../../client/lib/presence';
Expand All @@ -10,6 +10,11 @@ new Meteor.Streamer('user-presence');

type args = [username: string, statusChanged?: UserStatus, statusText?: string];

export const STATUS_MAP = [UserStatus.OFFLINE, UserStatus.ONLINE, UserStatus.AWAY, UserStatus.BUSY, UserStatus.DISABLED];

Meteor.StreamerCentral.on('stream-user-presence', (uid: string, [username, statusChanged, statusText]: args) => {
Presence.notify({ _id: uid, username, status: statusChanged, statusText });
if (!statusChanged) {
return;
}
Presence.notify({ _id: uid, username, status: STATUS_MAP[statusChanged as any], statusText });
});
14 changes: 11 additions & 3 deletions apps/meteor/server/modules/listeners/listeners.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus';
import type { ISetting as AppsSetting } from '@rocket.chat/apps-engine/definition/settings';
import type { IServiceClass } from '@rocket.chat/core-services';
import { EnterpriseSettings } from '@rocket.chat/core-services';
import { isSettingColor, isSettingEnterprise } from '@rocket.chat/core-typings';
import { isSettingColor, isSettingEnterprise, UserStatus } from '@rocket.chat/core-typings';
import type { IUser, IRoom, VideoConference, ISetting, IOmnichannelRoom } from '@rocket.chat/core-typings';
import { Logger } from '@rocket.chat/logger';
import { parse } from '@rocket.chat/message-parser';
Expand All @@ -12,6 +12,14 @@ import type { NotificationsModule } from '../notifications/notifications.module'

const isMessageParserDisabled = process.env.DISABLE_MESSAGE_PARSER === 'true';

const STATUS_MAP: Record<UserStatus, 0 | 1 | 2 | 3> = {
[UserStatus.OFFLINE]: 0,
[UserStatus.ONLINE]: 1,
[UserStatus.AWAY]: 2,
[UserStatus.BUSY]: 3,
[UserStatus.DISABLED]: 0,
} as const;

const minimongoChangeMap: Record<string, string> = {
inserted: 'added',
updated: 'changed',
Expand Down Expand Up @@ -145,10 +153,10 @@ export class ListenersModule {
return;
}

notifications.notifyLoggedInThisInstance('user-status', [_id, username, status, statusText, name, roles]);
notifications.notifyLoggedInThisInstance('user-status', [_id, username, STATUS_MAP[status], statusText, name, roles]);

if (_id) {
notifications.sendPresence(_id, username, status, statusText);
notifications.sendPresence(_id, username, STATUS_MAP[status], statusText);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Authorization, VideoConf } from '@rocket.chat/core-services';
import type { ISubscription, IOmnichannelRoom, IUser, UserStatus } from '@rocket.chat/core-typings';
import type { ISubscription, IOmnichannelRoom, IUser } from '@rocket.chat/core-typings';
import { Rooms, Subscriptions, Users, Settings } from '@rocket.chat/models';
import type { StreamerCallbackArgs, StreamKeys, StreamNames } from '@rocket.chat/ui-contexts';
import type { IStreamer, IStreamerConstructor, IPublication } from 'meteor/rocketchat:streamer';
Expand Down Expand Up @@ -531,7 +531,7 @@ export class NotificationsModule {
return this.streamUser.emitWithoutBroadcast(`${userId}/${eventName}`, ...args);
}

sendPresence(uid: string, ...args: [username: string, status?: UserStatus, statusText?: string]): void {
sendPresence(uid: string, ...args: [username: string, status?: 0 | 1 | 2 | 3, statusText?: string]): void {
emit(uid, [args]);
return this.streamPresence.emitWithoutBroadcast(uid, args);
}
Expand Down
5 changes: 2 additions & 3 deletions ee/packages/ddp-client/src/types/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type {
IBanner,
LicenseLimitKind,
ICustomUserStatus,
UserStatus,
} from '@rocket.chat/core-typings';
import type * as UiKit from '@rocket.chat/ui-kit';

Expand Down Expand Up @@ -243,7 +242,7 @@ export interface StreamerEvents {
[
uid: IUser['_id'],
username: IUser['username'],
status: UserStatus,
status: 0 | 1 | 2 | 3,
statusText: IUser['statusText'],
name: IUser['name'],
roles: IUser['roles'],
Expand Down Expand Up @@ -325,7 +324,7 @@ export interface StreamerEvents {
},
];

'user-presence': [{ key: string; args: [[username: string, statusChanged?: UserStatus, statusText?: string]] }];
'user-presence': [{ key: string; args: [[username: string, statusChanged?: 0 | 1 | 2 | 3, statusText?: string]] }];

// TODO: rename to 'integration-history'
'integrationHistory': [
Expand Down

0 comments on commit 5abac60

Please sign in to comment.