[Room] Add a onUpdate callback
This commit is contained in:
parent
902df33d50
commit
e6a859d83c
|
@ -34,6 +34,8 @@ import './User.dart';
|
||||||
import 'Connection.dart';
|
import 'Connection.dart';
|
||||||
import 'Timeline.dart';
|
import 'Timeline.dart';
|
||||||
|
|
||||||
|
typedef onRoomUpdate = void Function();
|
||||||
|
|
||||||
/// Represents a Matrix room.
|
/// Represents a Matrix room.
|
||||||
class Room {
|
class Room {
|
||||||
/// The full qualified Matrix ID for the room in the format '!localid:server.abc'.
|
/// The full qualified Matrix ID for the room in the format '!localid:server.abc'.
|
||||||
|
@ -64,6 +66,9 @@ class Room {
|
||||||
/// ID of the fully read marker event.
|
/// ID of the fully read marker event.
|
||||||
String fullyRead;
|
String fullyRead;
|
||||||
|
|
||||||
|
/// If something changes, this callback will be triggered.
|
||||||
|
onRoomUpdate onUpdate;
|
||||||
|
|
||||||
/// The name of the room if set by a participant.
|
/// The name of the room if set by a participant.
|
||||||
String get name {
|
String get name {
|
||||||
if (states["m.room.name"] != null &&
|
if (states["m.room.name"] != null &&
|
||||||
|
|
|
@ -140,6 +140,7 @@ class RoomList {
|
||||||
if (chatUpdate.summary.mInvitedMemberCount != null)
|
if (chatUpdate.summary.mInvitedMemberCount != null)
|
||||||
rooms[j].mInvitedMemberCount = chatUpdate.summary.mInvitedMemberCount;
|
rooms[j].mInvitedMemberCount = chatUpdate.summary.mInvitedMemberCount;
|
||||||
}
|
}
|
||||||
|
if (rooms[j].onUpdate != null) rooms[j].onUpdate();
|
||||||
}
|
}
|
||||||
sortAndUpdate();
|
sortAndUpdate();
|
||||||
}
|
}
|
||||||
|
@ -158,6 +159,7 @@ class RoomList {
|
||||||
if (rooms[j].states[stateEvent.key] != null &&
|
if (rooms[j].states[stateEvent.key] != null &&
|
||||||
rooms[j].states[stateEvent.key].time > stateEvent.time) return;
|
rooms[j].states[stateEvent.key].time > stateEvent.time) return;
|
||||||
rooms[j].states[stateEvent.key] = stateEvent;
|
rooms[j].states[stateEvent.key] = stateEvent;
|
||||||
|
if (rooms[j].onUpdate != null) rooms[j].onUpdate();
|
||||||
sortAndUpdate();
|
sortAndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,15 @@ void main() {
|
||||||
|
|
||||||
ChatTime now = ChatTime.now();
|
ChatTime now = ChatTime.now();
|
||||||
|
|
||||||
|
int roomUpdates = 0;
|
||||||
|
|
||||||
|
roomList.rooms[0].onUpdate = () {
|
||||||
|
roomUpdates++;
|
||||||
|
};
|
||||||
|
roomList.rooms[1].onUpdate = () {
|
||||||
|
roomUpdates++;
|
||||||
|
};
|
||||||
|
|
||||||
client.connection.onEvent.add(EventUpdate(
|
client.connection.onEvent.add(EventUpdate(
|
||||||
type: "timeline",
|
type: "timeline",
|
||||||
roomID: "1",
|
roomID: "1",
|
||||||
|
@ -158,6 +167,7 @@ void main() {
|
||||||
await new Future.delayed(new Duration(milliseconds: 50));
|
await new Future.delayed(new Duration(milliseconds: 50));
|
||||||
|
|
||||||
expect(updateCount, 4);
|
expect(updateCount, 4);
|
||||||
|
expect(roomUpdates, 2);
|
||||||
expect(insertList, [0, 1]);
|
expect(insertList, [0, 1]);
|
||||||
expect(removeList, []);
|
expect(removeList, []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue