Skip to content

Commit

Permalink
edit message stanza
Browse files Browse the repository at this point in the history
  • Loading branch information
dendidibe committed Oct 3, 2023
1 parent 5bfac1d commit ca4d422
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
20 changes: 13 additions & 7 deletions client-web/src/xmpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class XmppClass {
this.client.on("online", (jid) => {
xmppMessagesHandler.getListOfRooms(this);
this.subscribeToDefaultChats();
this.getPrivateXmlRooms()
this.getPrivateXmlRooms();
});
this.client.on("stanza", xmppMessagesHandler.onMessageHistory);
this.client.on("stanza", (stanza) =>
Expand Down Expand Up @@ -844,6 +844,17 @@ export class XmppClass {
messageId: string,
data: any
) => {
// <message
// id="replaceMessage"
// type="groupchat"
// to="[email protected]"
// >
// <replace
// id="1696317314425072"
// xmlns="urn:xmpp:message-correct:0"
// text="first message edited now"
// />
// </message>;
const stanza = xml(
"message",
{
Expand All @@ -852,15 +863,10 @@ export class XmppClass {
type: "groupchat",
to: roomJID,
},
xml("body", {}, replaceText),
xml("replace", {
id: messageId,
xmlns: "urn:xmpp:message-correct:0",
}),
xml("data", {
xmlns: "http://dev.dxmpp.com",
senderJID: this.client.jid?.toString(),
...data,
text: replaceText,
})
);
this.client.send(stanza);
Expand Down
16 changes: 9 additions & 7 deletions client-web/src/xmppHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class XmppHandler {
const data = stanza?.getChild("data");
const replace = stanza?.getChild("replace");
const archived = stanza?.getChild("archived");

const id = stanza.getChild("archived")?.attrs.id;
if (!data || !body || !id) {
return;
Expand Down Expand Up @@ -108,6 +107,7 @@ 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")
Expand Down Expand Up @@ -525,12 +525,14 @@ export class XmppHandler {
//when messages are edited in realtime then capture broadcast with id "replaceMessage" and replace the text.
onSendReplaceMessageStanza = (stanza: any) => {
if (stanza.attrs.id === "replaceMessage") {
const replaceMessageId = Number(
stanza.children.find((item) => item.name === "replace").attrs.id
);
const messageString = stanza.children.find((item) => item.name === "body")
.children[0];
useStoreState.getState().replaceMessage(replaceMessageId, messageString);
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()
.replaceMessage(+replaceMessage.id, messageString);
}
};

Expand Down

0 comments on commit ca4d422

Please sign in to comment.