Merge pull request 'Add support for XEP-0421.' (#45) from ikjot-2605/moxxmpp:feat_xep_0421 into master

Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/45
This commit is contained in:
PapaTutuWawa 2023-06-12 10:58:32 +00:00
commit 29a5417b31
4 changed files with 66 additions and 0 deletions

View File

@ -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/negotiators.dart';
export 'package:moxxmpp/src/xeps/xep_0388/user_agent.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_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_0424.dart';
export 'package:moxxmpp/src/xeps/xep_0444.dart'; export 'package:moxxmpp/src/xeps/xep_0444.dart';
export 'package:moxxmpp/src/xeps/xep_0446.dart'; export 'package:moxxmpp/src/xeps/xep_0446.dart';

View File

@ -32,3 +32,4 @@ const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager';
const stickersManager = 'org.moxxmpp.stickersmanager'; const stickersManager = 'org.moxxmpp.stickersmanager';
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities'; const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint'; const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint';
const occupantIdManager = 'org.moxxmpp.occupantidmanager';

View File

@ -123,6 +123,9 @@ const sasl2Xmlns = 'urn:xmpp:sasl:2';
// XEP-0420 // XEP-0420
const sceXmlns = 'urn:xmpp:sce:1'; const sceXmlns = 'urn:xmpp:sce:1';
// XEP-0421
const occupantIdXmlns = 'urn:xmpp:occupant-id:0';
// XEP-0422 // XEP-0422
const fasteningXmlns = 'urn:xmpp:fasten:0'; const fasteningXmlns = 'urn:xmpp:fasten:0';

View File

@ -0,0 +1,61 @@
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/message.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',
tagName: 'occupant-id',
tagXmlns: occupantIdXmlns,
callback: _onMessage,
// Before the MessageManager
priority: MessageManager.messageHandlerPriority + 1,
),
];
@override
Future<bool> isSupported() async => true;
Future<StanzaHandlerData> _onMessage(
Stanza stanza,
StanzaHandlerData state,
) async {
return state
..extensions.set(OccupantIdData(stanza.attributes['id']! as String));
}
}