From 6cebee9eb7a860acf385bda255d4a7945bbdf655 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 7 Aug 2019 09:50:40 +0200 Subject: [PATCH] [Room] Also query states for rooms --- lib/src/Room.dart | 6 ++++-- lib/src/Store.dart | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 0f265c5..46bdeef 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -395,9 +395,11 @@ class Room { return resp; } - /// Returns a Room from a json String which comes normally from the store. + /// Returns a Room from a json String which comes normally from the store. If the + /// state are also given, the method will await them. static Future getRoomFromTableRow( - Map row, Client matrix) async { + Map row, Client matrix, + {Future>> states}) async { String avatarUrl = row["avatar_url"]; if (avatarUrl == "") avatarUrl = await matrix.store?.getAvatarFromSingleChat(row["id"]) ?? ""; diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 116a3f2..cb50bd8 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -363,8 +363,8 @@ class Store { " ORDER BY origin_server_ts DESC "); List roomList = []; for (num i = 0; i < res.length; i++) { - Room room = await Room.getRoomFromTableRow( - res[i], client); // TODO: Also query the states for a room + Room room = await Room.getRoomFromTableRow(res[i], client, + states: getStatesFromRoomId(res[i]["id"])); roomList.add(room); } return roomList; @@ -375,7 +375,12 @@ class Store { List> res = await db.rawQuery("SELECT * FROM Rooms WHERE id=?", [id]); if (res.length != 1) return null; - return Room.getRoomFromTableRow(res[0], client); + return Room.getRoomFromTableRow(res[0], client, + states: getStatesFromRoomId(id)); + } + + Future>> getStatesFromRoomId(String id) async { + return db.rawQuery("SELECT * FROM States WHERE room_id=?", [id]); } Future forgetRoom(String roomID) async {