This commit is contained in:
Peter Maquiran
2022-09-29 16:43:32 +01:00
parent 8c729e900d
commit a5521585c7
6 changed files with 23 additions and 28 deletions
+17 -21
View File
@@ -39,7 +39,6 @@ export class RoomService {
name = ''
_updatedAt = {}
hasLoadHistory = false
hasLoadHistoryMessageRF = []
restoreFromOffline = false
duration = ''
isTyping = false
@@ -48,7 +47,6 @@ export class RoomService {
message = ''
lastMessageTxt = ''
userThatIsTyping = ''
mgsArray = [];
messagesLocalReference = []
members = []
u
@@ -276,6 +274,8 @@ export class RoomService {
const message = await this.prepareCreate({message: ChatMessage, save: true});
message.messageSend = true
message.from = 'stream'
message.loadHistory = this.hasLoadHistory
this.lastMessage = message;
this.calDateDuration(ChatMessage._updatedAt);
@@ -291,8 +291,9 @@ export class RoomService {
});
}
message.addMessageDB()
if(this.hasLoadHistory == true) {
await message.addMessageDB()
}
if(this.chatOpen == false) {
this.messageUnread = true
@@ -574,6 +575,8 @@ export class RoomService {
}
message.send()
message.from = 'send'
message.loadHistory = this.hasLoadHistory
if (environment.chatOffline) {
@@ -586,10 +589,6 @@ export class RoomService {
this.calDateDuration(message._updatedAt)
this.sortRoomList()
}
if(this.hasLoadHistory == false) {
this.hasLoadHistoryMessageRF.push(localReference)
}
}
@@ -671,14 +670,21 @@ export class RoomService {
for (let ChatMessage of messages) {
const wewMessage = await this.simplePrepareMessage(ChatMessage)
wewMessage.from = 'Offline'
wewMessage.loadHistory = this.hasLoadHistory
if(wewMessage.offline == false) {
const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage})
message.from = 'Offline'
message.loadHistory = this.hasLoadHistory
message?.decryptMessage()
} else {
const offlineMessage = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
offlineMessage.from = 'Offline'
offlineMessage.loadHistory = this.hasLoadHistory
if(offlineMessage) {
this.messagesLocalReference.push(offlineMessage.localReference)
@@ -745,13 +751,13 @@ export class RoomService {
async messageReorder() {
const reorderMessage: MessageService[] = this.messages.filter((message) =>
this.hasLoadHistoryMessageRF.includes(message?.localReference)
message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory
);
let i = 0
for(let message of this.messages) {
if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) {
if(message.from == 'send' && !message.loadHistory || message.from == 'stream' && !message.loadHistory) {
this.messages.splice(i, 1)
}
i++;
@@ -759,19 +765,9 @@ export class RoomService {
for(let message of reorderMessage) {
this.messages.push(message)
message.addMessageDB()
}
for(let message of this.messages) {
if(this.hasLoadHistoryMessageRF.includes(message?.localReference)) {
if(!message.addToDb) {
message.addMessageDB()
}
}
}
this.hasLoadHistoryMessageRF = [];
}