This commit is contained in:
tiago.kayaya
2022-02-09 18:18:27 +01:00
parent a6823d9bae
commit da240623dd
2 changed files with 27 additions and 24 deletions
+6 -7
View File
@@ -37,7 +37,7 @@ export class MessageService {
}
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
this.customFields = customFields
this.customFields = customFields
this.channels = channels || []
this.mentions = mentions || []
this.msg = msg || ""
@@ -78,7 +78,7 @@ export class MessageService {
const firstName = capitalizeTxt(username.split('.')[0])
const lastName = capitalizeTxt(username.split('.')[1])
return firstName + ' ' + lastName
}
}
getFileFromDb() {
@@ -113,14 +113,14 @@ export class MessageService {
if(this.hasSendAttachment == false) {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
}
this.uploadingFile = false
if(uploadSuccessfully || this.hasSendAttachment == false) {
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) => {
console.log('send sucees', data.result)
let ChatMessage = data.result
@@ -133,7 +133,6 @@ export class MessageService {
this.WsChatService.registerCallback({
type: 'reConnect',
funx:()=> {
alert('reConnect')
// this.send()
return true
}
@@ -143,11 +142,11 @@ export class MessageService {
this.errorUploadingAttachment = true
}
}
}
redefinedMessage(messagem, ChatMessage) {
redefinedMessage(messagem, ChatMessage) {
this.setData(ChatMessage)
}
+21 -17
View File
@@ -24,7 +24,7 @@ export class RoomService {
messages: MessageService[] = []
storageMessage: any[] = [];
lastMessage: MessageService;
customFields: any;
id = ''
t = ''
@@ -72,6 +72,7 @@ export class RoomService {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: ()=>{
alert("reConnect")
this.hasLoadHistory = false
}
})
@@ -106,32 +107,32 @@ export class RoomService {
ChatMessage = this.fix_updatedAt(ChatMessage)
// console.log('recivemessage', ChatMessage)
const messageIsFound = this.messages.find((message) => {
return message._id == ChatMessage._id
})
if(!messageIsFound) {
const message = this.prepareMessage(ChatMessage)
this.lastMessage = message
if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt)
setTimeout(() => {
this.scrollDown()
}, 100)
this.NativeNotificationService.sendNotificationChat({
message: message.msg,
title: this.name
});
if(this.isSenderIsNotMe(ChatMessage)) {
this.addMessageDB(ChatMessage)
}
}
}, 150)
@@ -241,7 +242,7 @@ export class RoomService {
file,
temporaryData
}
this.addMessageDB(offlineChatMessage)
const message: MessageService = this.prepareMessage(offlineChatMessage)
@@ -255,7 +256,7 @@ export class RoomService {
this.calDateDuration(message._updatedAt)
this.sortRoomList()
this.message= ''
}
@@ -357,29 +358,32 @@ export class RoomService {
setTimeout(()=> {
this.scrollDown()
}, 50)
})
}
// runs onces only
async loadHistory({limit = 100, forceUpdate = false }) {
async loadHistory({limit = 50, forceUpdate = false }) {
if (this.hasLoadHistory || forceUpdate) { return false }
if (this.hasLoadHistory || forceUpdate) {
return false
}
this.restoreMessageFromDB()
await this.restoreMessageFromDB()
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
console.log('loadHistory', chatHistory)
this.messages = []
await chatHistory.result.messages.reverse().forEach( async (message) => {
this.prepareMessage(message)
const wewMessage = this.prepareMessage(message, false)
/* const wewMessage = this.prepareMessage(message, false)
if(wewMessage.offline == false) {
this.prepareMessage(message)
}
} */
})
@@ -403,7 +407,7 @@ export class RoomService {
if (save) {
this.messages.push(wewMessage)
}
return wewMessage
}