diff --git a/app/lib/methods/subscriptions/room.ts b/app/lib/methods/subscriptions/room.ts index 56d87d28..d38a8464 100644 --- a/app/lib/methods/subscriptions/room.ts +++ b/app/lib/methods/subscriptions/room.ts @@ -138,6 +138,23 @@ export default class RoomSubscription { reduxStore.dispatch(removeUserTyping(name)); } } + } else if (ev === 'user-activity') { + const { user } = reduxStore.getState().login; + const { UI_Use_Real_Name } = reduxStore.getState().settings; + const { subscribedRoom } = reduxStore.getState().room; + if (subscribedRoom !== _rid) { + return; + } + const [name, activities] = ddpMessage.fields.args; + const key = UI_Use_Real_Name ? 'name' : 'username'; + if (name !== user[key]) { + if (activities.includes('user-typing')) { + reduxStore.dispatch(addUserTyping(name)); + } + if (!activities.length) { + reduxStore.dispatch(removeUserTyping(name)); + } + } } else if (ev === 'deleteMessage') { InteractionManager.runAfterInteractions(async () => { if (ddpMessage && ddpMessage.fields && ddpMessage.fields.args.length > 0) { diff --git a/app/lib/services/restApi.ts b/app/lib/services/restApi.ts index 75f256fb..eefb8983 100644 --- a/app/lib/services/restApi.ts +++ b/app/lib/services/restApi.ts @@ -812,10 +812,14 @@ export const addUsersToRoom = (rid: string): Promise => { }; export const emitTyping = (room: IRoom, typing = true) => { - const { login, settings } = reduxStore.getState(); + const { login, settings, server } = reduxStore.getState(); const { UI_Use_Real_Name } = settings; + const { version: serverVersion } = server; const { user } = login; const name = UI_Use_Real_Name ? user.name : user.username; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.0.0')) { + return sdk.methodCall('stream-notify-room', `${room}/user-activity`, name, typing ? ['user-typing'] : []); + } return sdk.methodCall('stream-notify-room', `${room}/typing`, name, typing); }; diff --git a/app/lib/services/sdk.ts b/app/lib/services/sdk.ts index 3f1e4796..e6b89121 100644 --- a/app/lib/services/sdk.ts +++ b/app/lib/services/sdk.ts @@ -6,7 +6,7 @@ import { twoFactor } from './twoFactor'; import { isSsl } from '../methods/helpers/url'; import { store as reduxStore } from '../store/auxStore'; import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../definitions/rest/helpers'; -import { random } from '../methods/helpers'; +import { compareServerVersion, random } from '../methods/helpers'; class Sdk { private sdk: typeof Rocketchat; @@ -162,7 +162,22 @@ class Sdk { } subscribeRoom(...args: any[]) { - return this.current.subscribeRoom(...args); + const { server } = reduxStore.getState(); + const { version: serverVersion } = server; + const topic = 'stream-notify-room'; + let eventUserTyping; + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.0.0')) { + eventUserTyping = this.subscribe(topic, `${args[0]}/user-activity`, ...args); + } else { + eventUserTyping = this.subscribe(topic, `${args[0]}/typing`, ...args); + } + + // Taken from https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/454b4ba784095057b8de862eb99340311b672e15/lib/drivers/ddp.ts#L555 + return Promise.all([ + this.subscribe('stream-room-messages', args[0], ...args), + eventUserTyping, + this.subscribe(topic, `${args[0]}/deleteMessage`, ...args) + ]); } unsubscribe(subscription: any[]) {