Skip to content

Commit

Permalink
fix: Use non obstructive trigger for chat.new_message event
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 10, 2022
1 parent 78e5d49 commit 07316fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 18 additions & 16 deletions src/chat/events/registerLiveLocationUpdateEvent.ts
Expand Up @@ -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);
});
});

/**
Expand Down
4 changes: 3 additions & 1 deletion src/chat/events/registerNewMessageEvent.ts
Expand Up @@ -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);
});
}
});
}

0 comments on commit 07316fb

Please sign in to comment.