diff --git a/apps/meteor/app/models/client/models/ChatPermissions.ts b/apps/meteor/app/models/client/models/ChatPermissions.ts index 8f1c7b18c06..e836f58ebb2 100644 --- a/apps/meteor/app/models/client/models/ChatPermissions.ts +++ b/apps/meteor/app/models/client/models/ChatPermissions.ts @@ -4,7 +4,7 @@ import { CachedCollection } from '../../../ui-cached-collection/client'; export const AuthzCachedCollection = new CachedCollection({ name: 'permissions', - eventType: 'onLogged', + eventType: 'notify-logged', }); export const ChatPermissions = AuthzCachedCollection.collection; diff --git a/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts b/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts index 9c970ccf697..77190992612 100644 --- a/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts +++ b/apps/meteor/app/ui-cached-collection/client/models/CachedCollection.ts @@ -1,4 +1,5 @@ import { Emitter } from '@rocket.chat/emitter'; +import type { StreamNames } from '@rocket.chat/ui-contexts'; import localforage from 'localforage'; import { Accounts } from 'meteor/accounts-base'; import { Meteor } from 'meteor/meteor'; @@ -10,11 +11,10 @@ import { baseURI } from '../../../../client/lib/baseURI'; import { getConfig } from '../../../../client/lib/utils/getConfig'; import { isTruthy } from '../../../../lib/isTruthy'; import { withDebouncing } from '../../../../lib/utils/highOrderFunctions'; -import Notifications from '../../../notifications/client/lib/Notifications'; import { sdk } from '../../../utils/client/lib/SDKClient'; import { CachedCollectionManager } from './CachedCollectionManager'; -export type EventType = Extract; +export type EventType = 'notify-logged' | 'notify-all' | 'notify-user'; type Name = 'rooms' | 'subscriptions' | 'permissions' | 'public-settings' | 'private-settings'; @@ -48,7 +48,7 @@ export class CachedCollection extends Emitter< public name: Name; - public eventType: EventType; + public eventType: StreamNames; public version = 18; @@ -60,7 +60,7 @@ export class CachedCollection extends Emitter< public timer: ReturnType; - constructor({ name, eventType = 'onUser', userRelated = true }: { name: Name; eventType?: EventType; userRelated?: boolean }) { + constructor({ name, eventType = 'notify-user', userRelated = true }: { name: Name; eventType?: StreamNames; userRelated?: boolean }) { super(); this.collection = new Mongo.Collection(null) as MinimongoCollection; @@ -85,7 +85,10 @@ export class CachedCollection extends Emitter< }); } - protected get eventName(): `${Name}-changed` { + protected get eventName(): `${Name}-changed` | `${string}/${Name}-changed` { + if (this.eventType === 'notify-user') { + return `${Meteor.userId()}/${this.name}-changed`; + } return `${this.name}-changed`; } @@ -232,7 +235,7 @@ export class CachedCollection extends Emitter< } async setupListener() { - (Notifications[this.eventType] as any)(this.eventName, async (action: 'removed' | 'changed', record: any) => { + sdk.stream(this.eventType, [this.eventName], (async (action: 'removed' | 'changed', record: any) => { this.log('record received', action, record); const newRecord = this.handleReceived(record, action); @@ -250,7 +253,7 @@ export class CachedCollection extends Emitter< this.collection.upsert({ _id } as any, newRecord); } await this.save(); - }); + }) as (...args: unknown[]) => void); } trySync(delay = 10) { diff --git a/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts b/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts index da3f7aa4397..b0276e75392 100644 --- a/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts +++ b/apps/meteor/client/lib/settings/PrivateSettingsCachedCollection.ts @@ -7,7 +7,7 @@ class PrivateSettingsCachedCollection extends CachedCollection { constructor() { super({ name: 'private-settings', - eventType: 'onLogged', + eventType: 'notify-logged', }); } diff --git a/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts b/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts index 7eab4b1dc7a..c01523252f8 100644 --- a/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts +++ b/apps/meteor/client/lib/settings/PublicSettingsCachedCollection.ts @@ -6,7 +6,7 @@ class PublicSettingsCachedCollection extends CachedCollection { constructor() { super({ name: 'public-settings', - eventType: 'onAll', + eventType: 'notify-all', userRelated: false, }); }