diff --git a/packages/moxxmpp/CHANGELOG.md b/packages/moxxmpp/CHANGELOG.md index 34fa8c7..071da45 100644 --- a/packages/moxxmpp/CHANGELOG.md +++ b/packages/moxxmpp/CHANGELOG.md @@ -5,6 +5,7 @@ - **BREAKING**: The user avatar's `subscribe` and `unsubscribe` no longer subscribe to the `:data` PubSub nodes - Renamed `ResourceBindingSuccessEvent` to `ResourceBoundEvent` - **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same +- The `PresenceManager` is now optional ## 0.1.6+1 diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 7c9c57c..a517826 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -861,9 +861,6 @@ class XmppConnection { // Tell consumers of the event stream that we're done with stream feature // negotiations await _sendEvent(StreamNegotiationsDoneEvent()); - - // Send out initial presence - await getPresenceManager().sendInitialPresence(); } Future _executeCurrentNegotiator(XMLNode nonza) async { @@ -1090,10 +1087,6 @@ class XmppConnection { /// Make sure that all required managers are registered void _runPreConnectionAssertions() { - assert( - _xmppManagers.containsKey(presenceManager), - 'A PresenceManager is mandatory', - ); assert( _xmppManagers.containsKey(rosterManager), 'A RosterManager is mandatory', diff --git a/packages/moxxmpp/lib/src/presence.dart b/packages/moxxmpp/lib/src/presence.dart index a461a85..570d8f7 100644 --- a/packages/moxxmpp/lib/src/presence.dart +++ b/packages/moxxmpp/lib/src/presence.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:moxxmpp/src/connection.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; @@ -6,8 +7,10 @@ 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/negotiators/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; +import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart'; /// 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 @@ -42,6 +45,19 @@ class PresenceManager extends XmppManagerBase { _presenceCallbacks.add(callback); } + @override + Future onXmppEvent(XmppEvent event) async { + if (event is StreamNegotiationsDoneEvent) { + // Send initial presence only when we have not resumed the stream + final sm = getAttributes().getNegotiatorById( + streamManagementNegotiator); + final isResumed = sm?.isResumed ?? false; + if (!isResumed) { + unawaited(sendInitialPresence()); + } + } + } + Future _onPresence( Stanza presence, StanzaHandlerData state, diff --git a/packages/moxxmpp/test/xeps/xep_0198_test.dart b/packages/moxxmpp/test/xeps/xep_0198_test.dart index fc985ef..6c1dc73 100644 --- a/packages/moxxmpp/test/xeps/xep_0198_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0198_test.dart @@ -431,7 +431,7 @@ void main() { await conn.connect( waitUntilLogin: true, ); - expect(fakeSocket.getState(), 5); + expect(fakeSocket.getState(), 6); expect(await conn.getConnectionState(), XmppConnectionState.connected); expect( conn @@ -589,7 +589,7 @@ void main() { waitUntilLogin: true, ); - expect(fakeSocket.getState(), 5); + expect(fakeSocket.getState(), 6); expect(await conn.getConnectionState(), XmppConnectionState.connected); expect( conn @@ -689,7 +689,7 @@ void main() { await conn.connect( waitUntilLogin: true, ); - expect(fakeSocket.getState(), 6); + expect(fakeSocket.getState(), 7); expect(await conn.getConnectionState(), XmppConnectionState.connected); expect( conn