diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index f6dbe7daf..b3e1bda3f 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -102,7 +102,7 @@ export class HomePage implements OnInit { window['inactivity/function'] = () => { - if (window.location.pathname != '/inactivity') { + if (window.location.pathname != '/inactivity' && window.location.pathname != '/') { document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()); document.querySelectorAll('.popover-viewport').forEach((e: any) => e.remove()); @@ -112,9 +112,11 @@ export class HomePage implements OnInit { SessionStore.setUrlBeforeInactivity(pathname) if (this.platform.is('mobileweb')) { - this.router.navigate(['/inactivity']); + // this.router.navigate(['/inactivity']); + window.location.pathname = '/inactivity' } else { - this.router.navigate(['/']); + // this.router.navigate(['/']); + window.location.pathname = '/' } } diff --git a/src/app/modals/profile/profile.page.ts b/src/app/modals/profile/profile.page.ts index 257b64fa3..912873482 100644 --- a/src/app/modals/profile/profile.page.ts +++ b/src/app/modals/profile/profile.page.ts @@ -59,7 +59,6 @@ export class ProfilePage implements OnInit { ngOnInit() { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - // console.log('Notifications not supported') this.getNotificationData(); } else { this.getNotificationData(); @@ -78,8 +77,6 @@ export class ProfilePage implements OnInit { async getNotificationData() { - console.log('profile',this.storageservice.key("Notifications")) - const keyExist = await this.storageservice.keyExist("Notifications") if(keyExist) { @@ -225,9 +222,8 @@ export class ProfilePage implements OnInit { setTimeout(() => { // alert('logout') this.router.navigateByUrl('/auth', { replaceUrl: true }); - this.router.navigate(['/auth']); - setTimeout(() =>{ + setTimeout(() => { if(this.logoutOut == false) { window.location.pathname = '/auth' } diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index fc116a9a2..8edea3bb2 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -3,7 +3,6 @@ import { environment } from 'src/environments/environment' const { ArrayField, JsonField} = models.indexedDB.fields export class MessageModel extends models.Model { - channels = ArrayField() mentions = ArrayField() msg = models.CharField() @@ -17,27 +16,33 @@ export class MessageModel extends models.Model { offline = models.BooleanField() viewed = ArrayField({blank:true}) received = ArrayField({blank:true}) - localReference = models.CharField({blank:true}) + localReference = models.CharField({blank:true, unique: true}) attachments = ArrayField({blank:true}) file = JsonField({blank:true}) + async getAttachments() { + const _attachments = await attachments.filter({id: this['id']}) + return _attachments + } +} + +export class attachments extends models.Model { + message = models.OneToOneField({model:MessageModel}) + attachments = ArrayField({default:[]}) } export class DeleteMessageModel extends models.Model { - messageId = models.CharField() rid = models.CharField() u = JsonField() needToReceiveBy = ArrayField() } - - models.register({ databaseName: 'chat-storage'+environment.version.lastCommitNumber, type: 'indexedDB', - version: 5, - models: [MessageModel, DeleteMessageModel] + version: 10, + models: [MessageModel, DeleteMessageModel, attachments] }) diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index dc8a49e1f..274e63b16 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -64,7 +64,7 @@ - +
Tentar
@@ -103,7 +103,7 @@ - +
Tentar
@@ -157,7 +157,7 @@ - +
Tentar
diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 427b039c6..e58d98f8f 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -61,7 +61,7 @@ - +
Tentar
@@ -98,7 +98,7 @@ - +
Tentar
@@ -164,7 +164,7 @@ - +
Tentar
diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.ts b/src/app/pages/gabinete-digital/gabinete-digital.page.ts index cee2c2fae..7b8e1226c 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.ts +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.ts @@ -206,7 +206,7 @@ export class GabineteDigitalPage implements OnInit { }) this.backgroundservice.registerBackService('Online', () => { - this.loadAllProcesses(); + // this.loadAllProcesses(); }); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 20287d5a9..d0c0b6d6f 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -116,9 +116,10 @@ export class AuthService { SessionStore.save() this.RochetChatConnectorService.setStatus('online') - + window['RochetChatConnectorService'] = this.RochetChatConnectorService setTimeout(() => { this.ChatSystemService.getAllRooms(); + this.RochetChatConnectorService.setStatus('online') }, 200); diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index cdef8f659..89e27fede 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -395,21 +395,27 @@ export class ChatService { if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) { this.RochetChatConnectorService.registerCallback({ + requestId: 'refreshtoken', type: 'reConnect', - funx: async ()=> { + funx: async () => { + this.resetTimer(); await this.refreshtoken(); - + + return true } }) } else { - this.resetTimer(); - await this.refreshtoken(); + + setTimeout(async () => { + this.resetTimer(); + await this.refreshtoken(); + }, 60000) + } } - } else if(!SessionStore.user.ChatData) { // do nothing } else if (!this.headers) { @@ -437,7 +443,6 @@ export class ChatService { } - functionTimer = null; timerEventTriggerDate = null timerEventTriggerDateLastUpdate = null @@ -447,8 +452,15 @@ export class ChatService { this.timerEventTriggerDate = new Date(+new Date() + 60000*15); this.functionTimer = setTimeout(() => { - this.refreshtoken(); - }, 60000 * 5); // time is in milliseconds + + if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) { + this.refreshtoken(); + } else { + this.resetTimer() + } + + }, 60000 * 15); // time is in milliseconds + } } diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index d66e1f5e6..07c820cfb 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -283,11 +283,12 @@ export class ChatSystemService { this.loadingWholeList = false await this.storage.set('Rooms', rooms); + this.sortRoomList() + setTimeout(() => { this.sortRoomList() }, 1000) - setTimeout(() => { this.sortRoomList() }, 10000) @@ -480,19 +481,19 @@ export class ChatSystemService { */ private getUserStatus(id?:string) { - this.RochetChatConnectorService.getUserStatus((d) => { + this.RochetChatConnectorService.getUserStatus(async (d) => { + const userId = d.fields.args[0][0] const username = d.fields.args[0][1] const statusNum = d.fields.args[0][2] - const statusText = this.statusNumberToText(statusNum) - this.users.forEach((user, index) => { - if(user.username == username) { - this.users[index].status = statusText + for ( const user of this.users) { + if(user._id == userId) { + user.status = statusText } - }) + } }) } diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 9943312a5..6a9610ea6 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -12,8 +12,8 @@ import { HttpEventType } from '@angular/common/http'; import { AttachmentsService } from 'src/app/services/attachments.service'; import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service'; import { ChatSystemService } from './chat-system.service'; -import { resolve } from 'dns'; -import { async } from '@angular/core/testing'; +import { v4 as uuidv4 } from 'uuid' + @Injectable({ providedIn: 'root' }) @@ -38,7 +38,6 @@ export class MessageService { _updatedAt file attachments - offline = true displayType = '' temporaryData: any = {} hasFile = false @@ -50,8 +49,8 @@ export class MessageService { from: 'Offline'|'History'|'stream'| 'send' duration = '' localReference = null - viewed = [] - received = [] + viewed: string[] = [] + received: string[]= [] addToDb = false messageSend = false @@ -73,7 +72,7 @@ export class MessageService { private ChatSystemService: ChatSystemService) { } - setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) { + setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) { this.channels = channels || [] this.mentions = mentions || [] @@ -102,11 +101,9 @@ export class MessageService { this.received = [...new Set([...received,...this.received])]; if(!this.ts) { - this.offline = true this.messageSend = false } else { this.messageSend = true - this.offline = false } if (this.file) { @@ -137,6 +134,34 @@ export class MessageService { this.calDateDuration() } + + get offline () { + if(!this._id) { + return true + } + + if(!this.ts) { + return true + } + + return false + } + + /** + * Message is on the server + */ + get online() { + return !this.offline + } + + /** + * if Message is already saved on database + */ + get save() { + return this.id != '' + } + + private usernameToDisplayName(username) { try { @@ -150,7 +175,6 @@ export class MessageService { } async send(): Promise { - if(this.messageSend) { return new Promise((resolve, reject) => { resolve('solve') @@ -183,7 +207,7 @@ export class MessageService { this.RochetChatConnectorService.registerCallback({ type: 'reConnect', - funx: async ()=> { + funx: async () => { this.send().catch((error) =>{ console.error(error) }) @@ -250,7 +274,6 @@ export class MessageService { } if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) { - // console.log('online send') if(this.msg == '') { if(this.sendAttempt >= 4) { @@ -259,7 +282,6 @@ export class MessageService { ChatMessage = ChatMessage.message.result clearTimeout(this.functionTimer); - this.messageSend = true this.redefinedMessage(ChatMessage) } @@ -270,12 +292,12 @@ export class MessageService { } } else { + this.RochetChatConnectorService.send(params).then( (ChatMessage: any) => { ChatMessage = ChatMessage.message.result clearTimeout(this.functionTimer); - this.messageSend = true this.redefinedMessage(ChatMessage) } @@ -286,7 +308,6 @@ export class MessageService { } this.functionTimer = setTimeout(() => { - this.RochetChatConnectorService.registerCallback({ type:'Onmessage', key:'ping-pong-message', @@ -300,7 +321,7 @@ export class MessageService { return true } - this.save() + this.saveChanges() } }) @@ -312,7 +333,6 @@ export class MessageService { this.RochetChatConnectorService.registerCallback({ type: 'reConnect', funx: async ()=> { - this.send().catch((error) =>{ console.error(error) }) @@ -329,11 +349,18 @@ export class MessageService { const message = this.getChatObj() this.manualRetry = false + this.messageSend = true ChatMessage = Object.assign(message, ChatMessage) this.setData(ChatMessage) - await this.save() + const roomObject = this.ChatSystemService.getRoomById(this.rid) + const users = roomObject.getUsersByStatus('online') + for(const user of users) { + this.addReceived(user._id) + } + + await this.saveChanges() } downloadFileMsg() { @@ -363,7 +390,7 @@ export class MessageService { } // save the changes to the storage - this.save() + this.saveChanges() this.downloadLoader = false; this.downloadAttachments = true this.downloadAttachmentsTemp++; @@ -384,30 +411,55 @@ export class MessageService { async delateStatusFalse() { this.delate = true - this.save() + this.saveChanges() + } + + addViewed(id: string) { + if(this.messageOwner()) { + let found = this.viewed.find((UserId) => UserId == id) + + if(!found) { + this.viewed.push(id) + return true + } + } + + return false + } + + addReceived(id: string) { + if(this.messageOwner()) { + let found = this.received.find((UserId) => UserId == id) + + if(!found) { + this.received.push(id) + return true + } + } + return false } async delateDB() { - const message = await MessageModel.get({_id: this._id}) + const message = await MessageModel.get({id: this.id}) await message.delete() } isSenderIsNotMe(ChatMessage) { - return SessionStore.user.UserName != ChatMessage.u.username + return SessionStore.user.ChatData.data.userId != ChatMessage.u._id } - messageOwnerById(id) { - return SessionStore.user.UserName != this.u.username + messageOwner() { + return SessionStore.user.ChatData.data.userId == this.u._id } private getChatObj() { return { channels: this.channels, mentions: this.mentions, - //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.UserName), + // msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.UserName), sendAttempt: this.sendAttempt, msg:this.msg, rid: this.rid, @@ -427,8 +479,10 @@ export class MessageService { } } + earlySave = false + async addMessageDB() { - if(!this.addToDb) { + if(!this.addToDb && this.save) { this.addToDb = true const message = this.getChatObj() @@ -436,15 +490,39 @@ export class MessageService { const createdMessage = await MessageModel.create(message) this.id = createdMessage.id + + if(this.earlySave) { + this.saveChanges(); + } } } - async save() { - const message = this.getChatObj() + async saveChanges() { + + + if(this.save) { + const message = this.getChatObj() + let a + + if (this.localReference) { + a = await MessageModel.get({localReference: this.localReference}) + } else if (this._id) { + a = await MessageModel.get({id: this.id}) + } else if(this.id) { + a = await MessageModel.get({_id: this._id}) + } + + for( const [name, value] of Object.entries(message)) { + a[name] = value + } + + await a.save() + + } else { + this.earlySave = true + console.log('save change to early') + } - - await MessageModel.update(message) - } decryptMessage() { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index ee94368b7..2d76dfcec 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -23,6 +23,7 @@ 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' +import * as FIFOProcessQueue from 'fifo-process-queue'; @Injectable({ providedIn: 'root' @@ -47,9 +48,9 @@ export class RoomService { message = '' lastMessageTxt = '' userThatIsTyping = '' - messagesLocalReference = [] - members = [] - membersExcludeMe = [] + messagesLocalReference: string[] = [] + members: chatUser[] = [] + membersExcludeMe: chatUser[] = [] u sessionStore = SessionStore countDownTime = '' @@ -186,9 +187,13 @@ export class RoomService { if(!this.isGroup) { for(let user of this.ChatSystemService.users) { - if(this.membersExcludeMe[0]._id == user._id) { - return user.status + + for (const members of this.membersExcludeMe) { + if(members._id == user._id) { + return user.status + } } + } } @@ -260,71 +265,7 @@ export class RoomService { "stream-room-messages", async (IncomingChatMessage:IncomingChatMessage) => { - let IncomingChatMessageArgs = IncomingChatMessage.fields.args[0] - let ChatMessage : ChatMessageInterface = this.fix_updatedAt(IncomingChatMessageArgs) - - 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}); - message.messageSend = true - message.from = 'stream' - message.loadHistory = this.hasLoadHistory - - this.lastMessage = message; - this.calDateDuration(ChatMessage._updatedAt); - - if (message.t == 'r') { - this.name = message.msg; - } - - if(this.isSenderIsNotMe(ChatMessage)) { - this.NativeNotificationService.sendNotificationChat({ - message: message.msg, - title: this.name - }); - } - - if(this.hasLoadHistory == true) { - await message.addMessageDB() - } - - if(this.chatOpen == false) { - this.messageUnread = true - } - - setTimeout(()=>{ - this.scrollDown() - }, 50) - } else { - - this.messages.forEach((message, index)=> { - if(message.localReference == ChatMessage.localReference) { - - const membersIds = this.membersExcludeMe.map((user)=> user._id) - - this.getAllUsers().forEach( async (users) => { - - if(membersIds.includes(users._id)) { - - if(users.status != 'offline') { - - this.messages[index].received.push(users._id) - - setTimeout(() => { - message.save() - }, 150) - - } - } - }); - } - }) - - } + this.appendReceiveMessage.push(IncomingChatMessage) } ) @@ -334,9 +275,7 @@ export class RoomService { if(message.fields.eventName == this.id+'/'+'typing') { const args = message.fields.args - - - + if (typeof args[1] != 'object') { this.userThatIsTyping = this.usernameToDisplayName(args[0]) @@ -350,7 +289,6 @@ export class RoomService { this.readAllMessage() } else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') { - this.deleteMessage(args[1]?.method?._id) } else { @@ -363,6 +301,68 @@ export class RoomService { }) } + appendReceiveMessage = FIFOProcessQueue(async (IncomingChatMessage:IncomingChatMessage, done) => { + + let IncomingChatMessageArgs = IncomingChatMessage.fields.args[0] + let ChatMessage : ChatMessageInterface = this.fix_updatedAt(IncomingChatMessageArgs) + + + let found = this.findMessageBy_id(ChatMessage._id) || + this.findMessageBy_localReference(ChatMessage?.localReference) + // || await this.findMessageInDBByData({_id:ChatMessage._id, localReference:ChatMessage.localReference }) + + if(!found) { + + const message = await this.prepareCreate({message: ChatMessage, save: true}); + this.registerSendMessage(message) + + message.from = 'stream' + message.loadHistory = this.hasLoadHistory + + this.lastMessage = message; + this.calDateDuration(ChatMessage._updatedAt); + + if (message.t == 'r') { + this.name = message.msg; + } + + if(this.isSenderIsNotMe(ChatMessage)) { + this.NativeNotificationService.sendNotificationChat({ + message: message.msg, + title: this.name + }); + } + + if(this.hasLoadHistory == true) { + await message.addMessageDB() + } + + if(this.chatOpen == false) { + this.messageUnread = true + } + + setTimeout(()=>{ + this.scrollDown() + }, 50) + + } + + setTimeout(() => { + done() + }, 5) + }) + + getUsersByStatus(status: 'offline' | 'online') { + + return this.getAllUsers().filter((user => { + for(const member of this.membersExcludeMe) { + if(user._id == member._id && user.status == status) { + return true + } + } + })) + + } getRoomMembersIds(): string[] { try { @@ -528,7 +528,7 @@ export class RoomService { this.RochetChatConnectorService.deleteMessage(msgId).then(async() => { message.delateRequest = true - await message.save(); + await message.saveChanges(); this.deleteMessage(msgId); }) @@ -564,8 +564,8 @@ export class RoomService { this.message= '' - this.messagesLocalReference.push(localReference) const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline}) + this.registerSendMessage(message) if(this.hasLoadHistory == true) { await message.addMessageDB() @@ -574,7 +574,6 @@ export class RoomService { message.send() message.from = 'send' message.loadHistory = this.hasLoadHistory - if (environment.chatOffline) { @@ -589,6 +588,24 @@ export class RoomService { } + /** + * Register all send message so that + * the incoming message wont be confuse to + * other user the localReference is the identifier + */ + registerSendMessage(message: MessageService) { + this.messagesLocalReference.push(message.localReference) + } + + + localReferenceExist(message: MessageService) { + for( const localReference of this.messagesLocalReference) { + if(localReference == message?.localReference) { + return true + } + } + return false + } sendTyping(text:string = this.message) { @@ -660,8 +677,11 @@ export class RoomService { return JSON.parse(str); } + + restoreOnce = false async restoreMessageFromDB() { - if(environment.chatOffline) { + if(environment.chatOffline && this.restoreOnce == false) { + this.restoreOnce = true const messages = await MessageModel.filter({rid:this.id}).execute() @@ -669,31 +689,24 @@ export class RoomService { const wewMessage = await this.simplePrepareMessage(ChatMessage) wewMessage.from = 'Offline' wewMessage.loadHistory = this.hasLoadHistory - if(wewMessage.offline == false) { - const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage}) - if(message) { - message.from = 'Offline' - message.loadHistory = this.hasLoadHistory - message?.decryptMessage() - } + const message = await this.prepareCreate({message:ChatMessage}) + message.from = 'Offline' + message.loadHistory = this.hasLoadHistory + message?.decryptMessage() } else { + + const offlineMessage = await this.prepareCreate({message:ChatMessage}) - const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage}) - - if(offlineMessage) { - offlineMessage.from = 'Offline' - offlineMessage.loadHistory = this.hasLoadHistory - - this.messagesLocalReference.push(offlineMessage.localReference) - - offlineMessage?.decryptMessage() - offlineMessage.send() - - } + offlineMessage.from = 'Offline' + offlineMessage.loadHistory = this.hasLoadHistory + this.registerSendMessage(offlineMessage) + offlineMessage?.decryptMessage() + offlineMessage.send() + // console.log('send offline', ChatMessage) } @@ -710,6 +723,7 @@ export class RoomService { } // runs onces only + async loadHistory({limit = 1000, forceUpdate = false }) { if(forceUpdate == false) { @@ -718,23 +732,27 @@ export class RoomService { } } - if(this.restoreFromOffline == false) { - this.restoreFromOffline = true - await this.restoreMessageFromDB() - } - - const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit) if(chatHistory?.result?.messages) { const messagesId = this.messages.map((message)=> message._id) + const users = this.getUsersByStatus('online') + for(let message of chatHistory.result.messages.reverse()) { if (!messagesId.includes(message._id)) { - const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); - if(messagesToSave) { + const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message}); + if(messagesToSave != null) { + + messagesToSave.received = users.map((user) => user._id) messagesToSave.addMessageDB() + + // console.log('add history', message) + } else { + // console.log('exit') } + } else { + // console.log('exit') } } @@ -744,28 +762,6 @@ export class RoomService { }, 50) this.hasLoadHistory = true - this.messageReorder(); - } - - } - - async messageReorder() { - const reorderMessage: MessageService[] = this.messages.filter((message) => - message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory - ); - - - let i = 0 - for(let message of this.messages) { - if(message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory) { - this.messages.splice(i, 1) - } - i++; - } - - for(let message of reorderMessage) { - this.messages.push(message) - message.addMessageDB() } } @@ -774,60 +770,11 @@ export class RoomService { async readAllMessage() { - - const membersIds = this.membersExcludeMe.map((user)=> user._id) - - - await this.messages.forEach( async (message, index) => { - if(message._id) { - if(message.viewed.length == 0) { - this.messages[index].viewed = membersIds; - this.messages[index].received = membersIds; - - await this.messages[index].save() - } - } - }) + this.ViewedMessageService.requestReadAll(this) } - /** - * @description find or create message - * @param message - * @param save - * @returns - */ - async prepareMessage({message, save = true, redefined = false}): Promise { - message = this.fix_updatedAt(message) - - const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService) - wewMessage.setData(message) - wewMessage.loadHistory = this.hasLoadHistory - - let foundIndex; - - const found = this.messages.find((MessageService, index) => { - if (MessageService._id == message._id) { - foundIndex = index - return true - } else { - return false - } - }) - - if(save) { - if (!found) { - this.messages.push(wewMessage) - return wewMessage - } - } else if(foundIndex) { - return this.messages[foundIndex] - } else { - return wewMessage - } - - } async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) { let foundIndex; @@ -849,48 +796,18 @@ export class RoomService { } - /** - * @description find or create message - * @param message - * @param save - * @returns - */ - async prepareCreate({message, save = true}): Promise { + + + async prepareCreate({message, save = true}): Promise { message = this.fix_updatedAt(message) const wewMessage = new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this.ChatSystemService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory - - - 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 - } + this.messages.push(wewMessage) return wewMessage - } @@ -903,40 +820,62 @@ export class RoomService { return wewMessage } + + private findMessageBy_id (id) { + for( let m of this.messages) { + if(m._id == id) { + return true + } + } + + return false + } + + private findMessageBy_localReference (localReference) { + for( let m of this.messages) { + if(m.localReference == localReference) { + return true + } + } + + return false + } + + private async findMessageInDBByLocalReference({localReference}) { + const a = await MessageModel.get({localReference: localReference}) + + return typeof a.id == 'number' + } + + private async findMessageInDBByLocalId({_id}) { + const a = await MessageModel.get({_id: _id}) + return typeof a.id == 'number' + } + + private async findMessageInDBByData({localReference, _id}) { + + // console.log('look') + const a = await MessageModel.filter({localReference: localReference}) + if(a.length >= 1) { + // console.log('localReference', localReference) + return true + } + + const c = await MessageModel.filter({_id: _id}) + if(c.length >= 1) { + // console.log('_id', _id) + return true + } + + // console.log('look not found') + return false + } + async prepareMessageCreateIfNotExist({message}) { message = this.fix_updatedAt(message) - let foundIndex; - const found = this.messages.find((MessageService, index) => { - if (MessageService._id == message._id || - MessageService.localReference == message.localReference ) { - foundIndex = index - return true - } else { - return false - } - }) - - if (!found) { - const wewMessage = this.simplePrepareMessage(message) - this.messages.push(wewMessage) - return wewMessage - } else { - return null - } - } - - - async prepareMessageCreateIfNotExist_iD({message}) { - message = this.fix_updatedAt(message) - - const found = this.messages.find((MessageService, index) => { - if (MessageService._id == message._id) { - return true - } else { - return false - } - }) + let found = await this.findMessageBy_id(message._id) || this.findMessageBy_localReference(message.localReference) + // || await this.findMessageInDBByData({_id:message._id, localReference:message.localReference }) if (!found) { const wewMessage = this.simplePrepareMessage(message) diff --git a/src/app/services/chat/viewed-message.service.ts b/src/app/services/chat/viewed-message.service.ts index bbc5e1582..779087eb5 100644 --- a/src/app/services/chat/viewed-message.service.ts +++ b/src/app/services/chat/viewed-message.service.ts @@ -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}) + } } diff --git a/src/app/services/inativity.service.ts b/src/app/services/inativity.service.ts index b916e493d..b118ce180 100644 --- a/src/app/services/inativity.service.ts +++ b/src/app/services/inativity.service.ts @@ -11,28 +11,28 @@ export class InativityService { private router: Router, ) { - // var time; - // window.onload = resetTimer; - // window.onmousemove = resetTimer; - // window.onmousedown = resetTimer; // catches touchscreen presses as well - // window.ontouchstart = resetTimer; // catches touchscreen swipes as well - // window.onclick = resetTimer; // catches touchpad clicks as well - // window.onkeydown = resetTimer; - // window.addEventListener('scroll', resetTimer, true); // improved; see comments + var time; + window.onload = resetTimer; + window.onmousemove = resetTimer; + window.onmousedown = resetTimer; // catches touchscreen presses as well + window.ontouchstart = resetTimer; // catches touchscreen swipes as well + window.onclick = resetTimer; // catches touchpad clicks as well + window.onkeydown = resetTimer; + window.addEventListener('scroll', resetTimer, true); // improved; see comments - // function userIsNotActive() { - // // your function for too long inactivity goes here - // // SessionStore.setInativity(false) - // // alert('go out') - // try { - // // window['inactivity/function']() - // } catch (error) {} + function userIsNotActive() { + // your function for too long inactivity goes here + SessionStore.setInativity(false) + // alert('go out') + try { + window['inactivity/function']() + } catch (error) {} - // } + } - // function resetTimer() { - // clearTimeout(time); - // time = setTimeout(userIsNotActive, 60000 * 1); // time is in milliseconds - // } + function resetTimer() { + clearTimeout(time); + time = setTimeout(userIsNotActive, 60000 * 5); // time is in milliseconds + } } } diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index 6c21a23f3..f41950b82 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -60,7 +60,7 @@ - +
Tentar
@@ -106,7 +106,7 @@ - +
Tentar
@@ -161,7 +161,7 @@ - +
Tentar
diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 07894481c..584c6c4e3 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.u.name}} {{msg.duration}}
@@ -59,9 +59,10 @@ - + + - +
Tentar
@@ -81,7 +82,7 @@
- {{msg.u.name}} + {{msg.u.name}} {{msg.duration}}
@@ -103,9 +104,9 @@
image - + {{ msg.viewed }} - +
Tentar
@@ -169,9 +170,9 @@
- + {{ msg.viewed }} - +
Tentar
@@ -189,7 +190,7 @@ Apagou a mensagem
- {{msg.u.name}} criou esta reunião
+ {{msg.u.name}} criou esta reunião

diff --git a/src/app/shared/chat/messages/messages.page.scss b/src/app/shared/chat/messages/messages.page.scss index 9349b4c69..388f21c6c 100644 --- a/src/app/shared/chat/messages/messages.page.scss +++ b/src/app/shared/chat/messages/messages.page.scss @@ -397,4 +397,11 @@ ion-footer { padding: 6px; border-radius: 10px; cursor: pointer; +} + +.red-top { + border-top: 1px solid red !important; +} +.red { + color: red !important; } \ No newline at end of file diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index ade54d692..f74cb4955 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -144,6 +144,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.deleteRecording() + + // this.ChatSystemService.getDmRoom(this.roomId).deleteAll() + } async ChatMessageDebuggingPage() { diff --git a/src/assets/icon/governoangola_A.png b/src/assets/icon/governoangola_A.png new file mode 100644 index 000000000..9c360396a Binary files /dev/null and b/src/assets/icon/governoangola_A.png differ diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 65fe42205..56998ebab 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,19 +1,19 @@ import { versionData } from '../../version/git-version' export const environment = { // apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', - apiURL: 'https://gd-api.oapr.gov.ao/api/', - //apiURL: 'https://gdapi-dev.dyndns.info/GabineteDigital.Services/V5/api/', + //apiURL: 'https://gd-api.oapr.gov.ao/api/', + apiURL: 'https://gdapi-dev.dyndns.info/GabineteDigital.Services/V5/api/', // apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', // apiChatUrl: 'http://192.168.0.29:3000/api/v1/', // apiWsChatUrl: 'wss://192.168.0.29:3000/websocket', - apiChatUrl: 'https://gd-chat.oapr.gov.ao/api/v1/', - apiWsChatUrl: 'wss://gd-chat.oapr.gov.ao/websocket', - /* apiChatUrl: 'https://gdchat-dev.dyndns.info/api/v1/', - apiWsChatUrl: 'wss://gdchat-dev.dyndns.info/websocket', */ + //apiChatUrl: 'https://gd-chat.oapr.gov.ao/api/v1/', + //apiWsChatUrl: 'wss://gd-chat.oapr.gov.ao/websocket', + apiChatUrl: 'https://gdchat-dev.dyndns.info/api/v1/', + apiWsChatUrl: 'wss://gdchat-dev.dyndns.info/websocket', production: true, domain: 'paulo.pinto@gabinetedigital.local', defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto@gabinetedigital.local - defaultuserpwd: 'M@p2022', //tabteste@006, + defaultuserpwd: 'tabteste@006', //tabteste@006, chatOffline: true, presidencia: false, version: versionData, diff --git a/src/index.html b/src/index.html index 6460cdd92..dcc59a249 100644 --- a/src/index.html +++ b/src/index.html @@ -56,7 +56,7 @@ - + diff --git a/version/git-version.ts b/version/git-version.ts index dd13a7a05..73dfd8450 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "572ab6db7", - "SHA": "572ab6db7b8cc05e5b32362f48dbad03cc948d52", + "shortSHA": "56c173394", + "SHA": "56c17339455d3377bd2bb274440cb502e780ff8d", "branch": "develop_bitOut-fix", "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Thu Jan 5 12:11:50 2023 +0100'", - "lastCommitMessage": "save", - "lastCommitNumber": "4613", + "lastCommitTime": "'Thu Jan 5 12:18:21 2023 +0100'", + "lastCommitMessage": "merge", + "lastCommitNumber": "4617", "change": "", - "changeStatus": "On branch develop_bitOut-fix\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: src/app/app.module.ts\n\tmodified: src/app/modals/profile/profile.page.html\n\tmodified: src/app/modals/profile/profile.page.ts\n\tmodified: src/app/pages/login/login.page.ts\n\tmodified: src/app/services/notifications.service.ts\n\tmodified: src/app/shared/header/header.page.ts\n\tmodified: src/environments/environment.ts\n\tmodified: src/main.ts", + "changeStatus": "On branch develop_bitOut-fix\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/home/home.page.ts\n\tmodified: src/app/modals/profile/profile.page.ts\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/app/pages/chat/group-messages/group-messages.page.html\n\tmodified: src/app/pages/chat/messages/messages.page.html\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.ts\n\tmodified: src/app/services/auth.service.ts\n\tmodified: src/app/services/chat.service.ts\n\tmodified: src/app/services/chat/chat-system.service.ts\n\tmodified: src/app/services/chat/message.service.ts\n\tmodified: src/app/services/chat/room.service.ts\n\tmodified: src/app/services/chat/viewed-message.service.ts\n\tmodified: src/app/services/inativity.service.ts\n\tmodified: src/app/shared/chat/group-messages/group-messages.page.html\n\tmodified: src/app/shared/chat/messages/messages.page.html\n\tmodified: src/app/shared/chat/messages/messages.page.scss\n\tmodified: src/app/shared/chat/messages/messages.page.ts\n\tnew file: src/assets/icon/governoangola_A.png\n\tmodified: src/environments/environment.ts\n\tmodified: src/index.html\n\tmodified: version/git-version.ts", "changeAuthor": "peter.maquiran" } \ No newline at end of file