From 90a5f32e202917f2f32116512b8b951468eed9fd Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 28 Jul 2019 20:19:58 +0200 Subject: [PATCH 1/2] [Room]/[Store] Load sender user when loading event by id Took 5 minutes --- lib/src/Room.dart | 4 +++- lib/src/Store.dart | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 9971108..06c46b9 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -503,6 +503,8 @@ class Room { final dynamic resp = await client.connection.jsonRequest( type: HTTPType.GET, action: "/client/r0/rooms/$id/event/$eventID"); if (resp is ErrorResponse) return null; - return Event.fromJson(resp, this); + return Event.fromJson(resp, this, + senderUser: + (await client.store.getUser(matrixID: resp["sender"], room: this))); } } diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 6bc7c81..adbcc3e 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -650,7 +650,9 @@ class Store { List> res = await db.rawQuery( "SELECT * FROM Events WHERE id=? AND chat_id=?", [eventID, room.id]); if (res.length == 0) return null; - return Event.fromJson(res[0], room); + return Event.fromJson(res[0], room, + senderUser: + (await this.getUser(matrixID: res[0]["sender"], room: room))); } Future forgetNotification(String roomID) async { From e42b4daa84b30848a66c7f2bb1e756f69c17e3c9 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 29 Jul 2019 16:16:20 +0200 Subject: [PATCH 2/2] [Room]/[Store] Load sender user from server when store is not available Took 19 minutes --- lib/src/Room.dart | 16 ++++++++++++++-- lib/src/Store.dart | 3 +-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 06c46b9..45edd10 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -493,6 +493,19 @@ class Room { return participants; } + Future getUserByMXID(String mxID) async { + if (client.store != null) { + final User storeEvent = + await client.store.getUser(matrixID: mxID, room: this); + if (storeEvent != null) return storeEvent; + } + final dynamic resp = await client.connection.jsonRequest( + type: HTTPType.GET, + action: "/client/r0/rooms/$id/state/m.room.member/$mxID"); + if (resp is ErrorResponse) return null; + return User.fromJson(resp, this); + } + /// Searches for the event in the store. If it isn't found, try to request it /// from the server. Returns null if not found. Future getEventById(String eventID) async { @@ -504,7 +517,6 @@ class Room { type: HTTPType.GET, action: "/client/r0/rooms/$id/event/$eventID"); if (resp is ErrorResponse) return null; return Event.fromJson(resp, this, - senderUser: - (await client.store.getUser(matrixID: resp["sender"], room: this))); + senderUser: (await getUserByMXID(resp["sender"]))); } } diff --git a/lib/src/Store.dart b/lib/src/Store.dart index adbcc3e..a52f03f 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -651,8 +651,7 @@ class Store { "SELECT * FROM Events WHERE id=? AND chat_id=?", [eventID, room.id]); if (res.length == 0) return null; return Event.fromJson(res[0], room, - senderUser: - (await this.getUser(matrixID: res[0]["sender"], room: room))); + senderUser: (await room.getUserByMXID(res[0]["sender"]))); } Future forgetNotification(String roomID) async {