improve chat

This commit is contained in:
Peter Maquiran
2023-01-09 10:49:58 +01:00
parent 56c1733945
commit a73dde467c
21 changed files with 436 additions and 373 deletions
+35 -17
View File
@@ -7,7 +7,8 @@ import { RoomService } from './room.service';
})
export class ViewedMessageService {
constructor() { }
constructor() {
}
viewQueue = FIFOProcessQueue(async ({room, userId, statusNum, statusText}, callback) => {
@@ -20,25 +21,15 @@ export class ViewedMessageService {
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()
for (const message of room.messages) {
if(message.online) {
for(let id of membersIds) {
if(message.addReceived(id)) {
await message.saveChanges()
}
}
}
})
}
setTimeout(function () {
callback();
@@ -47,8 +38,35 @@ export class ViewedMessageService {
}
})
viewReadQueue = FIFOProcessQueue(async ({room}, callback) => {
const membersIds: string[] = room.membersExcludeMe.map((user)=> user._id)
for (const message of room.messages) {
if(message.online) {
for(let id of membersIds) {
if(message.addViewed(id)) {
message.addReceived(id)
await message.saveChanges()
}
}
}
}
setTimeout(() => {
callback()
},100)
})
request(room:RoomService, userId, statusNum, statusText) {
this.viewQueue.push({room, userId, statusNum, statusText})
}
requestReadAll(room:RoomService) {
this.viewReadQueue.push({room})
}
}