diff --git a/apps/meteor/app/notifications/client/index.ts b/apps/meteor/app/notifications/client/index.ts deleted file mode 100644 index 1cb2af14e70ed..0000000000000 --- a/apps/meteor/app/notifications/client/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Notifications from './lib/Notifications'; - -export { Notifications }; diff --git a/apps/meteor/app/notifications/client/lib/Notifications.ts b/apps/meteor/app/notifications/client/lib/Notifications.ts deleted file mode 100644 index 8d77b9e3a0cb7..0000000000000 --- a/apps/meteor/app/notifications/client/lib/Notifications.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { StreamKeys, StreamerCallback } from '@rocket.chat/ddp-client/src/types/streams'; -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import './Presence'; -import { sdk } from '../../../utils/client/lib/SDKClient'; - -type ExtractSecondString = E extends `${string}/${infer X}` ? X : never; - -class Notifications { - private logged: boolean; - - private loginCb: any[]; - - private debug: boolean; - - constructor() { - this.logged = Meteor.userId() !== null; - this.loginCb = []; - Tracker.autorun(() => { - if (Meteor.userId() !== null && this.logged === false) { - this.loginCb.forEach((cb) => cb()); - } - this.logged = Meteor.userId() !== null; - }); - this.debug = false; - } - - onLogged>(eventName: E, callback: StreamerCallback<'notify-logged', E>) { - return this.onLogin(() => sdk.stream('notify-logged', [eventName], callback)); - } - - onAll>(eventName: E, callback: StreamerCallback<'notify-all', E>) { - return sdk.stream('notify-all', [eventName], callback); - } - - onRoom>>( - room: string, - eventName: E, - callback: StreamerCallback<'notify-room', `${string}/${E}`>, - ) { - return sdk.stream('notify-room', [`${room}/${eventName}`], callback); - } - - onUser>>( - eventName: E, - callback: StreamerCallback<'notify-user', `${string}/${E}`>, - ) { - return sdk.stream('notify-user', [`${Meteor.userId()}/${eventName}`], callback); - } - - onVisitor>>( - visitor: string, - eventName: E, - callback: StreamerCallback<'notify-user', `${string}/${E}`>, - ) { - return sdk.stream('notify-user', [`${visitor}/${eventName}`], callback); - } - - unUser>>(eventName: E) { - return sdk.stop('notify-user', `${Meteor.userId()}/${eventName}`); - } - - unRoom>>(room: string, eventName: E) { - return sdk.stop('notify-room', `${room}/${eventName}`); - } - - onLogin(cb: () => void) { - this.loginCb.push(cb); - if (this.logged) { - return cb(); - } - } - - notifyRoom>>(room: string, eventName: E, ...args: any[]) { - args.unshift(`${room}/${eventName}`); - return sdk.publish('notify-room', args); - } - - notifyVisitor>>(visitor: string, eventName: E, ...args: any[]) { - args.unshift(`${visitor}/${eventName}`); - return sdk.publish('notify-user', args); - } - - notifyUser>>(uid: string, eventName: E, ...args: any[]) { - args.unshift(`${uid}/${eventName}`); - return sdk.publish('notify-user', args); - } - - notifyUsersOfRoom>>(room: string, eventName: E, ...args: any[]) { - if (this.debug === true) { - console.log('RocketChat.Notifications: notifyUsersOfRoomExceptSender', [room, eventName, ...args]); - } - args.unshift(`${room}/${eventName}`); - return sdk.publish('notify-room-users', args); - } -} - -/** @deprecated it should be used `sdk`instead both perform the same */ -const ns = new Notifications(); - -export default ns; diff --git a/apps/meteor/app/webdav/client/startup/sync.js b/apps/meteor/app/webdav/client/startup/sync.ts similarity index 53% rename from apps/meteor/app/webdav/client/startup/sync.js rename to apps/meteor/app/webdav/client/startup/sync.ts index e048472aad715..16e82e719e63e 100644 --- a/apps/meteor/app/webdav/client/startup/sync.js +++ b/apps/meteor/app/webdav/client/startup/sync.ts @@ -1,13 +1,13 @@ +import type { IWebdavAccount } from '@rocket.chat/core-typings'; import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; import { WebdavAccounts } from '../../../models/client'; -import { Notifications } from '../../../notifications/client'; import { sdk } from '../../../utils/client/lib/SDKClient'; const events = { - changed: (account) => WebdavAccounts.upsert({ _id: account._id }, account), - removed: ({ _id }) => WebdavAccounts.remove({ _id }), + changed: (account: IWebdavAccount) => WebdavAccounts.upsert({ _id: account._id }, account), + removed: ({ _id }: { _id: IWebdavAccount['_id'] }) => WebdavAccounts.remove({ _id }), }; Tracker.autorun(async () => { @@ -16,5 +16,5 @@ Tracker.autorun(async () => { } const { accounts } = await sdk.rest.get('/v1/webdav.getMyAccounts'); accounts.forEach((account) => WebdavAccounts.insert(account)); - Notifications.onUser('webdav', ({ type, account }) => events[type](account)); + sdk.stream('notify-user', [`${Meteor.userId()}/webdav`], ({ type, account }) => events[type](account as IWebdavAccount)); }); diff --git a/apps/meteor/client/importPackages.ts b/apps/meteor/client/importPackages.ts index c60a13dbfc504..cbbcc03918841 100644 --- a/apps/meteor/client/importPackages.ts +++ b/apps/meteor/client/importPackages.ts @@ -39,7 +39,6 @@ import '../app/user-status/client'; import '../app/utils/client'; import '../app/settings/client'; import '../app/models/client'; -import '../app/notifications/client'; import '../app/ui-utils/client'; import '../app/ui-cached-collection/client'; import '../app/reactions/client'; diff --git a/packages/core-typings/src/IWebdavAccount.ts b/packages/core-typings/src/IWebdavAccount.ts index 8ab86fda573f0..53059382fb50a 100644 --- a/packages/core-typings/src/IWebdavAccount.ts +++ b/packages/core-typings/src/IWebdavAccount.ts @@ -3,14 +3,14 @@ import type { IRocketChatRecord } from './IRocketChatRecord'; export interface IWebdavAccount extends IRocketChatRecord { userId: string; serverURL: string; - username?: string; + username: string; password?: string; name: string; } export type IWebdavAccountIntegration = Pick; -export type IWebdavAccountPayload = Pick; +export type IWebdavAccountPayload = Pick & Partial>; export type IWebdavNode = { basename: string;