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
+3 -2
View File
@@ -19,7 +19,7 @@ import { AESEncrypt } from '../aesencrypt.service'
import { AttachmentsService } from 'src/app/services/attachments.service';
import { NetworkServiceService} from 'src/app/services/network-service.service';
import { JsonStore } from '../jsonStore.service';
import { ViewedMessageService } from './viewed-message.service'
@Injectable({
providedIn: 'root'
})
@@ -57,6 +57,7 @@ export class ChatSystemService {
private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService,
private NetworkServiceService: NetworkServiceService,
private ViewedMessageService: ViewedMessageService
) {
this.RochetChatConnectorService.registerCallback({
@@ -408,7 +409,7 @@ export class ChatSystemService {
if (setData.name != 'Rocket Cat') {
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this)
let room:RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.ViewedMessageService)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
+4 -31
View File
@@ -22,6 +22,7 @@ import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'sr
import { AttachmentsService } from 'src/app/services/attachments.service';
import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service';
import { ChatSystemService } from './chat-system.service';
import { ViewedMessageService } from './viewed-message.service'
@Injectable({
providedIn: 'root'
@@ -94,7 +95,8 @@ export class RoomService {
private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService,
private NetworkServiceService: NetworkServiceService,
private ChatSystemService: ChatSystemService
private ChatSystemService: ChatSystemService,
private ViewedMessageService: ViewedMessageService
) {
this.NativeNotificationService.askForPermission()
@@ -104,37 +106,8 @@ export class RoomService {
const statusNum = d.fields.args[0][2]
const statusText = this.statusNumberToText(statusNum)
if(this.membersExcludeMe?.map) {
const membersIds = this.membersExcludeMe.map((user)=> user._id)
this.ViewedMessageService.request(this, userId, statusNum, statusText)
if(membersIds.includes(userId)) {
if(statusText != 'offline') {
this.deleteMessageToReceive(userId)
}
this.messages.forEach((message, index) => {
if(!message.messageOwnerById(userId)) {
if(!this.messages[index]?.received?.includes(userId)) {
if(this.messages[index]._id) {
try {
if(!this.messages[index].received.includes(userId)) {
this.messages[index].received.push(userId)
}
} catch(e) {
this.messages[index].received = [userId]
}
this.messages[index].save()
}
}
}
})
}
}
})
this.RochetChatConnectorService.registerCallback({
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ViewedMessageService } from './viewed-message.service';
describe('ViewedMessageService', () => {
let service: ViewedMessageService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ViewedMessageService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -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})
}
}