diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 0b7b9b61a..ee9612b12 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}} 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; } 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 7f803a5c4..868443e7c 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -52,7 +52,7 @@ export class RoomService { this.NativeNotificationService.askForPermission() } - 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 @@ -74,7 +74,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 = message @@ -231,7 +231,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.messages.push(wewMessage) console.log('loadHistory 222', this.messages) @@ -250,8 +250,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) { @@ -265,12 +265,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.messages.push(wewMessage) console.log('loadHistory 222', this.messages) }); - }) + }) */ } @@ -280,44 +280,57 @@ export class RoomService { if (this.hasLoadHistory) { return false } - /* this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { - console.log('loadHistory', chatHistory) + this.storage.get('chatmsg' + this.id).then((messages = [])=>{ + messages.forEach(message => { + message = this.fix_updatedAt(message) + const wewMessage = new MessageService(this.storage) + wewMessage.setData(message) + this.messages.push(wewMessage) + }); + }) + this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { + console.log('loadHistory', chatHistory) + + + let localMessages = [] chatHistory.result.messages.reverse().forEach(message => { message = this.fix_updatedAt(message) - const wewMessage = new MessageService() + const wewMessage = new MessageService(this.storage) wewMessage.setData(message) - this.massages.push(wewMessage) + localMessages.push(wewMessage) }); + this.messages = localMessages - }) */ - - this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => { - - const mgsArray = chatHistory.result.messages.reverse(); - console.log(mgsArray); - - 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.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 a7b30102b..153579fdc 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -106,7 +106,8 @@ export class WsChatMethodsService { prepareRoom(roomData){ let room:RoomService; - room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.NativeNotificationService) + room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService) + room.setData({ customFields: roomData.customFields, id: this.getRoomId(roomData), diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 62c13ad87..10a3032be 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -73,9 +73,8 @@
-
+
image -
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 705a6108a..a7cd3595d 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -100,7 +100,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) => {