diff --git a/lib/src/Event.dart b/lib/src/Event.dart index 5067afb..b90dde3 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -137,6 +137,8 @@ class Event { print("jsonObj decode of event content failed: ${e.toString()}"); content = {}; } + else + content = {}; return Event( jsonObj["event_id"] ?? jsonObj["id"], diff --git a/lib/src/User.dart b/lib/src/User.dart index dedb1ca..cfd93c6 100644 --- a/lib/src/User.dart +++ b/lib/src/User.dart @@ -72,7 +72,7 @@ class User { /// Returns the displayname or the local part of the Matrix ID if the user /// has no displayname. - String calcDisplayname() => displayName.isEmpty + String calcDisplayname() => (displayName == null || displayName.isEmpty) ? id.replaceFirst("@", "").split(":")[0] : displayName; diff --git a/test/User_test.dart b/test/User_test.dart index 6991ff5..e6d0ae7 100644 --- a/test/User_test.dart +++ b/test/User_test.dart @@ -51,5 +51,14 @@ void main() { expect(user.powerLevel, powerLevel); expect(user.calcDisplayname(), displayName); }); + + test("calcDisplayname", () async { + final User user1 = User("@alice:example.com"); + final User user2 = User("@alice:example.com", displayName: "SuperAlice"); + final User user3 = User("@alice:example.com", displayName: ""); + expect(user1.calcDisplayname(), "alice"); + expect(user2.calcDisplayname(), "SuperAlice"); + expect(user3.calcDisplayname(), "alice"); + }); }); }