From 345ca084f10105d459aff07356f19852efad4129 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 15 Jul 2022 10:06:55 +0100 Subject: [PATCH 1/9] fix message order --- src/app/services/chat/room.service.ts | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 314f640d5..2ed102439 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -39,6 +39,7 @@ export class RoomService { name = '' _updatedAt = {} hasLoadHistory = false + hasLoadHistoryMessageRF = [] restoreFromOffline = false duration = '' isTyping = false @@ -516,7 +517,7 @@ export class RoomService { */ async send({file = null, attachments = null, temporaryData = {}}) { - const localReference = uuidv4() + const localReference = uuidv4(); let offlineChatMessage = { rid: this.id, @@ -547,7 +548,9 @@ export class RoomService { this.sortRoomList() } - + if(this.hasLoadHistory == false) { + this.hasLoadHistoryMessageRF.push(localReference) + } } @@ -703,6 +706,28 @@ export class RoomService { }, 50) this.hasLoadHistory = true + this.messageReorder(); + } + + async messageReorder() { + const reorderMessage: MessageService[] = this.messages.filter((message) => + this.hasLoadHistoryMessageRF.includes(message?.localReference) + ); + + await this.messages.forEach( async (message, i) => { + + if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) { + this.messages.splice(i, 1) + } + + }) + + this.hasLoadHistoryMessageRF = []; + + reorderMessage.forEach((message) => { + this.messages.push(message) + }); + } From 48eb19b1a1790f9660210ab86173d8e96a83c588 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 18 Jul 2022 15:46:24 +0100 Subject: [PATCH 2/9] fix repetition --- src/app/services/chat/room.service.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 2ed102439..90fd2413f 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -180,7 +180,7 @@ export class RoomService { if(difference < 0) { - this.deleteRoom() + this.deleteRoom(); } else { setTimeout(() => { @@ -494,8 +494,8 @@ export class RoomService { this.WsChatService.deleteMessage(msgId).then(async() => { message.delateRequest = true - await message.save() - this.deleteMessage(msgId) + await message.save(); + this.deleteMessage(msgId); }) } else { @@ -682,17 +682,17 @@ export class RoomService { } await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { - + // console.log('load history', chatHistory) // const messagesId = this.messages.map((message)=> message._id) - chatHistory.result.messages.reverse().forEach(async(message: any) => { + await chatHistory.result.messages.reverse().forEach(async(message: any) => { if (!messagesId.includes(message._id)) { const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); if(messagesToSave) { - await messagesToSave.addMessageDB() + messagesToSave.addMessageDB() } } @@ -865,7 +865,7 @@ export class RoomService { message = this.fix_updatedAt(message) const found = this.messages.find((MessageService, index) => { - if (MessageService._id == message._id ) { + if (MessageService._id == message._id) { return true } else { return false From 5533116e9dbcde857e30a472d055fcf2926a4472 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 21 Jul 2022 18:05:29 +0100 Subject: [PATCH 3/9] fix logout --- src/app/pages/chat/chat.page.html | 1 + src/app/pages/chat/chat.page.ts | 2 ++ src/app/pages/login/login.page.ts | 10 +++++++++- src/app/services/auth.service.ts | 10 ++++++++-- src/app/services/chat.service.ts | 18 +++++++++--------- src/app/services/chat/room.service.ts | 4 ++-- .../services/chat/ws-chat-methods.service.ts | 17 +++++------------ src/app/services/chat/ws-chat.service.ts | 14 ++++++++++++-- .../shared/chat/messages/messages.page.html | 1 + src/app/shared/chat/messages/messages.page.ts | 3 --- 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index 27c49e4f1..c08544c4c 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -37,6 +37,7 @@ +
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 636c72896..9aa2f37b2 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -125,6 +125,8 @@ export class ChatPage implements OnInit { this.showLoader = true; + this.segment = 'Contactos' + } ngOnInit() { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 74519ab76..d79528541 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -13,7 +13,10 @@ import { ThemeService } from 'src/app/services/theme.service'; import { StorageService } from 'src/app/services/storage.service'; import { PermissionService } from 'src/app/services/permission.service'; import { PermissionList } from 'src/app/models/permission/permissionList'; -import { MessageModel, DeleteMessageModel } from '../../models/beast-orm' +import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'; +import { WsChatService } from 'src/app/services/chat/ws-chat.service'; +import { Storage } from '@ionic/storage'; +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; @Component({ selector: 'app-login', templateUrl: './login.page.html', @@ -46,6 +49,9 @@ export class LoginPage implements OnInit { public ThemeService: ThemeService, private storageservice: StorageService, public p: PermissionService, + private WsChatService: WsChatService, + private storage: Storage, + public WsChatMethodsService: WsChatMethodsService, ) {} ngOnInit() { @@ -134,7 +140,9 @@ export class LoginPage implements OnInit { } else { + this.WsChatService.logout(); this.clearStoreService.clear(); + this.WsChatMethodsService.clearChat(); SessionStore.delete(); window.localStorage.clear(); await MessageModel.deleteAll() diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index c55f09766..908324f5c 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -20,7 +20,7 @@ import { RoomService } from './chat/room.service'; import { Storage } from '@ionic/storage'; import { InitialsService } from './functions/initials.service'; import { PermissionService } from './permission.service'; - +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; @Injectable({ providedIn: 'root' }) @@ -48,7 +48,8 @@ export class AuthService { private AttachmentsService: AttachmentsService, private storage: Storage, private initialsService: InitialsService, - public p: PermissionService, ) { + public p: PermissionService, + public WsChatMethodsService: WsChatMethodsService, ) { this.headers = new HttpHeaders(); @@ -201,6 +202,11 @@ export class AuthService { this.WsChatService.setStatus('online') + + setTimeout(() => { + this.WsChatMethodsService.getAllRooms(); + }, 200); + // alert('wsLogin') }).catch((message) => { diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index e21c11ab5..6d402df58 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -1,14 +1,13 @@ import { HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { AuthService } from './auth.service'; import { HttpService } from './http.service'; import { StorageService } from './storage.service'; -import { HttpClient, HttpHeaderResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import { Storage } from '@ionic/storage'; import { PermissionService } from './permission.service'; import { SessionStore } from '../store/session.service'; - +import { ChangeProfileService } from 'src/app/services/change-profile.service'; @Injectable({ providedIn: 'root' }) @@ -24,19 +23,21 @@ export class ChatService { constructor( private http: HttpClient, private httpService: HttpService, - private authService: AuthService, private storage: Storage, private storageService: StorageService, - public p: PermissionService) { + public p: PermissionService, + private changeProfileService: ChangeProfileService,) { - this.setheader() + this.changeProfileService.registerCallback(() => { + this.setheader(); + }) } getDocumentDetails(url: string) { let headersc = new HttpHeaders(); - headersc = headersc.set('X-User-Id', this.loggedUserChat['data'].userId); - headersc = headersc.set('X-Auth-Token', this.loggedUserChat['data'].authToken); + headersc = headersc.set('X-User-Id', SessionStore.user.ChatData.data.userId); + headersc = headersc.set('X-Auth-Token', SessionStore.user.ChatData.data.authToken); headersc = headersc.set('Sec-Fetch-Dest', 'attachment'); headersc = headersc.set('Sec-Fetch-Mode', 'navigate'); headersc = headersc.set('Cookie', 'rc_uid=fsMwcNdufWvdnChj7'); @@ -342,7 +343,6 @@ export class ChatService { setheader() { try { if (this.p.userPermission(this.p.permissionList.Chat.access)) { - this.loggedUserChat = this.authService.ValidatedUserChat; this.headers = new HttpHeaders(); if (this.p.userPermission(this.p.permissionList.Chat.access)) { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 90fd2413f..2104ed689 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -469,7 +469,7 @@ export class RoomService { deleteAll() { - this.messages.forEach((message)=>{ + this.messages.forEach((message) => { if(message?._id) { this.sendDeleteRequest(message._id) } @@ -478,7 +478,7 @@ export class RoomService { async delateMessageToSendToOthers(userId) { - const deleteMessage = await DeleteMessageModel.all() + const deleteMessage = await DeleteMessageModel.all(); const toSend = deleteMessage.filter((DeleteMessage:string[])=> ! DeleteMessage.includes(userId)) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 87976f395..d12c22731 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.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 { AuthService } from '../auth.service'; import { ChatStorageService } from './chat-storage.service'; import { ChatMethodsService } from './chat-methods.service'; import { AESEncrypt } from '../aesencrypt.service' @@ -41,7 +40,7 @@ export class WsChatMethodsService { users: chatUser[] = [] sessionStore = SessionStore - loggedUser: any; + delete = [] @@ -56,7 +55,6 @@ export class WsChatMethodsService { private NfService: NfService, private changeProfileService: ChangeProfileService, private chatService: ChatService, - private authService: AuthService, private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, private AESEncrypt: AESEncrypt, @@ -64,7 +62,7 @@ export class WsChatMethodsService { private NetworkServiceService: NetworkServiceService, ) { - this.loggedUser = authService.ValidatedUserChat['data']; + this.loadChat() @@ -93,13 +91,6 @@ export class WsChatMethodsService { }) - // on change profile remove a rooms - this.changeProfileService.registerCallback(() => { - this.clearChat() - this.ReLoadChat() - this.storage.remove('Rooms'); - }) - } private loadChat() { @@ -173,8 +164,10 @@ export class WsChatMethodsService { async getAllRooms () { this.loadingWholeList = true const rooms = await this.WsChatService.getRooms(); + try { + await this.storage.remove('Rooms'); + } catch(e) {} - await this.storage.remove('Rooms'); await rooms.result.update.forEach( async (roomData: room, index) => { const roomId = this.getRoomId(roomData); diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 173a9f167..2bc758e80 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -78,7 +78,6 @@ export class WsChatService { // if(message.result) { if(message.result.token) { - this.isLogin = true this.loginResponse = message @@ -106,6 +105,7 @@ export class WsChatService { getRooms(roomOlder = 1480377601) { + //const requestId = uuidv4() const requestId = uuidv4() const message = { @@ -121,7 +121,6 @@ export class WsChatService { this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ if(message.id == requestId) { // same request send resolve(message) - // return true } }}) @@ -186,6 +185,7 @@ export class WsChatService { logout() { this.isLogin = false this.ws.connected = false + this.ws.disconnect() } // send message to room @@ -749,6 +749,7 @@ export class WsChatService { const data = JSON.parse(event.data) // + // console.log(data) for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'Onmessage') { @@ -777,6 +778,15 @@ export class WsChatService { onerror: (event: any) => { + }, + disconnect:() => { + if(this.socket) { + this.socket.onopen = (event: any) => {} + this.socket.onmessage = (event: any) => {} + this.socket.onclose = (event: any) => {} + this.socket.onerror = (event: any) => {} + this.socket.close() + } } }} diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 66482dde6..58b1211e1 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,6 +49,7 @@
{{msg.u.name}} {{msg.duration}} + {{msg._id}}
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 2a91751fb..f5fd8e696 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -49,8 +49,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy @ViewChild('scrollMe') private myScrollContainer: ElementRef; @ViewChild('message-item') messageContainer: ElementRef; - loggedUser: any; - messages: any; dm: any; userPresence = ''; @@ -126,7 +124,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy private platform: Platform, private fileOpener: FileOpener, ) { - this.loggedUser = authService.ValidatedUserChat['data']; this.checkAudioPermission() } From 3a6b23b5f5f933b80f08070c351ccc96f8ed2a13 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 22 Jul 2022 15:52:10 +0100 Subject: [PATCH 4/9] improve --- src/app/modals/profile/profile.page.html | 3 +- src/app/pages/login/login.page.ts | 4 ++ src/app/services/chat.service.ts | 38 +++++++++++-------- .../shared/chat/messages/messages.page.html | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/app/modals/profile/profile.page.html b/src/app/modals/profile/profile.page.html index 0b4d029e5..7b4c9a65b 100644 --- a/src/app/modals/profile/profile.page.html +++ b/src/app/modals/profile/profile.page.html @@ -45,7 +45,8 @@
- {{notificationdata.length}} novas notificações + {{notificationdata.length}} novas notificações + 0 novas notificações
diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index d79528541..6a576a779 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -17,6 +17,7 @@ import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'; import { WsChatService } from 'src/app/services/chat/ws-chat.service'; import { Storage } from '@ionic/storage'; import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; +import { ChatService } from 'src/app/services/chat.service'; @Component({ selector: 'app-login', templateUrl: './login.page.html', @@ -52,6 +53,7 @@ export class LoginPage implements OnInit { private WsChatService: WsChatService, private storage: Storage, public WsChatMethodsService: WsChatMethodsService, + private ChatService: ChatService ) {} ngOnInit() { @@ -130,6 +132,7 @@ export class LoginPage implements OnInit { await this.authService.loginChat(attempt.ChatData.data); await this.authService.loginToChatWs(); + this.ChatService.setheader() } @@ -156,6 +159,7 @@ export class LoginPage implements OnInit { if(attempt.ChatData) { await this.authService.loginChat(attempt.ChatData.data); await this.authService.loginToChatWs(); + this.ChatService.setheader() } this.getToken(); diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 6d402df58..70978415c 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -360,24 +360,30 @@ export class ChatService { } refreshtoken() { - this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); - let options = { - headers: this.headers - }; - return this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).subscribe(async res => { - let data = { - status: res['status'], - data: { - userId: res['data'].userId, - authToken: res['data'].authToken + + if(this.headers) { + this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); + let options = { + headers: this.headers + }; + return this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).subscribe(async res => { + let data = { + status: res['status'], + data: { + userId: res['data'].userId, + authToken: res['data'].authToken + } } - } - SessionStore.user.ChatData = data - SessionStore.save() + SessionStore.user.ChatData = data + SessionStore.save() + this.setheader() + // console.log(res) + // console.log(SessionStore.user.ChatData) + }); + } else { this.setheader() - // console.log(res) - // console.log(SessionStore.user.ChatData) - }); + } + } } diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 58b1211e1..483e86441 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,7 +49,7 @@
{{msg.u.name}} {{msg.duration}} - {{msg._id}} +
From bc85eb6e1a0520b0837676055495df09ef33b5bb Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 22 Jul 2022 16:07:25 +0100 Subject: [PATCH 5/9] dont open document on delete message --- src/app/shared/chat/messages/messages.page.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index f5fd8e696..705e3445f 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -445,15 +445,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } else { - var str = msg.attachments[0].image_url; - str = str.substring(1, ((str.length) - 1)); + // var str = msg.attachments[0].image_url; + // str = str.substring(1, ((str.length) - 1)); - const encodedData = btoa(str); + // const encodedData = btoa(str); - let file = this.base64toBlob(encodedData, 'application/pdf') - let fileURL = URL.createObjectURL(file) + // let file = this.base64toBlob(encodedData, 'application/pdf') + // let fileURL = URL.createObjectURL(file) - window.open(fileURL); + // window.open(fileURL); } } From f0c8de79f2d7ff1919d3bf6aca09087e0deaa69d Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 22 Jul 2022 17:15:32 +0100 Subject: [PATCH 6/9] remove duplicate --- src/app/services/chat/message.service.ts | 2 +- src/app/services/chat/room.service.ts | 30 +++++++++++++++++-- .../shared/chat/messages/messages.page.html | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index a2603d28c..17c28b795 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -77,7 +77,7 @@ export class MessageService { this.ts = ts this.u = u || { name: this.usernameToDisplayName(SessionStore.user.UserName), username: SessionStore.user.UserName, _id: ""} this.t = t - this._id = _id + this._id = _id || "" this._updatedAt = _updatedAt || new Date().getTime() this.file = file this.temporaryData = temporaryData diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 2104ed689..310361ec0 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -530,9 +530,9 @@ export class RoomService { this.message= '' + this.messagesLocalReference.push(localReference) const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline}) - this.messagesLocalReference.push(localReference) await message.addMessageDB() message.send() @@ -822,7 +822,33 @@ export class RoomService { wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory - this.messages.push(wewMessage) + + let found; + + if(wewMessage.localReference != null) { + found = this.messages.find((MessageService, index) => { + if ( MessageService.localReference == wewMessage.localReference ) { + return true + } else { + return false + } + }) + } else { + found = this.messages.find((MessageService, index) => { + if ( MessageService._id == wewMessage._id) { + return true + } else { + return false + } + }) + } + + + if (!found) { + this.messages.push(wewMessage) + return wewMessage + } + return wewMessage } diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 483e86441..58b1211e1 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,7 +49,7 @@
{{msg.u.name}} {{msg.duration}} - + {{msg._id}}
From 341be0060e4d282ddf374457bb1c0bc9edacc8a1 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 25 Jul 2022 12:29:34 +0100 Subject: [PATCH 7/9] Improve chat list --- src/app/pages/chat/chat.page.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 9aa2f37b2..f5e5315ce 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -322,7 +322,6 @@ export class ChatPage implements OnInit { async setIntervenient(data) { this.taskParticipants = removeDuplicate(data) - } async setIntervenientCC(data) { @@ -341,12 +340,11 @@ export class ChatPage implements OnInit { } onSegmentChange() { - //this.load(); + this.wsChatMethodsService.getAllRooms(); } doRefresh(event) { setTimeout(() => { - //this.load(); event.target.complete(); }, 1000); } From 4e387c9f9394f34cef2d3519dc5df4cab9c28d51 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 25 Jul 2022 14:48:28 +0100 Subject: [PATCH 8/9] remove duplicate --- src/app/services/chat/message.service.ts | 2 +- src/app/services/chat/room.service.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 17c28b795..c0ee74133 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -310,7 +310,7 @@ export class MessageService { async addMessageDB() { if(!this.addToDb) { - this.addToDb= true + this.addToDb = true const message = this.getChatObj() delete message.id diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 310361ec0..4b16880ed 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -237,18 +237,20 @@ export class RoomService { let IncomingChatMessageArgs = IncomingChatMessage.fields.args[0] let ChatMessage : ChatMessageInterface = this.fix_updatedAt(IncomingChatMessageArgs) - if(!this.messagesLocalReference.includes(ChatMessage.localReference)) { + const allMessageIds = this.messages.map((e)=> e._id); + + if(!this.messagesLocalReference.includes(ChatMessage.localReference) && !allMessageIds.includes(ChatMessage?._id)) { this.messagesLocalReference.push(ChatMessage.localReference); - const message = await this.prepareCreate({message: ChatMessage, save: true}) + const message = await this.prepareCreate({message: ChatMessage, save: true}); message.messageSend = true - this.lastMessage = message - this.calDateDuration(ChatMessage._updatedAt) + this.lastMessage = message; + this.calDateDuration(ChatMessage._updatedAt); if (message.t == 'r') { - this.name = message.msg + this.name = message.msg; } if(this.isSenderIsNotMe(ChatMessage)) { @@ -739,10 +741,10 @@ export class RoomService { await this.messages.forEach( async (message, index) => { - if(message._id) { + if(message._id) { if(message.viewed.length == 0) { - this.messages[index].viewed = membersIds - this.messages[index].received = membersIds + this.messages[index].viewed = membersIds; + this.messages[index].received = membersIds; await this.messages[index].save() } From 1e3b4c30280743e0a4f4150cf2b39c01715bca2b Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 26 Jul 2022 14:11:12 +0100 Subject: [PATCH 9/9] improve --- src/app/pages/chat/chat.page.ts | 1 - src/app/pages/chat/group-messages/group-messages.page.ts | 1 - src/app/pages/chat/messages/contacts/contacts.page.ts | 2 -- src/app/pages/chat/messages/messages.page.ts | 2 -- src/app/services/chat/room.service.ts | 8 +++----- src/app/shared/chat/messages/messages.page.html | 1 - 6 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index f5e5315ce..7af4f7fa5 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -357,7 +357,6 @@ export class ChatPage implements OnInit { }); } - getDirectMessagesDB() { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { this.storageservice.get("rooms").then((rooms) =>{ diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index 092058387..980185f06 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -150,7 +150,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }) - //this.loadFiles(); } setStatus(status: string) { diff --git a/src/app/pages/chat/messages/contacts/contacts.page.ts b/src/app/pages/chat/messages/contacts/contacts.page.ts index 1c4bc1b2b..2e0777fdf 100644 --- a/src/app/pages/chat/messages/contacts/contacts.page.ts +++ b/src/app/pages/chat/messages/contacts/contacts.page.ts @@ -104,7 +104,6 @@ export class ContactsPage implements OnInit { this.room = res['room']; - await this.WsChatMethodsService.getAllRooms(); this.getDirectMessage(this.room._id); }); @@ -148,7 +147,6 @@ export class ContactsPage implements OnInit { /* this.getDirectMessage(this.room._id); */ - /* const modal = await this.modalController.create({ component: MessagesPage, cssClass: 'group-messages', diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 9299ace5c..febeaddaa 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -125,7 +125,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private sqlservice: SqliteService, public wsChatMethodsService: WsChatMethodsService, private AttachmentsService: AttachmentsService, - private CameraService: CameraService, private processesService: ProcessesService, private storage: Storage, @@ -149,7 +148,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } - this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({}) this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.openRoom(this.roomId) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 4b16880ed..1969b7d7f 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -315,19 +315,17 @@ export class RoomService { this.otherUserType = args[1] this.readAllMessage() - // - // alert(JSON.stringify(args)) + } else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') { this.readAllMessage() } else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') { - // alert('delete') - // + this.deleteMessage(args[1]?.method?._id) } else { - // alert('miss') + } diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 58b1211e1..66482dde6 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,7 +49,6 @@
{{msg.u.name}} {{msg.duration}} - {{msg._id}}