|
@@ -47,7 +47,8 @@ export default class {
|
|
|
private next = (type: 'private' | 'group', id: string) => {
|
|
|
const queue = this.messageQueues[`${type}:${id}`];
|
|
|
if (queue && queue.length) {
|
|
|
- queue[0]().then(() => queue.shift()).then(() => {
|
|
|
+ queue[0]().then(() => {
|
|
|
+ queue.shift();
|
|
|
if (!queue.length) delete this.messageQueues[`${type}:${id}`];
|
|
|
else this.next(type, id);
|
|
|
});
|
|
@@ -55,10 +56,11 @@ export default class {
|
|
|
};
|
|
|
|
|
|
private enqueue = (type: 'private' | 'group', id: string, resolver: () => Promise<void>) => {
|
|
|
- const queue = this.messageQueues[`${type}:${id}`] ||= [];
|
|
|
+ let wasEmpty = false;
|
|
|
+ const queue = this.messageQueues[`${type}:${id}`] ||= (() => { wasEmpty = true; return []; })();
|
|
|
queue.push(() => sleep(200).then(resolver));
|
|
|
logger.debug(`no. of message currently queued for ${type}:${id}: ${queue.length}`);
|
|
|
- if (queue.length === 1) this.next(type, id);
|
|
|
+ if (wasEmpty) this.next(type, id);
|
|
|
};
|
|
|
|
|
|
private getChat = async (session: Session): Promise<IChat> => {
|