feat(xep): Track our own affiliation and role
This commit is contained in:
parent
882d20dc7a
commit
e97d6e6517
@ -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.
|
||||
|
@ -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<PendingMessage> pendingMessages;
|
||||
|
||||
/// "List" of entities inside the MUC.
|
||||
|
@ -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.
|
||||
if (room.joined) {
|
||||
if (room.nick != from.resource ||
|
||||
room.affiliation != affiliation ||
|
||||
room.role != role) {
|
||||
// Notify us of the changed data.
|
||||
getAttributes().sendEvent(
|
||||
NickChangedByMUCEvent(
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user