mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
|
|
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})
|
||
|
|
}
|
||
|
|
}
|