feat(core): Make the PresenceManager optional

This commit is contained in:
PapaTutuWawa 2023-04-01 13:09:43 +02:00
parent 9358175925
commit 89fe8f0a9c
4 changed files with 20 additions and 10 deletions

View File

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

View File

@ -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<void> _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',

View File

@ -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<void> onXmppEvent(XmppEvent event) async {
if (event is StreamNegotiationsDoneEvent) {
// Send initial presence only when we have not resumed the stream
final sm = getAttributes().getNegotiatorById<StreamManagementNegotiator>(
streamManagementNegotiator);
final isResumed = sm?.isResumed ?? false;
if (!isResumed) {
unawaited(sendInitialPresence());
}
}
}
Future<StanzaHandlerData> _onPresence(
Stanza presence,
StanzaHandlerData state,

View File

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