mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add implementation
This commit is contained in:
@@ -47,7 +47,7 @@ export class MessageService {
|
||||
uploadingFile = false
|
||||
errorUploadingAttachment = false
|
||||
loadHistory = false
|
||||
from: 'Offline'|'History'|'stream'| 'send'
|
||||
from: 'Offline'|'History'|'stream'| 'send'
|
||||
duration = ''
|
||||
localReference = null
|
||||
viewed: string[] = []
|
||||
@@ -67,6 +67,8 @@ export class MessageService {
|
||||
messageModelInstance: MessageModel
|
||||
attachmentsModelData: any
|
||||
|
||||
dateLabel = false
|
||||
|
||||
|
||||
constructor(
|
||||
private NfService: NfService,
|
||||
@@ -177,7 +179,7 @@ export class MessageService {
|
||||
return firstName + ' ' + lastName
|
||||
} catch (error) {
|
||||
return username
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -193,9 +195,9 @@ export class MessageService {
|
||||
|
||||
if(!this.hasFile) {
|
||||
|
||||
const params = {
|
||||
roomId:this.rid,
|
||||
msg:this.msg,
|
||||
const params = {
|
||||
roomId:this.rid,
|
||||
msg:this.msg,
|
||||
localReference: this.localReference
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ export class MessageService {
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
|
||||
|
||||
await this.send().catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
@@ -257,10 +259,10 @@ export class MessageService {
|
||||
try {
|
||||
await this.getFileFromDB()
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.instanceHasTemporaryData) {
|
||||
|
||||
|
||||
await this.generateTemporaryData()
|
||||
}
|
||||
|
||||
@@ -277,14 +279,14 @@ export class MessageService {
|
||||
this.saveChanges()
|
||||
} catch (error) {
|
||||
this.uploadingFile = false
|
||||
|
||||
|
||||
|
||||
this.errorUploadingAttachment = true
|
||||
this.UploadAttachmentsTemp++
|
||||
|
||||
this.saveChanges()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return uploadSuccessfully
|
||||
@@ -305,7 +307,7 @@ export class MessageService {
|
||||
(ChatMessage: any) => {
|
||||
ChatMessage = ChatMessage.message.result
|
||||
clearTimeout(this.functionTimer);
|
||||
|
||||
|
||||
this.redefinedMessage(ChatMessage)
|
||||
}
|
||||
).catch((error) => {
|
||||
@@ -320,16 +322,16 @@ export class MessageService {
|
||||
(ChatMessage: any) => {
|
||||
ChatMessage = ChatMessage.message.result
|
||||
clearTimeout(this.functionTimer);
|
||||
|
||||
|
||||
this.redefinedMessage(ChatMessage)
|
||||
|
||||
|
||||
}
|
||||
).catch((error) => {
|
||||
clearTimeout(this.functionTimer);
|
||||
console.error(error)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
this.functionTimer = setTimeout(() => {
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type:'Onmessage',
|
||||
@@ -395,7 +397,7 @@ export class MessageService {
|
||||
this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg,this.rid)
|
||||
}
|
||||
|
||||
|
||||
|
||||
await this.saveChanges()
|
||||
}
|
||||
|
||||
@@ -415,7 +417,7 @@ export class MessageService {
|
||||
} else if (this.file.type != "application/img") {
|
||||
|
||||
downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
||||
|
||||
|
||||
}
|
||||
|
||||
this.attachments[0] = {
|
||||
@@ -462,7 +464,7 @@ export class MessageService {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -525,21 +527,21 @@ export class MessageService {
|
||||
}
|
||||
|
||||
earlySave = false
|
||||
|
||||
|
||||
async addMessageDB() {
|
||||
if(!this.addToDb && this.save) {
|
||||
this.addToDb = true
|
||||
const message = this.getChatObj()
|
||||
|
||||
if(this.instanceHasAttachment) {
|
||||
this.hasFile = true
|
||||
this.hasFile = true
|
||||
}
|
||||
|
||||
delete message.id
|
||||
const createdMessage = await MessageModel.create(message)
|
||||
|
||||
if(this.instanceHasAttachment) {
|
||||
this.addFileToDb()
|
||||
this.addFileToDb()
|
||||
}
|
||||
|
||||
this.messageModelInstance = createdMessage
|
||||
@@ -556,7 +558,7 @@ export class MessageService {
|
||||
if(!this.messageModelInstance) {
|
||||
this.messageModelInstance = await this.getRowInstance()
|
||||
}
|
||||
|
||||
|
||||
|
||||
const createdMessage: any = this.messageModelInstance
|
||||
try {
|
||||
@@ -566,7 +568,7 @@ export class MessageService {
|
||||
if(this.attachmentsModelData) {
|
||||
file = {image_url: this.attachmentsModelData?.fileBase64}
|
||||
}
|
||||
|
||||
|
||||
await attachments.create({messageId: createdMessage.id, attachments: this.attachments, file: Object.assign(this.file, file) })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
@@ -578,8 +580,8 @@ export class MessageService {
|
||||
if(!this.messageModelInstance) {
|
||||
this.messageModelInstance = await this.getRowInstance()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const data = await this.messageModelInstance.getAttachments()
|
||||
|
||||
console.log('data', data);
|
||||
@@ -590,7 +592,7 @@ export class MessageService {
|
||||
|
||||
async generateTemporaryData () {
|
||||
const blob: any = await this.base64StringToBlob(this.file.image_url)
|
||||
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
this.temporaryData = formData
|
||||
@@ -651,7 +653,7 @@ export class MessageService {
|
||||
if(!message.id) {
|
||||
delete message.id
|
||||
}
|
||||
|
||||
|
||||
if (this.localReference) {
|
||||
a = await MessageModel.get({localReference: this.localReference})
|
||||
} else if (this._id) {
|
||||
@@ -662,7 +664,7 @@ export class MessageService {
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async saveChanges() {
|
||||
@@ -683,13 +685,299 @@ export class MessageService {
|
||||
this.messageModelInstance[name] = value
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
|
||||
await this.messageModelInstance.save()
|
||||
|
||||
|
||||
} else {
|
||||
this.earlySave = true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
decryptMessage() {
|
||||
try {
|
||||
// this.msg = this.AESEncrypt.decrypt(this.msg, SessionStore.user.UserName)
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
UIdata() {
|
||||
this.incomingFromCurrentUser = this.u.username!= SessionStore.user.UserName
|
||||
this.hasMessage = this.msg !=''
|
||||
}
|
||||
|
||||
incomingFromCurrentUser = false
|
||||
hasMessage = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export class MessageServiceDateLabel {
|
||||
|
||||
customFields
|
||||
channels = []
|
||||
mentions = []
|
||||
msg = ''
|
||||
rid = ''
|
||||
ts = {}
|
||||
|
||||
u = {
|
||||
name: '',
|
||||
username: '',
|
||||
_id: ""
|
||||
}
|
||||
|
||||
t = ''
|
||||
_id = ''
|
||||
id = '' // table id
|
||||
_updatedAt
|
||||
file
|
||||
attachments
|
||||
displayType = ''
|
||||
temporaryData: any
|
||||
hasFile = false
|
||||
hasSendAttachment = false
|
||||
sendAttempt = 0
|
||||
uploadingFile = false
|
||||
errorUploadingAttachment = false
|
||||
loadHistory = false
|
||||
from: 'Offline'|'History'|'stream'| 'send'
|
||||
duration = ''
|
||||
localReference = null
|
||||
viewed: string[] = []
|
||||
received: string[]= []
|
||||
addToDb = false
|
||||
|
||||
messageSend = false
|
||||
delate = false
|
||||
delateRequest = false
|
||||
downloadLoader: boolean = false
|
||||
downloadAttachments = false;
|
||||
downloadAttachmentsTemp = 0;
|
||||
UploadAttachmentsTemp = 0;
|
||||
manualRetry = false
|
||||
origin: 'history' | 'stream' | 'local'
|
||||
|
||||
messageModelInstance: MessageModel
|
||||
attachmentsModelData: any
|
||||
ChatSystemService
|
||||
dateLabel = false
|
||||
|
||||
|
||||
constructor() {}
|
||||
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin, attachmentsModelData, hasFile = false, UploadAttachmentsTemp = 0 }:Message) {
|
||||
|
||||
this.channels = []
|
||||
this.mentions = []
|
||||
this.rid = rid
|
||||
this.ts = ts
|
||||
this.u = u || { name: this.usernameToDisplayName(SessionStore.user.UserName), username: SessionStore.user.UserName, _id: ""}
|
||||
this.t = t
|
||||
this._id = ""
|
||||
this._updatedAt = _updatedAt || new Date().getTime()
|
||||
this.file = file
|
||||
this.temporaryData = temporaryData
|
||||
this.localReference = localReference || null
|
||||
this.id = id
|
||||
this.delate = delate
|
||||
this.delateRequest = delateRequest
|
||||
this.sendAttempt = 0
|
||||
this.origin = origin
|
||||
this.attachmentsModelData = attachmentsModelData
|
||||
this.UploadAttachmentsTemp = UploadAttachmentsTemp
|
||||
|
||||
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
|
||||
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
|
||||
} else {
|
||||
this.attachments = attachments
|
||||
}
|
||||
|
||||
this.viewed = [];
|
||||
this.received = [];
|
||||
|
||||
this.messageSend = true
|
||||
this.hasFile = hasFile
|
||||
|
||||
this.hasFile = false
|
||||
|
||||
if(!this.u.name && this.u.username) {
|
||||
const user = this.ChatSystemService.users.find((u)=> u.username == this.u.username)
|
||||
if(user) {
|
||||
this.u.name = user.name
|
||||
} else if( this.u.username == SessionStore.user.UserName) {
|
||||
this.u.name = SessionStore.user.FullName
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
this.calDateDuration()
|
||||
}
|
||||
|
||||
|
||||
get offline () {
|
||||
if(!this._id) {
|
||||
return true
|
||||
}
|
||||
|
||||
if(!this.ts) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Message is on the server
|
||||
*/
|
||||
get online() {
|
||||
return !this.offline
|
||||
}
|
||||
|
||||
/**
|
||||
* if Message is already saved on database
|
||||
*/
|
||||
get save() {
|
||||
return this.id != ''
|
||||
}
|
||||
|
||||
|
||||
private usernameToDisplayName(username) {
|
||||
|
||||
try {
|
||||
const firstName = capitalizeTxt(username.split('.')[0])
|
||||
const lastName = capitalizeTxt(username.split('.')[1])
|
||||
return firstName + ' ' + lastName
|
||||
} catch (error) {
|
||||
return username
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async send(): Promise<any> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
functionTimer = null;
|
||||
|
||||
async sendRequestAttachment() {
|
||||
|
||||
}
|
||||
|
||||
async sendRequest(params) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
async redefinedMessage(ChatMessage , update = true) {
|
||||
|
||||
}
|
||||
|
||||
sendNotificaton
|
||||
|
||||
downloadFileMsg() {
|
||||
|
||||
}
|
||||
|
||||
private calDateDuration(date = null) {
|
||||
this.duration = showDateDuration(date || this._updatedAt);
|
||||
}
|
||||
|
||||
|
||||
async delateStatusFalse() {
|
||||
|
||||
}
|
||||
|
||||
addViewed(id: string) {
|
||||
|
||||
}
|
||||
|
||||
addReceived(id: string) {
|
||||
|
||||
}
|
||||
|
||||
async delateDB() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
isSenderIsNotMe(ChatMessage) {
|
||||
return SessionStore.user.ChatData.data.userId != ChatMessage.u._id
|
||||
}
|
||||
|
||||
messageOwner() {
|
||||
return SessionStore.user.ChatData.data.userId == this.u._id
|
||||
}
|
||||
|
||||
getChatObj() {
|
||||
|
||||
}
|
||||
|
||||
earlySave = false
|
||||
|
||||
async addMessageDB() {
|
||||
|
||||
}
|
||||
|
||||
async addFileToDb() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getFileFromDB() {
|
||||
|
||||
}
|
||||
|
||||
async generateTemporaryData () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
get instanceHasAttachment() {
|
||||
return false
|
||||
}
|
||||
|
||||
get instanceHasAttachmentBase64() {
|
||||
if (this.file) {
|
||||
if(this.file.type) {
|
||||
if(this.file?.image_url) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
get instanceHasTemporaryData() {
|
||||
if (!this.temporaryData) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
base64StringToBlob(base64Data) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getRowInstance () {
|
||||
|
||||
|
||||
}
|
||||
|
||||
async saveChanges() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
decryptMessage() {
|
||||
|
||||
Reference in New Issue
Block a user