fix delete message

This commit is contained in:
Peter Maquiran
2022-03-21 21:06:54 +01:00
parent b963b59a69
commit c9af986ae8
8 changed files with 76 additions and 113 deletions
+1
View File
@@ -242,6 +242,7 @@ export class MessageService {
async delateDB() {
// alert('delete data')
const message = await MessageModel.get({_id: this._id})
await message.delete()
+38 -6
View File
@@ -313,8 +313,6 @@ export class RoomService {
async deleteMessageToReceive(userId) {
const allDeleteMessages = await DeleteMessageModel.filter({rid: this.id}).execute()
for(let message_ of allDeleteMessages) {
@@ -392,6 +390,15 @@ export class RoomService {
}
deleteAll() {
this.messages.forEach((message)=>{
if(message?._id) {
this.sendDeleteRequest(message._id)
}
})
}
async delateMessageToSendToOthers(userId) {
const deleteMessage = await DeleteMessageModel.all()
@@ -410,10 +417,12 @@ export class RoomService {
(response: any) => {
message.delateRequest = true
message.save()
this.deleteMessage(msgId)
},
(response) => {
if (response.error.error.startsWith('No message found with the id of')) {
// alert('not found')
this.deleteMessage(msgId)
} else {
// this.deleteMessage(DeletedMessageId)
@@ -429,6 +438,7 @@ export class RoomService {
}
)
}
@@ -553,7 +563,7 @@ export class RoomService {
const wewMessage = await this.simplePrepareMessage(ChatMessage)
if(wewMessage.offline == false) {
const message = await this.prepareMessageCreateIfNotExist({message:ChatMessage})
const message = await this.prepareMessageCreateIfNotExist_iD({message:ChatMessage})
message?.decryptMessage()
} else {
@@ -584,7 +594,7 @@ export class RoomService {
}
// runs onces only
async loadHistory({limit = 10000000, forceUpdate = false }) {
async loadHistory({limit = 1000, forceUpdate = false }) {
if(forceUpdate == false) {
if (this.hasLoadHistory) {
@@ -599,12 +609,14 @@ export class RoomService {
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
console.log('load chatHistory', JSON.stringify(chatHistory))
const messagesId = this.messages.map((message)=> message._id)
chatHistory.result.messages.reverse().forEach(async(message: any) => {
if (!messagesId.includes(message._id)) {
const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message});
if(messagesToSave) {
await messagesToSave.addMessageDB()
}
@@ -612,7 +624,6 @@ export class RoomService {
})
// console.log('load chatHistory', chatHistory)
})
@@ -755,6 +766,27 @@ export class RoomService {
}
}
async prepareMessageCreateIfNotExist_iD({message}) {
message = this.fix_updatedAt(message)
const found = this.messages.find((MessageService, index) => {
if (MessageService._id == message._id ) {
return true
} else {
return false
}
})
if (!found) {
const wewMessage = this.simplePrepareMessage(message)
this.messages.push(wewMessage)
return wewMessage
} else {
return null
}
}
private calDateDuration(date = null) {
this.duration = showDateDuration(date || this._updatedAt);
this._updatedAt = date || this._updatedAt