git » sdk » commit f0bf34d

Helper to check if this is a channel

author Stephen Paul Weber
2023-10-18 16:20:55 UTC
committer Stephen Paul Weber
2023-10-18 16:21:30 UTC
parent 47fdbe8be41a8ca8fe2398bd29d778aadabbb2c5

Helper to check if this is a channel

xmpp/Caps.hx +6 -0
xmpp/Chat.hx +2 -2

diff --git a/xmpp/Caps.hx b/xmpp/Caps.hx
index 4aeae5a..5208627 100644
--- a/xmpp/Caps.hx
+++ b/xmpp/Caps.hx
@@ -3,6 +3,7 @@ package xmpp;
 import haxe.crypto.Base64;
 import haxe.crypto.Sha1;
 import haxe.io.Bytes;
+using Lambda;
 
 @:expose
 class Caps {
@@ -45,6 +46,11 @@ class Caps {
 		this.features = features;
 	}
 
+	public function isChannel(chatId: String) {
+		if (chatId.indexOf("@") < 0) return false; // MUC must have a localpart
+		return features.contains("http://jabber.org/protocol/muc") && identities.find((identity) -> identity.category == "conference") != null;
+	}
+
 	public function discoReply():Stanza {
 		final query = new Stanza("query", { xmlns: "http://jabber.org/protocol/disco#info" });
 		for (identity in identities) {
diff --git a/xmpp/Chat.hx b/xmpp/Chat.hx
index d67c3d0..922c934 100644
--- a/xmpp/Chat.hx
+++ b/xmpp/Chat.hx
@@ -59,7 +59,7 @@ abstract class Chat {
 
 	public function canAudioCall():Bool {
 		for (resource => cap in caps) {
-			if (cap.features.contains("urn:xmpp:jingle:apps:rtp:audio")) return true;
+			if (cap?.features?.contains("urn:xmpp:jingle:apps:rtp:audio") ?? false) return true;
 		}
 
 		return false;
@@ -67,7 +67,7 @@ abstract class Chat {
 
 	public function canVideoCall():Bool {
 		for (resource => cap in caps) {
-			if (cap.features.contains("urn:xmpp:jingle:apps:rtp:video")) return true;
+			if (cap?.features?.contains("urn:xmpp:jingle:apps:rtp:video") ?? false) return true;
 		}
 
 		return false;