feat(core): Check if we can do subscription pre-approval
This commit is contained in:
parent
da1d28a6d6
commit
963f3f2cd9
@ -18,7 +18,6 @@ export 'package:moxxmpp/src/managers/namespaces.dart';
|
|||||||
export 'package:moxxmpp/src/managers/priorities.dart';
|
export 'package:moxxmpp/src/managers/priorities.dart';
|
||||||
export 'package:moxxmpp/src/message.dart';
|
export 'package:moxxmpp/src/message.dart';
|
||||||
export 'package:moxxmpp/src/namespaces.dart';
|
export 'package:moxxmpp/src/namespaces.dart';
|
||||||
export 'package:moxxmpp/src/negotiators/manager.dart';
|
|
||||||
export 'package:moxxmpp/src/negotiators/namespaces.dart';
|
export 'package:moxxmpp/src/negotiators/namespaces.dart';
|
||||||
export 'package:moxxmpp/src/negotiators/negotiator.dart';
|
export 'package:moxxmpp/src/negotiators/negotiator.dart';
|
||||||
export 'package:moxxmpp/src/ping.dart';
|
export 'package:moxxmpp/src/ping.dart';
|
||||||
|
@ -9,6 +9,7 @@ const fullStanzaXmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas';
|
|||||||
// RFC 6121
|
// RFC 6121
|
||||||
const rosterXmlns = 'jabber:iq:roster';
|
const rosterXmlns = 'jabber:iq:roster';
|
||||||
const rosterVersioningXmlns = 'urn:xmpp:features:rosterver';
|
const rosterVersioningXmlns = 'urn:xmpp:features:rosterver';
|
||||||
|
const subscriptionPreApprovalXmlns = 'urn:xmpp:features:pre-approval';
|
||||||
|
|
||||||
// XEP-0004
|
// XEP-0004
|
||||||
const dataFormsXmlns = 'jabber:x:data';
|
const dataFormsXmlns = 'jabber:x:data';
|
||||||
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -11,3 +11,4 @@ const sasl2Negotiator = 'org.moxxmpp.sasl.sasl2';
|
|||||||
const bind2Negotiator = 'org.moxxmpp.bind2';
|
const bind2Negotiator = 'org.moxxmpp.bind2';
|
||||||
const saslFASTNegotiator = 'org.moxxmpp.sasl.fast';
|
const saslFASTNegotiator = 'org.moxxmpp.sasl.fast';
|
||||||
const carbonsNegotiator = 'org.moxxmpp.bind2.carbons';
|
const carbonsNegotiator = 'org.moxxmpp.bind2.carbons';
|
||||||
|
const presenceNegotiator = 'org.moxxmpp.core.presence';
|
||||||
|
@ -6,14 +6,44 @@ import 'package:moxxmpp/src/managers/data.dart';
|
|||||||
import 'package:moxxmpp/src/managers/handlers.dart';
|
import 'package:moxxmpp/src/managers/handlers.dart';
|
||||||
import 'package:moxxmpp/src/managers/namespaces.dart';
|
import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||||
import 'package:moxxmpp/src/namespaces.dart';
|
import 'package:moxxmpp/src/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/negotiators/namespaces.dart';
|
||||||
|
import 'package:moxxmpp/src/negotiators/negotiator.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
|
||||||
/// A function that will be called when presence, outside of subscription request
|
/// A function that will be called when presence, outside of subscription request
|
||||||
/// management, will be sent. Useful for managers that want to add [XMLNode]s to said
|
/// management, will be sent. Useful for managers that want to add [XMLNode]s to said
|
||||||
/// presence.
|
/// presence.
|
||||||
typedef PresencePreSendCallback = Future<List<XMLNode>> Function();
|
typedef PresencePreSendCallback = Future<List<XMLNode>> Function();
|
||||||
|
|
||||||
|
/// A pseudo-negotiator that does not really negotiate anything. Instead, its purpose
|
||||||
|
/// is to look for a stream feature indicating that we can pre-approve subscription
|
||||||
|
/// requests, shown by [PresenceNegotiator.preApprovalSupported].
|
||||||
|
class PresenceNegotiator extends XmppFeatureNegotiatorBase {
|
||||||
|
PresenceNegotiator()
|
||||||
|
: super(11, false, subscriptionPreApprovalXmlns, presenceNegotiator);
|
||||||
|
|
||||||
|
/// Flag indicating whether presence subscription pre-approval is supported
|
||||||
|
bool _supported = false;
|
||||||
|
bool get preApprovalSupported => _supported;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Result<NegotiatorState, NegotiatorError>> negotiate(
|
||||||
|
XMLNode nonza,
|
||||||
|
) async {
|
||||||
|
_supported = true;
|
||||||
|
return const Result(NegotiatorState.done);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void reset() {
|
||||||
|
_supported = false;
|
||||||
|
|
||||||
|
super.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A mandatory manager that handles initial presence sending, sending of subscription
|
/// A mandatory manager that handles initial presence sending, sending of subscription
|
||||||
/// request management requests and triggers events for incoming presence stanzas.
|
/// request management requests and triggers events for incoming presence stanzas.
|
||||||
class PresenceManager extends XmppManagerBase {
|
class PresenceManager extends XmppManagerBase {
|
||||||
|
@ -794,4 +794,20 @@ void main() {
|
|||||||
expect(fakeSocket.getState(), 9);
|
expect(fakeSocket.getState(), 9);
|
||||||
expect(await stanzaFuture != null, true);
|
expect(await stanzaFuture != null, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test subscription pre-approval parsing', () async {
|
||||||
|
final rawFeatures = XMLNode.fromString(
|
||||||
|
'''
|
||||||
|
<top-level>
|
||||||
|
<test-feature-1 xmlns="invalid:urn:features:1" />
|
||||||
|
<test-feature-2 xmlns="invalid:urn:features:2" />
|
||||||
|
<test-feature-3 xmlns="invalid:urn:features:3" />
|
||||||
|
<test-feature-4 xmlns="invalid:urn:features:4" />
|
||||||
|
<sub xmlns='urn:xmpp:features:pre-approval' />
|
||||||
|
</top-level>
|
||||||
|
''',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(PresenceNegotiator().matchesFeature(rawFeatures.children), true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user