fix: Handle roster items staying the same
This commit is contained in:
parent
473f8e4bb6
commit
41560682a1
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
import 'package:moxxmpp/src/jid.dart';
|
import 'package:moxxmpp/src/jid.dart';
|
||||||
import 'package:moxxmpp/src/managers/attributes.dart';
|
import 'package:moxxmpp/src/managers/attributes.dart';
|
||||||
import 'package:moxxmpp/src/managers/base.dart';
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
@ -14,13 +15,38 @@ 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';
|
import 'package:moxxmpp/src/types/result.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
class XmppRosterItem {
|
class XmppRosterItem {
|
||||||
XmppRosterItem({ required this.jid, required this.subscription, this.ask, this.name, this.groups = const [] });
|
const XmppRosterItem({ required this.jid, required this.subscription, this.ask, this.name, this.groups = const [] });
|
||||||
final String jid;
|
final String jid;
|
||||||
final String? name;
|
final String? name;
|
||||||
final String subscription;
|
final String subscription;
|
||||||
final String? ask;
|
final String? ask;
|
||||||
final List<String> groups;
|
final List<String> groups;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator==(Object other) {
|
||||||
|
// TODO(PapaTutuWawa): Implement the groups
|
||||||
|
return other is XmppRosterItem &&
|
||||||
|
other.jid == jid &&
|
||||||
|
other.name == name &&
|
||||||
|
other.subscription == subscription &&
|
||||||
|
other.ask == ask; /*&&
|
||||||
|
other.groups == groups;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => jid.hashCode ^ name.hashCode ^ subscription.hashCode ^ ask.hashCode ^ groups.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'XmppRosterItem('
|
||||||
|
'jid: $jid, '
|
||||||
|
'name: $name, '
|
||||||
|
'subscription: $subscription, '
|
||||||
|
'ask: $ask, '
|
||||||
|
'groups: $groups)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RosterRemovalResult {
|
enum RosterRemovalResult {
|
||||||
|
@ -114,7 +114,7 @@ abstract class BaseRosterStateManager {
|
|||||||
null,
|
null,
|
||||||
item,
|
item,
|
||||||
);
|
);
|
||||||
} else {
|
} else if (_currentRoster![index] != item) {
|
||||||
// The item is updated
|
// The item is updated
|
||||||
_currentRoster![index] = item;
|
_currentRoster![index] = item;
|
||||||
return _RosterProcessTriple(
|
return _RosterProcessTriple(
|
||||||
@ -123,6 +123,13 @@ abstract class BaseRosterStateManager {
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Item has not been modified or added
|
||||||
|
return const _RosterProcessTriple(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles a roster push from the RosterManager.
|
/// Handles a roster push from the RosterManager.
|
||||||
|
@ -95,4 +95,59 @@ void main() {
|
|||||||
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser2@server2.example') != -1, true);
|
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser2@server2.example') != -1, true);
|
||||||
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser3@server3.example') != -1, true);
|
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser3@server3.example') != -1, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test a roster fetch if we already have a roster', () async {
|
||||||
|
XmppEvent? event;
|
||||||
|
final rs = TestingRosterStateManager('aaaaa', [
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser@server.example',
|
||||||
|
subscription: 'both',
|
||||||
|
),
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser2@server2.example',
|
||||||
|
subscription: 'to',
|
||||||
|
),
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser3@server3.example',
|
||||||
|
subscription: 'from',
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
rs.register((_event) {
|
||||||
|
event = _event;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch the roster
|
||||||
|
await rs.handleRosterFetch(
|
||||||
|
RosterRequestResult(
|
||||||
|
[
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser@server.example',
|
||||||
|
subscription: 'both',
|
||||||
|
),
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser2@server2.example',
|
||||||
|
subscription: 'to',
|
||||||
|
),
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser3@server3.example',
|
||||||
|
subscription: 'both',
|
||||||
|
),
|
||||||
|
XmppRosterItem(
|
||||||
|
jid: 'testuser4@server4.example',
|
||||||
|
subscription: 'both',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
'bbbbb',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(event is RosterUpdatedEvent, true);
|
||||||
|
final updateEvent = event as RosterUpdatedEvent;
|
||||||
|
|
||||||
|
expect(updateEvent.added.length, 1);
|
||||||
|
expect(updateEvent.added.first.jid, 'testuser4@server4.example');
|
||||||
|
expect(updateEvent.modified.length, 1);
|
||||||
|
expect(updateEvent.modified.first.jid, 'testuser3@server3.example');
|
||||||
|
expect(updateEvent.removed.isEmpty, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user