Merge branch 'soru/equal-operator-on-receipt' into 'main'
feat: Add == operator to the Receipt, User and Room objects See merge request famedly/famedlysdk!571
This commit is contained in:
commit
155b47428a
|
|
@ -1730,4 +1730,7 @@ class Room {
|
||||||
TombstoneContent get extinctInformations => isExtinct
|
TombstoneContent get extinctInformations => isExtinct
|
||||||
? getState(EventTypes.RoomTombstone).parsedTombstoneContent
|
? getState(EventTypes.RoomTombstone).parsedTombstoneContent
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) => (other is Room && other.id == id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,4 +175,10 @@ class User extends Event {
|
||||||
/// Please be aware that you can only set the power level to at least your own!
|
/// Please be aware that you can only set the power level to at least your own!
|
||||||
bool get canChangePowerLevel =>
|
bool get canChangePowerLevel =>
|
||||||
room.canChangePowerLevel && powerLevel < room.ownPowerLevel;
|
room.canChangePowerLevel && powerLevel < room.ownPowerLevel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) => (other is User &&
|
||||||
|
other.id == id &&
|
||||||
|
other.room == room &&
|
||||||
|
other.membership == membership);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,9 @@ class Receipt {
|
||||||
final DateTime time;
|
final DateTime time;
|
||||||
|
|
||||||
const Receipt(this.user, this.time);
|
const Receipt(this.user, this.time);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(dynamic other) => (other is Receipt &&
|
||||||
|
other.user == user &&
|
||||||
|
other.time.microsecondsSinceEpoch == time.microsecondsSinceEpoch);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -453,6 +453,36 @@ void main() {
|
||||||
await client.dispose(closeDatabase: true);
|
await client.dispose(closeDatabase: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('object equality', () async {
|
||||||
|
final time1 = DateTime.fromMillisecondsSinceEpoch(1);
|
||||||
|
final time2 = DateTime.fromMillisecondsSinceEpoch(0);
|
||||||
|
final user1 = User('@user1:example.org', room: Room(id: '!room1'));
|
||||||
|
final user2 = User('@user2:example.org', room: Room(id: '!room1'));
|
||||||
|
// receipts
|
||||||
|
expect(Receipt(user1, time1) == Receipt(user1, time1), true);
|
||||||
|
expect(Receipt(user1, time1) == Receipt(user1, time2), false);
|
||||||
|
expect(Receipt(user1, time1) == Receipt(user2, time1), false);
|
||||||
|
// ignore: unrelated_type_equality_checks
|
||||||
|
expect(Receipt(user1, time1) == 'beep', false);
|
||||||
|
// users
|
||||||
|
expect(user1 == user1, true);
|
||||||
|
expect(user1 == user2, false);
|
||||||
|
expect(
|
||||||
|
user1 == User('@user1:example.org', room: Room(id: '!room2')), false);
|
||||||
|
expect(
|
||||||
|
user1 ==
|
||||||
|
User('@user1:example.org',
|
||||||
|
room: Room(id: '!room1'), membership: 'leave'),
|
||||||
|
false);
|
||||||
|
// ignore: unrelated_type_equality_checks
|
||||||
|
expect(user1 == 'beep', false);
|
||||||
|
// rooms
|
||||||
|
expect(Room(id: '!room1') == Room(id: '!room1'), true);
|
||||||
|
expect(Room(id: '!room1') == Room(id: '!room2'), false);
|
||||||
|
// ignore: unrelated_type_equality_checks
|
||||||
|
expect(Room(id: '!room1') == 'beep', false);
|
||||||
|
});
|
||||||
|
|
||||||
test('dispose', () async {
|
test('dispose', () async {
|
||||||
await matrix.dispose(closeDatabase: true);
|
await matrix.dispose(closeDatabase: true);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue