git » sdk » commit f08aa97

Check what we actually care about

author Stephen Paul Weber
2025-06-24 17:51:32 UTC
committer Stephen Paul Weber
2025-06-24 17:55:06 UTC
parent fd3cd0106be8bdd2a40a0cc48bb5dd62f490d647

Check what we actually care about

Make sure the version that we're going to use when sending has the id we
need before using it.

Also, send using this correct id to replace -- not the most recent version id, but
the original id.

snikket/Chat.hx +1 -1
snikket/ChatMessage.hx +1 -1

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index 68e4886..09b8b2a 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -1349,7 +1349,7 @@ class Channel extends Chat {
 		message.versions = [message.build()]; // This is a correction
 		message.localId = localId;
 		client.storeMessages([message.build()], (corrected) -> {
-			message.versions = corrected[0].localId == localId ? cast corrected[0].versions : [message.build()];
+			message.versions = corrected[0].versions[0]?.localId == localId ? cast corrected[0].versions : [message.build()];
 			message.localId = toSendId;
 			client.sendStanza(message.build().asStanza());
 			client.notifyMessageHandlers(corrected[0], CorrectionEvent);
diff --git a/snikket/ChatMessage.hx b/snikket/ChatMessage.hx
index 8ef52ee..38d6d4a 100644
--- a/snikket/ChatMessage.hx
+++ b/snikket/ChatMessage.hx
@@ -418,7 +418,7 @@ class ChatMessage {
 		if (to != null) attrs.set("to", to.asString());
 		if (localId != null) attrs.set("id", localId);
 		var stanza = new Stanza("message", attrs);
-		if (versions.length > 0 && versions[versions.length-1].localId != null) stanza.tag("replace", { xmlns: "urn:xmpp:message-correct:0", id: versions[versions.length-1].localId }).up();
+		if (versions.length > 0 && versions[0].localId != null) stanza.tag("replace", { xmlns: "urn:xmpp:message-correct:0", id: versions[0].localId }).up();
 		if (threadId != null) stanza.textTag("thread", threadId);
 		if (recipients.length > 1) {
 			final addresses = stanza.tag("addresses", { xmlns: "http://jabber.org/protocol/address" });