git » sdk » commit 45858a0

Find out who invited us to this chat

author Stephen Paul Weber
2025-12-01 15:06:15 UTC
committer Stephen Paul Weber
2025-12-01 15:06:15 UTC
parent 995155ef16e89dd1184c2262828608ae7830aac5

Find out who invited us to this chat

borogove/Chat.hx +20 -0

diff --git a/borogove/Chat.hx b/borogove/Chat.hx
index 826bda8..80dcaa9 100644
--- a/borogove/Chat.hx
+++ b/borogove/Chat.hx
@@ -846,6 +846,26 @@ abstract class Chat {
 		return jids;
 	}
 
+	/**
+		The Participant that originally invited us to this Chat, if we were invited
+	**/
+	public function invitedBy() {
+		final inviteEls = invites();
+		if (inviteEls.length < 1) return null;
+
+		final inviteFrom = JID.parse(inviteEls[0].attr.get("from"));
+		final bare = inviteFrom.asBare().asString();
+		final maybeChannel = client.getChat(bare);
+		if (maybeChannel != null) {
+			final channel = maybeChannel.downcast(Channel);
+			if (channel != null) {
+				return channel.getParticipantDetails(inviteFrom.asString());
+			}
+		}
+
+		return (maybeChannel ?? client.getDirectChat(bare)).getParticipantDetails(bare);
+	}
+
 	private function invites() {
 		return extensions.allTags("invite", "http://jabber.org/protocol/muc#user");
 	}