diff --git a/client-web/src/xmppHandler.ts b/client-web/src/xmppHandler.ts index df4fece9..0552f54e 100644 --- a/client-web/src/xmppHandler.ts +++ b/client-web/src/xmppHandler.ts @@ -39,7 +39,7 @@ export class XmppHandler { if (stanza.attrs.id === "sendMessage") { const body = stanza?.getChild("body"); const data = stanza?.getChild("data"); - const replace = stanza?.getChild("replace"); + const replace = stanza?.getChild("replaced"); const archived = stanza?.getChild("archived"); const id = stanza.getChild("archived")?.attrs.id; if (!data || !body || !id) { @@ -63,14 +63,6 @@ export class XmppHandler { return; } - if (replace) { - const replaceMessageId = Number(replace.attrs.id); - const messageString = body.getText(); - useStoreState - .getState() - .replaceMessage(replaceMessageId, messageString); - } - if (data.attrs.isReply) { const messageId = Number(msg.data?.mainMessage?.id); useStoreState.getState().setNumberOfReplies(messageId); @@ -107,7 +99,6 @@ export class XmppHandler { stanza.is("message") && stanza.children[0].attrs.xmlns === "urn:xmpp:mam:2" ) { - console.log(stanza.toString(), 'historyMessage') const body = stanza .getChild("result") ?.getChild("forwarded") @@ -126,7 +117,7 @@ export class XmppHandler { .getChild("result") ?.getChild("forwarded") ?.getChild("message") - ?.getChild("replace"); + ?.getChild("replaced"); const id = stanza.getChild("result")?.attrs.id; if (!data || !body || !delay || !id) { @@ -142,7 +133,7 @@ export class XmppHandler { } const msg = createMessage(data, body, id, stanza.attrs.from); - + msg.data.isEdited = !!replace; // console.log('TEST ', data.attrs) const blackList = useStoreState .getState() @@ -151,57 +142,32 @@ export class XmppHandler { if (blackList) { return; } - //if current stanza has replace tag - if (replace) { - //if message loading - if (this.isGettingMessages) { - const replaceItem: replaceMessageListItemProps = { - replaceMessageId: Number(replace.attrs.id), - replaceMessageText: body.getText(), - }; - //add the replace item, which has the id of the main message to be edited, in a temporory array - this.temporaryReplaceMessages.push(replaceItem); - } - //if message loading done - if (!this.isGettingMessages) { - const replaceMessageId = Number(replace.attrs.id); - const messageString = body.getText(); - //replace body/text of message id in messageHistory array - useStoreState - .getState() - .replaceMessage(replaceMessageId, messageString); - } - } else { - this.temporaryMessages.push(msg); - - if (!this.isGettingMessages) { - //check for messages in temp Replace message array agains the current stanza message id - const replaceItem = this.temporaryReplaceMessages.find( - (item) => item.replaceMessageId === msg.id - ); - //if exists then replace the body with current stanza body - if (replaceItem) { - msg.body = replaceItem.replaceMessageText; - } - useStoreState.getState().setNewMessageHistory(msg); - useStoreState.getState().sortMessageHistory(); + if (!this.isGettingMessages) { + //check for messages in temp Replace message array agains the current stanza message id + const replaceItem = this.temporaryReplaceMessages.find( + (item) => item.replaceMessageId === msg.id + ); + //if exists then replace the body with current stanza body + if (replaceItem) { + msg.body = replaceItem.replaceMessageText; } + useStoreState.getState().setNewMessageHistory(msg); + useStoreState.getState().sortMessageHistory(); + } - const untrackedRoom = useStoreState.getState().currentUntrackedChatRoom; - if ( - stanza.attrs.to.split("@")[0] !== - data.attrs.senderJID.split("@")[0] && - stanza.attrs.from.split("@")[0] !== untrackedRoom.split("@")[0] && - !this.isGettingFirstMessages && - data.attrs.roomJid - ) { - // useStoreState.getState().updateCounterChatRoom(data.attrs.roomJid); - } - if (data.attrs.isReply) { - const messageid = msg.data.mainMessage?.id; - useStoreState.getState().setNumberOfReplies(messageid); - this.updateTemporaryMessagesRepliesCount(messageid); - } + const untrackedRoom = useStoreState.getState().currentUntrackedChatRoom; + if ( + stanza.attrs.to.split("@")[0] !== data.attrs.senderJID.split("@")[0] && + stanza.attrs.from.split("@")[0] !== untrackedRoom.split("@")[0] && + !this.isGettingFirstMessages && + data.attrs.roomJid + ) { + // useStoreState.getState().updateCounterChatRoom(data.attrs.roomJid); + } + if (data.attrs.isReply) { + const messageid = msg.data.mainMessage?.id; + useStoreState.getState().setNumberOfReplies(messageid); + this.updateTemporaryMessagesRepliesCount(messageid); } } }; @@ -249,11 +215,6 @@ export class XmppHandler { } }); - this.temporaryReplaceMessages.forEach((item) => { - useStoreState - .getState() - .replaceMessage(item.replaceMessageId, item.replaceMessageText); - }); useStoreState.getState().setLoaderArchive(false); this.temporaryMessages = []; this.isGettingFirstMessages = false; @@ -528,7 +489,6 @@ export class XmppHandler { const replaceMessage: { text: string; id: string } = stanza.children.find( (item) => item.name === "replace" ).attrs; - console.log(stanza.toString(), 'editMessage') const messageString = replaceMessage?.text; useStoreState .getState()