From 07316fbef0b23af4d5968fa781c338ea9dc6954d Mon Sep 17 00:00:00 2001 From: Edgard Date: Sun, 10 Jul 2022 20:14:49 -0300 Subject: [PATCH] fix: Use non obstructive trigger for chat.new_message event --- .../events/registerLiveLocationUpdateEvent.ts | 34 ++++++++++--------- src/chat/events/registerNewMessageEvent.ts | 4 ++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/chat/events/registerLiveLocationUpdateEvent.ts b/src/chat/events/registerLiveLocationUpdateEvent.ts index 95dd959200..5b8c4eb116 100644 --- a/src/chat/events/registerLiveLocationUpdateEvent.ts +++ b/src/chat/events/registerLiveLocationUpdateEvent.ts @@ -82,23 +82,25 @@ function registerLiveLocationUpdateEvent() { return; } - internalEv.emit('chat.live_location_start', { - id: msg.sender!, - msgId: msg.id, - chat: msg.chat!.id, - lat: msg.lat!, - lng: msg.lng!, - accuracy: msg.accuracy, - speed: msg.speed, - degrees: msg.degrees, - shareDuration: msg.shareDuration!, - }); + queueMicrotask(() => { + internalEv.emit('chat.live_location_start', { + id: msg.sender!, + msgId: msg.id, + chat: msg.chat!.id, + lat: msg.lat!, + lng: msg.lng!, + accuracy: msg.accuracy, + speed: msg.speed, + degrees: msg.degrees, + shareDuration: msg.shareDuration!, + }); - LiveLocationStore.update(msg.chat!.id) - .then((liveLocation) => { - liveLocation.startViewingMap(); - }) - .catch(() => null); + LiveLocationStore.update(msg.chat!.id) + .then((liveLocation) => { + liveLocation.startViewingMap(); + }) + .catch(() => null); + }); }); /** diff --git a/src/chat/events/registerNewMessageEvent.ts b/src/chat/events/registerNewMessageEvent.ts index e14099b4f1..878f4ea9bc 100644 --- a/src/chat/events/registerNewMessageEvent.ts +++ b/src/chat/events/registerNewMessageEvent.ts @@ -23,7 +23,9 @@ webpack.onInjected(() => register()); function register() { MsgStore.on('add', (msg: MsgModel) => { if (msg.isNewMsg) { - internalEv.emit('chat.new_message', msg); + queueMicrotask(() => { + internalEv.emit('chat.new_message', msg); + }); } }); }