This commit is contained in:
Peter Maquiran
2022-01-28 16:30:30 +01:00
7 changed files with 134 additions and 51 deletions
@@ -49,7 +49,7 @@
</ion-refresher-content> </ion-refresher-content>
</ion-refresher> --> </ion-refresher> -->
<div (click)="handleClick()" class="messages" #scrollMe> <div (click)="handleClick()" class="messages" #scrollMe>
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).massages; let last = last" [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId" > <div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).messages; let last = last" [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId" >
<div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="downloadFileMsg(msg)" *ngIf="msg.msg !=''"> <div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="downloadFileMsg(msg)" *ngIf="msg.msg !=''">
<div class="title"> <div class="title">
<ion-label>{{msg.u.name}}</ion-label> <ion-label>{{msg.u.name}}</ion-label>
+70 -12
View File
@@ -16,6 +16,7 @@ import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-f
import { SqliteService } from 'src/app/services/sqlite.service'; import { SqliteService } from 'src/app/services/sqlite.service';
import { BackgroundService } from 'src/app/services/background.service'; import { BackgroundService } from 'src/app/services/background.service';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { Storage } from '@ionic/storage';
@Component({ @Component({
@@ -59,7 +60,7 @@ export class PublicationsPage implements OnInit {
hideRefreshBtn = true; hideRefreshBtn = true;
showSlidingOptions = true; showSlidingOptions = true;
idSelected: string; idSelected: string;
skeletonLoader:boolean; skeletonLoader: boolean;
constructor( constructor(
private router: Router, private router: Router,
@@ -71,6 +72,7 @@ export class PublicationsPage implements OnInit {
private backgroundservice: BackgroundService, private backgroundservice: BackgroundService,
private platform: Platform, private platform: Platform,
public ThemeService: ThemeService, public ThemeService: ThemeService,
private storage: Storage
) { ) {
this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; 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) => { this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == pathname) { if (event instanceof NavigationEnd && event.url == pathname) {
this.getActions(); this.getActions();
} }
}); });
this.hideRefreshButton(); this.hideRefreshButton();
this.backgroundservice.registerBackService('Online', () => { /* this.backgroundservice.registerBackService('Online', () => {
this.getActions(); this.getActions();
}) }) */
} }
@@ -143,12 +147,13 @@ export class PublicationsPage implements OnInit {
getActions() { getActions() {
this.showLoader = true; this.showLoader = true;
this.skeletonLoader = true; this.skeletonLoader = true;
this.publications.GetPublicationFolderList().subscribe(res => { this.getFromDB()
this.publications.GetPublicationFolderList().subscribe(async res => {
console.log('accoes', res) console.log('accoes', res)
this.publicationsEventFolderList = new Array(); let publicationsEventFolderList = new Array();
this.publicationsTravelFolderList = new Array(); let publicationsTravelFolderList = new Array();
res.forEach(data => { res.forEach(data => {
let folder: PublicationFolder = { let folder: PublicationFolder = {
@@ -164,22 +169,41 @@ export class PublicationsPage implements OnInit {
if (data.ActionType == "Evento") { if (data.ActionType == "Evento") {
console.log('Evento', folder) console.log('Evento', folder)
this.publicationsEventFolderList.push(folder); publicationsEventFolderList.push(folder);
} }
else { else {
console.log('Viagem', folder) 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.getFromDB();
}); } */);
this.skeletonLoader = false; 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) { addActionToDB(folder) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) { if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else { } else {
@@ -190,6 +214,40 @@ export class PublicationsPage implements OnInit {
getFromDB() { getFromDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) { 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 { } else {
this.sqliteservice.getAllActions().then((actions: any[]) => { this.sqliteservice.getAllActions().then((actions: any[]) => {
@@ -379,7 +437,7 @@ export class PublicationsPage implements OnInit {
this.desktopComponent.showAddNewPublication = true; this.desktopComponent.showAddNewPublication = true;
} }
async editPublication(foolderId:string){ async editPublication(foolderId: string) {
this.closeDesktopComponent(); this.closeDesktopComponent();
this.desktopComponent.showEditActions = true; this.desktopComponent.showEditActions = true;
} }
+13 -1
View File
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Message } from 'src/app/models/chatMethod'; import { Message } from 'src/app/models/chatMethod';
import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod' import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod'
import { Storage } from '@ionic/storage';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -20,7 +21,8 @@ export class MessageService {
file file
attachments attachments
constructor() { } constructor(private storage: Storage) {
}
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments}:Message) { setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments}:Message) {
this.customFields = customFields this.customFields = customFields
@@ -35,6 +37,16 @@ export class MessageService {
this._updatedAt = _updatedAt this._updatedAt = _updatedAt
this.file = file this.file = file
this.attachments = attachments 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() {} delete() {}
+45 -32
View File
@@ -52,7 +52,7 @@ export class RoomService {
this.NativeNotificationService.askForPermission() 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.customFields = customFields
this.id = id this.id = id
this.name = name this.name = name
@@ -74,7 +74,7 @@ export class RoomService {
console.log('recivemessage', ChatMessage) console.log('recivemessage', ChatMessage)
/* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */ /* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */
const message = new MessageService() const message = new MessageService(this.storage)
message.setData(ChatMessage) message.setData(ChatMessage)
this.lastMessage = message this.lastMessage = message
@@ -231,7 +231,7 @@ export class RoomService {
let mmessage = this.fix_updatedAt(msgChat) let mmessage = this.fix_updatedAt(msgChat)
console.log('FROM DB WEB', mmessage) console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService() const wewMessage = new MessageService(this.storage)
wewMessage.setData(mmessage) wewMessage.setData(mmessage)
this.messages.push(wewMessage) this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages) console.log('loadHistory 222', this.messages)
@@ -250,8 +250,8 @@ export class RoomService {
getMsgFromDB() { 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 => { message.forEach(message => {
if (message.file) { if (message.file) {
@@ -265,12 +265,12 @@ export class RoomService {
let mmessage = this.fix_updatedAt(message) let mmessage = this.fix_updatedAt(message)
console.log('FROM DB WEB', mmessage) console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService() const wewMessage = new MessageService(this.storage)
wewMessage.setData(mmessage) wewMessage.setData(mmessage)
this.messages.push(wewMessage) this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages) console.log('loadHistory 222', this.messages)
}); });
}) }) */
} }
@@ -280,44 +280,57 @@ export class RoomService {
if (this.hasLoadHistory) { return false } if (this.hasLoadHistory) { return false }
/* this.WsChatService.loadHistory(this.id, limit).then((chatHistory: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) console.log('loadHistory', chatHistory)
let localMessages = []
chatHistory.result.messages.reverse().forEach(message => { chatHistory.result.messages.reverse().forEach(message => {
message = this.fix_updatedAt(message) message = this.fix_updatedAt(message)
const wewMessage = new MessageService() const wewMessage = new MessageService(this.storage)
wewMessage.setData(message) wewMessage.setData(message)
this.massages.push(wewMessage) localMessages.push(wewMessage)
}); });
this.messages = 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();
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.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(() => { setTimeout(() => {
this.scrollDown() this.scrollDown()
}, 50) }, 50)
@@ -106,7 +106,8 @@ export class WsChatMethodsService {
prepareRoom(roomData){ prepareRoom(roomData){
let room:RoomService; 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({ room.setData({
customFields: roomData.customFields, customFields: roomData.customFields,
id: this.getRoomId(roomData), id: this.getRoomId(roomData),
@@ -73,9 +73,8 @@
<div> <div>
<div *ngIf="msg.attachments" class="message-attachments"> <div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments"> <div *ngFor="let file of msg.attachments">
<div *ngIf="msg.file.type == 'application/img'" (click)="downloadFileMsg(msg)" dfsdvsvs> <div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)" dfsdvsvs>
<img src={{msg.file.image_url}} alt="image"> <img src={{msg.file.image_url}} alt="image">
<ion-icon *ngIf="msg.file.image_url == null" name="download-outline"></ion-icon>
</div> </div>
<div *ngIf="msg.file.type != 'application/img'"> <div *ngIf="msg.file.type != 'application/img'">
<div class="file"> <div class="file">
@@ -100,7 +100,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() 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 this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
/* console.log('DATATATA', this.wsChatMethodsService.getDmRoom(this.roomId).massages) /* console.log('DATATATA', this.wsChatMethodsService.getDmRoom(this.roomId).massages)
this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => { this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => {