Merge branch 'room-enhance-live-updating' into 'master'
[Room] Live updating See merge request famedly/famedlysdk!69
This commit is contained in:
commit
fa3b45d953
|
@ -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 &&
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -378,6 +378,7 @@ class Store {
|
|||
}
|
||||
|
||||
/// Returns a room without events and participants.
|
||||
@deprecated
|
||||
Future<Room> getRoomById(String id) async {
|
||||
List<Map<String, dynamic>> res =
|
||||
await db.rawQuery("SELECT * FROM Rooms WHERE room_id=?", [id]);
|
||||
|
|
|
@ -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, []);
|
||||
|
||||
|
|
Loading…
Reference in a new issue