diff --git a/lib/src/Event.dart b/lib/src/Event.dart index fd4f8ae..c17da83 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -50,6 +50,8 @@ class Event { /// The type of this event. Mostly this is 'timeline'. final String environment; + Event replyEvent; + /// The status of this event. /// -1=ERROR /// 0=SENDING @@ -69,6 +71,7 @@ class Event { this.status = 2, this.environment, this.content, + this.replyEvent, }); /// Returns the body of this event if it has a body. diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index dc519b0..21661d9 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -80,14 +80,41 @@ class Timeline { events[i] = Event.fromJson(eventUpdate.content, room); } } else { - User user = await room.client.store + Event newEvent; + User senderUser = await room.client.store ?.getUser(matrixID: eventUpdate.content["sender"], room: room); - if (user != null) { - eventUpdate.content["displayname"] = user.displayName; - eventUpdate.content["avatar_url"] = user.avatarUrl.mxc; + if (senderUser != null) { + eventUpdate.content["displayname"] = senderUser.displayName; + eventUpdate.content["avatar_url"] = senderUser.avatarUrl.mxc; } - Event newEvent = Event.fromJson(eventUpdate.content, room); + User stateKeyUser; + if (eventUpdate.content.containsKey("state_key")) { + stateKeyUser = await room.client.store?.getUser( + matrixID: eventUpdate.content["state_key"], room: room); + } + + if (senderUser != null && stateKeyUser != null) { + newEvent = Event.fromJson(eventUpdate.content, room, + senderUser: senderUser, stateKeyUser: stateKeyUser); + } else if (senderUser != null) { + newEvent = Event.fromJson(eventUpdate.content, room, + senderUser: senderUser); + } else if (stateKeyUser != null) { + newEvent = Event.fromJson(eventUpdate.content, room, + stateKeyUser: stateKeyUser); + } else { + newEvent = Event.fromJson(eventUpdate.content, room); + } + + // TODO update to type check when https://gitlab.com/famedly/famedlysdk/merge_requests/28/ is merged + if (newEvent.content.containsKey("m.relates_to")) { + Map relates_to = newEvent.content["m.relates_to"]; + if (relates_to.containsKey("m.in_reply_to")) { + newEvent.replyEvent = await room.getEventById(newEvent + .content["m.relates_to"]["m.in_reply_to"]["event_id"]); + } + } events.insert(0, newEvent); if (onInsert != null) onInsert(0); diff --git a/pubspec.lock b/pubspec.lock index ad155ed..ef602eb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: analyzer: dependency: transitive @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" boolean_selector: dependency: transitive description: @@ -297,7 +297,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.7.0" pool: dependency: transitive description: @@ -325,7 +325,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" shelf: dependency: transitive description: @@ -414,7 +414,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.4" + version: "0.2.5" timing: dependency: transitive description: