diff --git a/src/app/services/chat/chat-storage.service.spec.ts b/src/app/services/chat/chat-storage.service.spec.ts deleted file mode 100644 index 34a01e3a9..000000000 --- a/src/app/services/chat/chat-storage.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ChatStorageService } from './chat-storage.service'; - -describe('ChatStorageService', () => { - let service: ChatStorageService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(ChatStorageService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/src/app/services/chat/chat-storage.service.ts b/src/app/services/chat/chat-storage.service.ts deleted file mode 100644 index 523326c6d..000000000 --- a/src/app/services/chat/chat-storage.service.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Storage } from '@ionic/storage'; -import { environment } from 'src/environments/environment'; - -@Injectable({ - providedIn: 'root' -}) -export class ChatStorageService { - - constructor( - private storage: Storage, - ) { } - - /** - * @description delete message in the DB. get all messages, delete then corresponding message and update the store - * @param id message ID - */ - - async deleteMessageFromDb(messageId, roomId) { - if (environment.chatOffline) { - await this.storage.get('chatmsg' + roomId).then(async(messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - await messages.forEach( async (message, index) => { - - if(message._id == messageId) { - messages.splice(index, 1) - } - - }) - - this.storage.set('chatmsg' + roomId, messages).then((value) => { - // - }); - - }) - } - } - - async updateMessageDB(ChatMessage, roomId, identificator) { - - if (environment.chatOffline) { - await this.storage.get('chatmsg' + roomId).then(async(messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - let index; - const find = messages.find((message, _index)=> { - - if(message?.localReference == ChatMessage?.localReference || - message?._id == ChatMessage?._id) { - index = _index - return true - } - - return false - }) - - if(find) { - - - messages[index] = Object.assign(messages[index], ChatMessage) - - await this.storage.set('chatmsg' + roomId, messages) - } else { - // - } - - }) - } - - } - - async updateChat(history, roomId, identificator = '_id') { - if (environment.chatOffline) { - await this.storage.get('chatmsg' + roomId).then(async(messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - history.forEach( async(ChatMessage)=>{ - let index; - const find = messages.find((message, _index)=> { - - if(message[identificator]) { - if(message[identificator] == ChatMessage[identificator]) { - index = _index - return true - } - } - - return false - }) - - if(find) { - - - messages[index] = Object.assign(messages[index], ChatMessage) - - // if(messages[index].msg.includes('***********')) { - // - // - // - // } - - await this.storage.set('chatmsg' + roomId, messages) - } else { - - } - }) - - - - }) - } - } - - async addMessageDB(ChatMessage, roomId) { - if (environment.chatOffline) { - await this.storage.get('chatmsg' + roomId).then(async(messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - - if(!ChatMessage._id && environment.chatOffline) { - - delete ChatMessage.temporaryData - messages.push(ChatMessage) - - - await this.storage.set('chatmsg' + roomId, messages) - // - - } else { - const find = messages.find((message)=> { - return message._id == ChatMessage._id - }) - - if(!find) { - delete ChatMessage.temporaryData - messages.push(ChatMessage) - await this.storage.set('chatmsg' + roomId, messages) - // - } else { - - } - - } - }) - } - } - - async addManyMessageDB(_ChatMessage: any[], roomId) { - if (environment.chatOffline) { - await this.storage.get('chatmsg' + roomId).then(async(messages: any = []) => { - if(!Array.isArray(messages)) { - messages = [] - } - - await _ChatMessage.forEach(async(ChatMessage)=>{ - if(!ChatMessage._id && environment.chatOffline) { - - delete ChatMessage.temporaryData - messages.push(ChatMessage) - // - - } else { - const find = messages.find((message)=> { - return message._id == ChatMessage._id - }) - - if(!find) { - delete ChatMessage.temporaryData - messages.push(ChatMessage) - // - - - } - } - }) - - await this.storage.set('chatmsg' + roomId, messages) - - }) - } - } - -} diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index 72aafee78..4e27dc131 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -14,7 +14,6 @@ import { SortService } from '../functions/sort.service'; import { chatUser } from 'src/app/models/chatMethod'; import { NfService } from 'src/app/services/chat/nf.service' import { ChangeProfileService } from '../change-profile.service'; -import { ChatStorageService } from './chat-storage.service'; import { ChatMethodsService } from './chat-methods.service'; import { AESEncrypt } from '../aesencrypt.service' import { AttachmentsService } from 'src/app/services/attachments.service'; @@ -55,7 +54,6 @@ export class ChatSystemService { private NfService: NfService, private changeProfileService: ChangeProfileService, private chatService: ChatService, - private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, private AESEncrypt: AESEncrypt, private AttachmentsService:AttachmentsService, @@ -389,7 +387,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.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, 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.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this) room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 6cb8db940..d52b15cf6 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -6,7 +6,6 @@ import { capitalizeTxt } from 'src/plugin/text' import { NfService } from 'src/app/services/chat/nf.service' import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; import { showDateDuration } from 'src/plugin/showDateDuration'; -import { ChatStorageService } from './chat-storage.service' import { ChatMethodsService } from './chat-methods.service' import { MessageModel } from '../../models/beast-orm' import { AESEncrypt } from '../aesencrypt.service' @@ -62,10 +61,9 @@ export class MessageService { downloadAttachmentsTemp = 0; UploadAttachmentsTemp = 0; - constructor(private storage: Storage, + constructor( private NfService: NfService, private RochetChatConnectorService: RochetChatConnectorService, - private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, private AESEncrypt: AESEncrypt, private AttachmentsService: AttachmentsService, diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index d5f7039bf..9b6db56a1 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -15,7 +15,6 @@ import { environment } from 'src/environments/environment'; import { ChatService } from 'src/app/services/chat.service'; import { NfService } from 'src/app/services/chat/nf.service'; import { v4 as uuidv4 } from 'uuid' -import { ChatStorageService } from './chat-storage.service'; import { ChatMethodsService } from './chat-methods.service'; import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'; import { AESEncrypt } from '../aesencrypt.service'; @@ -88,7 +87,6 @@ export class RoomService { private sortService: SortService, private chatService: ChatService, private NfService: NfService, - private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, private AESEncrypt: AESEncrypt, private AttachmentsService: AttachmentsService, @@ -181,7 +179,7 @@ export class RoomService { } } - setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) { + setData({membersExcludeMe, members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -807,7 +805,7 @@ export class RoomService { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -864,7 +862,7 @@ export class RoomService { async prepareCreate({message, save = true}): Promise { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -902,7 +900,7 @@ export class RoomService { simplePrepareMessage(message) { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.RochetChatConnectorService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) + const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory