mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
82 lines
1.8 KiB
TypeScript
82 lines
1.8 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)
|
|
}
|
|
|
|
let n = 0
|
|
for (const message of room.messages) {
|
|
if(message.online) {
|
|
for(let id of membersIds) {
|
|
if(message.addReceived(id)) {
|
|
n++
|
|
// setTimeout(async() => {
|
|
await message.saveChanges()
|
|
// }, 100 * n)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setTimeout(function () {
|
|
callback();
|
|
}, 100);
|
|
}
|
|
}
|
|
|
|
})
|
|
|
|
|
|
viewReadQueue = FIFOProcessQueue(async ({room}, callback) => {
|
|
|
|
const membersIds: string[] = room.membersExcludeMe.map((user)=> user._id)
|
|
|
|
let n = 0
|
|
for (const message of room.messages) {
|
|
if(message.online) {
|
|
for(let id of membersIds) {
|
|
|
|
if(message.addViewed(id)) {
|
|
message.addReceived(id)
|
|
n++
|
|
// setTimeout(async() => {
|
|
await message.saveChanges()
|
|
// }, 100 * n)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setTimeout(() => {
|
|
callback()
|
|
},100)
|
|
|
|
})
|
|
|
|
request(room:RoomService, userId, statusNum, statusText) {
|
|
this.viewQueue.push({room, userId, statusNum, statusText})
|
|
}
|
|
|
|
requestReadAll(room:RoomService) {
|
|
this.viewReadQueue.push({room})
|
|
}
|
|
}
|