diff --git a/lib/msc_extensions/msc_1236_widgets/src/widget.dart b/lib/msc_extensions/msc_1236_widgets/src/widget.dart index bc97ec30..bfb36cf7 100644 --- a/lib/msc_extensions/msc_1236_widgets/src/widget.dart +++ b/lib/msc_extensions/msc_1236_widgets/src/widget.dart @@ -91,7 +91,7 @@ class MatrixWidget { // See https://github.com/matrix-org/matrix-doc/issues/1236 for a // description, specifically the section // `What does the other stuff in content mean?` - final userProfile = await room.client.ownProfile; + final userProfile = await room.client.fetchOwnProfile(); var parsedUri = url; // a key-value map with the strings to be replaced diff --git a/lib/src/client.dart b/lib/src/client.dart index cea34fb8..3a253bbd 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -707,11 +707,14 @@ class Client extends MatrixApi { return id; } + @Deprecated('Use fetchOwnProfile() instead') + Future get ownProfile => fetchOwnProfile(); + /// Returns the user's own displayname and avatar url. In Matrix it is possible that /// one user can have different displaynames and avatar urls in different rooms. So /// this endpoint first checks if the profile is the same in all rooms. If not, the /// profile will be requested from the homserver. - Future get ownProfile async { + Future fetchOwnProfile() async { if (rooms.isNotEmpty) { final profileSet = {}; for (final room in rooms) { diff --git a/lib/src/event.dart b/lib/src/event.dart index 2c0146cb..f94600a1 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -37,8 +37,12 @@ abstract class RelationshipTypes { /// All data exchanged over Matrix is expressed as an "event". Typically each client action (e.g. sending a message) correlates with exactly one event. class Event extends MatrixEvent { - Future get eventSender async => - await room.requestUser(senderId, ignoreErrors: true); + /// Requests the user object of the sender of this event. + Future fetchSenderUser() => room.requestUser( + senderId, + ignoreErrors: true, + ); + @Deprecated( 'Use eventSender instead or senderFromMemoryOrFallback for a synchronous alternative') User get sender => senderFromMemoryOrFallback; @@ -632,21 +636,21 @@ class Event extends MatrixEvent { /// plaintextBody instead of the normal body. /// [removeMarkdown] allow to remove the markdown formating from the event body. /// Usefull form message preview or notifications text. - Future getLocalizedBodyAsync(MatrixLocalizations i18n, + Future calcLocalizedBody(MatrixLocalizations i18n, {bool withSenderNamePrefix = false, bool hideReply = false, bool hideEdit = false, bool plaintextBody = false, bool removeMarkdown = false}) async { if (redacted) { - await redactedBecause?.eventSender; + await redactedBecause?.fetchSenderUser(); } if (withSenderNamePrefix && (type == EventTypes.Message || type.contains(EventTypes.Encrypted))) { // To be sure that if the event need to be localized, the user is in memory. // used by EventLocalizations._localizedBodyNormalMessage - await eventSender; + await fetchSenderUser(); } return _getLocalizedBody(i18n, @@ -657,7 +661,7 @@ class Event extends MatrixEvent { removeMarkdown: removeMarkdown); } - @Deprecated('Use getLocalizedBodyAsync') + @Deprecated('Use calcLocalizedBody') String getLocalizedBody(MatrixLocalizations i18n, {bool withSenderNamePrefix = false, bool hideReply = false, diff --git a/lib/src/room.dart b/lib/src/room.dart index 5831f72d..505c3f6d 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -525,9 +525,12 @@ class Room { /// in muted rooms, use [hasNewMessages]. bool get isUnread => notificationCount > 0 || markedUnread; + @Deprecated('Use waitForRoomInSync() instead') + Future get waitForSync => waitForRoomInSync(); + /// Wait for the room to appear in join, leave or invited section of the /// sync. - Future get waitForSync async { + Future waitForRoomInSync() async { return await client.waitForRoomInSync(id); } diff --git a/lib/src/user.dart b/lib/src/user.dart index b6af3123..dcff2dcd 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -159,8 +159,11 @@ class User extends Event { @Deprecated('Deprecated in favour of currentPresence.') Presence? get presence => room.client.presences[id]?.toPresence(); + @Deprecated('Use fetchCurrentPresence() instead') + Future get currentPresence => fetchCurrentPresence(); + /// The newest presence of this user if there is any. Fetches it from the server if necessary or returns offline. - Future get currentPresence async { + Future fetchCurrentPresence() async { final cachedPresence = room.client.presences[id]; if (cachedPresence != null) { return cachedPresence; diff --git a/lib/src/voip.dart b/lib/src/voip.dart index d6c9f5b1..97340cbd 100644 --- a/lib/src/voip.dart +++ b/lib/src/voip.dart @@ -1240,8 +1240,8 @@ class VoIP { final newCall = createNewCall(opts); newCall.remotePartyId = partyId; - newCall.remoteUser = - (await event.eventSender) ?? User(event.senderId, room: event.room); + newCall.remoteUser = (await event.fetchSenderUser()) ?? + User(event.senderId, room: event.room); final offer = RTCSessionDescription( event.content['offer']['sdp'], event.content['offer']['type'], @@ -1285,8 +1285,8 @@ class VoIP { } call.remotePartyId = partyId; - call.remoteUser = - await event.eventSender ?? User(event.senderId, room: event.room); + call.remoteUser = await event.fetchSenderUser() ?? + User(event.senderId, room: event.room); final answer = RTCSessionDescription( event.content['answer']['sdp'], event.content['answer']['type']); diff --git a/test/client_test.dart b/test/client_test.dart index fd764bf0..ec33a508 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -561,7 +561,7 @@ void main() { await client.database?.clearCache(); await client.handleSync(SyncUpdate.fromJson(jsonDecode( '{\"next_batch\":\"s82_571_2_6_39_1_2_34_1\",\"account_data\":{\"events\":[{\"type\":\"m.push_rules\",\"content\":{\"global\":{\"underride\":[{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.call.invite\"}],\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"ring\"},{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.call\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"room_member_count\",\"is\":\"2\"},{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.message\"}],\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"default\"},{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.room_one_to_one\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"room_member_count\",\"is\":\"2\"},{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.encrypted\"}],\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"default\"},{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.encrypted_room_one_to_one\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.message\"}],\"actions\":[\"notify\",{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.message\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.encrypted\"}],\"actions\":[\"notify\",{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.encrypted\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"im.vector.modular.widgets\"},{\"kind\":\"event_match\",\"key\":\"content.type\",\"pattern\":\"jitsi\"},{\"kind\":\"event_match\",\"key\":\"state_key\",\"pattern\":\"*\"}],\"actions\":[\"notify\",{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".im.vector.jitsi\",\"default\":true,\"enabled\":true}],\"sender\":[],\"room\":[],\"content\":[{\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"default\"},{\"set_tweak\":\"highlight\"}],\"pattern\":\"056d6976-fb61-47cf-86f0-147387461565\",\"rule_id\":\".m.rule.contains_user_name\",\"default\":true,\"enabled\":true}],\"override\":[{\"conditions\":[],\"actions\":[\"dont_notify\"],\"rule_id\":\".m.rule.master\",\"default\":true,\"enabled\":false},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"content.msgtype\",\"pattern\":\"m.notice\"}],\"actions\":[\"dont_notify\"],\"rule_id\":\".m.rule.suppress_notices\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.member\"},{\"kind\":\"event_match\",\"key\":\"content.membership\",\"pattern\":\"invite\"},{\"kind\":\"event_match\",\"key\":\"state_key\",\"pattern\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\"}],\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"default\"},{\"set_tweak\":\"highlight\",\"value\":false}],\"rule_id\":\".m.rule.invite_for_me\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.member\"}],\"actions\":[\"dont_notify\"],\"rule_id\":\".m.rule.member_event\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"contains_display_name\"}],\"actions\":[\"notify\",{\"set_tweak\":\"sound\",\"value\":\"default\"},{\"set_tweak\":\"highlight\"}],\"rule_id\":\".m.rule.contains_display_name\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"content.body\",\"pattern\":\"@room\"},{\"kind\":\"sender_notification_permission\",\"key\":\"room\"}],\"actions\":[\"notify\",{\"set_tweak\":\"highlight\",\"value\":true}],\"rule_id\":\".m.rule.roomnotif\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.room.tombstone\"},{\"kind\":\"event_match\",\"key\":\"state_key\",\"pattern\":\"\"}],\"actions\":[\"notify\",{\"set_tweak\":\"highlight\",\"value\":true}],\"rule_id\":\".m.rule.tombstone\",\"default\":true,\"enabled\":true},{\"conditions\":[{\"kind\":\"event_match\",\"key\":\"type\",\"pattern\":\"m.reaction\"}],\"actions\":[\"dont_notify\"],\"rule_id\":\".m.rule.reaction\",\"default\":true,\"enabled\":true}]},\"device\":{}}}]},\"presence\":{\"events\":[{\"type\":\"m.presence\",\"sender\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"presence\":\"online\",\"last_active_ago\":43,\"currently_active\":true}}]},\"device_one_time_keys_count\":{\"signed_curve25519\":66},\"org.matrix.msc2732.device_unused_fallback_key_types\":[\"signed_curve25519\"],\"device_unused_fallback_key_types\":[\"signed_curve25519\"],\"rooms\":{\"join\":{\"!MEgZosbiZqjSjbHFqI:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\":{\"timeline\":{\"events\":[{\"type\":\"m.room.member\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"membership\":\"join\",\"displayname\":\"Lars Kaiser\"},\"state_key\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"origin_server_ts\":1647296944593,\"unsigned\":{\"age\":545455},\"event_id\":\"\$mk9kFUEAKBZJgarWApLyYqOZQQocLIVV8tWp_gJEZFU\"},{\"type\":\"m.room.power_levels\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"users\":{\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\":100},\"users_default\":0,\"events\":{\"m.room.name\":50,\"m.room.power_levels\":100,\"m.room.history_visibility\":100,\"m.room.canonical_alias\":50,\"m.room.avatar\":50,\"m.room.tombstone\":100,\"m.room.server_acl\":100,\"m.room.encryption\":100},\"events_default\":0,\"state_default\":50,\"ban\":50,\"kick\":50,\"redact\":50,\"invite\":50,\"historical\":100},\"state_key\":\"\",\"origin_server_ts\":1647296944690,\"unsigned\":{\"age\":545358},\"event_id\":\"\$3wL2YgVNQzgfl8y_ksi3BPMqRs94jb_m0WRonL1HNpY\"},{\"type\":\"m.room.canonical_alias\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"alias\":\"#user-discovery:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\"},\"state_key\":\"\",\"origin_server_ts\":1647296944806,\"unsigned\":{\"age\":545242},\"event_id\":\"\$yXaVETL9F4jSN9rpRNyT_kUoctzD07n5Z4AIHziP7DQ\"},{\"type\":\"m.room.join_rules\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"join_rule\":\"public\"},\"state_key\":\"\",\"origin_server_ts\":1647296944894,\"unsigned\":{\"age\":545154},\"event_id\":\"\$jBDHhgpNqr125eWUsGVw4r7ZG2hgr0BTzzR77S-ubvY\"},{\"type\":\"m.room.history_visibility\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"history_visibility\":\"shared\"},\"state_key\":\"\",\"origin_server_ts\":1647296944965,\"unsigned\":{\"age\":545083},\"event_id\":\"\$kMessP7gAphUKW7mzOLlJT6NT8IsVGPmGir3_1uBNCE\"},{\"type\":\"m.room.name\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"name\":\"User Discovery\"},\"state_key\":\"\",\"origin_server_ts\":1647296945062,\"unsigned\":{\"age\":544986},\"event_id\":\"\$Bo9Ut_0vcr3FuxCRye4IHEMxUxIIcSwc-ePnMzx-hYU\"},{\"type\":\"m.room.member\",\"sender\":\"@test:fakeServer.notExisting\",\"content\":{\"membership\":\"join\",\"displayname\":\"1c2e5c2b-f958-45a5-9fcb-eef3969c31df\"},\"state_key\":\"@test:fakeServer.notExisting\",\"origin_server_ts\":1647296989893,\"unsigned\":{\"age\":500155},\"event_id\":\"\$fYCf2qtlHwzcdLgwjHb2EOdStv3isAlIUy2Esh5qfVE\"},{\"type\":\"m.room.member\",\"sender\":\"@test:fakeServer.notExisting\",\"content\":{\"membership\":\"join\",\"displayname\":\"Some First Name Some Last Name\"},\"state_key\":\"@test:fakeServer.notExisting\",\"origin_server_ts\":1647296990076,\"unsigned\":{\"replaces_state\":\"\$fYCf2qtlHwzcdLgwjHb2EOdStv3isAlIUy2Esh5qfVE\",\"prev_content\":{\"membership\":\"join\",\"displayname\":\"1c2e5c2b-f958-45a5-9fcb-eef3969c31df\"},\"prev_sender\":\"@test:fakeServer.notExisting\",\"age\":499972},\"event_id\":\"\$3Ut97nFBgOtsrnRPW-pqr28z7ETNMttj7GcjkIv4zWw\"},{\"type\":\"m.room.member\",\"sender\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"membership\":\"join\",\"displayname\":\"056d6976-fb61-47cf-86f0-147387461565\"},\"state_key\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"origin_server_ts\":1647297489154,\"unsigned\":{\"age\":894},\"event_id\":\"\$6EsjHSLQDVDW9WDH1c5Eu57VaPGZmOPtNRjCjtWPLV0\"},{\"type\":\"m.room.member\",\"sender\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"membership\":\"join\",\"displayname\":\"Another User\"},\"state_key\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"origin_server_ts\":1647297489290,\"unsigned\":{\"replaces_state\":\"\$6EsjHSLQDVDW9WDH1c5Eu57VaPGZmOPtNRjCjtWPLV0\",\"prev_content\":{\"membership\":\"join\",\"displayname\":\"056d6976-fb61-47cf-86f0-147387461565\"},\"prev_sender\":\"@056d6976-fb61-47cf-86f0-147387461565:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"age\":758},\"event_id\":\"\$dtQblqCbjr3TGc3WmrQ4YTkHaXJ2PcO0TAYDr9K7iQc\"}],\"prev_batch\":\"t2-62_571_2_6_39_1_2_34_1\",\"limited\":true},\"state\":{\"events\":[{\"type\":\"m.room.create\",\"sender\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\",\"content\":{\"m.federate\":false,\"room_version\":\"9\",\"creator\":\"@8640f1e6-a824-4f9c-9924-2d8fc40bc030:c3d35860-36fe-45d1-8e16-936cf50513fb.gedisa-staging.famedly.de\"},\"state_key\":\"\",\"origin_server_ts\":1647296944511,\"unsigned\":{\"age\":545537},\"event_id\":\"\$PAWKKULBVOLnqfrAAtXZz8tHEPXXjgRVbJJLifwQWbE\"}]},\"account_data\":{\"events\":[]},\"ephemeral\":{\"events\":[]},\"unread_notifications\":{\"notification_count\":0,\"highlight_count\":0},\"summary\":{\"m.joined_member_count\":3,\"m.invited_member_count\":0},\"org.matrix.msc2654.unread_count\":0}}}}'))); - final profile = await client.ownProfile; + final profile = await client.fetchOwnProfile(); expect(profile.displayName, 'Some First Name Some Last Name'); }); test('sendToDeviceEncrypted', () async { diff --git a/test/event_test.dart b/test/event_test.dart index 2512c288..e03cf41f 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -362,7 +362,7 @@ void main() { } } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Removed by Example'); expect(event.isEventTypeKnown, true); @@ -429,7 +429,7 @@ void main() { 'type': 'm.sticker', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example sent a sticker'); expect(event.isEventTypeKnown, true); @@ -443,7 +443,7 @@ void main() { 'type': 'm.room.redaction', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example redacted an event'); expect(event.isEventTypeKnown, true); @@ -459,7 +459,7 @@ void main() { 'type': 'm.room.aliases', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the room aliases'); expect(event.isEventTypeKnown, true); @@ -475,7 +475,7 @@ void main() { 'type': 'm.room.aliases', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the room aliases'); expect(event.isEventTypeKnown, true); @@ -489,7 +489,7 @@ void main() { 'type': 'm.room.canonical_alias', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the room invitation link'); expect(event.isEventTypeKnown, true); @@ -511,7 +511,7 @@ void main() { 'type': 'm.room.create', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example created the chat'); expect(event.isEventTypeKnown, true); @@ -528,7 +528,7 @@ void main() { 'type': 'm.room.tombstone', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Room has been upgraded'); expect(event.isEventTypeKnown, true); @@ -542,7 +542,7 @@ void main() { 'type': 'm.room.join_rules', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the join rules to Anyone can join'); expect(event.isEventTypeKnown, true); @@ -560,7 +560,7 @@ void main() { 'type': 'm.room.member', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Alice joined the chat'); expect(event.isEventTypeKnown, true); @@ -573,7 +573,7 @@ void main() { 'state_key': '@alice:example.org', 'type': 'm.room.member' }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example has invited Alice'); expect(event.isEventTypeKnown, true); @@ -589,7 +589,7 @@ void main() { 'prev_content': {'membership': 'join'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example kicked Alice'); expect(event.isEventTypeKnown, true); @@ -605,7 +605,7 @@ void main() { 'prev_content': {'membership': 'join'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example banned Alice'); expect(event.isEventTypeKnown, true); @@ -621,7 +621,7 @@ void main() { 'prev_content': {'membership': 'invite'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Alice accepted the invitation'); expect(event.isEventTypeKnown, true); @@ -637,7 +637,7 @@ void main() { 'prev_content': {'membership': 'join'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example has invited Alice'); expect(event.isEventTypeKnown, true); @@ -653,7 +653,7 @@ void main() { 'prev_content': {'membership': 'invite'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example has withdrawn the invitation for Alice'); expect(event.isEventTypeKnown, true); @@ -669,7 +669,7 @@ void main() { 'prev_content': {'membership': 'invite'}, } }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Alice rejected the invitation'); expect(event.isEventTypeKnown, true); @@ -694,7 +694,7 @@ void main() { 'type': 'm.room.power_levels', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the chat permissions'); expect(event.isEventTypeKnown, true); @@ -708,7 +708,7 @@ void main() { 'type': 'm.room.name', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the chat name to The room name'); expect(event.isEventTypeKnown, true); @@ -722,7 +722,7 @@ void main() { 'type': 'm.room.topic', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the chat description to A room topic'); expect(event.isEventTypeKnown, true); @@ -739,7 +739,7 @@ void main() { 'type': 'm.room.avatar', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the chat avatar'); expect(event.isEventTypeKnown, true); @@ -753,7 +753,7 @@ void main() { 'type': 'm.room.history_visibility', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example changed the history visibility to Visible for all participants'); expect(event.isEventTypeKnown, true); @@ -771,7 +771,7 @@ void main() { 'type': 'm.room.encryption', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example activated end to end encryption. Need pantalaimon'); expect(event.isEventTypeKnown, true); @@ -789,7 +789,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'This is an example text message'); expect(event.isEventTypeKnown, true); @@ -807,7 +807,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), '* thinks this is an example emote'); expect(event.isEventTypeKnown, true); @@ -825,7 +825,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'This is an example notice'); expect(event.isEventTypeKnown, true); @@ -843,7 +843,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example sent a picture'); expect(event.isEventTypeKnown, true); @@ -862,7 +862,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example sent a file'); expect(event.isEventTypeKnown, true); @@ -884,7 +884,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example sent an audio'); expect(event.isEventTypeKnown, true); @@ -910,7 +910,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example shared the location'); expect(event.isEventTypeKnown, true); @@ -941,7 +941,7 @@ void main() { 'type': 'm.room.message', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Example sent a video'); expect(event.isEventTypeKnown, true); @@ -954,7 +954,7 @@ void main() { 'type': 'unknown.event.type', 'unsigned': {'age': 1234} }, room); - expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()), + expect(await event.calcLocalizedBody(MatrixDefaultLocalizations()), 'Unknown event unknown.event.type'); expect(event.isEventTypeKnown, false); }); @@ -977,7 +977,7 @@ void main() { 'unsigned': {'age': 1234} }, room); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), plaintextBody: true), '**This is an example text message**'); @@ -1006,11 +1006,11 @@ void main() { 'unsigned': {'age': 1234} }, room); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), hideEdit: true), 'This is an example text message'); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), hideEdit: true, plaintextBody: true), '**This is an example text message**'); @@ -1029,11 +1029,11 @@ void main() { 'unsigned': {'age': 1234} }, room); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), hideReply: true), 'hmm, fox'); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), hideReply: true, plaintextBody: true), 'hmm, *fox*'); @@ -1054,19 +1054,19 @@ void main() { 'unsigned': {'age': 1234} }, room); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), removeMarkdown: true), 'Title\nsome text and link\nokay and this is important'); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), removeMarkdown: true, plaintextBody: true), 'Title\nsome text and 🔗link\nokay and this is important'); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), removeMarkdown: true, withSenderNamePrefix: true), 'Example: Title\nsome text and link\nokay and this is important'); expect( - await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(), + await event.calcLocalizedBody(MatrixDefaultLocalizations(), removeMarkdown: true, plaintextBody: true, withSenderNamePrefix: true), diff --git a/test/user_test.dart b/test/user_test.dart index fee0f421..491f5caa 100644 --- a/test/user_test.dart +++ b/test/user_test.dart @@ -131,7 +131,8 @@ void main() { ] } })); - expect((await user1.currentPresence).presence, PresenceType.online); + expect( + (await user1.fetchCurrentPresence()).presence, PresenceType.online); }); test('canBan', () async { expect(user1.canBan, false);