git » sdk » commit 99bee19

Get MUC avatar from disco

author Stephen Paul Weber
2026-02-10 13:47:26 UTC
committer Stephen Paul Weber
2026-02-10 13:49:46 UTC
parent 63b683a4046a81b4cc6798c676f2378583f98f8a

Get MUC avatar from disco

borogove/Chat.hx +20 -0
borogove/Client.hx +1 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 3736aeb..c62d420 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -20,6 +20,7 @@ import borogove.calls.Session;
 import borogove.queries.DiscoInfoGet;
 import borogove.queries.DiscoItemsGet;
 import borogove.queries.MAMQuery;
+import borogove.queries.VcardTempGet;
 using Lambda;
 using StringTools;
 using borogove.Util;
@@ -1555,6 +1556,25 @@ class Channel extends Chat {
 				persistence.storeChats(client.accountId(), [this]);
 			}
 			if (callback != null) callback();
+			final avatarSha1Hex = info()?.field("muc#roominfo_avatarhash")?.value?.join("");
+			if (avatarSha1Hex != null && avatarSha1Hex != "") {
+				final hash = Hash.fromHex("sha-1", avatarSha1Hex);
+				avatarSha1 = hash.hash;
+				persistence.hasMedia("sha-1", avatarSha1).then((has) -> {
+					if (!has) {
+trace("XYZZY no MUC avatar locally matching so fetch vcard", chatId, avatarSha1Hex);
+						final vcardGet = new VcardTempGet(JID.parse(chatId));
+						vcardGet.onFinished(() -> {
+							final vcard = vcardGet.getResult();
+							if (vcard.photo == null) return;
+							persistence.storeMedia(vcard.photo.mime, vcard.photo.data.getData()).then(_ -> {
+								client.trigger("chats/update", [this]);
+							});
+						});
+						client.sendQueryLazy(vcardGet);
+					}
+				});
+			}
 		});
 		client.sendQuery(discoGet);
 	}
diff --git a/borogove/Client.hx b/borogove/Client.hx
index 2d086f0..95eefed 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -1533,6 +1533,7 @@ class Client extends EventEmitter {
 		}, 2000);
 	}
 
+	@:allow(borogove)
 	private function sendQueryLazy(query:GenericQuery) {
 		queriesToSend.push(query);
 		sendNextLazyQuery();