Get Sender from Store
This commit is contained in:
parent
3d59aae034
commit
a70b82e88d
|
@ -127,7 +127,8 @@ class Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a new Event object from a json string, mostly a table row.
|
/// Generate a new Event object from a json string, mostly a table row.
|
||||||
static Event fromJson(Map<String, dynamic> jsonObj, Room room) {
|
static Event fromJson(Map<String, dynamic> jsonObj, Room room,
|
||||||
|
{User senderUser, User stateKeyUser}) {
|
||||||
Map<String, dynamic> content = jsonObj["content"];
|
Map<String, dynamic> content = jsonObj["content"];
|
||||||
|
|
||||||
if (content == null && jsonObj["content_json"] != null)
|
if (content == null && jsonObj["content_json"] != null)
|
||||||
|
@ -137,14 +138,16 @@ class Event {
|
||||||
print("jsonObj decode of event content failed: ${e.toString()}");
|
print("jsonObj decode of event content failed: ${e.toString()}");
|
||||||
content = {};
|
content = {};
|
||||||
}
|
}
|
||||||
else
|
else if (content == null) content = {};
|
||||||
content = {};
|
|
||||||
|
if (senderUser == null) senderUser = User(jsonObj["sender"]);
|
||||||
|
if (stateKeyUser == null) stateKeyUser = User(jsonObj["state_key"]);
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
jsonObj["event_id"] ?? jsonObj["id"],
|
jsonObj["event_id"] ?? jsonObj["id"],
|
||||||
User.fromJson(jsonObj, room),
|
senderUser,
|
||||||
ChatTime(jsonObj["origin_server_ts"]),
|
ChatTime(jsonObj["origin_server_ts"]),
|
||||||
stateKey: User(jsonObj["state_key"]),
|
stateKey: stateKeyUser,
|
||||||
environment: jsonObj["type"],
|
environment: jsonObj["type"],
|
||||||
status: jsonObj["status"] ?? 2,
|
status: jsonObj["status"] ?? 2,
|
||||||
content: content,
|
content: content,
|
||||||
|
|
|
@ -463,11 +463,16 @@ class Store {
|
||||||
|
|
||||||
/// Returns a list of events for the given room and sets all participants.
|
/// Returns a list of events for the given room and sets all participants.
|
||||||
Future<List<Event>> getEventList(Room room) async {
|
Future<List<Event>> getEventList(Room room) async {
|
||||||
|
List<Map<String, dynamic>> memberRes = await db.rawQuery(
|
||||||
|
"SELECT * " + " FROM Users " + " WHERE users.chat_id=?", [room.id]);
|
||||||
|
Map<String, User> userMap = {};
|
||||||
|
for (num i = 0; i < memberRes.length; i++)
|
||||||
|
userMap[memberRes[i]["matrix_id"]] = User.fromJson(memberRes[i], room);
|
||||||
|
|
||||||
List<Map<String, dynamic>> eventRes = await db.rawQuery(
|
List<Map<String, dynamic>> eventRes = await db.rawQuery(
|
||||||
"SELECT * " +
|
"SELECT * " +
|
||||||
" FROM Events events, User user " +
|
" FROM Events events " +
|
||||||
" WHERE events.chat_id=?" +
|
" WHERE events.chat_id=?" +
|
||||||
" AND events.sender=user.matrix_id " +
|
|
||||||
" GROUP BY events.id " +
|
" GROUP BY events.id " +
|
||||||
" ORDER BY origin_server_ts DESC",
|
" ORDER BY origin_server_ts DESC",
|
||||||
[room.id]);
|
[room.id]);
|
||||||
|
@ -475,7 +480,9 @@ class Store {
|
||||||
List<Event> eventList = [];
|
List<Event> eventList = [];
|
||||||
|
|
||||||
for (num i = 0; i < eventRes.length; i++)
|
for (num i = 0; i < eventRes.length; i++)
|
||||||
eventList.add(Event.fromJson(eventRes[i], room));
|
eventList.add(Event.fromJson(eventRes[i], room,
|
||||||
|
senderUser: userMap[eventRes[i]["sender"]],
|
||||||
|
stateKeyUser: userMap[eventRes[i]["state_key"]]));
|
||||||
|
|
||||||
return eventList;
|
return eventList;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue