mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
change storage package to beast-rom
This commit is contained in:
@@ -9,7 +9,8 @@ import { environment } from 'src/environments/environment';
|
||||
import { showDateDuration } from 'src/plugin/showDateDuration';
|
||||
import { ChatStorageService } from './chat-storage.service'
|
||||
import { ChatMethodsService } from './chat-methods.service'
|
||||
|
||||
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
|
||||
import { AESEncrypt } from '../aesencrypt.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -31,6 +32,7 @@ export class MessageService {
|
||||
|
||||
t = ''
|
||||
_id = ''
|
||||
id = '' // table id
|
||||
_updatedAt
|
||||
file
|
||||
attachments
|
||||
@@ -47,6 +49,7 @@ export class MessageService {
|
||||
localReference = null
|
||||
viewed = []
|
||||
received = []
|
||||
addToDb = false
|
||||
|
||||
messageSend = false
|
||||
|
||||
@@ -54,10 +57,11 @@ export class MessageService {
|
||||
private NfService: NfService,
|
||||
private WsChatService: WsChatService,
|
||||
private ChatStorageService: ChatStorageService,
|
||||
private ChatMethodsService: ChatMethodsService) {
|
||||
private ChatMethodsService: ChatMethodsService,
|
||||
private AESEncrypt: AESEncrypt) {
|
||||
}
|
||||
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = []}:Message) {
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = []}:Message) {
|
||||
|
||||
this.channels = channels || []
|
||||
this.mentions = mentions || []
|
||||
@@ -72,6 +76,7 @@ export class MessageService {
|
||||
this.attachments = attachments
|
||||
this.temporaryData = temporaryData
|
||||
this.localReference = localReference || null
|
||||
this.id = id
|
||||
|
||||
this.viewed = [...new Set([...viewed,...this.viewed])];
|
||||
this.received = [...new Set([...received,...this.received])];
|
||||
@@ -210,7 +215,6 @@ export class MessageService {
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
this.send()
|
||||
|
||||
return true
|
||||
}
|
||||
})
|
||||
@@ -230,35 +234,13 @@ export class MessageService {
|
||||
|
||||
async redefinedMessage(ChatMessage , update = true) {
|
||||
ChatMessage = this.NfService.fix_updatedAt(ChatMessage)
|
||||
|
||||
let reference
|
||||
if(this._id) {
|
||||
reference = '_id'
|
||||
} else {
|
||||
reference = 'localReference'
|
||||
}
|
||||
|
||||
|
||||
const message = this.getChatObj()
|
||||
|
||||
// const viewed = [...new Set([...ChatMessage.viewed,...this.viewed])];
|
||||
// const received = [...new Set([...ChatMessage.received,...this.received])];
|
||||
// if(ChatMessage.msg.includes('***********')) {
|
||||
// console.log('redefinedMessage')
|
||||
// console.log(JSON.stringify(ChatMessage))
|
||||
// console.log(JSON.stringify(message))
|
||||
// console.log(JSON.stringify(Object.assign(message, ChatMessage)))
|
||||
|
||||
// }
|
||||
|
||||
ChatMessage = Object.assign(message, ChatMessage)
|
||||
|
||||
|
||||
if(update) {
|
||||
await this.ChatStorageService.updateMessageDB(ChatMessage, this.rid, reference)
|
||||
}
|
||||
|
||||
this.setData(ChatMessage)
|
||||
|
||||
await this.save()
|
||||
}
|
||||
|
||||
async downloadFileMsg() {
|
||||
@@ -277,8 +259,20 @@ export class MessageService {
|
||||
return this.u.username != SessionStore.user.RochetChatUser
|
||||
}
|
||||
|
||||
async delete() {
|
||||
await this.ChatStorageService.deleteMessageFromDb(this._id, this.rid)
|
||||
async delete(allMemberThatIsNotOffline) {
|
||||
|
||||
|
||||
|
||||
DeleteMessageModel.create({
|
||||
messageId: this._id,
|
||||
rid: this.rid,
|
||||
ts: this.ts,
|
||||
u: this.u,
|
||||
receivedBy: allMemberThatIsNotOffline
|
||||
})
|
||||
|
||||
const message = await MessageModel.get({_id: this._id})
|
||||
await message.delete()
|
||||
}
|
||||
|
||||
isSenderIsNotMe(ChatMessage) {
|
||||
@@ -293,38 +287,47 @@ export class MessageService {
|
||||
return {
|
||||
channels: this.channels,
|
||||
mentions: this.mentions,
|
||||
msg: this.msg,
|
||||
//msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser),
|
||||
msg:this.msg,
|
||||
rid: this.rid,
|
||||
ts: this.ts,
|
||||
u: this.u,
|
||||
_id: this._id,
|
||||
id: this.id,
|
||||
_updatedAt: this._updatedAt,
|
||||
messageSend: this.messageSend,
|
||||
offline: this.offline,
|
||||
viewed: this.viewed,
|
||||
received: this.received,
|
||||
localReference: this.localReference
|
||||
localReference: this.localReference,
|
||||
attachments: this.attachments,
|
||||
file: this.file
|
||||
}
|
||||
}
|
||||
|
||||
async addMessageDB() {
|
||||
if(!this.addToDb) {
|
||||
this.addToDb= true
|
||||
const message = this.getChatObj()
|
||||
|
||||
const message = this.getChatObj()
|
||||
delete message.id
|
||||
const createdMessage = await MessageModel.create(message)
|
||||
|
||||
await this.ChatStorageService.addMessageDB(message, this.rid)
|
||||
this.id = createdMessage.id
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
const message = this.getChatObj()
|
||||
|
||||
let reference
|
||||
if(this._id) {
|
||||
reference = '_id'
|
||||
} else {
|
||||
reference = 'localReference'
|
||||
}
|
||||
await MessageModel.update(message)
|
||||
|
||||
await this.ChatStorageService.updateMessageDB(message, this.rid, reference)
|
||||
}
|
||||
|
||||
decryptMessage() {
|
||||
try {
|
||||
// this.msg = this.AESEncrypt.decrypt(this.msg, SessionStore.user.RochetChatUser)
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user