git » sdk » commit c5ac62d

Default notifications when first making a Channel

author Stephen Paul Weber
2025-10-01 13:25:22 UTC
committer Stephen Paul Weber
2025-10-01 13:25:35 UTC
parent feb93406380897115cc96d20c72c7d36db1c27ca

Default notifications when first making a Channel

The other strategy didn't work because we already have disco and don't
need to refresh whenever we actually add a new Channel...

borogove/Chat.hx +6 -2
borogove/Client.hx +2 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index e0f397d..9de00bc 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -1268,14 +1268,18 @@ class Channel extends Chat {
 		return disco.features.contains("muc_membersonly");
 	}
 
+	@:allow(borogove)
+	private function setupNotifications() {
+		if (disco == null) return;
+		if (!isPrivate()) notificationSettings = { mention: true, reply: false };
+	}
+
 	@:allow(borogove)
 	private function refreshDisco(?callback: ()->Void) {
 		final discoGet = new DiscoInfoGet(chatId);
 		discoGet.onFinished(() -> {
 			if (discoGet.getResult() != null) {
-				final setupNotifications = disco == null && notificationSettings == null;
 				disco = discoGet.getResult();
-				if (setupNotifications && !isPrivate()) notificationSettings = { mention: true, reply: false };
 				persistence.storeCaps(discoGet.getResult());
 				persistence.storeChats(client.accountId(), [this]);
 			}
diff --git a/borogove/Client.hx b/borogove/Client.hx
index c1fff97..ad74773 100644
--- a/borogove/Client.hx
+++ b/borogove/Client.hx
@@ -977,6 +977,7 @@ class Client extends EventEmitter {
 
 		final chat = if (availableChat.isChannel()) {
 			final channel = new Channel(this, this.stream, this.persistence, availableChat.chatId, Open, false, null, availableChat.caps);
+			channel.setupNotifications();
 			chats.unshift(channel);
 			channel.selfPing(false);
 			channel;
@@ -1480,6 +1481,7 @@ class Client extends EventEmitter {
 				final uiState = handleCaps(resultCaps);
 				if (resultCaps.isChannel(jid)) {
 					final chat = new Channel(this, this.stream, this.persistence, jid, uiState, false, null, resultCaps);
+					chat.setupNotifications();
 					handleChat(chat);
 					chats.unshift(chat);
 					persistence.storeChats(accountId(), [chat]);