diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 954089660..6fe433f8a 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -126,6 +126,12 @@ export class HomePage implements OnInit { } + window.addEventListener('storage', (event) => { + // When local storage changes, dump the list to + // the console. + console.log(event); + }); + } goto(url) { diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index 8edea3bb2..2aa6e8069 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -11,6 +11,7 @@ export class MessageModel extends models.Model { ts = JsonField({blank:true}) u = JsonField() _id = models.CharField({blank:true}) + origin = models.CharField({blank:true}) _updatedAt = models.IntegerField() messageSend = models.BooleanField() offline = models.BooleanField() @@ -41,7 +42,7 @@ export class DeleteMessageModel extends models.Model { models.register({ databaseName: 'chat-storage'+environment.version.lastCommitNumber, type: 'indexedDB', - version: 10, + version: 11, models: [MessageModel, DeleteMessageModel, attachments] }) diff --git a/src/app/models/chatMethod.ts b/src/app/models/chatMethod.ts index 73570fa16..56ee9fa79 100644 --- a/src/app/models/chatMethod.ts +++ b/src/app/models/chatMethod.ts @@ -75,6 +75,7 @@ export interface Message { u: U; from: 'Offline'|'History'|'stream'| 'send' t: string; + origin: 'history' | 'stream' | 'local' _updatedAt: ''; mentions: any[]; channels: any[]; diff --git a/src/app/models/message.model.ts b/src/app/models/message.model.ts index 732672370..341262051 100644 --- a/src/app/models/message.model.ts +++ b/src/app/models/message.model.ts @@ -43,6 +43,7 @@ export interface ChatMessageInterface { _updatedAt: number; mentions: any[]; channels: any[]; + origin?: 'history' | 'stream' | 'local' }; diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index 2665c5223..43d891c63 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -93,7 +93,6 @@ -
@@ -114,11 +113,11 @@
- - diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 5926dbdee..83255aa43 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -61,6 +61,9 @@ export class MessageService { downloadAttachmentsTemp = 0; UploadAttachmentsTemp = 0; manualRetry = false + origin: 'history' | 'stream' | 'local' + + rowInstance: MessageModel constructor( private NfService: NfService, @@ -72,7 +75,7 @@ export class MessageService { private ChatSystemService: ChatSystemService) { } - 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) { + 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, origin }:Message) { this.channels = channels || [] this.mentions = mentions || [] @@ -90,6 +93,7 @@ export class MessageService { this.delate = delate this.delateRequest = delateRequest this.sendAttempt = 0 + this.origin = origin if(this.attachments?.length >= 1 && attachments?.length >= 1) { this.attachments[0] = Object.assign(this.attachments[0], attachments[0]) @@ -257,6 +261,7 @@ export class MessageService { } catch (error) { this.uploadingFile = false this.errorUploadingAttachment = true + this.UploadAttachmentsTemp++ console.error('beforeSendAttachment error:', error) } @@ -467,6 +472,7 @@ export class MessageService { u: this.u, _id: this._id, id: this.id, + origin: this.origin, _updatedAt: this._updatedAt, messageSend: this.messageSend, offline: this.offline, @@ -489,6 +495,7 @@ export class MessageService { delete message.id const createdMessage = await MessageModel.create(message) + this.rowInstance = createdMessage this.id = createdMessage.id if(this.earlySave) { @@ -497,8 +504,8 @@ export class MessageService { } } - async saveChanges() { + async getRowInstance () { if(this.save) { const message = this.getChatObj() @@ -516,12 +523,29 @@ export class MessageService { a = await MessageModel.get({id: this.id}) } - if(a) { - for( const [name, value] of Object.entries(message)) { - a[name] = value - } - await a.save() + return a + } + + } + + async saveChanges() { + + if(!this.rowInstance) { + this.rowInstance = await this.getRowInstance() + } + + if(this.save && this.rowInstance) { + const message = this.getChatObj() + + if(!message.id) { + delete message.id } + + for( const [name, value] of Object.entries(message)) { + this.rowInstance[name] = value + } + + await this.rowInstance.save() } else { this.earlySave = true diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index a5a4d20ca..b67bfc32e 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -275,18 +275,25 @@ 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]) this.isTyping = args[1] this.otherUserType = args[1] - this.readAllMessage() + const user = args[0] + if(SessionStore.user.UserName != user) { + this.readAllMessage() + } } else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') { - - this.readAllMessage() + const user = args[0] + + if(SessionStore.user.UserName != user) { + this.readAllMessage() + } + } else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') { this.deleteMessage(args[1]?.method?._id) @@ -295,7 +302,6 @@ export class RoomService { } - } else if (message.fields.eventName == this.id+'/'+'deleteMessage') {} }) @@ -313,6 +319,7 @@ export class RoomService { if(!found) { + ChatMessage.origin = 'stream' const message = await this.prepareCreate({message: ChatMessage, save: true}); this.registerSendMessage(message) @@ -556,7 +563,8 @@ export class RoomService { attachments, file, temporaryData, - localReference + localReference, + origin: 'local' } this.message= '' @@ -657,6 +665,7 @@ export class RoomService { // this.typing(this.message) this.chatOpen = true this.messageUnread = false + this.sendReadMessage() } @@ -737,6 +746,7 @@ export class RoomService { for(let message of chatHistory.result.messages.reverse()) { if (!messagesId.includes(message._id)) { + message.origin = 'history' const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message}); if(messagesToSave != null) { diff --git a/src/app/services/chat/viewed-message.service.ts b/src/app/services/chat/viewed-message.service.ts index 7266b57ae..9411d766d 100644 --- a/src/app/services/chat/viewed-message.service.ts +++ b/src/app/services/chat/viewed-message.service.ts @@ -27,9 +27,9 @@ export class ViewedMessageService { for(let id of membersIds) { if(message.addReceived(id)) { n++ - setTimeout(async() => { + // setTimeout(async() => { await message.saveChanges() - }, 100 * n) + // }, 100 * n) } } } @@ -56,9 +56,9 @@ export class ViewedMessageService { if(message.addViewed(id)) { message.addReceived(id) n++ - setTimeout(async() => { + // setTimeout(async() => { await message.saveChanges() - }, 100 * n) + // }, 100 * n) } } diff --git a/version/git-version.ts b/version/git-version.ts index 24c18d890..d2dc25d6d 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "895b84b58", - "SHA": "895b84b586c6a927cfb7000fa8bac3fa3a20a22e", + "shortSHA": "cb9e9f266", + "SHA": "cb9e9f2667180616a340ff7f6b751f07622f70cd", "branch": "no_bug_movemente", "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Tue Jan 17 10:57:26 2023 +0100'", - "lastCommitMessage": "remove clock", - "lastCommitNumber": "4634", - "change": "", - "changeStatus": "On branch no_bug_movemente\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: src/environments/environment.prod.ts\n\tmodified: src/environments/environment.ts\n\tmodified: version/git-version.ts", + "lastCommitTime": "'Tue Jan 17 12:16:48 2023 +0100'", + "lastCommitMessage": "merge", + "lastCommitNumber": "4636", + "change": "diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts\nindex 954089660..6fe433f8a 100644\n--- a/src/app/home/home.page.ts\n+++ b/src/app/home/home.page.ts\n@@ -126,6 +126,12 @@ export class HomePage implements OnInit {\n \n }\n \n+ window.addEventListener('storage', (event) => {\n+ // When local storage changes, dump the list to\n+ // the console.\n+ console.log(event);\n+ });\n+\n }\n \n goto(url) {\ndiff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts\nindex 8edea3bb2..2aa6e8069 100644\n--- a/src/app/models/beast-orm.ts\n+++ b/src/app/models/beast-orm.ts\n@@ -11,6 +11,7 @@ export class MessageModel extends models.Model {\n \tts = JsonField({blank:true})\n \tu = JsonField()\n \t_id = models.CharField({blank:true})\n+\torigin = models.CharField({blank:true})\n \t_updatedAt = models.IntegerField()\n \tmessageSend = models.BooleanField()\n \toffline = models.BooleanField()\n@@ -41,7 +42,7 @@ export class DeleteMessageModel extends models.Model {\n models.register({\n databaseName: 'chat-storage'+environment.version.lastCommitNumber,\n type: 'indexedDB',\n- version: 10,\n+ version: 11,\n models: [MessageModel, DeleteMessageModel, attachments]\n })\n \ndiff --git a/src/app/models/chatMethod.ts b/src/app/models/chatMethod.ts\nindex 73570fa16..56ee9fa79 100644\n--- a/src/app/models/chatMethod.ts\n+++ b/src/app/models/chatMethod.ts\n@@ -75,6 +75,7 @@ export interface Message {\n u: U;\n \tfrom: 'Offline'|'History'|'stream'| 'send' \n t: string;\n+\torigin: 'history' | 'stream' | 'local'\n _updatedAt: '';\n mentions: any[];\n channels: any[];\ndiff --git a/src/app/models/message.model.ts b/src/app/models/message.model.ts\nindex 732672370..341262051 100644\n--- a/src/app/models/message.model.ts\n+++ b/src/app/models/message.model.ts\n@@ -43,6 +43,7 @@ export interface ChatMessageInterface {\n _updatedAt: number;\n mentions: any[];\n channels: any[];\n+ origin?: 'history' | 'stream' | 'local'\n };\n \n \ndiff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts\nindex 5926dbdee..83255aa43 100644\n--- a/src/app/services/chat/message.service.ts\n+++ b/src/app/services/chat/message.service.ts\n@@ -61,6 +61,9 @@ export class MessageService {\n downloadAttachmentsTemp = 0;\n UploadAttachmentsTemp = 0;\n manualRetry = false\n+ origin: 'history' | 'stream' | 'local'\n+\n+ rowInstance: MessageModel\n \n constructor(\n private NfService: NfService,\n@@ -72,7 +75,7 @@ export class MessageService {\n private ChatSystemService: ChatSystemService) {\n }\n \n- 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) {\n+ 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, origin }:Message) {\n \n this.channels = channels || []\n this.mentions = mentions || []\n@@ -90,6 +93,7 @@ export class MessageService {\n this.delate = delate\n this.delateRequest = delateRequest\n this.sendAttempt = 0\n+ this.origin = origin\n \n if(this.attachments?.length >= 1 && attachments?.length >= 1) {\n this.attachments[0] = Object.assign(this.attachments[0], attachments[0])\n@@ -257,6 +261,7 @@ export class MessageService {\n } catch (error) {\n this.uploadingFile = false\n this.errorUploadingAttachment = true\n+ this.UploadAttachmentsTemp++\n console.error('beforeSendAttachment error:', error)\n \n }\n@@ -467,6 +472,7 @@ export class MessageService {\n u: this.u,\n _id: this._id,\n id: this.id,\n+ origin: this.origin,\n _updatedAt: this._updatedAt,\n messageSend: this.messageSend,\n offline: this.offline,\n@@ -489,6 +495,7 @@ export class MessageService {\n delete message.id\n const createdMessage = await MessageModel.create(message)\n \n+ this.rowInstance = createdMessage\n this.id = createdMessage.id\n \n if(this.earlySave) {\n@@ -497,8 +504,8 @@ export class MessageService {\n }\n }\n \n- async saveChanges() {\n \n+ async getRowInstance () {\n \n if(this.save) {\n const message = this.getChatObj()\n@@ -516,12 +523,29 @@ export class MessageService {\n a = await MessageModel.get({id: this.id})\n }\n \n- if(a) {\n- for( const [name, value] of Object.entries(message)) {\n- a[name] = value\n- }\n- await a.save()\n+ return a\n+ }\n+ \n+ }\n+\n+ async saveChanges() {\n+\n+ if(!this.rowInstance) {\n+ this.rowInstance = await this.getRowInstance()\n+ }\n+\n+ if(this.save && this.rowInstance) {\n+ const message = this.getChatObj()\n+\n+ if(!message.id) {\n+ delete message.id\n+ }\n+\n+ for( const [name, value] of Object.entries(message)) {\n+ this.rowInstance[name] = value\n }\n+ \n+ await this.rowInstance.save()\n \n } else {\n this.earlySave = true\ndiff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts\nindex a5a4d20ca..b67bfc32e 100644\n--- a/src/app/services/chat/room.service.ts\n+++ b/src/app/services/chat/room.service.ts\n@@ -275,18 +275,25 @@ export class RoomService {\n if(message.fields.eventName == this.id+'/'+'typing') {\n \n const args = message.fields.args\n- \n+\n if (typeof args[1] != 'object') {\n this.userThatIsTyping = this.usernameToDisplayName(args[0])\n \n this.isTyping = args[1]\n this.otherUserType = args[1]\n- this.readAllMessage()\n \n+ const user = args[0]\n+ if(SessionStore.user.UserName != user) {\n+ this.readAllMessage()\n+ }\n \n } else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {\n- \n- this.readAllMessage()\n+ const user = args[0]\n+\n+ if(SessionStore.user.UserName != user) {\n+ this.readAllMessage()\n+ }\n+\n } else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {\n \n this.deleteMessage(args[1]?.method?._id)\n@@ -295,7 +302,6 @@ export class RoomService {\n \n }\n \n-\n } else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}\n \n })\n@@ -313,6 +319,7 @@ export class RoomService {\n \n if(!found) {\n \n+ ChatMessage.origin = 'stream' \n const message = await this.prepareCreate({message: ChatMessage, save: true});\n this.registerSendMessage(message)\n \n@@ -556,7 +563,8 @@ export class RoomService {\n attachments,\n file,\n temporaryData,\n- localReference\n+ localReference,\n+ origin: 'local'\n }\n \n this.message= ''\n@@ -657,6 +665,7 @@ export class RoomService {\n // this.typing(this.message)\n this.chatOpen = true\n this.messageUnread = false\n+ this.sendReadMessage()\n }\n \n \n@@ -737,6 +746,7 @@ export class RoomService {\n \n for(let message of chatHistory.result.messages.reverse()) {\n if (!messagesId.includes(message._id)) {\n+ message.origin = 'history'\n const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});\n if(messagesToSave != null) {\n \ndiff --git a/src/app/services/chat/viewed-message.service.ts b/src/app/services/chat/viewed-message.service.ts\nindex 7266b57ae..9411d766d 100644\n--- a/src/app/services/chat/viewed-message.service.ts\n+++ b/src/app/services/chat/viewed-message.service.ts\n@@ -27,9 +27,9 @@ export class ViewedMessageService {\n for(let id of membersIds) {\n if(message.addReceived(id)) {\n n++\n- setTimeout(async() => {\n+ // setTimeout(async() => {\n await message.saveChanges()\n- }, 100 * n)\n+ // }, 100 * n)\n }\n }\n }\n@@ -56,9 +56,9 @@ export class ViewedMessageService {\n if(message.addViewed(id)) {\n message.addReceived(id)\n n++\n- setTimeout(async() => {\n+ // setTimeout(async() => {\n await message.saveChanges()\n- }, 100 * n)\n+ // }, 100 * n)\n \n }\n }", + "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/agenda/agenda.page.html\n\nChanges not staged for commit:\n (use \"git add ...\" to update what will be committed)\n (use \"git restore ...\" to discard changes in working directory)\n\tmodified: src/app/home/home.page.ts\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/app/models/chatMethod.ts\n\tmodified: src/app/models/message.model.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", "changeAuthor": "peter.maquiran" } \ No newline at end of file