From 33eddc7b737a7d47dcbe62bcf2cc2bfa1aec8abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 28 Jan 2022 13:25:28 +0100 Subject: [PATCH 1/4] change method from downloadmsg to preview --- src/app/shared/chat/messages/messages.page.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index c8c6f57c6..099226592 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -73,8 +73,8 @@
-
- image +
+ image
From f31d5fb0ffc064ca6c7a52fb950a4f7d8272b79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 28 Jan 2022 15:28:21 +0100 Subject: [PATCH 2/4] Bug msg repeated --- src/app/services/chat/message.service.ts | 14 +++- src/app/services/chat/room.service.ts | 77 +++++++++++-------- .../services/chat/ws-chat-methods.service.ts | 2 +- src/app/shared/chat/messages/messages.page.ts | 2 +- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 4c28ea287..02ea997be 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { Message } from 'src/app/models/chatMethod'; import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod' +import { Storage } from '@ionic/storage'; @Injectable({ providedIn: 'root' @@ -20,7 +21,8 @@ export class MessageService { file attachments - constructor() { } + constructor(private storage: Storage) { + } setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments}:Message) { this.customFields = customFields @@ -35,6 +37,16 @@ export class MessageService { this._updatedAt = _updatedAt this.file = file this.attachments = attachments + + + if (this.file) { + if (this.file.guid) { + this.storage.get(this.file.guid).then((image) => { + console.log('IMAGE FROM STORAGE', image) + this.file.image_url = image + }); + } + } } delete() {} diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 8d9c3a482..f19c46755 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -39,7 +39,7 @@ export class RoomService { private sqlservice: SqliteService, ) { } - setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) { + setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -60,7 +60,7 @@ export class RoomService { console.log('recivemessage', ChatMessage) /* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */ - const message = new MessageService() + const message = new MessageService(this.storage) message.setData(ChatMessage) this.lastMessage.msg = message.msg @@ -122,7 +122,7 @@ export class RoomService { let mmessage = this.fix_updatedAt(msgChat) console.log('FROM DB WEB', mmessage) - const wewMessage = new MessageService() + const wewMessage = new MessageService(this.storage) wewMessage.setData(mmessage) this.massages.push(wewMessage) console.log('loadHistory 222', this.massages) @@ -141,8 +141,8 @@ export class RoomService { getMsgFromDB() { - this.storage.get('chatmsg' + this.id).then((message) => { - + /* this.storage.get('chatmsg' + this.id).then((message) => { + console.log('ALL MESSAGE WEB', message) message.forEach(message => { if (message.file) { @@ -156,12 +156,12 @@ export class RoomService { let mmessage = this.fix_updatedAt(message) console.log('FROM DB WEB', mmessage) - const wewMessage = new MessageService() + const wewMessage = new MessageService(this.storage) wewMessage.setData(mmessage) this.massages.push(wewMessage) console.log('loadHistory 222', this.massages) }); - }) + }) */ } @@ -171,42 +171,57 @@ export class RoomService { if (this.hasLoadHistory) { return false } - /* this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { - console.log('loadHistory', chatHistory) - - chatHistory.result.messages.reverse().forEach(message => { - + this.storage.get('chatmsg' + this.id).then((messages = [])=>{ + messages.forEach(message => { message = this.fix_updatedAt(message) - const wewMessage = new MessageService() + const wewMessage = new MessageService(this.storage) wewMessage.setData(message) this.massages.push(wewMessage) }); + }) + this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { + console.log('loadHistory', chatHistory) + - }) */ + let localMessages = [] + chatHistory.result.messages.reverse().forEach(message => { - this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => { + message = this.fix_updatedAt(message) + const wewMessage = new MessageService(this.storage) + wewMessage.setData(message) + localMessages.push(wewMessage) + }); - const mgsArray = chatHistory.result.messages.reverse(); - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - await this.storage.remove('chatmsg' + this.id).then(() => { - console.log('MSG REMOVE ON STORAGE') - }) - await this.storage.set('chatmsg' + this.id, mgsArray).then((value) => { - console.log('MSG SAVED ON STORAGE', value) - this.getMsgFromDB() - }); - } else { - mgsArray.forEach((element) => { - console.log('SQLITE WEBSOCKET', element) - this.sqlservice.addChatMSG(element) - }) - this.getMsgFromDBMobile() - } + this.massages = localMessages + + this.storage.set('chatmsg' + this.id, chatHistory.result.messages.reverse()) }) + /* this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => { + + const mgsArray = chatHistory.result.messages.reverse(); + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + await this.storage.remove('chatmsg' + this.id).then(() => { + console.log('MSG REMOVE ON STORAGE') + }) + await this.storage.set('chatmsg' + this.id, mgsArray).then((value) => { + console.log('MSG SAVED ON STORAGE', value) + this.getMsgFromDB() + }); + } else { + mgsArray.forEach((element) => { + console.log('SQLITE WEBSOCKET', element) + this.sqlservice.addChatMSG(element) + }) + this.getMsgFromDBMobile() + } + + + }) */ + setTimeout(() => { this.scrollDown() }, 50) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 1db0198c6..76f0d6ccf 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -92,7 +92,7 @@ export class WsChatMethodsService { prepareRoom(roomData){ let room:RoomService; - room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice) + room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice) room.setData({ customFields: roomData.customFields, id: this.getRoomId(roomData), diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 8759a86ac..ef58ed942 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -101,7 +101,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } ngOnChanges(changes: SimpleChanges): void { this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() - this.wsChatMethodsService.getDmRoom(this.roomId).getMsgFromDB() + //this.wsChatMethodsService.getDmRoom(this.roomId).getMsgFromDB() this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked /* console.log('DATATATA', this.wsChatMethodsService.getDmRoom(this.roomId).massages) this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => { From 61053975d1d6a87751c628529be367641579a844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 28 Jan 2022 16:19:54 +0100 Subject: [PATCH 3/4] publication from db --- .../pages/publications/publications.page.ts | 82 ++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index 4ff0d213c..70912831c 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -16,6 +16,7 @@ import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-f import { SqliteService } from 'src/app/services/sqlite.service'; import { BackgroundService } from 'src/app/services/background.service'; import { ThemeService } from 'src/app/services/theme.service' +import { Storage } from '@ionic/storage'; @Component({ @@ -59,7 +60,7 @@ export class PublicationsPage implements OnInit { hideRefreshBtn = true; showSlidingOptions = true; idSelected: string; - skeletonLoader:boolean; + skeletonLoader: boolean; constructor( private router: Router, @@ -71,6 +72,7 @@ export class PublicationsPage implements OnInit { private backgroundservice: BackgroundService, private platform: Platform, public ThemeService: ThemeService, + private storage: Storage ) { this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; @@ -85,13 +87,15 @@ export class PublicationsPage implements OnInit { this.router.events.forEach((event) => { if (event instanceof NavigationEnd && event.url == pathname) { this.getActions(); + + } }); this.hideRefreshButton(); - this.backgroundservice.registerBackService('Online', () => { + /* this.backgroundservice.registerBackService('Online', () => { this.getActions(); - }) + }) */ } @@ -143,12 +147,13 @@ export class PublicationsPage implements OnInit { getActions() { this.showLoader = true; this.skeletonLoader = true; - this.publications.GetPublicationFolderList().subscribe(res => { + this.getFromDB() + this.publications.GetPublicationFolderList().subscribe(async res => { console.log('accoes', res) - this.publicationsEventFolderList = new Array(); - this.publicationsTravelFolderList = new Array(); + let publicationsEventFolderList = new Array(); + let publicationsTravelFolderList = new Array(); res.forEach(data => { let folder: PublicationFolder = { @@ -164,22 +169,41 @@ export class PublicationsPage implements OnInit { if (data.ActionType == "Evento") { console.log('Evento', folder) - this.publicationsEventFolderList.push(folder); + publicationsEventFolderList.push(folder); } else { console.log('Viagem', folder) - this.publicationsTravelFolderList.push(folder); + publicationsTravelFolderList.push(folder); } - this.showLoader = false; + + }); + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + await this.storage.set('actionsEvents', publicationsEventFolderList); + await this.storage.set('actionsViagens', publicationsTravelFolderList); + this.getFromDB() + } else { + this.getFromDB() + } - }, (error) => { + this.showLoader = false; + + }/* , (error) => { this.getFromDB(); - }); + } */); this.skeletonLoader = false; } + addActionToStorage(events, viagens) { + console.log('actionsWEBDB', events, viagens) + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + this.storage.set('actionsEvents', events); + this.storage.set('actionsViagens', viagens); + } + } + + addActionToDB(folder) { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { } else { @@ -190,6 +214,40 @@ export class PublicationsPage implements OnInit { getFromDB() { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + this.publicationsEventFolderList = new Array(); + this.publicationsTravelFolderList = new Array(); + this.storage.get('actionsEvents').then((events) => { + console.log('actionsEvents', events) + events.forEach(data => { + let folder: PublicationFolder = { + ProcessId: data.ProcessId, + Description: data.Description, + Detail: data.Detail, + DateBegin: data.DateBegin, + DateEnd: data.DateEnd, + ActionType: data.ActionType, + } + + this.publicationsEventFolderList.push(folder); + this.showLoader = false; + }); + }); + this.storage.get('actionsViagens').then((viagens) => { + console.log('actionsViagens', viagens) + viagens.forEach(data => { + let folder: PublicationFolder = { + ProcessId: data.ProcessId, + Description: data.Description, + Detail: data.Detail, + DateBegin: data.DateBegin, + DateEnd: data.DateEnd, + ActionType: data.ActionType, + } + + this.publicationsTravelFolderList.push(folder); + this.showLoader = false; + }); + }); } else { this.sqliteservice.getAllActions().then((actions: any[]) => { @@ -379,7 +437,7 @@ export class PublicationsPage implements OnInit { this.desktopComponent.showAddNewPublication = true; } - async editPublication(foolderId:string){ + async editPublication(foolderId: string) { this.closeDesktopComponent(); this.desktopComponent.showEditActions = true; } From f2d649b9b2cb5e80fcffa64943c4a17734240cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 28 Jan 2022 16:21:26 +0100 Subject: [PATCH 4/4] massage to message --- src/app/pages/chat/messages/messages.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 6630716f5..3dd99eaf6 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -49,7 +49,7 @@ -->
-
+
{{msg.u.name}}