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';
|
import 'package:moxxmpp/src/xeps/xep_0045/types.dart';
|
||||||
|
|
||||||
/// Triggered when the MUC changes our nickname.
|
/// Triggered when the MUC changes our nickname.
|
||||||
class NickChangedByMUCEvent extends XmppEvent {
|
class OwnDataChangedEvent extends XmppEvent {
|
||||||
NickChangedByMUCEvent(this.roomJid, this.nick);
|
OwnDataChangedEvent(
|
||||||
|
this.roomJid,
|
||||||
|
this.nick,
|
||||||
|
this.affiliation,
|
||||||
|
this.role,
|
||||||
|
);
|
||||||
|
|
||||||
/// The JID of the room.
|
/// The JID of the room.
|
||||||
final JID roomJid;
|
final JID roomJid;
|
||||||
|
|
||||||
/// The new nickname.
|
/// Our nickname.
|
||||||
final String nick;
|
final String nick;
|
||||||
|
|
||||||
|
/// Our affiliation.
|
||||||
|
final Affiliation affiliation;
|
||||||
|
|
||||||
|
/// Our role.
|
||||||
|
final Role role;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggered when an entity joins the MUC.
|
/// Triggered when an entity joins the MUC.
|
||||||
|
@ -149,6 +149,13 @@ class RoomState {
|
|||||||
/// Flag whether we're joined and can process messages
|
/// Flag whether we're joined and can process messages
|
||||||
bool joined;
|
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;
|
late final List<PendingMessage> pendingMessages;
|
||||||
|
|
||||||
/// "List" of entities inside the MUC.
|
/// "List" of entities inside the MUC.
|
||||||
|
@ -300,20 +300,32 @@ class MUCManager extends XmppManagerBase {
|
|||||||
final role = Role.fromString(
|
final role = Role.fromString(
|
||||||
item.attributes['role']! as String,
|
item.attributes['role']! as String,
|
||||||
);
|
);
|
||||||
|
final affiliation = Affiliation.fromString(
|
||||||
|
item.attributes['affiliation']! as String,
|
||||||
|
);
|
||||||
|
|
||||||
if (statuses.contains('110')) {
|
if (statuses.contains('110')) {
|
||||||
if (room.nick != from.resource) {
|
if (room.joined) {
|
||||||
// Notify us of the changed nick.
|
if (room.nick != from.resource ||
|
||||||
getAttributes().sendEvent(
|
room.affiliation != affiliation ||
|
||||||
NickChangedByMUCEvent(
|
room.role != role) {
|
||||||
bareFrom,
|
// Notify us of the changed data.
|
||||||
from.resource,
|
getAttributes().sendEvent(
|
||||||
),
|
OwnDataChangedEvent(
|
||||||
);
|
bareFrom,
|
||||||
|
from.resource,
|
||||||
|
affiliation,
|
||||||
|
role,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the nick to make sure we're in sync with the MUC.
|
// Set the data to make sure we're in sync with the MUC.
|
||||||
room.nick = from.resource;
|
room
|
||||||
|
..nick = from.resource
|
||||||
|
..affiliation = affiliation
|
||||||
|
..role = role;
|
||||||
logger.finest('Self-presence handled');
|
logger.finest('Self-presence handled');
|
||||||
return StanzaHandlerData(
|
return StanzaHandlerData(
|
||||||
true,
|
true,
|
||||||
|
Loading…
Reference in New Issue
Block a user