[RoomList] Fix update on room summary
This commit is contained in:
parent
71f0acd498
commit
3203c4366a
|
@ -97,6 +97,9 @@ class Client {
|
||||||
/// A list of all rooms the user is participating or invited.
|
/// A list of all rooms the user is participating or invited.
|
||||||
RoomList roomList;
|
RoomList roomList;
|
||||||
|
|
||||||
|
/// A list of all rooms the user is not participating anymore.
|
||||||
|
RoomList archive;
|
||||||
|
|
||||||
/// Key/Value store of account data.
|
/// Key/Value store of account data.
|
||||||
Map<String, AccountData> accountData = {};
|
Map<String, AccountData> accountData = {};
|
||||||
|
|
||||||
|
@ -251,27 +254,29 @@ class Client {
|
||||||
await connection.clear();
|
await connection.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads the Rooms from the [store] and creates a new [RoomList] object.
|
/// Creates a new [RoomList] object.
|
||||||
Future<RoomList> getRoomList(
|
RoomList getRoomList(
|
||||||
{bool onlyLeft = false,
|
{bool onlyLeft = false,
|
||||||
bool onlyDirect = false,
|
|
||||||
bool onlyGroups = false,
|
|
||||||
onRoomListUpdateCallback onUpdate,
|
onRoomListUpdateCallback onUpdate,
|
||||||
onRoomListInsertCallback onInsert,
|
onRoomListInsertCallback onInsert,
|
||||||
onRoomListRemoveCallback onRemove}) async {
|
onRoomListRemoveCallback onRemove}) {
|
||||||
List<Room> rooms = await store.getRoomList(
|
List<Room> rooms = onlyLeft ? archive.rooms : roomList.rooms;
|
||||||
onlyLeft: onlyLeft, onlyGroups: onlyGroups, onlyDirect: onlyDirect);
|
|
||||||
return RoomList(
|
return RoomList(
|
||||||
client: this,
|
client: this,
|
||||||
onlyLeft: onlyLeft,
|
onlyLeft: onlyLeft,
|
||||||
onlyDirect: onlyDirect,
|
|
||||||
onlyGroups: onlyGroups,
|
|
||||||
onUpdate: onUpdate,
|
onUpdate: onUpdate,
|
||||||
onInsert: onInsert,
|
onInsert: onInsert,
|
||||||
onRemove: onRemove,
|
onRemove: onRemove,
|
||||||
rooms: rooms);
|
rooms: rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Searches in the roomList and in the archive for a room with the given [id].
|
||||||
|
Room getRoomById(String id) {
|
||||||
|
Room room = roomList.getRoomById(id);
|
||||||
|
if (room == null) room = archive.getRoomById(id);
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
|
||||||
Future<dynamic> joinRoomById(String id) async {
|
Future<dynamic> joinRoomById(String id) async {
|
||||||
return await connection.jsonRequest(
|
return await connection.jsonRequest(
|
||||||
type: HTTPType.POST, action: "/client/r0/join/$id");
|
type: HTTPType.POST, action: "/client/r0/join/$id");
|
||||||
|
|
|
@ -152,10 +152,11 @@ class Connection {
|
||||||
client.prevBatch = newPrevBatch;
|
client.prevBatch = newPrevBatch;
|
||||||
|
|
||||||
List<Room> rooms = [];
|
List<Room> rooms = [];
|
||||||
|
List<Room> archivedRooms = [];
|
||||||
if (client.store != null) {
|
if (client.store != null) {
|
||||||
client.store.storeClient();
|
client.store.storeClient();
|
||||||
rooms = await client.store
|
rooms = await client.store.getRoomList(onlyLeft: false);
|
||||||
.getRoomList(onlyLeft: false, onlyGroups: false, onlyDirect: false);
|
archivedRooms = await client.store.getRoomList(onlyLeft: true);
|
||||||
client.accountData = await client.store.getAccountData();
|
client.accountData = await client.store.getAccountData();
|
||||||
client.presences = await client.store.getPresences();
|
client.presences = await client.store.getPresences();
|
||||||
}
|
}
|
||||||
|
@ -163,13 +164,19 @@ class Connection {
|
||||||
client.roomList = RoomList(
|
client.roomList = RoomList(
|
||||||
client: client,
|
client: client,
|
||||||
onlyLeft: false,
|
onlyLeft: false,
|
||||||
onlyDirect: false,
|
|
||||||
onlyGroups: false,
|
|
||||||
onUpdate: null,
|
onUpdate: null,
|
||||||
onInsert: null,
|
onInsert: null,
|
||||||
onRemove: null,
|
onRemove: null,
|
||||||
rooms: rooms);
|
rooms: rooms);
|
||||||
|
|
||||||
|
client.archive = RoomList(
|
||||||
|
client: client,
|
||||||
|
onlyLeft: true,
|
||||||
|
onUpdate: null,
|
||||||
|
onInsert: null,
|
||||||
|
onRemove: null,
|
||||||
|
rooms: archivedRooms);
|
||||||
|
|
||||||
_userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate);
|
_userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate);
|
||||||
|
|
||||||
onLoginStateChanged.add(LoginState.logged);
|
onLoginStateChanged.add(LoginState.logged);
|
||||||
|
|
|
@ -45,8 +45,6 @@ class RoomList {
|
||||||
List<Room> rooms = [];
|
List<Room> rooms = [];
|
||||||
|
|
||||||
final bool onlyLeft;
|
final bool onlyLeft;
|
||||||
final bool onlyDirect;
|
|
||||||
final bool onlyGroups;
|
|
||||||
|
|
||||||
/// Will be called, when the room list has changed. Can be used e.g. to update
|
/// Will be called, when the room list has changed. Can be used e.g. to update
|
||||||
/// the state of a StatefulWidget.
|
/// the state of a StatefulWidget.
|
||||||
|
@ -67,9 +65,7 @@ class RoomList {
|
||||||
this.onUpdate,
|
this.onUpdate,
|
||||||
this.onInsert,
|
this.onInsert,
|
||||||
this.onRemove,
|
this.onRemove,
|
||||||
this.onlyLeft = false,
|
this.onlyLeft = false}) {
|
||||||
this.onlyDirect = false,
|
|
||||||
this.onlyGroups = false}) {
|
|
||||||
eventSub ??= client.connection.onEvent.stream.listen(_handleEventUpdate);
|
eventSub ??= client.connection.onEvent.stream.listen(_handleEventUpdate);
|
||||||
roomSub ??= client.connection.onRoomUpdate.stream.listen(_handleRoomUpdate);
|
roomSub ??= client.connection.onRoomUpdate.stream.listen(_handleRoomUpdate);
|
||||||
sort();
|
sort();
|
||||||
|
@ -125,13 +121,16 @@ class RoomList {
|
||||||
rooms.removeAt(j);
|
rooms.removeAt(j);
|
||||||
if (onRemove != null) onRemove(j);
|
if (onRemove != null) onRemove(j);
|
||||||
}
|
}
|
||||||
// Update notification and highlight count
|
// Update notification, highlight count and/or additional informations
|
||||||
else if (found &&
|
else if (found &&
|
||||||
chatUpdate.membership != Membership.leave &&
|
chatUpdate.membership != Membership.leave &&
|
||||||
(rooms[j].notificationCount != chatUpdate.notification_count ||
|
(rooms[j].notificationCount != chatUpdate.notification_count ||
|
||||||
rooms[j].highlightCount != chatUpdate.highlight_count)) {
|
rooms[j].highlightCount != chatUpdate.highlight_count ||
|
||||||
|
chatUpdate.summary != null)) {
|
||||||
rooms[j].notificationCount = chatUpdate.notification_count;
|
rooms[j].notificationCount = chatUpdate.notification_count;
|
||||||
rooms[j].highlightCount = chatUpdate.highlight_count;
|
rooms[j].highlightCount = chatUpdate.highlight_count;
|
||||||
|
if (chatUpdate.prev_batch != null)
|
||||||
|
rooms[j].prev_batch = chatUpdate.prev_batch;
|
||||||
if (chatUpdate.summary != null) {
|
if (chatUpdate.summary != null) {
|
||||||
if (chatUpdate.summary.mHeroes != null)
|
if (chatUpdate.summary.mHeroes != null)
|
||||||
rooms[j].mHeroes = chatUpdate.summary.mHeroes;
|
rooms[j].mHeroes = chatUpdate.summary.mHeroes;
|
||||||
|
|
|
@ -357,11 +357,7 @@ class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all rooms, the client is participating. Excludes left rooms.
|
/// Returns all rooms, the client is participating. Excludes left rooms.
|
||||||
Future<List<Room>> getRoomList(
|
Future<List<Room>> getRoomList({bool onlyLeft = false}) async {
|
||||||
{bool onlyLeft = false,
|
|
||||||
bool onlyDirect = false,
|
|
||||||
bool onlyGroups = false}) async {
|
|
||||||
if (onlyDirect && onlyGroups) return [];
|
|
||||||
List<Map<String, dynamic>> res = await db.rawQuery("SELECT * " +
|
List<Map<String, dynamic>> res = await db.rawQuery("SELECT * " +
|
||||||
" FROM Rooms" +
|
" FROM Rooms" +
|
||||||
" WHERE membership" +
|
" WHERE membership" +
|
||||||
|
@ -399,7 +395,8 @@ class Store {
|
||||||
/// Searches for the event in the store.
|
/// Searches for the event in the store.
|
||||||
Future<Event> getEventById(String eventID, Room room) async {
|
Future<Event> getEventById(String eventID, Room room) async {
|
||||||
List<Map<String, dynamic>> res = await db.rawQuery(
|
List<Map<String, dynamic>> res = await db.rawQuery(
|
||||||
"SELECT * FROM Events WHERE event_id=? AND room_id=?", [eventID, room.id]);
|
"SELECT * FROM Events WHERE event_id=? AND room_id=?",
|
||||||
|
[eventID, room.id]);
|
||||||
if (res.length == 0) return null;
|
if (res.length == 0) return null;
|
||||||
return Event.fromJson(res[0], room);
|
return Event.fromJson(res[0], room);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,17 @@ void main() {
|
||||||
limitedTimeline: false,
|
limitedTimeline: false,
|
||||||
prev_batch: "1234",
|
prev_batch: "1234",
|
||||||
));
|
));
|
||||||
|
client.connection.onRoomUpdate.add(RoomUpdate(
|
||||||
|
id: "1",
|
||||||
|
membership: Membership.join,
|
||||||
|
notification_count: 2,
|
||||||
|
highlight_count: 1,
|
||||||
|
limitedTimeline: false,
|
||||||
|
prev_batch: "12345",
|
||||||
|
summary: RoomSummary(
|
||||||
|
mHeroes: ["@alice:example.com"],
|
||||||
|
mJoinedMemberCount: 1,
|
||||||
|
mInvitedMemberCount: 1)));
|
||||||
|
|
||||||
await new Future.delayed(new Duration(milliseconds: 50));
|
await new Future.delayed(new Duration(milliseconds: 50));
|
||||||
|
|
||||||
|
@ -126,6 +137,10 @@ void main() {
|
||||||
expect(roomList.roomSub != null, true);
|
expect(roomList.roomSub != null, true);
|
||||||
expect(roomList.rooms[0].id, "1");
|
expect(roomList.rooms[0].id, "1");
|
||||||
expect(roomList.rooms[1].id, "2");
|
expect(roomList.rooms[1].id, "2");
|
||||||
|
expect(roomList.rooms[0].prev_batch, "12345");
|
||||||
|
expect(roomList.rooms[0].displayname, "alice");
|
||||||
|
expect(roomList.rooms[0].mJoinedMemberCount, 1);
|
||||||
|
expect(roomList.rooms[0].mInvitedMemberCount, 1);
|
||||||
|
|
||||||
ChatTime now = ChatTime.now();
|
ChatTime now = ChatTime.now();
|
||||||
|
|
||||||
|
@ -166,7 +181,7 @@ void main() {
|
||||||
|
|
||||||
await new Future.delayed(new Duration(milliseconds: 50));
|
await new Future.delayed(new Duration(milliseconds: 50));
|
||||||
|
|
||||||
expect(updateCount, 4);
|
expect(updateCount, 5);
|
||||||
expect(roomUpdates, 2);
|
expect(roomUpdates, 2);
|
||||||
expect(insertList, [0, 1]);
|
expect(insertList, [0, 1]);
|
||||||
expect(removeList, []);
|
expect(removeList, []);
|
||||||
|
|
Loading…
Reference in a new issue