mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
improve chat
This commit is contained in:
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user