feat: Refactor RosterPushEvent to RosterPushResult
This commit is contained in:
parent
e12f4688d3
commit
67446285c1
@ -54,13 +54,6 @@ class StreamResumedEvent extends XmppEvent {
|
|||||||
/// Triggered when stream resumption failed
|
/// Triggered when stream resumption failed
|
||||||
class StreamResumeFailedEvent extends XmppEvent {}
|
class StreamResumeFailedEvent extends XmppEvent {}
|
||||||
|
|
||||||
/// Triggered when a roster push is received
|
|
||||||
class RosterPushEvent extends XmppEvent {
|
|
||||||
RosterPushEvent({ required this.item, this.ver });
|
|
||||||
final XmppRosterItem item;
|
|
||||||
final String? ver;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Triggered when the roster has been modified
|
/// Triggered when the roster has been modified
|
||||||
class RosterUpdatedEvent extends XmppEvent {
|
class RosterUpdatedEvent extends XmppEvent {
|
||||||
RosterUpdatedEvent(this.removed, this.modified, this.added);
|
RosterUpdatedEvent(this.removed, this.modified, this.added);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:moxxmpp/src/events.dart';
|
|
||||||
import 'package:moxxmpp/src/jid.dart';
|
import 'package:moxxmpp/src/jid.dart';
|
||||||
import 'package:moxxmpp/src/managers/base.dart';
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
import 'package:moxxmpp/src/managers/data.dart';
|
import 'package:moxxmpp/src/managers/data.dart';
|
||||||
@ -30,11 +29,17 @@ enum RosterRemovalResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RosterRequestResult {
|
class RosterRequestResult {
|
||||||
RosterRequestResult({ required this.items, this.ver });
|
RosterRequestResult(this.items, this.ver);
|
||||||
List<XmppRosterItem> items;
|
List<XmppRosterItem> items;
|
||||||
String? ver;
|
String? ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RosterPushResult {
|
||||||
|
RosterPushResult(this.item, this.ver);
|
||||||
|
final XmppRosterItem item;
|
||||||
|
final String? ver;
|
||||||
|
}
|
||||||
|
|
||||||
/// A Stub feature negotiator for finding out whether roster versioning is supported.
|
/// A Stub feature negotiator for finding out whether roster versioning is supported.
|
||||||
class RosterFeatureNegotiator extends XmppFeatureNegotiatorBase {
|
class RosterFeatureNegotiator extends XmppFeatureNegotiatorBase {
|
||||||
RosterFeatureNegotiator() : _supported = false, super(11, false, rosterVersioningXmlns, rosterNegotiator);
|
RosterFeatureNegotiator() : _supported = false, super(11, false, rosterVersioningXmlns, rosterNegotiator);
|
||||||
@ -110,14 +115,14 @@ class RosterManager extends XmppManagerBase {
|
|||||||
|
|
||||||
unawaited(
|
unawaited(
|
||||||
_stateManager.handleRosterPush(
|
_stateManager.handleRosterPush(
|
||||||
RosterPushEvent(
|
RosterPushResult(
|
||||||
item: XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: item.attributes['jid']! as String,
|
jid: item.attributes['jid']! as String,
|
||||||
subscription: item.attributes['subscription']! as String,
|
subscription: item.attributes['subscription']! as String,
|
||||||
ask: item.attributes['ask'] as String?,
|
ask: item.attributes['ask'] as String?,
|
||||||
name: item.attributes['name'] as String?,
|
name: item.attributes['name'] as String?,
|
||||||
),
|
),
|
||||||
ver: query.attributes['ver'] as String?,
|
query.attributes['ver'] as String?,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -150,8 +155,8 @@ class RosterManager extends XmppManagerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final result = RosterRequestResult(
|
final result = RosterRequestResult(
|
||||||
items: items,
|
items,
|
||||||
ver: rosterVersion,
|
rosterVersion,
|
||||||
);
|
);
|
||||||
|
|
||||||
unawaited(
|
unawaited(
|
||||||
|
@ -126,7 +126,7 @@ abstract class BaseRosterStateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles a roster push from the RosterManager.
|
/// Handles a roster push from the RosterManager.
|
||||||
Future<void> handleRosterPush(RosterPushEvent event) async {
|
Future<void> handleRosterPush(RosterPushResult event) async {
|
||||||
await _lock.synchronized(() async {
|
await _lock.synchronized(() async {
|
||||||
await _loadRosterCache();
|
await _loadRosterCache();
|
||||||
|
|
||||||
|
@ -4,13 +4,15 @@ import 'package:test/test.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
test('Test receiving a roster push', () async {
|
test('Test receiving a roster push', () async {
|
||||||
final rs = TestingRosterStateManager(null, []);
|
final rs = TestingRosterStateManager(null, []);
|
||||||
|
rs.register((_) {});
|
||||||
|
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushEvent(
|
RosterPushResult(
|
||||||
item: XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -23,11 +25,12 @@ void main() {
|
|||||||
|
|
||||||
// Receive another roster push
|
// Receive another roster push
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushEvent(
|
RosterPushResult(
|
||||||
item: XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'to',
|
subscription: 'to',
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -40,11 +43,12 @@ void main() {
|
|||||||
|
|
||||||
// Remove one of the items
|
// Remove one of the items
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushEvent(
|
RosterPushResult(
|
||||||
item: XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'remove',
|
subscription: 'remove',
|
||||||
),
|
),
|
||||||
|
null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -62,11 +66,12 @@ void main() {
|
|||||||
|
|
||||||
test('Test a roster fetch', () async {
|
test('Test a roster fetch', () async {
|
||||||
final rs = TestingRosterStateManager(null, []);
|
final rs = TestingRosterStateManager(null, []);
|
||||||
|
rs.register((_) {});
|
||||||
|
|
||||||
// Fetch the roster
|
// Fetch the roster
|
||||||
await rs.handleRosterFetch(
|
await rs.handleRosterFetch(
|
||||||
RosterRequestResult(
|
RosterRequestResult(
|
||||||
items: [
|
[
|
||||||
XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
@ -80,7 +85,7 @@ void main() {
|
|||||||
subscription: 'from',
|
subscription: 'from',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ver: 'aaaaaaaa',
|
'aaaaaaaa',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user