diff --git a/lib/src/Room.dart b/lib/src/Room.dart index bb198d00..a744a8bd 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -34,6 +34,8 @@ import './User.dart'; import 'Connection.dart'; import 'Timeline.dart'; +typedef onRoomUpdate = void Function(); + /// Represents a Matrix room. class Room { /// 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. String fullyRead; + /// If something changes, this callback will be triggered. + onRoomUpdate onUpdate; + /// The name of the room if set by a participant. String get name { if (states["m.room.name"] != null && diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index a26819ba..b4c4460e 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -140,6 +140,7 @@ class RoomList { if (chatUpdate.summary.mInvitedMemberCount != null) rooms[j].mInvitedMemberCount = chatUpdate.summary.mInvitedMemberCount; } + if (rooms[j].onUpdate != null) rooms[j].onUpdate(); } sortAndUpdate(); } @@ -158,6 +159,7 @@ class RoomList { if (rooms[j].states[stateEvent.key] != null && rooms[j].states[stateEvent.key].time > stateEvent.time) return; rooms[j].states[stateEvent.key] = stateEvent; + if (rooms[j].onUpdate != null) rooms[j].onUpdate(); sortAndUpdate(); } diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 3eb39593..c7644721 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -378,6 +378,7 @@ class Store { } /// Returns a room without events and participants. + @deprecated Future getRoomById(String id) async { List> res = await db.rawQuery("SELECT * FROM Rooms WHERE room_id=?", [id]); diff --git a/test/RoomList_test.dart b/test/RoomList_test.dart index 52f4f281..29ade6e5 100644 --- a/test/RoomList_test.dart +++ b/test/RoomList_test.dart @@ -129,6 +129,15 @@ void main() { ChatTime now = ChatTime.now(); + int roomUpdates = 0; + + roomList.rooms[0].onUpdate = () { + roomUpdates++; + }; + roomList.rooms[1].onUpdate = () { + roomUpdates++; + }; + client.connection.onEvent.add(EventUpdate( type: "timeline", roomID: "1", @@ -158,6 +167,7 @@ void main() { await new Future.delayed(new Duration(milliseconds: 50)); expect(updateCount, 4); + expect(roomUpdates, 2); expect(insertList, [0, 1]); expect(removeList, []);