-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
431 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1082,77 +1082,61 @@ export class ChatStore { | |
if (stanza.children[0].attrs.xmlns === "urn:xmpp:mam:2") { | ||
const singleMessageDetailArray = | ||
stanza.children[0].children[0].children[0].children; | ||
|
||
const replace = stanza | ||
.getChild("result") | ||
?.getChild("forwarded") | ||
?.getChild("message") | ||
?.getChild("replaced"); | ||
const message = createMessageObject(singleMessageDetailArray); | ||
if (message._id === "1676444732726065") { | ||
console.log(message); | ||
} | ||
//check if the stanza is a replace stanza | ||
if (message.isReplace) { | ||
this.addToReplaceMessageList( | ||
message.replaceMessageId, | ||
message.text as string | ||
); | ||
} else { | ||
//check if the current stanza is an edited message. | ||
const replaceMessageItem = this.replaceMessageList.find( | ||
(item) => message._id === item.replaceMessageId | ||
); | ||
if (replaceMessageItem) { | ||
message.text = replaceMessageItem.replaceMessageText; | ||
message.isEdited = true; | ||
this.removeFromReplaceMessageList( | ||
replaceMessageItem.replaceMessageId | ||
); | ||
} | ||
// if(this.replaceMessageList.find(item => message._id === item.replaceMessageId)){ | ||
// message.text = item.rep | ||
// } | ||
const messageAlreadyExist = this.messages.findIndex( | ||
(x: { _id: string }) => x._id === message._id | ||
); | ||
if (messageAlreadyExist === -1) { | ||
temporaryArchiveMessages.push(message); | ||
if ( | ||
this.blackList.find((item) => item.userJid === message.user._id) | ||
?.userJid | ||
) { | ||
return; | ||
} | ||
message.isEdited = !!replace; | ||
|
||
if (message.system) { | ||
if (message?.contractAddress && message.nftId) { | ||
await updateMessageToWrapped(message.receiverMessageId, { | ||
nftId: message.nftId, | ||
contractAddress: message.contractAddress, | ||
}); | ||
} | ||
// if(this.replaceMessageList.find(item => message._id === item.replaceMessageId)){ | ||
// message.text = item.rep | ||
// } | ||
const messageAlreadyExist = this.messages.findIndex( | ||
(x: { _id: string }) => x._id === message._id | ||
); | ||
if (messageAlreadyExist === -1) { | ||
temporaryArchiveMessages.push(message); | ||
if ( | ||
this.blackList.find((item) => item.userJid === message.user._id) | ||
?.userJid | ||
) { | ||
return; | ||
} | ||
|
||
message.tokenAmount && | ||
(await updateTokenAmount( | ||
message.receiverMessageId, | ||
message.tokenAmount | ||
)); | ||
if (message.system) { | ||
if (message?.contractAddress && message.nftId) { | ||
await updateMessageToWrapped(message.receiverMessageId, { | ||
nftId: message.nftId, | ||
contractAddress: message.contractAddress, | ||
}); | ||
} | ||
|
||
if (message.isReply && message.mainMessage?.id) { | ||
const thread = temporaryArchiveMessages.filter( | ||
(item) => item.mainMessage?.id === message.mainMessage?.id | ||
); | ||
this.updateMessageProperty( | ||
message.mainMessage?.id, | ||
"numberOfReplies", | ||
thread.length | ||
); | ||
await updateNumberOfReplies( | ||
message.mainMessage.id, | ||
thread.length | ||
); | ||
} | ||
message.tokenAmount && | ||
(await updateTokenAmount( | ||
message.receiverMessageId, | ||
message.tokenAmount | ||
)); | ||
} | ||
|
||
await insertMessages(message); | ||
this.addMessage(message); | ||
if (message.isReply && message.mainMessage?.id) { | ||
const thread = temporaryArchiveMessages.filter( | ||
(item) => item.mainMessage?.id === message.mainMessage?.id | ||
); | ||
this.updateMessageProperty( | ||
message.mainMessage?.id, | ||
"numberOfReplies", | ||
thread.length | ||
); | ||
await updateNumberOfReplies( | ||
message.mainMessage.id, | ||
thread.length | ||
); | ||
} | ||
|
||
await insertMessages(message); | ||
this.addMessage(message); | ||
} | ||
} | ||
|
||
|
@@ -1223,22 +1207,13 @@ export class ChatStore { | |
|
||
//response to when a message is edited | ||
if (stanza.attrs.id === XMPP_TYPES.replaceMessage) { | ||
// <message xmlns="jabber:client" xml:lang="en" to="olek@localhost/1216574346180782548712130" from="[email protected]/olek" type="groupchat" id="1635229272917013"> | ||
// <archived by="[email protected]" id="1635233863744841" xmlns="urn:xmpp:mam:tmp"/> | ||
// <stanza-id by="[email protected]" id="1635233863744841" xmlns="urn:xmpp:sid:0"/> | ||
// <replace xmlns="urn:xmpp:message-correct:0" id="1635229272917013"/> | ||
// <body>Wow</body> | ||
// </message> | ||
const replaceMessageId = stanza.children.find( | ||
(item: { name: string }) => item.name === "replace" | ||
).attrs.id; | ||
const messageString = stanza.children.find( | ||
(item: { name: string }) => item.name === "body" | ||
).children[0]; | ||
// this.addToReplaceMessageList(replaceMessageId, messageString); | ||
|
||
this.editMessage(replaceMessageId, messageString); | ||
await updateMessageText(replaceMessageId, messageString); | ||
const replaceMessage: { text: string; id: string } = | ||
stanza.children.find((item) => item.name === "replace").attrs; | ||
const replaceMessageId = replaceMessage.id; | ||
const replaceMessageText = replaceMessage.text; | ||
|
||
this.editMessage(replaceMessageId, replaceMessageText); | ||
await updateMessageText(replaceMessageId, replaceMessageText); | ||
} | ||
|
||
//capture message composing | ||
|
Oops, something went wrong.