This commit is contained in:
Peter Maquiran
2023-01-17 14:14:53 +01:00
parent cb9e9f2667
commit d5827a1840
9 changed files with 70 additions and 28 deletions
+31 -7
View File
@@ -61,6 +61,9 @@ export class MessageService {
downloadAttachmentsTemp = 0;
UploadAttachmentsTemp = 0;
manualRetry = false
origin: 'history' | 'stream' | 'local'
rowInstance: MessageModel
constructor(
private NfService: NfService,
@@ -72,7 +75,7 @@ export class MessageService {
private ChatSystemService: ChatSystemService) {
}
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 }:Message) {
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 }:Message) {
this.channels = channels || []
this.mentions = mentions || []
@@ -90,6 +93,7 @@ export class MessageService {
this.delate = delate
this.delateRequest = delateRequest
this.sendAttempt = 0
this.origin = origin
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
@@ -257,6 +261,7 @@ export class MessageService {
} catch (error) {
this.uploadingFile = false
this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++
console.error('beforeSendAttachment error:', error)
}
@@ -467,6 +472,7 @@ export class MessageService {
u: this.u,
_id: this._id,
id: this.id,
origin: this.origin,
_updatedAt: this._updatedAt,
messageSend: this.messageSend,
offline: this.offline,
@@ -489,6 +495,7 @@ export class MessageService {
delete message.id
const createdMessage = await MessageModel.create(message)
this.rowInstance = createdMessage
this.id = createdMessage.id
if(this.earlySave) {
@@ -497,8 +504,8 @@ export class MessageService {
}
}
async saveChanges() {
async getRowInstance () {
if(this.save) {
const message = this.getChatObj()
@@ -516,12 +523,29 @@ export class MessageService {
a = await MessageModel.get({id: this.id})
}
if(a) {
for( const [name, value] of Object.entries(message)) {
a[name] = value
}
await a.save()
return a
}
}
async saveChanges() {
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
if(this.save && this.rowInstance) {
const message = this.getChatObj()
if(!message.id) {
delete message.id
}
for( const [name, value] of Object.entries(message)) {
this.rowInstance[name] = value
}
await this.rowInstance.save()
} else {
this.earlySave = true
+16 -6
View File
@@ -275,18 +275,25 @@ export class RoomService {
if(message.fields.eventName == this.id+'/'+'typing') {
const args = message.fields.args
if (typeof args[1] != 'object') {
this.userThatIsTyping = this.usernameToDisplayName(args[0])
this.isTyping = args[1]
this.otherUserType = args[1]
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'viewMessage' || args[1]?.method == 'viewMessage') {
this.readAllMessage()
const user = args[0]
if(SessionStore.user.UserName != user) {
this.readAllMessage()
}
} else if(args[0]?.method == 'deleteMessage' || args[1]?.method == 'deleteMessage') {
this.deleteMessage(args[1]?.method?._id)
@@ -295,7 +302,6 @@ export class RoomService {
}
} else if (message.fields.eventName == this.id+'/'+'deleteMessage') {}
})
@@ -313,6 +319,7 @@ export class RoomService {
if(!found) {
ChatMessage.origin = 'stream'
const message = await this.prepareCreate({message: ChatMessage, save: true});
this.registerSendMessage(message)
@@ -556,7 +563,8 @@ export class RoomService {
attachments,
file,
temporaryData,
localReference
localReference,
origin: 'local'
}
this.message= ''
@@ -657,6 +665,7 @@ export class RoomService {
// this.typing(this.message)
this.chatOpen = true
this.messageUnread = false
this.sendReadMessage()
}
@@ -737,6 +746,7 @@ export class RoomService {
for(let message of chatHistory.result.messages.reverse()) {
if (!messagesId.includes(message._id)) {
message.origin = 'history'
const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
if(messagesToSave != null) {
@@ -27,9 +27,9 @@ export class ViewedMessageService {
for(let id of membersIds) {
if(message.addReceived(id)) {
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}
}
@@ -56,9 +56,9 @@ export class ViewedMessageService {
if(message.addViewed(id)) {
message.addReceived(id)
n++
setTimeout(async() => {
// setTimeout(async() => {
await message.saveChanges()
}, 100 * n)
// }, 100 * n)
}
}