This commit is contained in:
Peter Maquiran
2023-01-05 12:11:50 +01:00
parent 0d485672d8
commit 572ab6db7b
12 changed files with 165 additions and 88 deletions
@@ -0,0 +1,54 @@
import { Injectable } from '@angular/core';
import * as FIFOProcessQueue from 'fifo-process-queue';
import { RoomService } from './room.service';
@Injectable({
providedIn: 'root'
})
export class ViewedMessageService {
constructor() { }
viewQueue = FIFOProcessQueue(async ({room, userId, statusNum, statusText}, callback) => {
if(room.membersExcludeMe?.map) {
const membersIds = room.membersExcludeMe.map((user)=> user._id)
if(membersIds.includes(userId)) {
if(statusText != 'offline') {
room.deleteMessageToReceive(userId)
}
await room.messages.forEach(async (message, index) => {
if(!message.messageOwnerById(userId)) {
if(!room.messages[index]?.received?.includes(userId)) {
if(room.messages[index]._id) {
try {
if(!room.messages[index].received.includes(userId)) {
room.messages[index].received.push(userId)
}
} catch(e) {
room.messages[index].received = [userId]
}
room.messages[index].save()
}
}
}
})
setTimeout(function () {
callback();
}, 100);
}
}
})
request(room:RoomService, userId, statusNum, statusText) {
this.viewQueue.push({room, userId, statusNum, statusText})
}
}