mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
Merge branch 'developer' of bitbucket.org:equilibriumito/gabinete-digital into developer
This commit is contained in:
@@ -10,6 +10,8 @@ import { ChatStorageService } from './chat-storage.service'
|
||||
import { ChatMethodsService } from './chat-methods.service'
|
||||
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
|
||||
import { AESEncrypt } from '../aesencrypt.service'
|
||||
import { HttpClient, HttpEventType } from '@angular/common/http';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -59,7 +61,8 @@ export class MessageService {
|
||||
private WsChatService: WsChatService,
|
||||
private ChatStorageService: ChatStorageService,
|
||||
private ChatMethodsService: ChatMethodsService,
|
||||
private AESEncrypt: AESEncrypt) {
|
||||
private AESEncrypt: AESEncrypt,
|
||||
private AttachmentsService: AttachmentsService,) {
|
||||
}
|
||||
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) {
|
||||
@@ -74,17 +77,21 @@ export class MessageService {
|
||||
this._id = _id
|
||||
this._updatedAt = _updatedAt || new Date().getTime()
|
||||
this.file = file
|
||||
this.attachments = attachments
|
||||
this.temporaryData = temporaryData
|
||||
this.localReference = localReference || null
|
||||
this.id = id
|
||||
this.delate = delate
|
||||
this.delateRequest = delateRequest
|
||||
|
||||
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
|
||||
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
|
||||
} else {
|
||||
this.attachments = attachments
|
||||
}
|
||||
|
||||
this.viewed = [...new Set([...viewed,...this.viewed])];
|
||||
this.received = [...new Set([...received,...this.received])];
|
||||
|
||||
|
||||
if(!this.ts) {
|
||||
this.offline = true
|
||||
this.messageSend = false
|
||||
@@ -102,7 +109,6 @@ export class MessageService {
|
||||
}
|
||||
|
||||
if(this.hasFile) {
|
||||
// this.getFileFromDb()
|
||||
if(this.file.type != 'application/webtrix') {
|
||||
this.displayType = this.file.type.replace('application/','').toUpperCase()
|
||||
}
|
||||
@@ -118,19 +124,6 @@ export class MessageService {
|
||||
return firstName + ' ' + lastName
|
||||
}
|
||||
|
||||
// getFileFromDb() {
|
||||
|
||||
// if(this.hasFile) {
|
||||
// if (this.file.guid) {
|
||||
// this.storage.get(this.file.guid).then((image) => {
|
||||
// if(image != null) {
|
||||
// this.file.image_url = image
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
async send(): Promise<any> {
|
||||
|
||||
this.sendAttempt++;
|
||||
@@ -152,7 +145,7 @@ export class MessageService {
|
||||
|
||||
this.uploadingFile = false
|
||||
|
||||
if(uploadSuccessfully || this.hasSendAttachment == false) {
|
||||
if(uploadSuccessfully) {
|
||||
this.hasSendAttachment = true
|
||||
this.errorUploadingAttachment = false
|
||||
this.temporaryData = {}
|
||||
@@ -186,6 +179,11 @@ export class MessageService {
|
||||
}
|
||||
|
||||
async sendRequest(params) {
|
||||
|
||||
if(params?.attachments?.image_url) {
|
||||
delete params?.attachments?.image_url
|
||||
}
|
||||
|
||||
this.ChatMethodsService.send(params).subscribe(
|
||||
(response: any) => {
|
||||
const ChatMessage = response.message
|
||||
@@ -198,12 +196,7 @@ export class MessageService {
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
|
||||
this.WsChatService.send(params).then(({message, requestId}) => {
|
||||
let ChatMessage = message.result
|
||||
this.messageSend = true
|
||||
this.redefinedMessage(ChatMessage)
|
||||
|
||||
})
|
||||
this.send()
|
||||
return true
|
||||
}
|
||||
})
|
||||
@@ -222,11 +215,36 @@ export class MessageService {
|
||||
await this.save()
|
||||
}
|
||||
|
||||
async downloadFileMsg() {
|
||||
const result = await this.NfService.beforeSendAttachment(this)
|
||||
if(result) {
|
||||
downloadFileMsg() {
|
||||
|
||||
}
|
||||
let downloadFile = "";
|
||||
this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => {
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
if (this.file.type == "application/img") {
|
||||
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
} else if (this.file.type === 'application/pdf') {
|
||||
|
||||
downloadFile = event.body as any;
|
||||
} else if (this.file.type == 'application/audio') {
|
||||
downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
||||
}
|
||||
|
||||
this.attachments[0] = {
|
||||
image_url: downloadFile,
|
||||
name: this.attachments[0].name,
|
||||
title: this.attachments[0].title,
|
||||
title_link: downloadFile,
|
||||
title_link_download: this.attachments[0].title_link_download,
|
||||
ts: this.attachments[0].ts
|
||||
}
|
||||
|
||||
// save the changes to the storage
|
||||
this.save()
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -242,7 +260,6 @@ export class MessageService {
|
||||
|
||||
async delateDB() {
|
||||
|
||||
// alert('delete data')
|
||||
const message = await MessageModel.get({_id: this._id})
|
||||
await message.delete()
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import { ChatMethodsService } from './chat-methods.service'
|
||||
import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
|
||||
import { AESEncrypt } from '../aesencrypt.service'
|
||||
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -75,7 +76,8 @@ export class RoomService {
|
||||
private NfService: NfService,
|
||||
private ChatStorageService: ChatStorageService,
|
||||
private ChatMethodsService: ChatMethodsService,
|
||||
private AESEncrypt: AESEncrypt
|
||||
private AESEncrypt: AESEncrypt,
|
||||
private AttachmentsService: AttachmentsService
|
||||
) {
|
||||
this.NativeNotificationService.askForPermission()
|
||||
|
||||
@@ -143,7 +145,7 @@ export class RoomService {
|
||||
}
|
||||
}
|
||||
|
||||
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), _updatedAt }) {
|
||||
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), _updatedAt }) {
|
||||
this.customFields = customFields
|
||||
this.id = id
|
||||
this.name = name
|
||||
@@ -236,7 +238,6 @@ export class RoomService {
|
||||
|
||||
const args = message.fields.args
|
||||
|
||||
// alert(JSON.stringify(args))
|
||||
|
||||
|
||||
if (typeof args[1] != 'object') {
|
||||
@@ -269,7 +270,12 @@ export class RoomService {
|
||||
|
||||
|
||||
getRoomMembersIds(): string[] {
|
||||
return this.members.map((user)=> user._id)
|
||||
try {
|
||||
return this.members.map((user)=> user._id)
|
||||
} catch(error) {
|
||||
return []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getAllMemberThatIsNotOffline(): string[] {
|
||||
@@ -357,37 +363,46 @@ export class RoomService {
|
||||
* @description delete message in the view
|
||||
* @param id message ID
|
||||
*/
|
||||
async deleteMessage(id) {
|
||||
await this.messages.forEach(async(message, index) => {
|
||||
if(message._id == id) {
|
||||
|
||||
this.messages.splice(index, 1)
|
||||
async deleteMessage(_id) {
|
||||
|
||||
const id = _id
|
||||
|
||||
for (let i =0; i <= this.messages.length; i++) {
|
||||
|
||||
if(this.messages[i]?._id == id ) {
|
||||
|
||||
|
||||
|
||||
if (SessionStore.user.RochetChatUser == message.u.username) {
|
||||
//Get previous last message from room
|
||||
const previousLastMessage = this.messages.slice(-1)[0];
|
||||
this.lastMessage = previousLastMessage;
|
||||
|
||||
this.calDateDuration(previousLastMessage._updatedAt)
|
||||
this.sortRoomList()
|
||||
|
||||
if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) {
|
||||
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
|
||||
|
||||
await DeleteMessageModel.create({
|
||||
messageId: message._id,
|
||||
rid: message.rid,
|
||||
ts: message.ts,
|
||||
u: message.u,
|
||||
DeleteMessageModel.create({
|
||||
messageId: this.messages[i]._id,
|
||||
rid: this.messages[i].rid,
|
||||
ts: this.messages[i].ts,
|
||||
u: this.messages[i].u,
|
||||
needToReceiveBy: allMemberThatIsOffline
|
||||
})
|
||||
}
|
||||
|
||||
message.delateStatusFalse()
|
||||
message.delateDB()
|
||||
this.messages[i]?.delateDB()
|
||||
|
||||
//Get previous last message from room
|
||||
const previousLastMessage = this.messages.slice(-1)[0];
|
||||
// console.log(_id,'==',this.messages[i]?._id, true)
|
||||
this.messages.splice(i, 1)
|
||||
|
||||
this.lastMessage = previousLastMessage;
|
||||
this.calDateDuration(previousLastMessage._updatedAt)
|
||||
this.sortRoomList()
|
||||
return true
|
||||
|
||||
} else {
|
||||
// console.log(_id,'==',this.messages[i]?._id, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -411,22 +426,26 @@ export class RoomService {
|
||||
|
||||
async sendDeleteRequest(msgId) {
|
||||
|
||||
const message = this.messages.find((e)=>e._id = msgId)
|
||||
message.delateStatusFalse()
|
||||
const message = this.messages.find((e)=>e._id == msgId)
|
||||
await message.delateStatusFalse()
|
||||
|
||||
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
|
||||
(response: any) => {
|
||||
message.delateRequest = true
|
||||
message.save()
|
||||
this.deleteMessage(msgId)
|
||||
},
|
||||
(response) => {
|
||||
async (response: any) => {
|
||||
|
||||
if (response.error.error.startsWith('No message found with the id of')) {
|
||||
// alert('not found')
|
||||
message.delateRequest = true
|
||||
await message.save()
|
||||
this.deleteMessage(msgId)
|
||||
|
||||
},
|
||||
async (response) => {
|
||||
|
||||
if (response?.error?.error.startsWith('No message found with the id of')) {
|
||||
|
||||
this.deleteMessage(msgId)
|
||||
message.delateRequest = true
|
||||
await message.save()
|
||||
|
||||
} else {
|
||||
// this.deleteMessage(DeletedMessageId)
|
||||
this.WsChatService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
@@ -666,7 +685,7 @@ export class RoomService {
|
||||
message = this.fix_updatedAt(message)
|
||||
|
||||
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
||||
wewMessage.setData(message)
|
||||
wewMessage.loadHistory = this.hasLoadHistory
|
||||
|
||||
@@ -694,8 +713,6 @@ export class RoomService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) {
|
||||
let foundIndex;
|
||||
|
||||
@@ -725,7 +742,7 @@ export class RoomService {
|
||||
async prepareCreate({message, save = true}): Promise<MessageService> {
|
||||
message = this.fix_updatedAt(message)
|
||||
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
||||
wewMessage.setData(message)
|
||||
wewMessage.loadHistory = this.hasLoadHistory
|
||||
|
||||
@@ -737,7 +754,7 @@ export class RoomService {
|
||||
|
||||
simplePrepareMessage(message) {
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
||||
wewMessage.setData(message)
|
||||
wewMessage.loadHistory = this.hasLoadHistory
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import { AuthService } from '../auth.service';
|
||||
import { ChatStorageService } from './chat-storage.service'
|
||||
import { ChatMethodsService } from './chat-methods.service'
|
||||
import { AESEncrypt } from '../aesencrypt.service'
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -55,7 +56,8 @@ export class WsChatMethodsService {
|
||||
private authService: AuthService,
|
||||
private ChatStorageService: ChatStorageService,
|
||||
private ChatMethodsService:ChatMethodsService,
|
||||
private AESEncrypt: AESEncrypt
|
||||
private AESEncrypt: AESEncrypt,
|
||||
private AttachmentsService:AttachmentsService
|
||||
) {
|
||||
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
@@ -158,7 +160,10 @@ export class WsChatMethodsService {
|
||||
|
||||
} catch(e){}
|
||||
|
||||
this.sortRoomList()
|
||||
setTimeout(()=>{
|
||||
this.sortRoomList()
|
||||
}, 1000)
|
||||
|
||||
}
|
||||
|
||||
async getAllRooms () {
|
||||
@@ -202,7 +207,11 @@ export class WsChatMethodsService {
|
||||
console.log('save rooms', rooms)
|
||||
await this.storage.set('Rooms', rooms);
|
||||
|
||||
this.sortRoomList()
|
||||
|
||||
setTimeout(()=>{
|
||||
this.sortRoomList()
|
||||
}, 1000)
|
||||
|
||||
this.loadingWholeList = false
|
||||
}
|
||||
|
||||
@@ -305,7 +314,7 @@ export class WsChatMethodsService {
|
||||
|
||||
// create room
|
||||
if(!this.roomExist(roomId)) {
|
||||
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
|
||||
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
|
||||
room.setData(setData)
|
||||
room.receiveMessage()
|
||||
room.getAllUsers = this.getUsers
|
||||
|
||||
@@ -728,7 +728,7 @@ export class WsChatService {
|
||||
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
console.log('messageStr', messageStr)
|
||||
// console.log('messageStr', messageStr)
|
||||
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user