refactor: Replace `Notifications` in favor of `sdk.stream`; (#31409)

pull/31461/head
gabriellsh 2 years ago committed by GitHub
parent 0c3a563b3a
commit 6526b2ff03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      apps/meteor/app/e2e/client/rocketchat.e2e.room.js
  2. 2
      apps/meteor/app/emoji-custom/client/index.ts
  3. 6
      apps/meteor/app/emoji-custom/client/notifications/deleteEmojiCustom.ts
  4. 6
      apps/meteor/app/emoji-custom/client/notifications/updateEmojiCustom.ts
  5. 19
      apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts
  6. 28
      apps/meteor/app/ui/client/lib/UserAction.ts
  7. 2
      apps/meteor/app/user-status/client/index.ts
  8. 6
      apps/meteor/app/user-status/client/notifications/deleteCustomUserStatus.js
  9. 6
      apps/meteor/app/user-status/client/notifications/updateCustomUserStatus.js
  10. 4
      apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts
  11. 3
      apps/meteor/client/lib/userData.ts
  12. 11
      apps/meteor/client/providers/EmojiPickerProvider/EmojiPickerProvider.tsx
  13. 1
      apps/meteor/client/providers/EmojiPickerProvider/index.ts
  14. 17
      apps/meteor/client/providers/EmojiPickerProvider/useUpdateCustomEmoji.ts
  15. 7
      apps/meteor/client/providers/UserProvider/UserProvider.tsx
  16. 32
      apps/meteor/client/providers/UserProvider/hooks/useDeleteUser.ts
  17. 15
      apps/meteor/client/providers/UserProvider/hooks/useUpdateAvatar.ts
  18. 17
      apps/meteor/client/providers/UserProvider/hooks/useUpdateCustomUserStatus.ts
  19. 28
      apps/meteor/client/startup/UserDeleted.ts
  20. 10
      apps/meteor/client/startup/e2e.ts
  21. 4
      apps/meteor/client/startup/forceLogout.ts
  22. 8
      apps/meteor/client/startup/incomingMessages.ts
  23. 1
      apps/meteor/client/startup/index.ts
  24. 2
      apps/meteor/client/startup/notifications/index.ts
  25. 11
      apps/meteor/client/startup/notifications/konchatNotifications.ts
  26. 12
      apps/meteor/client/startup/notifications/updateAvatar.ts
  27. 69
      apps/meteor/client/startup/notifications/usersNameChanged.ts
  28. 3
      apps/meteor/client/startup/userRoles.ts
  29. 12
      apps/meteor/client/views/room/providers/RoomProvider.tsx
  30. 69
      apps/meteor/client/views/room/providers/hooks/useUsersNameChanged.ts
  31. 2
      ee/packages/ddp-client/src/types/streams.ts

@ -7,7 +7,6 @@ import { RoomManager } from '../../../client/lib/RoomManager';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { RoomSettingsEnum } from '../../../definition/IRoomTypeConfig';
import { ChatRoom, Subscriptions, Messages } from '../../models/client';
import { Notifications } from '../../notifications/client';
import { sdk } from '../../utils/client/lib/SDKClient';
import { E2ERoomState } from './E2ERoomState';
import {
@ -240,7 +239,7 @@ export class E2ERoom extends Emitter {
this.setState(E2ERoomState.WAITING_KEYS);
this.log('Requesting room key');
Notifications.notifyUsersOfRoom(this.roomId, 'e2ekeyRequest', this.roomId, room.e2eKeyId);
sdk.publish('notify-room-users', [`${this.roomId}/e2ekeyRequest`, this.roomId, room.e2eKeyId]);
} catch (error) {
// this.error = error;
this.setState(E2ERoomState.ERROR);

@ -1,3 +1 @@
import './lib/emojiCustom';
import './notifications/deleteEmojiCustom';
import './notifications/updateEmojiCustom';

@ -1,6 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Notifications } from '../../../notifications/client';
import { deleteEmojiCustom } from '../lib/emojiCustom';
Meteor.startup(() => Notifications.onLogged('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData)));

@ -1,6 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Notifications } from '../../../notifications/client';
import { updateEmojiCustom } from '../lib/emojiCustom';
Meteor.startup(() => Notifications.onLogged('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData)));

@ -9,7 +9,6 @@ import { fireGlobalEvent } from '../../../../client/lib/utils/fireGlobalEvent';
import { getConfig } from '../../../../client/lib/utils/getConfig';
import { callbacks } from '../../../../lib/callbacks';
import { CachedChatRoom, ChatMessage, ChatSubscription, CachedChatSubscription } from '../../../models/client';
import { Notifications } from '../../../notifications/client';
import { sdk } from '../../../utils/client/lib/SDKClient';
import { upsertMessage, RoomHistoryManager } from './RoomHistoryManager';
import { mainReady } from './mainReady';
@ -37,8 +36,8 @@ function close(typeName: string) {
if (openedRooms[typeName]) {
if (openedRooms[typeName].rid) {
sdk.stop('room-messages', openedRooms[typeName].rid);
Notifications.unRoom(openedRooms[typeName].rid, 'deleteMessage');
Notifications.unRoom(openedRooms[typeName].rid, 'deleteMessageBulk');
sdk.stop('notify-room', `${openedRooms[typeName].rid}/deleteMessage`);
sdk.stop('notify-room', `${openedRooms[typeName].rid}/deleteMessageBulk`);
}
openedRooms[typeName].ready = false;
@ -135,20 +134,21 @@ const computation = Tracker.autorun(() => {
});
// when we receive a messages imported event we just clear the room history and fetch it again
Notifications.onRoom(record.rid, 'messagesImported', async () => {
sdk.stream('notify-room', [`${record.rid}/messagesImported`], async () => {
await RoomHistoryManager.clear(record.rid);
await RoomHistoryManager.getMore(record.rid);
});
Notifications.onRoom(record.rid, 'deleteMessage', (msg) => {
sdk.stream('notify-room', [`${record.rid}/deleteMessage`], (msg) => {
ChatMessage.remove({ _id: msg._id });
// remove thread refenrece from deleted message
ChatMessage.update({ tmid: msg._id }, { $unset: { tmid: 1 } }, { multi: true });
});
Notifications.onRoom(
record.rid,
'deleteMessageBulk',
sdk.stream(
'notify-room',
[`${record.rid}/deleteMessageBulk`],
({ rid, ts, excludePinned, ignoreDiscussion, users, ids, showDeletedStatus }) => {
const query: Mongo.Selector<IMessage> = { rid };
@ -177,7 +177,8 @@ const computation = Tracker.autorun(() => {
return ChatMessage.remove(query);
},
);
Notifications.onRoom(record.rid, 'messagesRead', ({ tmid, until }) => {
sdk.stream('notify-room', [`${record.rid}/messagesRead`], ({ tmid, until }) => {
if (tmid) {
return ChatMessage.update(
{

@ -3,8 +3,8 @@ import { debounce } from 'lodash';
import { Meteor } from 'meteor/meteor';
import { ReactiveDict } from 'meteor/reactive-dict';
import { Notifications } from '../../../notifications/client';
import { settings } from '../../../settings/client';
import { sdk } from '../../../utils/client/lib/SDKClient';
const TIMEOUT = 15000;
const RENEW = TIMEOUT / 3;
@ -38,7 +38,7 @@ const shownName = function (user: IUser | null | undefined): string | undefined
const emitActivities = debounce(async (rid: string, extras: IExtras): Promise<void> => {
const activities = roomActivities.get(extras?.tmid || rid) || new Set();
Notifications.notifyRoom(rid, USER_ACTIVITY, shownName(Meteor.user() as unknown as IUser), [...activities], extras);
sdk.publish('notify-room', [`${rid}/${USER_ACTIVITY}`, shownName(Meteor.user() as unknown as IUser), [...activities], extras]);
}, 500);
function handleStreamAction(rid: string, username: string, activityTypes: string[], extras?: IExtras): void {
@ -65,10 +65,11 @@ function handleStreamAction(rid: string, username: string, activityTypes: string
performingUsers.set(rid, roomActivities);
}
export const UserAction = new (class {
addStream(rid: string): void {
addStream(rid: string): () => void {
if (rooms.get(rid)) {
return;
throw new Error('UserAction - addStream should only be called once per room');
}
const handler = function (username: string, activityType: string[], extras?: object): void {
const user = Meteor.users.findOne(Meteor.userId() || undefined, {
fields: { name: 1, username: 1 },
@ -79,7 +80,15 @@ export const UserAction = new (class {
handleStreamAction(rid, username, activityType, extras);
};
rooms.set(rid, handler);
Notifications.onRoom(rid, USER_ACTIVITY, handler);
const { stop } = sdk.stream('notify-room', [`${rid}/${USER_ACTIVITY}`], handler);
return () => {
if (!rooms.get(rid)) {
return;
}
stop();
rooms.delete(rid);
};
}
performContinuously(rid: string, activityType: string, extras: IExtras = {}): void {
@ -156,15 +165,6 @@ export const UserAction = new (class {
void emitActivities(rid, extras);
}
cancel(rid: string): void {
if (!rooms.get(rid)) {
return;
}
Notifications.unRoom(rid, USER_ACTIVITY);
rooms.delete(rid);
}
get(roomId: string): IRoomActivity | undefined {
return performingUsers.get(roomId);
}

@ -1,5 +1,3 @@
import './notifications/deleteCustomUserStatus';
import './notifications/updateCustomUserStatus';
import './lib/customUserStatus';
export { userStatus } from './lib/userStatus';

@ -1,6 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Notifications } from '../../../notifications/client';
import { deleteCustomUserStatus } from '../lib/customUserStatus';
Meteor.startup(() => Notifications.onLogged('deleteCustomUserStatus', (data) => deleteCustomUserStatus(data.userStatusData)));

@ -1,6 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Notifications } from '../../../notifications/client';
import { updateCustomUserStatus } from '../lib/customUserStatus';
Meteor.startup(() => Notifications.onLogged('updateCustomUserStatus', (data) => updateCustomUserStatus(data.userStatusData)));

@ -1,7 +1,7 @@
import type { ISetting } from '@rocket.chat/core-typings';
import { Notifications } from '../../../app/notifications/client';
import { CachedCollection } from '../../../app/ui-cached-collection/client';
import { sdk } from '../../../app/utils/client/lib/SDKClient';
class PrivateSettingsCachedCollection extends CachedCollection<ISetting> {
constructor() {
@ -12,7 +12,7 @@ class PrivateSettingsCachedCollection extends CachedCollection<ISetting> {
}
async setupListener(): Promise<void> {
Notifications.onLogged(this.eventName as 'private-settings-changed', async (t: string, { _id, ...record }: { _id: string }) => {
sdk.stream('notify-logged', [this.eventName as 'private-settings-changed'], async (t: string, { _id, ...record }: { _id: string }) => {
this.log('record received', t, { _id, ...record });
this.collection.upsert({ _id }, record);
this.sync();

@ -2,7 +2,6 @@ import type { ILivechatAgent, IUser, Serialized } from '@rocket.chat/core-typing
import { ReactiveVar } from 'meteor/reactive-var';
import { Users } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
export const isSyncReady = new ReactiveVar(false);
@ -60,7 +59,7 @@ export const synchronizeUserData = async (uid: IUser['_id']): Promise<RawUserDat
cancel?.();
const result = Notifications.onUser('userData', (data) => {
const result = sdk.stream('notify-user', [`${uid}/userData`], (data) => {
switch (data.type) {
case 'inserted':
// eslint-disable-next-line @typescript-eslint/no-unused-vars

@ -2,10 +2,11 @@ import { useDebouncedState, useLocalStorage } from '@rocket.chat/fuselage-hooks'
import type { ReactNode, ReactElement, ContextType } from 'react';
import React, { useState, useCallback, useMemo, useEffect } from 'react';
import type { EmojiByCategory } from '../../app/emoji/client';
import { emoji, getFrequentEmoji, updateRecent, createEmojiList, createPickerEmojis, CUSTOM_CATEGORY } from '../../app/emoji/client';
import { EmojiPickerContext } from '../contexts/EmojiPickerContext';
import EmojiPicker from '../views/composer/EmojiPicker/EmojiPicker';
import type { EmojiByCategory } from '../../../app/emoji/client';
import { emoji, getFrequentEmoji, updateRecent, createEmojiList, createPickerEmojis, CUSTOM_CATEGORY } from '../../../app/emoji/client';
import { EmojiPickerContext } from '../../contexts/EmojiPickerContext';
import EmojiPicker from '../../views/composer/EmojiPicker/EmojiPicker';
import { useUpdateCustomEmoji } from './useUpdateCustomEmoji';
const DEFAULT_ITEMS_LIMIT = 90;
@ -23,6 +24,8 @@ const EmojiPickerProvider = ({ children }: { children: ReactNode }): ReactElemen
getFrequentEmoji(frequentEmojis.map(([emoji]) => emoji)),
);
useUpdateCustomEmoji();
const addFrequentEmojis = useCallback(
(emoji: string) => {
const empty: [string, number][] = frequentEmojis.some(([emojiName]) => emojiName === emoji) ? [] : [[emoji, 0]];

@ -0,0 +1 @@
export { default } from './EmojiPickerProvider';

@ -0,0 +1,17 @@
import { useStream } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { updateEmojiCustom, deleteEmojiCustom } from '../../../app/emoji-custom/client/lib/emojiCustom';
export const useUpdateCustomEmoji = () => {
const notify = useStream('notify-logged');
useEffect(() => {
const unsubUpdate = notify('updateEmojiCustom', (data) => updateEmojiCustom(data.emojiData));
const unsubDelete = notify('deleteEmojiCustom', (data) => deleteEmojiCustom(data.emojiData));
return () => {
unsubUpdate();
unsubDelete();
};
}, [notify]);
};

@ -13,8 +13,11 @@ import { afterLogoutCleanUpCallback } from '../../../lib/callbacks/afterLogoutCl
import { useReactiveValue } from '../../hooks/useReactiveValue';
import { createReactiveSubscriptionFactory } from '../../lib/createReactiveSubscriptionFactory';
import { useCreateFontStyleElement } from '../../views/account/accessibility/hooks/useCreateFontStyleElement';
import { useDeleteUser } from './hooks/useDeleteUser';
import { useEmailVerificationWarning } from './hooks/useEmailVerificationWarning';
import { useLDAPAndCrowdCollisionWarning } from './hooks/useLDAPAndCrowdCollisionWarning';
import { useUpdateAvatar } from './hooks/useUpdateAvatar';
import { useUpdateCustomUserStatus } from './hooks/useUpdateCustomUserStatus';
const getUserId = (): string | null => Meteor.userId();
@ -78,6 +81,10 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
useLDAPAndCrowdCollisionWarning();
useEmailVerificationWarning(user ?? undefined);
useUpdateCustomUserStatus();
useDeleteUser();
useUpdateAvatar();
const contextValue = useMemo(
(): ContextType<typeof UserContext> => ({
userId,

@ -0,0 +1,32 @@
import { useStream } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { ChatMessage } from '../../../../app/models/client';
export const useDeleteUser = () => {
const notify = useStream('notify-logged');
useEffect(() => {
return notify('Users:Deleted', ({ userId, messageErasureType, replaceByUser }) => {
if (messageErasureType === 'Unlink' && replaceByUser) {
return ChatMessage.update(
{
'u._id': userId,
},
{
$set: {
'alias': replaceByUser.alias,
'u._id': replaceByUser._id,
'u.username': replaceByUser.username,
'u.name': undefined,
},
},
{ multi: true },
);
}
ChatMessage.remove({
'u._id': userId,
});
});
}, [notify]);
};

@ -0,0 +1,15 @@
import { useStream } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import { useEffect } from 'react';
export const useUpdateAvatar = () => {
const notify = useStream('notify-logged');
useEffect(() => {
return notify('updateAvatar', (data) => {
if ('username' in data) {
const { username, etag } = data;
username && Meteor.users.update({ username }, { $set: { avatarETag: etag } });
}
});
}, [notify]);
};

@ -0,0 +1,17 @@
import { useStream } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { updateCustomUserStatus, deleteCustomUserStatus } from '../../../../app/user-status/client/lib/customUserStatus';
export const useUpdateCustomUserStatus = () => {
const notify = useStream('notify-logged');
useEffect(() => {
const unsubUpdate = notify('updateCustomUserStatus', (data) => updateCustomUserStatus(data.userStatusData));
const unsubDelete = notify('deleteCustomUserStatus', (data) => deleteCustomUserStatus(data.userStatusData));
return () => {
unsubUpdate();
unsubDelete();
};
}, [notify]);
};

@ -1,28 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { ChatMessage } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
Meteor.startup(() => {
Notifications.onLogged('Users:Deleted', ({ userId, messageErasureType, replaceByUser }) => {
if (messageErasureType === 'Unlink' && replaceByUser) {
return ChatMessage.update(
{
'u._id': userId,
},
{
$set: {
'alias': replaceByUser.alias,
'u._id': replaceByUser._id,
'u.username': replaceByUser.username,
'u.name': undefined,
},
},
{ multi: true },
);
}
ChatMessage.remove({
'u._id': userId,
});
});
});

@ -4,8 +4,8 @@ import { Tracker } from 'meteor/tracker';
import { e2e } from '../../app/e2e/client/rocketchat.e2e';
import { Subscriptions, ChatRoom } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
import { settings } from '../../app/settings/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
import { onClientBeforeSendMessage } from '../lib/onClientBeforeSendMessage';
import { onClientMessageReceived } from '../lib/onClientMessageReceived';
import { isLayoutEmbedded } from '../lib/utils/isLayoutEmbedded';
@ -38,23 +38,25 @@ Meteor.startup(() => {
let observable: Meteor.LiveQueryHandle | null = null;
let offClientMessageReceived: undefined | (() => void);
let offClientBeforeSendMessage: undefined | (() => void);
let unsubNotifyUser: undefined | (() => void);
Tracker.autorun(() => {
if (!e2e.isReady()) {
offClientMessageReceived?.();
Notifications.unUser('e2ekeyRequest');
unsubNotifyUser?.();
unsubNotifyUser = undefined;
observable?.stop();
offClientBeforeSendMessage?.();
return;
}
Notifications.onUser('e2ekeyRequest', async (roomId, keyId): Promise<void> => {
unsubNotifyUser = sdk.stream('notify-user', [`${Meteor.userId()}/e2ekeyRequest`], async (roomId, keyId): Promise<void> => {
const e2eRoom = await e2e.getInstanceByRoomId(roomId);
if (!e2eRoom) {
return;
}
e2eRoom.provideKeyToUser(keyId);
});
}).stop;
observable = Subscriptions.find().observe({
changed: async (sub: ISubscription) => {

@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { Tracker } from 'meteor/tracker';
import { Notifications } from '../../app/notifications/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
Meteor.startup(() => {
Tracker.autorun(() => {
@ -12,7 +12,7 @@ Meteor.startup(() => {
return;
}
Session.set('force_logout', false);
Notifications.onUser('force_logout', () => {
sdk.stream('notify-user', [`${userId}/force_logout`], () => {
Session.set('force_logout', true);
});
});

@ -2,8 +2,8 @@ import type { IMessage } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { ChatMessage } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
import { CachedCollectionManager } from '../../app/ui-cached-collection/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
Meteor.startup(() => {
Tracker.autorun(() => {
@ -11,7 +11,9 @@ Meteor.startup(() => {
return;
}
Notifications.onUser('message', (msg: IMessage) => {
// Only event I found triggers this is from ephemeral messages
// Other types of messages come from another stream
sdk.stream('notify-user', [`${Meteor.userId()}/message`], (msg: IMessage) => {
msg.u = msg.u || { username: 'rocket.cat' };
msg.private = true;
@ -20,7 +22,7 @@ Meteor.startup(() => {
});
CachedCollectionManager.onLogin(() => {
Notifications.onUser('subscriptions-changed', (_action, sub) => {
sdk.stream('notify-user', [`${Meteor.userId()}/subscriptions-changed`], (_action, sub) => {
ChatMessage.update(
{
rid: sub.rid,

@ -25,6 +25,5 @@ import './slashCommands';
import './startup';
import './streamMessage';
import './unread';
import './UserDeleted';
import './userRoles';
import './userStatusManuallySet';

@ -1,4 +1,2 @@
import './konchatNotifications';
import './notification';
import './updateAvatar';
import './usersNameChanged';

@ -4,10 +4,10 @@ import { Tracker } from 'meteor/tracker';
import { lazy } from 'react';
import { CachedChatSubscription } from '../../../app/models/client';
import { Notifications } from '../../../app/notifications/client';
import { settings } from '../../../app/settings/client';
import { KonchatNotification } from '../../../app/ui/client/lib/KonchatNotification';
import { getUserPreference } from '../../../app/utils/client';
import { sdk } from '../../../app/utils/client/lib/SDKClient';
import { RoomManager } from '../../lib/RoomManager';
import { imperativeModal } from '../../lib/imperativeModal';
import { fireGlobalEvent } from '../../lib/utils/fireGlobalEvent';
@ -71,17 +71,18 @@ Meteor.startup(() => {
};
Tracker.autorun(() => {
if (!Meteor.userId() || !settings.get('Outlook_Calendar_Enabled')) {
return Notifications.unUser('calendar');
sdk.stop('notify-user', `${Meteor.userId()}/calendar`);
}
Notifications.onUser('calendar', notifyUserCalendar);
sdk.stream('notify-user', [`${Meteor.userId()}/calendar`], notifyUserCalendar);
});
Tracker.autorun(() => {
if (!Meteor.userId()) {
return;
}
Notifications.onUser('notification', (notification) => {
sdk.stream('notify-user', [`${Meteor.userId()}/notification`], (notification) => {
const openedRoomId = ['channel', 'group', 'direct'].includes(router.getRouteName()!) ? RoomManager.opened : undefined;
// This logic is duplicated in /client/startup/unread.coffee.
@ -111,7 +112,7 @@ Meteor.startup(() => {
void notifyNewRoom(sub);
});
Notifications.onUser('subscriptions-changed', (action, sub) => {
sdk.stream('notify-user', [`${Meteor.userId()}/subscriptions-changed`], (action, sub) => {
if (action === 'removed') {
return;
}

@ -1,12 +0,0 @@
import { Meteor } from 'meteor/meteor';
import { Notifications } from '../../../app/notifications/client';
Meteor.startup(() => {
Notifications.onLogged('updateAvatar', (data) => {
if ('username' in data) {
const { username, etag } = data;
username && Meteor.users.update({ username }, { $set: { avatarETag: etag } });
}
});
});

@ -1,69 +0,0 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { Messages, Subscriptions } from '../../../app/models/client';
import { Notifications } from '../../../app/notifications/client';
type UsersNameChangedEvent = Partial<IUser>;
Meteor.startup(() => {
Notifications.onLogged('Users:NameChanged', ({ _id, name, username }: UsersNameChangedEvent) => {
Messages.update(
{
'u._id': _id,
},
{
$set: {
'u.username': username,
'u.name': name,
},
},
{
multi: true,
},
);
Messages.update(
{
'editedBy._id': _id,
},
{
$set: {
'editedBy.username': username,
},
},
{
multi: true,
},
);
Messages.update(
{
mentions: {
$elemMatch: { _id },
},
},
{
$set: {
'mentions.$.username': username,
'mentions.$.name': name,
},
},
{
multi: true,
},
);
Subscriptions.update(
{
name: username,
t: 'd',
},
{
$set: {
fname: name,
},
},
);
});
});

@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { UserRoles, ChatMessage } from '../../app/models/client';
import { Notifications } from '../../app/notifications/client';
import { sdk } from '../../app/utils/client/lib/SDKClient';
import { dispatchToastMessage } from '../lib/toast';
@ -20,7 +19,7 @@ Meteor.startup(() => {
dispatchToastMessage({ type: 'error', message: error });
});
Notifications.onLogged('roles-change', (role) => {
sdk.stream('notify-logged', ['roles-change'], (role) => {
if (role.type === 'added') {
if (!role.scope) {
if (!role.u) {

@ -19,6 +19,7 @@ import ComposerPopupProvider from './ComposerPopupProvider';
import RoomToolboxProvider from './RoomToolboxProvider';
import { useRedirectOnSettingsChanged } from './hooks/useRedirectOnSettingsChanged';
import { useRoomQuery } from './hooks/useRoomQuery';
import { useUsersNameChanged } from './hooks/useUsersNameChanged';
type RoomProviderProps = {
children: ReactNode;
@ -42,6 +43,8 @@ const RoomProvider = ({ rid, children }: RoomProviderProps): ReactElement => {
useRedirectOnSettingsChanged(subscriptionQuery.data);
useUsersNameChanged();
const pseudoRoom = useMemo(() => {
if (!room) {
return null;
@ -96,14 +99,7 @@ const RoomProvider = ({ rid, children }: RoomProviderProps): ReactElement => {
return;
}
UserAction.addStream(rid);
return (): void => {
try {
UserAction.cancel(rid);
} catch (error) {
// Do nothing
}
};
return UserAction.addStream(rid);
}, [rid, subscribed]);
if (!pseudoRoom) {

@ -0,0 +1,69 @@
import { useStream } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { Messages, Subscriptions } from '../../../../../app/models/client';
export const useUsersNameChanged = () => {
const notify = useStream('notify-logged');
useEffect(() => {
return notify('Users:NameChanged', ({ _id, name, username }) => {
Messages.update(
{
'u._id': _id,
},
{
$set: {
'u.username': username,
'u.name': name,
},
},
{
multi: true,
},
);
Messages.update(
{
'editedBy._id': _id,
},
{
$set: {
'editedBy.username': username,
},
},
{
multi: true,
},
);
Messages.update(
{
mentions: {
$elemMatch: { _id },
},
},
{
$set: {
'mentions.$.username': username,
'mentions.$.name': name,
},
},
{
multi: true,
},
);
Subscriptions.update(
{
name: username,
t: 'd',
},
{
$set: {
fname: name,
},
},
);
});
}, [notify]);
};

@ -231,7 +231,7 @@ export interface StreamerEvents {
},
];
},
{ key: 'Users:NameChanged'; args: [Pick<IUser, '_id' | 'name'>] },
{ key: 'Users:NameChanged'; args: [Pick<IUser, '_id' | 'name' | 'username'>] },
{ key: 'private-settings-changed'; args: ['inserted' | 'updated' | 'removed' | 'changed', ISetting] },
{ key: 'deleteCustomUserStatus'; args: [{ userStatusData: unknown }] },
{ key: 'user-status'; args: [[IUser['_id'], IUser['username'], 0 | 1 | 2 | 3, IUser['statusText'], IUser['name'], IUser['roles']]] },

Loading…
Cancel
Save