mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
fix delete message
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user