performace

This commit is contained in:
Peter Maquiran
2023-09-29 16:40:50 +01:00
parent 7f1dbf13aa
commit 93ad41eab9
12 changed files with 175 additions and 106 deletions
+11 -15
View File
@@ -71,7 +71,7 @@
"@ionic-native/local-notifications": "^4.20.0", "@ionic-native/local-notifications": "^4.20.0",
"@ionic-native/media": "^5.36.0", "@ionic-native/media": "^5.36.0",
"@ionic-native/media-capture": "^5.36.0", "@ionic-native/media-capture": "^5.36.0",
"@ionic-native/network": "^5.22.0-beta-1", "@ionic-native/network": "^5.36.0",
"@ionic-native/photo-viewer": "^5.36.0", "@ionic-native/photo-viewer": "^5.36.0",
"@ionic-native/screen-orientation": "^5.35.0", "@ionic-native/screen-orientation": "^5.35.0",
"@ionic-native/social-sharing": "^5.36.0", "@ionic-native/social-sharing": "^5.36.0",
@@ -135,7 +135,6 @@
"howler": "^2.2.3", "howler": "^2.2.3",
"http-server": "^14.1.1", "http-server": "^14.1.1",
"husky": "^8.0.2", "husky": "^8.0.2",
"i": "^0.3.7",
"ionic-angular": "^3.9.10", "ionic-angular": "^3.9.10",
"ionic-image-loader": "^6.3.3", "ionic-image-loader": "^6.3.3",
"ionic-image-loader-v5": "^1.0.2", "ionic-image-loader-v5": "^1.0.2",
@@ -4692,8 +4691,9 @@
} }
}, },
"node_modules/@ionic-native/network": { "node_modules/@ionic-native/network": {
"version": "5.22.0-beta-1", "version": "5.36.0",
"license": "MIT", "resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.36.0.tgz",
"integrity": "sha512-gpa7cJqodEK+zmmViYJCqEpXoKSXcaYLaaRKdv5gn5M++bpmiw2pKM9JH8VoqYWaYDcUwD3S0yYeBBkG5DE0Kg==",
"dependencies": { "dependencies": {
"@types/cordova": "latest" "@types/cordova": "latest"
}, },
@@ -11990,8 +11990,9 @@
}, },
"node_modules/cordova-plugin-network-information": { "node_modules/cordova-plugin-network-information": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/cordova-plugin-network-information/-/cordova-plugin-network-information-3.0.0.tgz",
"integrity": "sha512-bBtP3PxIX8vshsfR0+F6co2e2cFLgjt18yKIdigzMwk6ANudWQ72RB3g2qMPyT6fBDWmUyE1Qd+bKQB/fZtQwQ==",
"dev": true, "dev": true,
"license": "Apache-2.0",
"engines": { "engines": {
"cordovaDependencies": { "cordovaDependencies": {
"3.0.0": { "3.0.0": {
@@ -16325,12 +16326,6 @@
"url": "https://github.com/sponsors/typicode" "url": "https://github.com/sponsors/typicode"
} }
}, },
"node_modules/i": {
"version": "0.3.7",
"engines": {
"node": ">=0.4"
}
},
"node_modules/iconv-lite": { "node_modules/iconv-lite": {
"version": "0.6.3", "version": "0.6.3",
"license": "MIT", "license": "MIT",
@@ -43726,7 +43721,9 @@
} }
}, },
"@ionic-native/network": { "@ionic-native/network": {
"version": "5.22.0-beta-1", "version": "5.36.0",
"resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.36.0.tgz",
"integrity": "sha512-gpa7cJqodEK+zmmViYJCqEpXoKSXcaYLaaRKdv5gn5M++bpmiw2pKM9JH8VoqYWaYDcUwD3S0yYeBBkG5DE0Kg==",
"requires": { "requires": {
"@types/cordova": "latest" "@types/cordova": "latest"
} }
@@ -48906,6 +48903,8 @@
}, },
"cordova-plugin-network-information": { "cordova-plugin-network-information": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/cordova-plugin-network-information/-/cordova-plugin-network-information-3.0.0.tgz",
"integrity": "sha512-bBtP3PxIX8vshsfR0+F6co2e2cFLgjt18yKIdigzMwk6ANudWQ72RB3g2qMPyT6fBDWmUyE1Qd+bKQB/fZtQwQ==",
"dev": true "dev": true
}, },
"cordova-plugin-okhttp": { "cordova-plugin-okhttp": {
@@ -51796,9 +51795,6 @@
"resolved": "https://registry.npmjs.org/husky/-/husky-8.0.2.tgz", "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.2.tgz",
"integrity": "sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg==" "integrity": "sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg=="
}, },
"i": {
"version": "0.3.7"
},
"iconv-lite": { "iconv-lite": {
"version": "0.6.3", "version": "0.6.3",
"requires": { "requires": {
+1 -2
View File
@@ -85,7 +85,7 @@
"@ionic-native/local-notifications": "^4.20.0", "@ionic-native/local-notifications": "^4.20.0",
"@ionic-native/media": "^5.36.0", "@ionic-native/media": "^5.36.0",
"@ionic-native/media-capture": "^5.36.0", "@ionic-native/media-capture": "^5.36.0",
"@ionic-native/network": "^5.22.0-beta-1", "@ionic-native/network": "^5.36.0",
"@ionic-native/photo-viewer": "^5.36.0", "@ionic-native/photo-viewer": "^5.36.0",
"@ionic-native/screen-orientation": "^5.35.0", "@ionic-native/screen-orientation": "^5.35.0",
"@ionic-native/social-sharing": "^5.36.0", "@ionic-native/social-sharing": "^5.36.0",
@@ -149,7 +149,6 @@
"howler": "^2.2.3", "howler": "^2.2.3",
"http-server": "^14.1.1", "http-server": "^14.1.1",
"husky": "^8.0.2", "husky": "^8.0.2",
"i": "^0.3.7",
"ionic-angular": "^3.9.10", "ionic-angular": "^3.9.10",
"ionic-image-loader": "^6.3.3", "ionic-image-loader": "^6.3.3",
"ionic-image-loader-v5": "^1.0.2", "ionic-image-loader-v5": "^1.0.2",
@@ -58,8 +58,8 @@
<span class="time">{{msg.time}}</span> <span class="time">{{msg.time}}</span>
</div> </div>
<div class="message"> <div class="message">
<pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<pre *ngIf="msg.delate == true" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == true" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<ion-label class="float-status-all float-status" *ngIf="msg.u.username==sessionStore.user.UserName"> <ion-label class="float-status-all float-status" *ngIf="msg.u.username==sessionStore.user.UserName">
@@ -11,7 +11,7 @@
<div class="middle-container" *ngIf="!showMessageOptions"> <div class="middle-container" *ngIf="!showMessageOptions">
<div class="middle"> <div class="middle">
<ion-label class="title">{{ChatSystemService.getDmRoom(roomId).name}}</ion-label> <ion-label class="title">{{ChatSystemService.getDmRoom(roomId).name}}</ion-label>
<span><ion-icon class="{{ ChatSystemService.getDmRoom(this.roomId).online }}" name="ellipse"></ion-icon></span> <span><ion-icon *ngIf="RochetChatConnectorService.isLogin" class="{{ ChatSystemService.getDmRoom(this.roomId).online }}" name="ellipse"></ion-icon></span>
</div> </div>
</div> </div>
@@ -58,7 +58,7 @@
<div> <div>
<div class="file"> <div class="file">
<pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<!-- <ion-label *ngIf="msg.delate == false" class="message-box">{{msg.msg}} </ion-label> --> <!-- <ion-label *ngIf="msg.delate == false" class="message-box">{{msg.msg}} </ion-label> -->
<ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label> <ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label>
+24 -23
View File
@@ -32,7 +32,7 @@ import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { Filesystem, Directory } from '@capacitor/filesystem'; import { Filesystem, Directory } from '@capacitor/filesystem';
import { NewEventPage } from '../../agenda/new-event/new-event.page'; import { NewEventPage } from '../../agenda/new-event/new-event.page';
import { NotificationsService } from 'src/app/services/notifications.service'; import { NotificationsService } from 'src/app/services/notifications.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'
const IMAGE_DIR = 'stored-images'; const IMAGE_DIR = 'stored-images';
@@ -115,7 +115,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
// private document: DocumentViewer // private document: DocumentViewer
private file: File, private file: File,
private fileOpener: FileOpener, private fileOpener: FileOpener,
private router: Router private router: Router,
public RochetChatConnectorService: RochetChatConnectorService,
) { ) {
this.loggedUser = SessionStore.user.ChatData['data']; this.loggedUser = SessionStore.user.ChatData['data'];
this.roomId = this.navParams.get('roomId'); this.roomId = this.navParams.get('roomId');
@@ -140,7 +141,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
ngOnInit() { ngOnInit() {
console.log(this.router.url); console.log(this.router.url);
this.createDirectoryImage() this.createDirectoryImage()
// this.chatService.refreshtoken(); // this.chatService.refreshtoken();
this.ChatSystemService.getUserOfRoom(this.roomId).then((value) => { this.ChatSystemService.getUserOfRoom(this.roomId).then((value) => {
@@ -151,7 +152,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.getChatMembers(); this.getChatMembers();
} }
ngAfterViewInit() { ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event); this.scrollChangeCallback = () => this.onContentScrolled(event);
@@ -324,7 +325,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
async goToEvent(event: any) { async goToEvent(event: any) {
let classs; let classs;
if (window.innerWidth < 701) { if (window.innerWidth < 701) {
classs = 'modal modal-desktop' classs = 'modal modal-desktop'
@@ -384,7 +385,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else if (msg.u.username == this.members[0].username) { } else if (msg.u.username == this.members[0].username) {
this.notificationService.ChatSendMessageNotification(this.members[1].username,this.members[1].name,lastMsg.msg,this.roomId) this.notificationService.ChatSendMessageNotification(this.members[1].username,this.members[1].name,lastMsg.msg,this.roomId)
} }
}) })
} */ } */
@@ -593,7 +594,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'modal modal-desktop', cssClass: 'modal modal-desktop',
backdropDismiss: false backdropDismiss: false
}); });
modal.onDidDismiss().then((data) => { modal.onDidDismiss().then((data) => {
if (data?.data && data.data.id) { if (data?.data && data.data.id) {
@@ -631,7 +632,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}); });
var imageBase64 = 'data:image/jpeg;base64,' + file.base64String var imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const compressedImage = await this.compressImageBase64( const compressedImage = await this.compressImageBase64(
imageBase64, imageBase64,
@@ -671,25 +672,25 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
// convert base64 to raw binary data held in a string // convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]); var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component // separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0] var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer // write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length); var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer // create a view into the buffer
var ia = new Uint8Array(ab); var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values // set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) { for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i); ia[i] = byteString.charCodeAt(i);
} }
// write the ArrayBuffer to a blob, and you're done // write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString}); var blob = new Blob([ab], {type: mimeString});
return blob; return blob;
} }
async addImageMobile() { async addImageMobile() {
@@ -761,7 +762,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
// //
var imageBase64 = 'data:image/jpeg;base64,' + file.base64String var imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const compressedImage = await this.compressImageBase64( const compressedImage = await this.compressImageBase64(
imageBase64, imageBase64,
@@ -1054,7 +1055,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else { } else {
pathFile = this.file.externalRootDirectory pathFile = this.file.externalRootDirectory
} }
console.log(pathFile) console.log(pathFile)
await Filesystem.writeFile({ await Filesystem.writeFile({
@@ -1192,32 +1193,32 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const image = new (window as any).Image(); const image = new (window as any).Image();
image.src = base64String; image.src = base64String;
image.onload = async () => { image.onload = async () => {
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
let newWidth = image.width; let newWidth = image.width;
let newHeight = image.height; let newHeight = image.height;
if (newWidth > maxWidth) { if (newWidth > maxWidth) {
newHeight *= maxWidth / newWidth; newHeight *= maxWidth / newWidth;
newWidth = maxWidth; newWidth = maxWidth;
} }
if (newHeight > maxHeight) { if (newHeight > maxHeight) {
newWidth *= maxHeight / newHeight; newWidth *= maxHeight / newHeight;
newHeight = maxHeight; newHeight = maxHeight;
} }
canvas.width = newWidth; canvas.width = newWidth;
canvas.height = newHeight; canvas.height = newHeight;
const context = canvas.getContext('2d'); const context = canvas.getContext('2d');
context?.drawImage(image, 0, 0, newWidth, newHeight); context?.drawImage(image, 0, 0, newWidth, newHeight);
const compressedBase64 = canvas.toDataURL('image/jpeg', quality); const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
resolve(compressedBase64); resolve(compressedBase64);
}; };
image.onerror = (error) => { image.onerror = (error) => {
reject(error); reject(error);
}; };
+15 -13
View File
@@ -33,7 +33,7 @@ export class AuthService {
opts:any; opts:any;
tabIsActive = true tabIsActive = true
constructor( constructor(
private http: HttpClient, private http: HttpClient,
private storageService:StorageService, private storageService:StorageService,
@@ -62,7 +62,7 @@ export class AuthService {
if(!this.tabIsActive) { if(!this.tabIsActive) {
this.tabIsActive = true this.tabIsActive = true
const data = SessionStore.getDataFromLocalStorage(); const data = SessionStore.getDataFromLocalStorage();
if(!data?.user?.Authorization && SessionStore?.user?.Authorization) { if(!data?.user?.Authorization && SessionStore?.user?.Authorization) {
window.location.reload(); window.location.reload();
} }
@@ -72,7 +72,7 @@ export class AuthService {
} }
} }
}); });
window.addEventListener('blur', (event) => { window.addEventListener('blur', (event) => {
this.tabIsActive = false this.tabIsActive = false
}); });
@@ -91,7 +91,7 @@ export class AuthService {
try { try {
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise(); response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
if(saveSession) { if(saveSession) {
this.SetSession(response, user) this.SetSession(response, user)
@@ -152,7 +152,7 @@ export class AuthService {
}else { }else {
session.Profile = 'Unknown' session.Profile = 'Unknown'
} }
session.Password = user.password session.Password = user.password
session.BasicAuthKey = user.BasicAuthKey session.BasicAuthKey = user.BasicAuthKey
SessionStore.reset(session) SessionStore.reset(session)
@@ -165,11 +165,11 @@ export class AuthService {
loginToChatWs() { loginToChatWs() {
setTimeout(() => { setTimeout(() => {
if(SessionStore.user.ChatData?.data) { if(SessionStore.user.ChatData?.data) {
this.RochetChatConnectorService.connect(); this.RochetChatConnectorService.connect();
this.RochetChatConnectorService.login().then((message: any) => { this.RochetChatConnectorService.login().then((message: any) => {
SessionStore.user.RochetChatUserId = message.result.id SessionStore.user.RochetChatUserId = message.result.id
SessionStore.save() SessionStore.save()
@@ -179,13 +179,13 @@ export class AuthService {
this.ChatSystemService.getAllRooms(); this.ChatSystemService.getAllRooms();
this.RochetChatConnectorService.setStatus('online') this.RochetChatConnectorService.setStatus('online')
}, 200); }, 200);
}).catch((error) => { }).catch((error) => {
// console.error(SessionStore.user.ChatData, 'web socket login',error) // console.error(SessionStore.user.ChatData, 'web socket login',error)
}) })
} }
// before sending a message with a attachment // before sending a message with a attachment
@@ -200,6 +200,7 @@ export class AuthService {
message.file.guid = guid.path message.file.guid = guid.path
message.downloadFileMsg() message.downloadFileMsg()
message.uploadingFile = false
return true return true
} catch(e) { } catch(e) {
@@ -219,10 +220,11 @@ export class AuthService {
message.attachments[0].title_link = url_no_options message.attachments[0].title_link = url_no_options
message.attachments[0].message_link = url_no_options message.attachments[0].message_link = url_no_options
return true message.uploadingFile = false
return true
} catch(e) { } catch(e) {
window['e'] = e window['e'] = e
console.error('BeforesendAtachment', e) console.error('BeforesendAtachment', e)
message.uploadingFile = false message.uploadingFile = false
return false return false
@@ -235,7 +237,7 @@ export class AuthService {
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => { this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
// //
let downloadFile = ""; let downloadFile = "";
if (message.file.type == "application/img") { if (message.file.type == "application/img") {
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise(); const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
@@ -279,7 +281,7 @@ export class AuthService {
logoutChat() { logoutChat() {
} }
async presentAlert(message: string) { async presentAlert(message: string) {
const alert = await this.alertController.create({ const alert = await this.alertController.create({
cssClass: 'my-custom-class', cssClass: 'my-custom-class',
+29 -25
View File
@@ -206,19 +206,15 @@ export class ChatSystemService {
async restoreRooms() { async restoreRooms() {
try { try {
const rooms = await this.storage.get('Rooms'); const _rooms = await this.storage.get('Rooms');
if(rooms) { if(_rooms) {
for (let roomData of rooms.result.update) { for (let roomData of this.sortArrayISODate(_rooms)) {
await this.prepareRoom(roomData); await this.prepareRoom(roomData);
} }
} }
} catch(e){} } catch(e){}
setTimeout(() => {
this.sortRoomList()
}, 10000)
} }
async restoreUsers () { async restoreUsers () {
@@ -230,6 +226,14 @@ export class ChatSystemService {
} }
} }
sortArrayISODate(messages: any): any[] {
return messages.sort((a,b) =>
new Date(b._updatedAt ).getTime()
-
new Date(a._updatedAt).getTime())
}
async getAllRooms (callback:Function = () =>{} , roomIdCallback = "") { async getAllRooms (callback:Function = () =>{} , roomIdCallback = "") {
this.loadingWholeList = true this.loadingWholeList = true
var rooms; var rooms;
@@ -248,8 +252,17 @@ export class ChatSystemService {
let index = 0 let index = 0
if(rooms?.result?.update) { let _rooms = rooms?.result?.update
for (let roomData of rooms.result.update) {
if(_rooms) {
_rooms = _rooms.map( e => {
e["_updatedAt"] = e._updatedAt || e._updatedAt['$date']
return e
})
for (let roomData of this.sortArrayISODate(_rooms) ) {
const roomId = this.getRoomId(roomData); const roomId = this.getRoomId(roomData);
@@ -272,8 +285,8 @@ export class ChatSystemService {
const members = res['members']; const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName); const users = members.filter(data => data.username != this.sessionStore.user.UserName);
rooms.result.update[index]['members'] = members _rooms[index]['members'] = members
rooms.result.update[index]['membersExcludeMe'] = users _rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData); await this.prepareRoom(roomData);
} else { } else {
@@ -295,8 +308,8 @@ export class ChatSystemService {
const members = res['members']; const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName); const users = members.filter(data => data.username != this.sessionStore.user.UserName);
rooms.result.update[index]['members'] = members _rooms[index]['members'] = members
rooms.result.update[index]['membersExcludeMe'] = users _rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData); await this.prepareRoom(roomData);
@@ -322,8 +335,8 @@ export class ChatSystemService {
const members = res['members']; const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName); const users = members.filter(data => data.username != this.sessionStore.user.UserName);
rooms.result.update[index]['members'] = members _rooms[index]['members'] = members
rooms.result.update[index]['membersExcludeMe'] = users _rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData); await this.prepareRoom(roomData);
} }
@@ -339,17 +352,8 @@ export class ChatSystemService {
} }
this.loadingWholeList = false this.loadingWholeList = false
await this.storage.set('Rooms', rooms);
this.sortRoomList() this.sortRoomList()
await this.storage.set('Rooms', _rooms);
setTimeout(() => {
this.sortRoomList()
}, 1000)
setTimeout(() => {
this.sortRoomList()
}, 10000)
this.onRoomsLoad.executor() this.onRoomsLoad.executor()
} }
+28 -13
View File
@@ -220,6 +220,7 @@ export class MessageService {
this.RochetChatConnectorService.registerCallback({ this.RochetChatConnectorService.registerCallback({
type: 'reConnect', type: 'reConnect',
funx: async () => { funx: async () => {
console.log('send now have login')
this.send().catch((error) =>{ this.send().catch((error) =>{
console.error(error) console.error(error)
}) })
@@ -227,7 +228,16 @@ export class MessageService {
} }
}) })
console.log('no login')
} else if (this.UploadAttachmentsTemp <= 3) {
console.log('temp'+ this.UploadAttachmentsTemp)
setTimeout(async () => {
return await this.send()
}, 4000)
} else if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) { } else if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) {
console.log('recooonect')
this.RochetChatConnectorService.registerCallback({ this.RochetChatConnectorService.registerCallback({
type: 'reConnect', type: 'reConnect',
funx: async ()=> { funx: async ()=> {
@@ -238,11 +248,8 @@ export class MessageService {
return true return true
} }
}) })
} else if (this.UploadAttachmentsTemp <= 3) {
setTimeout(async () => {
return await this.send()
}, 3000)
} else if (this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) { } else if (this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
console.log('manual')
this.manualRetry = true this.manualRetry = true
} }
@@ -256,6 +263,7 @@ export class MessageService {
async sendRequestAttachment() { async sendRequestAttachment() {
console.log('sendRequestAttachment')
this.uploadingFile = true this.uploadingFile = true
let uploadSuccessfully = false let uploadSuccessfully = false
@@ -270,23 +278,30 @@ export class MessageService {
await this.generateTemporaryData() await this.generateTemporaryData()
} }
console.log('send temp')
if(this.hasSendAttachment == false) { if(this.hasSendAttachment == false) {
try { try {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
this.UploadAttachmentsTemp++
this.uploadingFile = false
this.manualRetry = false this.manualRetry = false
this.errorUploadingAttachment = false this.errorUploadingAttachment = false
this.hasSendAttachment = true this.UploadAttachmentsTemp++
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
this.uploadingFile = false
this.hasSendAttachment = uploadSuccessfully
if(this.hasSendAttachment) {
console.log('send uploadSuccessfully')
} else {
console.log('not send uploadSuccessfully')
}
this.saveChanges() this.saveChanges()
} catch (error) { } catch (error) {
this.uploadingFile = false this.uploadingFile = false
console.log('send not uploadSuccessfully')
this.errorUploadingAttachment = true this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++
this.saveChanges() this.saveChanges()
} }
@@ -409,14 +424,14 @@ export class MessageService {
if(!roomObject.isGroup) { if(!roomObject.isGroup) {
var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe
this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg,this.rid) this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid)
} else { } else {
var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe
var usersNames = []; var usersNames = [];
for(let i = 0; i < memeberTosend.length; i++) { for(let i = 0; i < memeberTosend.length; i++) {
usersNames.push(memeberTosend[i].username) usersNames.push(memeberTosend[i].username)
} }
this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg,this.rid) this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid)
} }
@@ -766,6 +766,7 @@ export class RochetChatConnectorService {
setTimeout(()=>{ setTimeout(()=>{
this.ws.wsMsgQueue() this.ws.wsMsgQueue()
}, 10) }, 10)
console.log('rec conect')
if(this.wsReconnect >= 1) { if(this.wsReconnect >= 1) {
for (const [key, value] of Object.entries(this.wsCallbacks)) { for (const [key, value] of Object.entries(this.wsCallbacks)) {
+56 -7
View File
@@ -42,6 +42,7 @@ export class RoomService {
name = '' name = ''
_updatedAt = {} _updatedAt = {}
hasLoadHistory = false hasLoadHistory = false
DoneLoadingHistory = false
restoreFromOffline = false restoreFromOffline = false
duration = '' duration = ''
isTyping = false isTyping = false
@@ -327,7 +328,7 @@ export class RoomService {
this.registerSendMessage(message) this.registerSendMessage(message)
message.from = 'stream' message.from = 'stream'
message.loadHistory = this.hasLoadHistory message.loadHistory = this.DoneLoadingHistory
this.lastMessage = message; this.lastMessage = message;
this.calDateDuration(ChatMessage._updatedAt); this.calDateDuration(ChatMessage._updatedAt);
@@ -352,6 +353,7 @@ export class RoomService {
this.messageUnread = true this.messageUnread = true
// this.sortRoomList()
setTimeout(() => { setTimeout(() => {
this.scrollDown() this.scrollDown()
}, 50) }, 50)
@@ -550,6 +552,30 @@ export class RoomService {
} }
/**
* @description delete message in the view
* @param id message ID
*/
async deleteMessageFromArray(_id) {
const id = _id
for (let i =0; i <= this.messages.length; i++) {
if(this.messages[i]?._id == id ) {
this.messages.splice(i, 1)
return true
} else {
//
}
}
}
deleteAll() { deleteAll() {
this.messages.forEach((message) => { this.messages.forEach((message) => {
if(message?._id) { if(message?._id) {
@@ -619,7 +645,7 @@ export class RoomService {
} }
console.log('offlineChatMessage', offlineChatMessage) //console.log('offlineChatMessage', offlineChatMessage)
this.message= '' this.message= ''
@@ -792,7 +818,7 @@ export class RoomService {
this.messages.push(cloneMessage as any) this.messages.push(cloneMessage as any)
console.log(currentDateMessage) // console.log(currentDateMessage)
} }
} }
} }
@@ -851,9 +877,6 @@ export class RoomService {
const messages = this.sortArrayISODate(await MessageModel.filter({rid:this.id}).execute()).reverse() const messages = this.sortArrayISODate(await MessageModel.filter({rid:this.id}).execute()).reverse()
console.log('MessageModel', messages)
for (let ChatMessage of messages) { for (let ChatMessage of messages) {
@@ -907,6 +930,7 @@ export class RoomService {
// runs onces only // runs onces only
loadHistoryCount = 0 loadHistoryCount = 0
localMessages = []
async loadHistory({limit = 1000, forceUpdate = false }) { async loadHistory({limit = 1000, forceUpdate = false }) {
if(forceUpdate == false) { if(forceUpdate == false) {
@@ -920,6 +944,8 @@ export class RoomService {
await this.restoreMessageFromDB() await this.restoreMessageFromDB()
const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit) const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit)
this.localMessages = this.messages.map( e => e._id)
if(chatHistory?.result?.messages) { if(chatHistory?.result?.messages) {
const users = this.getUsersByStatus('online') const users = this.getUsersByStatus('online')
@@ -955,6 +981,8 @@ export class RoomService {
} }
this.DoneLoadingHistory = true
if(chatHistory?.result?.messages) { if(chatHistory?.result?.messages) {
if(!this.lastMessage) { if(!this.lastMessage) {
@@ -962,10 +990,31 @@ export class RoomService {
} }
} }
this.deletedMessages(chatHistory)
} }
deletedMessages(chatHistory: chatHistory) {
const messagesToDelete = this.localMessages.filter( id => {
const found = chatHistory.result.messages.find( e => {
return e._id == id
})
if(!found) {
return true
}
return false
})
for (const id of messagesToDelete) {
if(id != '') {
this.deleteMessage(id)
}
}
}
addMessageDB = FIFOProcessQueue(async ({messagesToSave}, callback) => { addMessageDB = FIFOProcessQueue(async ({messagesToSave}, callback) => {
await messagesToSave.addMessageDB() await messagesToSave.addMessageDB()
@@ -6,6 +6,7 @@
<ion-label class="title">{{ ChatSystemService.getGroupRoom(roomId).name.split('-').join(' ') }}</ion-label> <ion-label class="title">{{ ChatSystemService.getGroupRoom(roomId).name.split('-').join(' ') }}</ion-label>
</div> </div>
<div class="right"> <div class="right">
<!-- <div (click)=" ChatSystemService.getGroupRoom(this.roomId).deleteAll()">delete all</div> -->
<button title="Menu" class="btn-no-color" (click)="openGroupMessagesOptions()"> <button title="Menu" class="btn-no-color" (click)="openGroupMessagesOptions()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/icons-menu.svg"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/icons-menu.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-menu.svg"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-menu.svg"></ion-icon>
@@ -55,8 +56,8 @@
</div> </div>
<div class="message"> <div class="message">
<pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<pre *ngIf="msg.delate == true" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == true" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<ion-label class="float-status-all float-status" *ngIf="msg.u.username==sessionStore.user.UserName"> <ion-label class="float-status-all float-status" *ngIf="msg.u.username==sessionStore.user.UserName">
@@ -5,7 +5,7 @@
<div class="middle"> <div class="middle">
<ion-label class="title">{{ ChatSystemService.getDmRoom(this.roomId).name }}</ion-label> <ion-label class="title">{{ ChatSystemService.getDmRoom(this.roomId).name }}</ion-label>
<!-- <button (click)="ChatMessageDebuggingPage()">Dev</button> --> <!-- <button (click)="ChatMessageDebuggingPage()">Dev</button> -->
<span><ion-icon class="{{ ChatSystemService.getDmRoom(this.roomId).online }}" name="ellipse"></ion-icon></span> <span><ion-icon *ngIf="RochetChatConnectorService.isLogin" class="{{ ChatSystemService.getDmRoom(this.roomId).online }}" name="ellipse"></ion-icon></span>
</div> </div>
<div hidden class="right"> <div hidden class="right">
<button title="Menu" class="btn-no-color" (click)="_openMessagesOptions()"> <button title="Menu" class="btn-no-color" (click)="_openMessagesOptions()">
@@ -37,6 +37,7 @@
<div class="messages" #scrollMe> <div class="messages" #scrollMe>
<ion-list> <ion-list>
<!-- <div (click)=" ChatSystemService.getDmRoom(this.roomId).deleteAll()">delete all</div> -->
<div class="messages-list-item-wrapper container-width-100" <div class="messages-list-item-wrapper container-width-100"
*ngFor="let msg of ChatSystemService.getDmRoom(roomId).messages; index as i; let last = last" > *ngFor="let msg of ChatSystemService.getDmRoom(roomId).messages; index as i; let last = last" >
@@ -54,7 +55,7 @@
</div> </div>
<div class="d-block justify-space-between"> <div class="d-block justify-space-between">
<pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}} </pre> <pre *ngIf="msg.delate == false" class="message-box text ma-0 font-13-rem" style="font-size: 0.8125rem !important;" >{{msg.msg}}</pre>
<!-- <ion-label *ngIf="msg.delate == false" class="message-box">{{msg.msg}} </ion-label> --> <!-- <ion-label *ngIf="msg.delate == false" class="message-box">{{msg.msg}} </ion-label> -->
<ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label> <ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label>