From 864151ec838690452a38879019ca2170c64b24cc Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 17 Jul 2020 12:02:43 +0200 Subject: [PATCH] use prev_content to calculate displayname and avatar_url, if content unavailable --- lib/src/event.dart | 8 +++++++- lib/src/user.dart | 15 +++++++++++---- pubspec.lock | 37 +++++++++++++++---------------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index d80b56c..50c3563 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -89,7 +89,13 @@ class Event extends MatrixEvent { this.roomId = roomId ?? room?.id; this.senderId = senderId; this.unsigned = unsigned; - this.prevContent = prevContent; + // synapse unfortunatley isn't following the spec and tosses the prev_content + // into the unsigned block + this.prevContent = prevContent != null && prevContent.isNotEmpty + ? prevContent + : (unsigned != null && unsigned['prev_content'] is Map + ? unsigned['prev_content'] + : null); this.stateKey = stateKey; this.originServerTs = originServerTs; } diff --git a/lib/src/user.dart b/lib/src/user.dart index c87ebbc..3efedf4 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -71,7 +71,10 @@ class User extends Event { String get id => stateKey; /// The displayname of the user if the user has set one. - String get displayName => content != null ? content['displayname'] : null; + String get displayName => + content != null && content.containsKey('displayname') + ? content['displayname'] + : (prevContent != null ? prevContent['displayname'] : null); /// Returns the power level of this user. int get powerLevel => room?.getPowerLevelByUserId(id); @@ -89,9 +92,13 @@ class User extends Event { }, orElse: () => Membership.join); /// The avatar if the user has one. - Uri get avatarUrl => content != null && content['avatar_url'] is String - ? Uri.parse(content['avatar_url']) - : null; + Uri get avatarUrl => content != null && content.containsKey('avatar_url') + ? (content['avatar_url'] is String + ? Uri.parse(content['avatar_url']) + : null) + : (prevContent != null && prevContent['avatar_url'] is String + ? Uri.parse(prevContent['avatar_url']) + : null); /// Returns the displayname or the local part of the Matrix ID if the user /// has no displayname. If [formatLocalpart] is true, then the localpart will diff --git a/pubspec.lock b/pubspec.lock index 7f80235..faec33f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -22,13 +22,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.2" - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.13" args: dependency: transitive description: @@ -323,6 +316,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.6" + matrix_file_e2ee: + dependency: "direct main" + description: + name: matrix_file_e2ee + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" meta: dependency: transitive description: @@ -331,7 +331,7 @@ packages: source: hosted version: "1.1.8" mime: - dependency: transitive + dependency: "direct main" description: name: mime url: "https://pub.dartlang.org" @@ -386,6 +386,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.8" + olm: + dependency: "direct main" + description: + name: olm + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" package_config: dependency: transitive description: @@ -414,13 +421,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.2" pointycastle: dependency: transitive description: @@ -652,13 +652,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.5.4" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.7.0" yaml: dependency: transitive description: