Compare commits

..

4 Commits

Author SHA1 Message Date
29a5417b31 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
2023-06-12 10:58:32 +00:00
Ikjot Singh Dhody
255d0f88e0 feat(xep): Use cascading operation to return state
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-12 15:00:37 +05:30
Ikjot Singh Dhody
fa11a3a384 feat(xep): Checked for the occupant-id directly.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-11 23:29:17 +05:30
Ikjot Singh Dhody
ac5bb9e461 feat(xep): Implement XEP 0421 in Moxxmpp.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-11 22:09:29 +05:30
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/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';

View File

@ -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';

View File

@ -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';

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));
}
}