Merge branch 'roomlist-fix-summaryupdate' into 'master'
[RoomList] Fix update on room summary See merge request famedly/famedlysdk!82
This commit is contained in:
commit
97034743fe
|
@ -97,6 +97,9 @@ class Client {
|
|||
/// A list of all rooms the user is participating or invited.
|
||||
RoomList roomList;
|
||||
|
||||
/// A list of all rooms the user is not participating anymore.
|
||||
RoomList archive;
|
||||
|
||||
/// Key/Value store of account data.
|
||||
Map<String, AccountData> accountData = {};
|
||||
|
||||
|
@ -251,27 +254,29 @@ class Client {
|
|||
await connection.clear();
|
||||
}
|
||||
|
||||
/// Loads the Rooms from the [store] and creates a new [RoomList] object.
|
||||
Future<RoomList> getRoomList(
|
||||
/// Creates a new [RoomList] object.
|
||||
RoomList getRoomList(
|
||||
{bool onlyLeft = false,
|
||||
bool onlyDirect = false,
|
||||
bool onlyGroups = false,
|
||||
onRoomListUpdateCallback onUpdate,
|
||||
onRoomListInsertCallback onInsert,
|
||||
onRoomListRemoveCallback onRemove}) async {
|
||||
List<Room> rooms = await store.getRoomList(
|
||||
onlyLeft: onlyLeft, onlyGroups: onlyGroups, onlyDirect: onlyDirect);
|
||||
onRoomListRemoveCallback onRemove}) {
|
||||
List<Room> rooms = onlyLeft ? archive.rooms : roomList.rooms;
|
||||
return RoomList(
|
||||
client: this,
|
||||
onlyLeft: onlyLeft,
|
||||
onlyDirect: onlyDirect,
|
||||
onlyGroups: onlyGroups,
|
||||
onUpdate: onUpdate,
|
||||
onInsert: onInsert,
|
||||
onRemove: onRemove,
|
||||
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 {
|
||||
return await connection.jsonRequest(
|
||||
type: HTTPType.POST, action: "/client/r0/join/$id");
|
||||
|
|
|
@ -152,10 +152,11 @@ class Connection {
|
|||
client.prevBatch = newPrevBatch;
|
||||
|
||||
List<Room> rooms = [];
|
||||
List<Room> archivedRooms = [];
|
||||
if (client.store != null) {
|
||||
client.store.storeClient();
|
||||
rooms = await client.store
|
||||
.getRoomList(onlyLeft: false, onlyGroups: false, onlyDirect: false);
|
||||
rooms = await client.store.getRoomList(onlyLeft: false);
|
||||
archivedRooms = await client.store.getRoomList(onlyLeft: true);
|
||||
client.accountData = await client.store.getAccountData();
|
||||
client.presences = await client.store.getPresences();
|
||||
}
|
||||
|
@ -163,13 +164,19 @@ class Connection {
|
|||
client.roomList = RoomList(
|
||||
client: client,
|
||||
onlyLeft: false,
|
||||
onlyDirect: false,
|
||||
onlyGroups: false,
|
||||
onUpdate: null,
|
||||
onInsert: null,
|
||||
onRemove: null,
|
||||
rooms: rooms);
|
||||
|
||||
client.archive = RoomList(
|
||||
client: client,
|
||||
onlyLeft: true,
|
||||
onUpdate: null,
|
||||
onInsert: null,
|
||||
onRemove: null,
|
||||
rooms: archivedRooms);
|
||||
|
||||
_userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate);
|
||||
|
||||
onLoginStateChanged.add(LoginState.logged);
|
||||
|
|
|
@ -45,8 +45,6 @@ class RoomList {
|
|||
List<Room> rooms = [];
|
||||
|
||||
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
|
||||
/// the state of a StatefulWidget.
|
||||
|
@ -67,9 +65,7 @@ class RoomList {
|
|||
this.onUpdate,
|
||||
this.onInsert,
|
||||
this.onRemove,
|
||||
this.onlyLeft = false,
|
||||
this.onlyDirect = false,
|
||||
this.onlyGroups = false}) {
|
||||
this.onlyLeft = false}) {
|
||||
eventSub ??= client.connection.onEvent.stream.listen(_handleEventUpdate);
|
||||
roomSub ??= client.connection.onRoomUpdate.stream.listen(_handleRoomUpdate);
|
||||
sort();
|
||||
|
@ -125,13 +121,16 @@ class RoomList {
|
|||
rooms.removeAt(j);
|
||||
if (onRemove != null) onRemove(j);
|
||||
}
|
||||
// Update notification and highlight count
|
||||
// Update notification, highlight count and/or additional informations
|
||||
else if (found &&
|
||||
chatUpdate.membership != Membership.leave &&
|
||||
(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].highlightCount = chatUpdate.highlight_count;
|
||||
if (chatUpdate.prev_batch != null)
|
||||
rooms[j].prev_batch = chatUpdate.prev_batch;
|
||||
if (chatUpdate.summary != null) {
|
||||
if (chatUpdate.summary.mHeroes != null)
|
||||
rooms[j].mHeroes = chatUpdate.summary.mHeroes;
|
||||
|
|
|
@ -357,11 +357,7 @@ class Store {
|
|||
}
|
||||
|
||||
/// Returns all rooms, the client is participating. Excludes left rooms.
|
||||
Future<List<Room>> getRoomList(
|
||||
{bool onlyLeft = false,
|
||||
bool onlyDirect = false,
|
||||
bool onlyGroups = false}) async {
|
||||
if (onlyDirect && onlyGroups) return [];
|
||||
Future<List<Room>> getRoomList({bool onlyLeft = false}) async {
|
||||
List<Map<String, dynamic>> res = await db.rawQuery("SELECT * " +
|
||||
" FROM Rooms" +
|
||||
" WHERE membership" +
|
||||
|
@ -399,7 +395,8 @@ class Store {
|
|||
/// Searches for the event in the store.
|
||||
Future<Event> getEventById(String eventID, Room room) async {
|
||||
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;
|
||||
return Event.fromJson(res[0], room);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,17 @@ void main() {
|
|||
limitedTimeline: false,
|
||||
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));
|
||||
|
||||
|
@ -126,6 +137,10 @@ void main() {
|
|||
expect(roomList.roomSub != null, true);
|
||||
expect(roomList.rooms[0].id, "1");
|
||||
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();
|
||||
|
||||
|
@ -166,7 +181,7 @@ void main() {
|
|||
|
||||
await new Future.delayed(new Duration(milliseconds: 50));
|
||||
|
||||
expect(updateCount, 4);
|
||||
expect(updateCount, 5);
|
||||
expect(roomUpdates, 2);
|
||||
expect(insertList, [0, 1]);
|
||||
expect(removeList, []);
|
||||
|
|
Loading…
Reference in a new issue