git » sdk » commit 825dda9

Don't notify UI about presence if still joining MUC

author Stephen Paul Weber
2023-11-01 15:58:27 UTC
committer Stephen Paul Weber
2023-11-08 21:16:35 UTC
parent f287e7b0e1298b7e553389cf5e65e27870f180a7

Don't notify UI about presence if still joining MUC

xmpp/Chat.hx +9 -0
xmpp/Client.hx +3 -3

diff --git a/xmpp/Chat.hx b/xmpp/Chat.hx
index 1593ce5..e7a001b 100644
--- a/xmpp/Chat.hx
+++ b/xmpp/Chat.hx
@@ -151,6 +151,11 @@ abstract class Chat {
 		return this.trusted;
 	}
 
+
+	public function livePresence() {
+		return false;
+	}
+
 	public function canAudioCall():Bool {
 		for (resource => p in presence) {
 			if (p.caps?.features?.contains("urn:xmpp:jingle:apps:rtp:audio") ?? false) return true;
@@ -404,6 +409,10 @@ class Channel extends Chat {
 		client.sendQuery(discoGet);
 	}
 
+	override public function livePresence() {
+		return presence.exists(client.displayName());
+	}
+
 	private function getFullJid() {
 		final jid = JID.parse(chatId);
 		return new JID(jid.node, jid.domain, client.displayName());
diff --git a/xmpp/Client.hx b/xmpp/Client.hx
index 0b8388f..c8b77fd 100644
--- a/xmpp/Client.hx
+++ b/xmpp/Client.hx
@@ -290,7 +290,7 @@ class Client extends xmpp.EventEmitter {
 				if (c == null) {
 					chat.setCaps(JID.parse(stanza.attr.get("from")).resource, null);
 					persistence.storeChat(jid, chat);
-					this.trigger("chats/update", [chat]);
+					if (chat.livePresence()) this.trigger("chats/update", [chat]);
 				} else {
 					persistence.getCaps(c.attr.get("ver"), (caps) -> {
 						if (caps == null) {
@@ -299,13 +299,13 @@ class Client extends xmpp.EventEmitter {
 								chat.setCaps(JID.parse(stanza.attr.get("from")).resource, discoGet.getResult());
 								if (discoGet.getResult() != null) persistence.storeCaps(discoGet.getResult());
 								persistence.storeChat(jid, chat);
-								this.trigger("chats/update", [chat]);
+								if (chat.livePresence()) this.trigger("chats/update", [chat]);
 							});
 							sendQuery(discoGet);
 						} else {
 							chat.setCaps(JID.parse(stanza.attr.get("from")).resource, caps);
 							persistence.storeChat(jid, chat);
-							this.trigger("chats/update", [chat]);
+							if (chat.livePresence()) this.trigger("chats/update", [chat]);
 						}
 					});
 				}