From e97d6e6517c756de830f550528c6006996cf8a7c Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Fri, 29 Sep 2023 22:45:56 +0200 Subject: [PATCH] feat(xep): Track our own affiliation and role --- .../moxxmpp/lib/src/xeps/xep_0045/events.dart | 17 ++++++++-- .../moxxmpp/lib/src/xeps/xep_0045/types.dart | 7 ++++ .../lib/src/xeps/xep_0045/xep_0045.dart | 32 +++++++++++++------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/events.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/events.dart index 8eec00f..2ce352f 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/events.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/events.dart @@ -3,14 +3,25 @@ import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/xeps/xep_0045/types.dart'; /// Triggered when the MUC changes our nickname. -class NickChangedByMUCEvent extends XmppEvent { - NickChangedByMUCEvent(this.roomJid, this.nick); +class OwnDataChangedEvent extends XmppEvent { + OwnDataChangedEvent( + this.roomJid, + this.nick, + this.affiliation, + this.role, + ); /// The JID of the room. final JID roomJid; - /// The new nickname. + /// Our nickname. final String nick; + + /// Our affiliation. + final Affiliation affiliation; + + /// Our role. + final Role role; } /// Triggered when an entity joins the MUC. diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart index 06bb806..58ba309 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/types.dart @@ -149,6 +149,13 @@ class RoomState { /// Flag whether we're joined and can process messages bool joined; + /// Our own affiliation inside the MUC. + Affiliation? affiliation; + + /// Our own role inside the MUC. + Role? role; + + /// The list of messages that we sent and are waiting for their echo. late final List pendingMessages; /// "List" of entities inside the MUC. diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart index 08b08cb..0b121c5 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart @@ -300,20 +300,32 @@ class MUCManager extends XmppManagerBase { final role = Role.fromString( item.attributes['role']! as String, ); + final affiliation = Affiliation.fromString( + item.attributes['affiliation']! as String, + ); if (statuses.contains('110')) { - if (room.nick != from.resource) { - // Notify us of the changed nick. - getAttributes().sendEvent( - NickChangedByMUCEvent( - bareFrom, - from.resource, - ), - ); + if (room.joined) { + if (room.nick != from.resource || + room.affiliation != affiliation || + room.role != role) { + // Notify us of the changed data. + getAttributes().sendEvent( + OwnDataChangedEvent( + bareFrom, + from.resource, + affiliation, + role, + ), + ); + } } - // Set the nick to make sure we're in sync with the MUC. - room.nick = from.resource; + // Set the data to make sure we're in sync with the MUC. + room + ..nick = from.resource + ..affiliation = affiliation + ..role = role; logger.finest('Self-presence handled'); return StanzaHandlerData( true,