git » sdk » commit a391803

Preserve 110 if not present

author Stephen Paul Weber
2024-11-08 03:10:02 UTC
committer Stephen Paul Weber
2024-11-08 03:10:02 UTC
parent 5a959328b840d0b76712caf89c10507698da6249

Preserve 110 if not present

Some servers (ejabberd) send self-presence updates without 110. So if a
presence was 110 and isn't now, let's assume it still is.

snikket/Chat.hx +9 -1

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index 68ba702..73e19e7 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -921,8 +921,16 @@ class Channel extends Chat {
 	}
 
 	override public function setPresence(resource:String, presence:Presence) {
-		super.setPresence(resource, presence);
 		final oneTen = presence?.mucUser?.allTags("status").find((status) -> status.attr.get("code") == "110");
+		if (presence != null && presence.mucUser != null && oneTen == null) {
+			final existing = this.presence.get(resource);
+			if (existing != null && existing?.mucUser?.allTags("status").find((status) -> status.attr.get("code") == "110") != null) {
+				presence.mucUser.tag("status", { code: "110" });
+				setPresence(resource, presence);
+				return;
+			}
+		}
+		super.setPresence(resource, presence);
 		final tripleThree = presence?.mucUser?.allTags("status").find((status) -> status.attr.get("code") == "333");
 		if (!inSync && oneTen != null) {
 			persistence.lastId(client.accountId(), chatId, doSync);