mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Merge branch 'developer' of https://bitbucket.org/equilibriumito/gabinete-digital into developer
This commit is contained in:
@@ -152,10 +152,13 @@ export class HomePage implements OnInit {
|
|||||||
} else {
|
} else {
|
||||||
this.synchWhenOnline()
|
this.synchWhenOnline()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this.WsChatService.login()
|
||||||
});
|
});
|
||||||
window.addEventListener('offline', () => {
|
window.addEventListener('offline', () => {
|
||||||
console.log('Became offline')
|
console.log('Became offline')
|
||||||
this.backgroundservice.offline()
|
this.backgroundservice.offline()
|
||||||
|
//this.WsChatService.logout()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateList()
|
this.updateList()
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div (click)="openPreview(msg)">
|
<div (click)="openPreview(msg)">
|
||||||
File
|
File
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -102,8 +102,8 @@
|
|||||||
<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)="openPreview(msg)">
|
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image" >
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image" >
|
||||||
<ion-icon *ngIf="msg.file.image_url == null" name="download-outline"></ion-icon>
|
<ion-icon *ngIf="msg.attachments[0].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">
|
||||||
|
|||||||
@@ -454,8 +454,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": capturedImage
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
@@ -533,8 +532,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({
|
this.wsChatMethodsService.getDmRoom(this.roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": imageData
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
|
|||||||
@@ -83,8 +83,8 @@
|
|||||||
<div *ngIf="msg.attachments" class="message-attachments">
|
<div *ngIf="msg.attachments" class="message-attachments">
|
||||||
<div *ngFor="let file of msg.attachments let i = index">
|
<div *ngFor="let file of msg.attachments let i = index">
|
||||||
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
|
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
|
||||||
<ion-icon *ngIf="msg.file.image_url == null" name="download-outline"></ion-icon>
|
<ion-icon *ngIf="msg.attachments[0].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">
|
||||||
|
|||||||
@@ -540,8 +540,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": capturedImage
|
|
||||||
},
|
},
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"image_url": capturedImage,
|
"image_url": capturedImage,
|
||||||
@@ -582,7 +581,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
const roomId = this.roomId
|
const roomId = this.roomId
|
||||||
|
|
||||||
if(data.selected) {
|
if(data.selected) {
|
||||||
const loader = this.toastService.loading();
|
|
||||||
|
|
||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file:{
|
file:{
|
||||||
@@ -604,8 +602,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
loader.remove();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -632,8 +628,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": 'data:image/jpeg;base64,' +file.base64String
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
@@ -663,7 +658,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": imageData
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
|
||||||
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
|
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { HttpService } from './http.service';
|
import { HttpService } from './http.service';
|
||||||
@@ -18,6 +18,7 @@ import { ProcessesService } from 'src/app/services/processes.service';
|
|||||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||||
import { RoomService } from './chat/room.service';
|
import { RoomService } from './chat/room.service';
|
||||||
import { Storage } from '@ionic/storage';
|
import { Storage } from '@ionic/storage';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
@@ -173,6 +174,7 @@ export class AuthService {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +188,7 @@ export class AuthService {
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +197,43 @@ export class AuthService {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||||
|
|
||||||
|
console.log('FILE TYPE', message.file.type)
|
||||||
|
let downloadFile = "";
|
||||||
|
if (message.file.type == "application/img") {
|
||||||
|
const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||||
|
|
||||||
|
console.log('FILE TYPE 22', message.file.guid)
|
||||||
|
|
||||||
|
if (event.type === HttpEventType.DownloadProgress) {
|
||||||
|
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||||
|
console.log('FILE TYPE 33', message.file.type)
|
||||||
|
return true
|
||||||
|
} else if (event.type === HttpEventType.Response) {
|
||||||
|
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||||
|
|
||||||
|
message.file = {
|
||||||
|
guid: message.file.guid,
|
||||||
|
image_url: downloadFile,
|
||||||
|
type: message.file.type
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.storage.set(message.file.guid, downloadFile).then(() => {
|
||||||
|
console.log('IMAGE SAVED')
|
||||||
|
});
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}, 1)
|
}, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import { ChatService } from '../chat.service';
|
|||||||
})
|
})
|
||||||
export class ChatMethodsService {
|
export class ChatMethodsService {
|
||||||
|
|
||||||
constructor(private chatService: ChatService) {
|
constructor(
|
||||||
|
private chatService: ChatService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(roomId:string, data:any) {
|
sendMessage(roomId:string, data:any) {
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ export class MessageService {
|
|||||||
temporaryData: any = {}
|
temporaryData: any = {}
|
||||||
hasFile = false
|
hasFile = false
|
||||||
hasSendAttachment = false
|
hasSendAttachment = false
|
||||||
|
sendAttempt = 0
|
||||||
|
uploadingFile = false
|
||||||
|
errorUploadingAttachment = false
|
||||||
|
|
||||||
constructor(private storage: Storage,
|
constructor(private storage: Storage,
|
||||||
private NfService: NfService,
|
private NfService: NfService,
|
||||||
@@ -90,34 +93,71 @@ export class MessageService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendFile() {
|
async send() {
|
||||||
if(this.file == null && this.attachments == null) {
|
|
||||||
|
this.sendAttempt++;
|
||||||
|
|
||||||
|
if(!this.hasFile) {
|
||||||
console.log('simple send')
|
console.log('simple send')
|
||||||
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
|
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
|
||||||
let ChatMessage = data.result
|
let ChatMessage = data.result
|
||||||
this.redefinedMessage(this, ChatMessage)
|
this.redefinedMessage(this, ChatMessage)
|
||||||
|
this.offline = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('complex send')
|
console.log('complex send')
|
||||||
|
|
||||||
const result = this.NfService.beforeSendAttachment(this)
|
this.uploadingFile = true
|
||||||
|
|
||||||
|
let uploadSuccessfully = false
|
||||||
|
if(this.hasSendAttachment == false) {
|
||||||
|
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
|
||||||
|
}
|
||||||
|
|
||||||
if(result) {
|
this.uploadingFile = false
|
||||||
|
|
||||||
|
if(uploadSuccessfully || this.hasSendAttachment == false) {
|
||||||
this.hasSendAttachment = true
|
this.hasSendAttachment = true
|
||||||
|
this.errorUploadingAttachment = false
|
||||||
|
this.temporaryData = {}
|
||||||
|
|
||||||
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
|
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
|
||||||
console.log('send sucees', data.result)
|
console.log('send sucees', data.result)
|
||||||
let ChatMessage = data.result
|
let ChatMessage = data.result
|
||||||
this.redefinedMessage(this, ChatMessage)
|
this.redefinedMessage(this, ChatMessage)
|
||||||
|
this.offline = false
|
||||||
})
|
})
|
||||||
|
} else if(this.WsChatService.isLogin == false) {
|
||||||
|
|
||||||
|
|
||||||
|
this.WsChatService.registerCallback({
|
||||||
|
type: 'reConnect',
|
||||||
|
funx:()=> {
|
||||||
|
alert('reConnect')
|
||||||
|
// this.send()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} else if(uploadSuccessfully == false) {
|
||||||
|
|
||||||
|
this.errorUploadingAttachment = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redefinedMessage(messagem, ChatMessage){
|
redefinedMessage(messagem, ChatMessage) {
|
||||||
this.setData(ChatMessage)
|
this.setData(ChatMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async downloadFileMsg() {
|
||||||
|
const result = await this.NfService.beforeSendAttachment(this)
|
||||||
|
if(result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { RoomService } from './room.service';
|
|||||||
export class NfService {
|
export class NfService {
|
||||||
|
|
||||||
beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
||||||
|
downloadFileMsg = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
|||||||
import { MessageService } from 'src/app/services/chat/message.service';
|
import { MessageService } from 'src/app/services/chat/message.service';
|
||||||
import { showDateDuration } from 'src/plugin/showDateDuration';
|
import { showDateDuration } from 'src/plugin/showDateDuration';
|
||||||
import { ToastsService } from '../toast.service';
|
import { ToastsService } from '../toast.service';
|
||||||
import { chatHistory, ChatMessage } from 'src/app/models/chatMethod';
|
import { chatHistory } from 'src/app/models/chatMethod';
|
||||||
import { Storage } from '@ionic/storage';
|
import { Storage } from '@ionic/storage';
|
||||||
import { Platform } from '@ionic/angular';
|
import { Platform } from '@ionic/angular';
|
||||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||||
@@ -91,31 +91,40 @@ export class RoomService {
|
|||||||
this.id,
|
this.id,
|
||||||
"stream-room-messages",
|
"stream-room-messages",
|
||||||
(ChatMessage) => {
|
(ChatMessage) => {
|
||||||
ChatMessage = ChatMessage.fields.args[0]
|
|
||||||
|
|
||||||
if(environment.chatOffline == false || this.isSenderIsNotMe(ChatMessage)) {
|
setTimeout(()=>{
|
||||||
|
ChatMessage = ChatMessage.fields.args[0]
|
||||||
|
|
||||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||||
console.log('recivemessage', ChatMessage)
|
// console.log('recivemessage', ChatMessage)
|
||||||
|
|
||||||
const message = this.prepareMessage(ChatMessage)
|
const messageIsFound = this.messages.find((message) => {
|
||||||
|
return message._id == ChatMessage._id
|
||||||
|
})
|
||||||
|
|
||||||
this.lastMessage = message
|
if(!messageIsFound) {
|
||||||
if (message.t == 'r') { this.name = message.msg }
|
console.log('messageIsFound', messageIsFound)
|
||||||
this.calDateDuration(ChatMessage._updatedAt)
|
const message = this.prepareMessage(ChatMessage)
|
||||||
|
|
||||||
setTimeout(() => {
|
this.lastMessage = message
|
||||||
this.scrollDown()
|
if (message.t == 'r') { this.name = message.msg }
|
||||||
}, 100)
|
this.calDateDuration(ChatMessage._updatedAt)
|
||||||
|
|
||||||
this.NativeNotificationService.sendNotificationChat({
|
setTimeout(() => {
|
||||||
message: message.msg,
|
this.scrollDown()
|
||||||
title: this.name
|
}, 100)
|
||||||
});
|
|
||||||
|
|
||||||
this.addMessageDB(ChatMessage)
|
this.NativeNotificationService.sendNotificationChat({
|
||||||
|
message: message.msg,
|
||||||
|
title: this.name
|
||||||
|
});
|
||||||
|
|
||||||
|
this.addMessageDB(ChatMessage)
|
||||||
|
} else {
|
||||||
|
console.log('have')
|
||||||
|
}
|
||||||
|
}, 150)
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -132,12 +141,13 @@ export class RoomService {
|
|||||||
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
|
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
|
||||||
|
|
||||||
})
|
})
|
||||||
this.WsChatService.registerCallback
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
addMessageDB(ChatMessage) {
|
addMessageDB(ChatMessage) {
|
||||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||||
|
if(messages==null) messages = []
|
||||||
|
|
||||||
delete ChatMessage.temporaryData
|
delete ChatMessage.temporaryData
|
||||||
messages.push(ChatMessage)
|
messages.push(ChatMessage)
|
||||||
|
|
||||||
@@ -158,7 +168,7 @@ export class RoomService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.WsChatService.registerCallback
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,6 +198,7 @@ export class RoomService {
|
|||||||
*/
|
*/
|
||||||
private deleteMessageFromDb(id) {
|
private deleteMessageFromDb(id) {
|
||||||
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
|
||||||
|
if(messages==null) messages = []
|
||||||
|
|
||||||
messages.forEach((message, index) => {
|
messages.forEach((message, index) => {
|
||||||
|
|
||||||
@@ -228,31 +239,7 @@ export class RoomService {
|
|||||||
|
|
||||||
this.lastMessage = message
|
this.lastMessage = message
|
||||||
|
|
||||||
|
message.send()
|
||||||
if(file == null && attachments == null) {
|
|
||||||
console.log('simple send')
|
|
||||||
this.WsChatService.send({roomId:this.id, msg:message.msg}).then((data: any) => {
|
|
||||||
let ChatMessage = data.result
|
|
||||||
this.redefinedMessage(message, ChatMessage)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.log('complex send')
|
|
||||||
|
|
||||||
const result = await this.NfService.beforeSendAttachment(message, this)
|
|
||||||
|
|
||||||
|
|
||||||
if(result) {
|
|
||||||
message.hasSendAttachment = true
|
|
||||||
|
|
||||||
this.WsChatService.send({roomId:this.id, msg:message.msg, attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
|
|
||||||
console.log('send sucees', data.result)
|
|
||||||
let ChatMessage = data.result
|
|
||||||
this.redefinedMessage(message, ChatMessage)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.calDateDuration(message._updatedAt)
|
this.calDateDuration(message._updatedAt)
|
||||||
this.sortRoomList()
|
this.sortRoomList()
|
||||||
@@ -342,29 +329,21 @@ export class RoomService {
|
|||||||
|
|
||||||
async restoreMessageFromDB() {
|
async restoreMessageFromDB() {
|
||||||
await this.storage.get('chatmsg' + this.id).then( async (messages = []) => {
|
await this.storage.get('chatmsg' + this.id).then( async (messages = []) => {
|
||||||
|
|
||||||
if(messages==null) messages = []
|
if(messages==null) messages = []
|
||||||
|
|
||||||
await messages.forEach( async (ChatMessage, index) => {
|
await messages.forEach( async (ChatMessage, index) => {
|
||||||
const wewMessage = this.prepareMessage(ChatMessage)
|
const wewMessage = this.prepareMessage(ChatMessage, false)
|
||||||
|
|
||||||
if(wewMessage.offline == true) {
|
if(wewMessage.offline == false) {
|
||||||
// this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
|
this.prepareMessage(ChatMessage)
|
||||||
// let _ChatMessage = data.result
|
|
||||||
// this.redefinedMessage(wewMessage, _ChatMessage)
|
|
||||||
// messages[index] = _ChatMessage
|
|
||||||
// this.storage.set('chatmsg' + this.id, messages)
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.messages = alasql('SELECT * FROM ? ORDER BY _updatedAt',[ this.messages]);
|
|
||||||
setTimeout(()=> {
|
setTimeout(()=> {
|
||||||
this.scrollDown()
|
this.scrollDown()
|
||||||
}, 50)
|
}, 50)
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +352,7 @@ export class RoomService {
|
|||||||
|
|
||||||
if (this.hasLoadHistory) { return false }
|
if (this.hasLoadHistory) { return false }
|
||||||
|
|
||||||
await this.restoreMessageFromDB()
|
this.restoreMessageFromDB()
|
||||||
|
|
||||||
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
||||||
console.log('loadHistory', chatHistory)
|
console.log('loadHistory', chatHistory)
|
||||||
@@ -381,17 +360,8 @@ export class RoomService {
|
|||||||
|
|
||||||
await chatHistory.result.messages.reverse().forEach( async (message) => {
|
await chatHistory.result.messages.reverse().forEach( async (message) => {
|
||||||
this.prepareMessage(message)
|
this.prepareMessage(message)
|
||||||
|
|
||||||
// const result = alasql(`SELECT * FROM ? WHERE _id = "${message._id}" `,[ this.messages]);
|
|
||||||
// if(result.length == 0) {
|
|
||||||
// this.prepareMessage(message)
|
|
||||||
// this.storage.set('chatmsg' + this.id, chatHistory.result.messages.concat([message]))
|
|
||||||
// }
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(chatHistory.result.messages);
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -403,19 +373,18 @@ export class RoomService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
prepareMessage(message): MessageService {
|
prepareMessage(message, save = true): MessageService {
|
||||||
message = this.fix_updatedAt(message)
|
message = this.fix_updatedAt(message)
|
||||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
||||||
wewMessage.setData(message)
|
wewMessage.setData(message)
|
||||||
this.messages.push(wewMessage)
|
|
||||||
|
if (save) {
|
||||||
|
this.messages.push(wewMessage)
|
||||||
|
}
|
||||||
|
|
||||||
return wewMessage
|
return wewMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMeessage(messageID, imgbase64) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async returnData(res) {
|
async returnData(res) {
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -13,13 +13,14 @@ import { NativeNotificationService } from 'src/app/services/native-notification.
|
|||||||
import { SortService } from '../functions/sort.service';
|
import { SortService } from '../functions/sort.service';
|
||||||
import { chatUser } from 'src/app/models/chatMethod';
|
import { chatUser } from 'src/app/models/chatMethod';
|
||||||
import { NfService } from 'src/app/services/chat/nf.service'
|
import { NfService } from 'src/app/services/chat/nf.service'
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class WsChatMethodsService {
|
export class WsChatMethodsService {
|
||||||
|
|
||||||
dm: {[key: string]: RoomService} = {}
|
dm = {}
|
||||||
group: {[key: string]: RoomService} = {}
|
group = {}
|
||||||
|
|
||||||
|
|
||||||
_dm = []
|
_dm = []
|
||||||
@@ -42,9 +43,10 @@ export class WsChatMethodsService {
|
|||||||
private NativeNotificationService: NativeNotificationService,
|
private NativeNotificationService: NativeNotificationService,
|
||||||
private sortService: SortService,
|
private sortService: SortService,
|
||||||
private ChatService: ChatService,
|
private ChatService: ChatService,
|
||||||
private NfService: NfService
|
private NfService: NfService,
|
||||||
) {
|
) {
|
||||||
(async()=>{
|
(async()=>{
|
||||||
|
await this.restoreRooms()
|
||||||
await this.getAllRooms();
|
await this.getAllRooms();
|
||||||
this.subscribeToRoom()
|
this.subscribeToRoom()
|
||||||
|
|
||||||
@@ -67,6 +69,39 @@ export class WsChatMethodsService {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// this.WsChatService.registerCallback({
|
||||||
|
// type:'Onmessage',
|
||||||
|
// funx:(message) => {
|
||||||
|
|
||||||
|
// if(message.msg =='changed' && message.collection == "stream-room-messages") {
|
||||||
|
// if(message.fields.args[0].rid) {
|
||||||
|
// // new message
|
||||||
|
// const ChatMessage = message.fields.args[0]
|
||||||
|
// const messageId = ChatMessage.rid
|
||||||
|
|
||||||
|
// setTimeout(()=>{
|
||||||
|
// this.sortRoomList()
|
||||||
|
// }, 100)
|
||||||
|
|
||||||
|
// }
|
||||||
|
// } else if(message.msg =='changed' && message.collection == "stream-notify-room") {
|
||||||
|
// if(message.fields.eventName.includes('deleteMessage')) {
|
||||||
|
// // delete message
|
||||||
|
// const DeletedMessageId = message.fields.args[0]._id;
|
||||||
|
|
||||||
|
// setTimeout(()=>{
|
||||||
|
// this.sortRoomList()
|
||||||
|
// }, 100)
|
||||||
|
|
||||||
|
// } else if(message.fields.eventName.includes('typing')) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getRoomFromDb() {
|
getRoomFromDb() {
|
||||||
@@ -98,6 +133,24 @@ export class WsChatMethodsService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async restoreRooms() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rooms = await this.storage.get('Rooms');
|
||||||
|
|
||||||
|
if(rooms) {
|
||||||
|
await rooms.result.update.forEach( async (roomData: room) => {
|
||||||
|
await this.prepareRoom(roomData);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(e){}
|
||||||
|
|
||||||
|
this.sortRoomList()
|
||||||
|
}
|
||||||
|
|
||||||
async getAllRooms () {
|
async getAllRooms () {
|
||||||
this.loadingWholeList = true
|
this.loadingWholeList = true
|
||||||
//this.getRoomFromDb();
|
//this.getRoomFromDb();
|
||||||
@@ -105,31 +158,12 @@ export class WsChatMethodsService {
|
|||||||
await this.storage.remove('Rooms');
|
await this.storage.remove('Rooms');
|
||||||
await this.storage.set('Rooms', rooms);
|
await this.storage.set('Rooms', rooms);
|
||||||
|
|
||||||
// console.log("ROOMS" + JSON.stringify(rooms))
|
console.log('rooms', rooms)
|
||||||
this.WsChatService.registerCallback({
|
|
||||||
type:'Onmessage',
|
|
||||||
funx:(message)=>{
|
|
||||||
|
|
||||||
if(message.msg =='changed' && message.collection == "stream-room-messages") {
|
this.dm = {}
|
||||||
if(message.fields.args[0].rid) {
|
this.group = {}
|
||||||
|
this._dm = []
|
||||||
setTimeout(()=>{
|
this._group = []
|
||||||
this.sortRoomList()
|
|
||||||
|
|
||||||
}, 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message.msg =='changed' && message.collection == "stream-notify-room") {
|
|
||||||
if(message.fields.eventName.includes('deleteMessage')){
|
|
||||||
setTimeout(()=>{
|
|
||||||
|
|
||||||
this.sortRoomList()
|
|
||||||
}, 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
await rooms.result.update.forEach( async (roomData: room) => {
|
await rooms.result.update.forEach( async (roomData: room) => {
|
||||||
await this.prepareRoom(roomData);
|
await this.prepareRoom(roomData);
|
||||||
@@ -249,20 +283,20 @@ export class WsChatMethodsService {
|
|||||||
*/
|
*/
|
||||||
private getUserStatus(id?:string) {
|
private getUserStatus(id?:string) {
|
||||||
|
|
||||||
this.WsChatService.getUserStatus((d) => {
|
// this.WsChatService.getUserStatus((d) => {
|
||||||
|
|
||||||
const username = d.fields.args[0][1]
|
// const username = d.fields.args[0][1]
|
||||||
const statusNum = d.fields.args[0][2]
|
// const statusNum = d.fields.args[0][2]
|
||||||
|
|
||||||
const statusText = this.statusNumberToText(statusNum)
|
// const statusText = this.statusNumberToText(statusNum)
|
||||||
|
|
||||||
const user = this.getUserByName(username)
|
// const user = this.getUserByName(username)
|
||||||
|
|
||||||
if(user) {
|
// if(user) {
|
||||||
user.status = statusText
|
// user.status = statusText
|
||||||
}
|
// }
|
||||||
|
|
||||||
})
|
// })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ export class WsChatService {
|
|||||||
loginResponse = {}
|
loginResponse = {}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('online', ()=>{
|
|
||||||
this.connect()
|
|
||||||
this.login()
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
@@ -612,13 +605,15 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
|||||||
private wsCallbacks: {[key: string]: wsCallbacksParams} = {}
|
private wsCallbacks: {[key: string]: wsCallbacksParams} = {}
|
||||||
private wsReconnect = 0
|
private wsReconnect = 0
|
||||||
|
|
||||||
|
private n = 0
|
||||||
|
|
||||||
private ws = {
|
private ws = {
|
||||||
connected: false,
|
connected: false,
|
||||||
registerCallback:(params: wsCallbacksParams) => {
|
registerCallback:(params: wsCallbacksParams) => {
|
||||||
|
|
||||||
let id = params.requestId || params.key || uuidv4()
|
let id = params.requestId || params.key || uuidv4()
|
||||||
this.wsCallbacks[id] = params
|
this.wsCallbacks[id] = params
|
||||||
|
this.n++
|
||||||
return id
|
return id
|
||||||
},
|
},
|
||||||
connect:()=> {
|
connect:()=> {
|
||||||
@@ -629,19 +624,19 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
|||||||
this.socket.onclose = this.ws.onclose;
|
this.socket.onclose = this.ws.onclose;
|
||||||
this.socket.onerror = this.ws.onerror;
|
this.socket.onerror = this.ws.onerror;
|
||||||
},
|
},
|
||||||
onopen:()=> {
|
onopen: async ()=> {
|
||||||
this.ws.connected = true
|
this.ws.connected = true
|
||||||
|
|
||||||
console.log('================== welcome to socket server =====================')
|
console.log('================== welcome to socket server =====================')
|
||||||
|
|
||||||
this.ws.wsMsgQueue()
|
this.ws.wsMsgQueue()
|
||||||
|
|
||||||
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)) {
|
||||||
if(value.type== 'reConnect') {
|
if(value.type== 'reConnect') {
|
||||||
const dontRepeat = value.funx()
|
const dontRepeat = await value.funx()
|
||||||
|
|
||||||
if(dontRepeat) {
|
if(dontRepeat) {
|
||||||
|
this.n--
|
||||||
delete this.wsCallbacks[key]
|
delete this.wsCallbacks[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,15 +676,16 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
|||||||
return requestId
|
return requestId
|
||||||
},
|
},
|
||||||
|
|
||||||
onmessage:(event: any)=> {
|
onmessage: async (event: any)=> {
|
||||||
const data = JSON.parse(event.data)
|
const data = JSON.parse(event.data)
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||||
if(value.type== 'Onmessage') {
|
if(value.type== 'Onmessage') {
|
||||||
const dontRepeat = value.funx(data)
|
const dontRepeat = await value.funx(data)
|
||||||
|
|
||||||
if(dontRepeat) {
|
if(dontRepeat) {
|
||||||
delete this.wsCallbacks[key]
|
delete this.wsCallbacks[key]
|
||||||
|
this.n--
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,8 @@
|
|||||||
<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)="openPreview(msg)">
|
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)">
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
|
||||||
<ion-icon *ngIf="msg.file.image_url == null" name="download-outline"></ion-icon>
|
<ion-icon *ngIf="msg.attachments[0].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">
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
<div *ngIf="msg.file" class="message-attachments">
|
<div *ngIf="msg.file" class="message-attachments">
|
||||||
<div>
|
<div>
|
||||||
<div (click)="openPreview(msg)">
|
<div (click)="openPreview(msg)">
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -558,8 +558,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": capturedImage
|
|
||||||
},
|
},
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": capturedImageTitle ,
|
"title": capturedImageTitle ,
|
||||||
@@ -642,8 +641,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": imageData
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
|
|||||||
@@ -67,14 +67,14 @@
|
|||||||
</mat-menu>
|
</mat-menu>
|
||||||
</div>
|
</div>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<ion-label>{{msg.u.name}} </ion-label>
|
<ion-label>{{msg.u.name}} </ion-label>
|
||||||
<span class="time">{{showDateDuration(msg.duration)}}</span>
|
<span class="time">{{showDateDuration(msg.duration)}}</span>
|
||||||
</div>
|
</div>
|
||||||
<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)="openPreview(msg)">
|
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)" dfsdvsvs>
|
||||||
<img src={{msg.file.image_url}} alt="image">
|
<img src={{msg.attachments[0].image_url}} alt="image">
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="msg.file.type != 'application/img'">
|
<div *ngIf="msg.file.type != 'application/img'">
|
||||||
<div class="file">
|
<div class="file">
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div (click)="openPreview(msg)">
|
<div (click)="openPreview(msg)">
|
||||||
File
|
File
|
||||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -277,7 +277,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
changeInput() {
|
changeInput() {
|
||||||
this.wsChatMethodsService.getDmRoom(this.roomId).typing()
|
this.wsChatMethodsService.getDmRoom(this.roomId).typing()
|
||||||
}
|
}
|
||||||
@@ -466,7 +465,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": 'data:image/jpeg;base64,' +file.base64String
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
@@ -497,8 +495,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": capturedImage
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
@@ -583,8 +580,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": ''
|
||||||
"image_url": 'data:image/jpeg;base64,' +file.base64String
|
|
||||||
},
|
},
|
||||||
temporaryData: formData,
|
temporaryData: formData,
|
||||||
attachments: [{
|
attachments: [{
|
||||||
@@ -614,7 +610,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
file: {
|
file: {
|
||||||
"type": "application/img",
|
"type": "application/img",
|
||||||
"guid": '',
|
"guid": '',
|
||||||
"image_url": imageData, // GPR
|
|
||||||
},
|
},
|
||||||
attachments: [{
|
attachments: [{
|
||||||
"title": file.name ,
|
"title": file.name ,
|
||||||
|
|||||||
Reference in New Issue
Block a user