feat(xep): Implement XEP 0421 in Moxxmpp.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
This commit is contained in:
parent
aa71d3ed5d
commit
ac5bb9e461
@ -85,6 +85,7 @@ export 'package:moxxmpp/src/xeps/xep_0388/errors.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0388/user_agent.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0421.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0424.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0444.dart';
|
||||
export 'package:moxxmpp/src/xeps/xep_0446.dart';
|
||||
|
@ -32,3 +32,4 @@ const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager';
|
||||
const stickersManager = 'org.moxxmpp.stickersmanager';
|
||||
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
|
||||
const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint';
|
||||
const occupantIdManager = 'org.moxxmpp.occupantidmanager';
|
||||
|
@ -123,6 +123,9 @@ const sasl2Xmlns = 'urn:xmpp:sasl:2';
|
||||
// XEP-0420
|
||||
const sceXmlns = 'urn:xmpp:sce:1';
|
||||
|
||||
// XEP-0421
|
||||
const occupantIdXmlns = 'urn:xmpp:occupant-id:0';
|
||||
|
||||
// XEP-0422
|
||||
const fasteningXmlns = 'urn:xmpp:fasten:0';
|
||||
|
||||
|
66
packages/moxxmpp/lib/src/xeps/xep_0421.dart
Normal file
66
packages/moxxmpp/lib/src/xeps/xep_0421.dart
Normal file
@ -0,0 +1,66 @@
|
||||
import 'dart:async';
|
||||
import 'package:moxxmpp/src/managers/base.dart';
|
||||
import 'package:moxxmpp/src/managers/data.dart';
|
||||
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||
import 'package:moxxmpp/src/namespaces.dart';
|
||||
import 'package:moxxmpp/src/stanza.dart';
|
||||
import 'package:moxxmpp/src/stringxml.dart';
|
||||
|
||||
/// Representation of a <occupant-id /> element.
|
||||
class OccupantIdData implements StanzaHandlerExtension {
|
||||
const OccupantIdData(
|
||||
this.id,
|
||||
);
|
||||
|
||||
/// The unique occupant id.
|
||||
final String id;
|
||||
|
||||
XMLNode toXML() {
|
||||
return XMLNode.xmlns(
|
||||
tag: 'occupant-id',
|
||||
xmlns: occupantIdXmlns,
|
||||
attributes: {
|
||||
'id': id,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class OccupantIdManager extends XmppManagerBase {
|
||||
OccupantIdManager() : super(occupantIdManager);
|
||||
|
||||
@override
|
||||
List<String> getDiscoFeatures() => [
|
||||
occupantIdXmlns,
|
||||
];
|
||||
|
||||
@override
|
||||
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
||||
StanzaHandler(
|
||||
stanzaTag: 'message',
|
||||
callback: _onMessage,
|
||||
// Before the MessageManager
|
||||
priority: -99,
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<bool> isSupported() async => true;
|
||||
|
||||
Future<StanzaHandlerData> _onMessage(
|
||||
Stanza stanza,
|
||||
StanzaHandlerData state,
|
||||
) async {
|
||||
OccupantIdData? occupantId;
|
||||
final occupantIdElement =
|
||||
stanza.firstTag('occupant-id', xmlns: occupantIdXmlns);
|
||||
// Process the occupant id
|
||||
if (occupantIdElement != null) {
|
||||
occupantId =
|
||||
OccupantIdData(occupantIdElement.attributes['id']! as String);
|
||||
state.extensions.set(occupantId);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user