From d6bb91f7e1e2473099608490ba1d9aade90356af Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 16 Mar 2022 16:31:02 +0100 Subject: [PATCH] chore: Update to matrix v1.2 --- .gitignore | 4 + lib/fake_matrix_api.dart | 350 +++++++------- lib/src/generated/api.dart | 619 +++++++++++++------------ lib/src/generated/model.dart | 680 +++++++++++++++++++--------- lib/src/generated/model.g.dart | 802 +++++++++++++++++++++++++++++++++ lib/src/matrix_api.dart | 28 +- pubspec.yaml | 3 + test/matrix_api_test.dart | 110 +++-- 8 files changed, 1829 insertions(+), 767 deletions(-) create mode 100644 lib/src/generated/model.g.dart diff --git a/.gitignore b/.gitignore index 0ab205ed..4d9b87d1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ test/.test_coverage.dart coverage/ coverage_badge.svg +# codegen related +*.bak +*.bakmacoscompat + # IntelliJ related *.iml *.ipr diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index d626dccd..37e02927 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -89,17 +89,17 @@ class FakeMatrixApi extends MockClient { statusCode = 405; } } else if (method == 'PUT' && - action.contains('/client/r0/sendToDevice/')) { + action.contains('/client/v3/sendToDevice/')) { res = {}; } else if (method == 'GET' && - action.contains('/client/r0/rooms/') && + action.contains('/client/v3/rooms/') && action.contains('/state/m.room.member/')) { res = {'displayname': ''}; } else if (method == 'PUT' && action.contains( - '/client/r0/rooms/!1234%3AfakeServer.notExisting/send/')) { + '/client/v3/rooms/!1234%3AfakeServer.notExisting/send/')) { res = {'event_id': '\$event${FakeMatrixApi.eventCounter++}'}; - } else if (action.contains('/client/r0/sync')) { + } else if (action.contains('/client/v3/sync')) { res = { 'next_batch': DateTime.now().millisecondsSinceEpoch.toString }; @@ -752,11 +752,11 @@ class FakeMatrixApi extends MockClient { 'errcode': 'M_FORBIDDEN', 'error': 'Blabla', }, - '/media/r0/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10': (var req) => { + '/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10': (var req) => { 'og:image': 'mxc://example.com/ascERGshawAWawugaAcauga', 'matrix:image:size': 102400 }, - '/media/r0/config': (var req) => {'m.upload.size': 50000000}, + '/media/v3/config': (var req) => {'m.upload.size': 50000000}, '/.well-known/matrix/client': (var req) => { 'm.homeserver': { 'base_url': 'https://fakeserver.notexisting', @@ -768,7 +768,7 @@ class FakeMatrixApi extends MockClient { 'app_url': 'https://custom.app.fakeserver.notexisting' } }, - '/client/r0/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags': + '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags': (var req) => { 'tags': { 'm.favourite': {'order': 0.1}, @@ -776,7 +776,7 @@ class FakeMatrixApi extends MockClient { 'u.Customers': {} } }, - '/client/r0/events?from=1234&timeout=10&room_id=%211234': (var req) => { + '/client/v3/events?from=1234&timeout=10&room_id=%211234': (var req) => { 'start': 's3456_9_0', 'end': 's3457_9_0', 'chunk': [ @@ -796,35 +796,35 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/thirdparty/location?alias=1234': (var req) => [ + '/client/v3/thirdparty/location?alias=1234': (var req) => [ { 'alias': '#freenode_#matrix:matrix.org', 'protocol': 'irc', 'fields': {'network': 'freenode', 'channel': '#matrix'} } ], - '/client/r0/thirdparty/location/irc': (var req) => [ + '/client/v3/thirdparty/location/irc': (var req) => [ { 'alias': '#freenode_#matrix:matrix.org', 'protocol': 'irc', 'fields': {'network': 'freenode', 'channel': '#matrix'} } ], - '/client/r0/thirdparty/user/irc': (var req) => [ + '/client/v3/thirdparty/user/irc': (var req) => [ { 'userid': '@_gitter_jim:matrix.org', 'protocol': 'gitter', 'fields': {'user': 'jim'} } ], - '/client/r0/thirdparty/user?userid=1234': (var req) => [ + '/client/v3/thirdparty/user?userid=1234': (var req) => [ { 'userid': '@_gitter_jim:matrix.org', 'protocol': 'gitter', 'fields': {'user': 'jim'} } ], - '/client/r0/thirdparty/protocol/irc': (var req) => { + '/client/v3/thirdparty/protocol/irc': (var req) => { 'user_fields': ['network', 'nickname'], 'location_fields': ['network', 'channel'], 'icon': 'mxc://example.org/aBcDeFgH', @@ -845,7 +845,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/thirdparty/protocols': (var req) => { + '/client/v3/thirdparty/protocols': (var req) => { 'irc': { 'user_fields': ['network', 'nickname'], 'location_fields': ['network', 'channel'], @@ -888,9 +888,9 @@ class FakeMatrixApi extends MockClient { ] } }, - '/client/r0/account/whoami': (var req) => + '/client/v3/account/whoami': (var req) => {'user_id': 'alice@example.com'}, - '/client/r0/capabilities': (var req) => { + '/client/v3/capabilities': (var req) => { 'capabilities': { 'm.change_password': {'enabled': false}, 'm.room_versions': { @@ -905,7 +905,7 @@ class FakeMatrixApi extends MockClient { 'com.example.custom.ratelimit': {'max_requests_per_hour': 600} } }, - '/client/r0/rooms/1234/context/1234?limit=10&filter=%7B%7D': (var req) => + '/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D': (var req) => { 'end': 't29-57_2_0_2', 'events_after': [ @@ -996,7 +996,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/admin/whois/%40alice%3Aexample.com': (var req) => { + '/client/v3/admin/whois/%40alice%3Aexample.com': (var req) => { 'user_id': '@peter:rabbit.rocks', 'devices': { 'teapot': { @@ -1020,15 +1020,15 @@ class FakeMatrixApi extends MockClient { } } }, - '/client/r0/user/%40alice%3Aexample.com/account_data/test.account.data': + '/client/v3/user/%40alice%3Aexample.com/account_data/test.account.data': (var req) => {'foo': 'bar'}, - '/client/r0/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': + '/client/v3/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': (var req) => {'foo': 'bar'}, - '/client/r0/directory/room/%23testalias%3Aexample.com': (var reqI) => { + '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => { 'room_id': '!abnjk1jdasj98:capuchins.com', 'servers': ['capuchins.com', 'matrix.org', 'another.com'] }, - '/client/r0/account/3pid': (var req) => { + '/client/v3/account/3pid': (var req) => { 'threepids': [ { 'medium': 'email', @@ -1038,7 +1038,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/devices': (var req) => { + '/client/v3/devices': (var req) => { 'devices': [ { 'device_id': 'QBUAZIFURK', @@ -1048,7 +1048,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/notifications?from=1234&limit=10&only=1234': (var req) => { + '/client/v3/notifications?from=1234&limit=10&only=1234': (var req) => { 'next_token': 'abcdef', 'notifications': [ { @@ -1074,21 +1074,21 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/devices/QBUAZIFURK': (var req) => { + '/client/v3/devices/QBUAZIFURK': (var req) => { 'device_id': 'QBUAZIFURK', 'display_name': 'android', 'last_seen_ip': '1.2.3.4', 'last_seen_ts': 1474491775024 }, - '/client/r0/profile/%40alice%3Aexample.com/displayname': (var reqI) => + '/client/v3/profile/%40alice%3Aexample.com/displayname': (var reqI) => {'displayname': 'Alice M'}, - '/client/r0/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => + '/client/v3/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => {'avatar_url': 'mxc://test'}, - '/client/r0/profile/%40alice%3Aexample.com': (var reqI) => { + '/client/v3/profile/%40alice%3Aexample.com': (var reqI) => { 'avatar_url': 'mxc://test', 'displayname': 'Alice M', }, - '/client/r0/voip/turnServer': (var req) => { + '/client/v3/voip/turnServer': (var req) => { 'username': '1443779631:@user:example.com', 'password': 'JlKfBy1QwLrO20385QyAtEyIv0=', 'uris': [ @@ -1098,18 +1098,18 @@ class FakeMatrixApi extends MockClient { ], 'ttl': 86400 }, - '/client/r0/presence/${Uri.encodeComponent('@alice:example.com')}/status': + '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status': (var req) => { 'presence': 'unavailable', 'last_active_ago': 420845, 'status_msg': 'test', 'currently_active': false }, - '/client/r0/keys/changes?from=1234&to=1234': (var req) => { + '/client/v3/keys/changes?from=1234&to=1234': (var req) => { 'changed': ['@alice:example.com', '@bob:example.org'], 'left': ['@clara:example.com', '@doug:example.org'] }, - '/client/r0/pushers': (var req) => { + '/client/v3/pushers': (var req) => { 'pushers': [ { 'pushkey': 'Xp/MzCt8/9DcSNE9cuiaoT5Ac55job3TdLSSmtmYl4A=', @@ -1126,11 +1126,10 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/publicRooms?limit=10&since=1234&server=example.com': + '/client/v3/publicRooms?limit=10&since=1234&server=example.com': (var req) => { 'chunk': [ { - 'aliases': ['#murrays:cheese.bar'], 'canonical_alias': '#murrays:cheese.bar', 'avatar_url': 'mxc://bleeker.street/CHEDDARandBRIE', 'guest_can_join': false, @@ -1145,30 +1144,30 @@ class FakeMatrixApi extends MockClient { 'prev_batch': 'p1902', 'total_room_count_estimate': 115 }, - '/client/r0/rooms/!localpart%3Aexample.com/aliases': (var req) => { + '/client/v3/rooms/!localpart%3Aexample.com/aliases': (var req) => { 'aliases': [ '#somewhere:example.com', '#another:example.com', '#hat_trick:example.com' ] }, - '/client/r0/joined_rooms': (var req) => { + '/client/v3/joined_rooms': (var req) => { 'joined_rooms': ['!foo:example.com'] }, - '/client/r0/directory/list/room/!localpart%3Aexample.com': (var req) => + '/client/v3/directory/list/room/!localpart%3Aexample.com': (var req) => {'visibility': 'public'}, - '/client/r0/rooms/1/state/m.room.member/@alice:example.com': (var req) => + '/client/v3/rooms/1/state/m.room.member/@alice:example.com': (var req) => {'displayname': 'Alice'}, - '/client/r0/profile/%40getme%3Aexample.com': (var req) => { + '/client/v3/profile/%40getme%3Aexample.com': (var req) => { 'avatar_url': 'mxc://test', 'displayname': 'You got me', }, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.member/@getme%3Aexample.com': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.member/@getme%3Aexample.com': (var req) => { 'avatar_url': 'mxc://test', 'displayname': 'You got me', }, - '/client/r0/rooms/!localpart%3Aserver.abc/state': (var req) => [ + '/client/v3/rooms/!localpart%3Aserver.abc/state': (var req) => [ { 'content': {'join_rule': 'public'}, 'type': 'm.room.join_rules', @@ -1233,12 +1232,12 @@ class FakeMatrixApi extends MockClient { 'state_key': '' } ], - '/client/r0/rooms/!localpart:server.abc/state/m.room.member/@getme:example.com': + '/client/v3/rooms/!localpart:server.abc/state/m.room.member/@getme:example.com': (var req) => { 'avatar_url': 'mxc://test', 'displayname': 'You got me', }, - '/client/r0/rooms/!localpart:server.abc/event/1234': (var req) => { + '/client/v3/rooms/!localpart:server.abc/event/1234': (var req) => { 'content': { 'body': 'This is an example text message', 'msgtype': 'm.text', @@ -1252,7 +1251,7 @@ class FakeMatrixApi extends MockClient { 'origin_server_ts': 1432735824653, 'unsigned': {'age': 1234} }, - '/client/r0/rooms/!localpart%3Aserver.abc/event/1234': (var req) => { + '/client/v3/rooms/!localpart%3Aserver.abc/event/1234': (var req) => { 'content': { 'body': 'This is an example text message', 'msgtype': 'm.text', @@ -1266,11 +1265,11 @@ class FakeMatrixApi extends MockClient { 'origin_server_ts': 1432735824653, 'unsigned': {'age': 1234} }, - '/client/r0/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D': + '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D': (var req) => messagesResponse, - '/client/r0/rooms/!localpart%3Aserver.abc/messages?from=&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D': + '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D': (var req) => messagesResponse, - '/client/r0/rooms/!1234%3Aexample.com/messages?from=1234&dir=b&limit=100&filter=%7B%22lazy_load_members%22%3Atrue%7D': + '/client/v3/rooms/!1234%3Aexample.com/messages?from=1234&dir=b&limit=100&filter=%7B%22lazy_load_members%22%3Atrue%7D': (var req) => messagesResponse, '/client/versions': (var req) => { 'versions': [ @@ -1283,12 +1282,12 @@ class FakeMatrixApi extends MockClient { ], 'unstable_features': {'m.lazy_load_members': true}, }, - '/client/r0/login': (var req) => { + '/client/v3/login': (var req) => { 'flows': [ {'type': 'm.login.password'} ] }, - '/client/r0/rooms/!localpart%3Aserver.abc/joined_members': (var req) => { + '/client/v3/rooms/!localpart%3Aserver.abc/joined_members': (var req) => { 'joined': { '@bar:example.com': { 'display_name': 'Bar', @@ -1296,7 +1295,7 @@ class FakeMatrixApi extends MockClient { } } }, - '/client/r0/rooms/!localpart%3Aserver.abc/members?at=1234&membership=join¬_membership=leave': + '/client/v3/rooms/!localpart%3Aserver.abc/members?at=1234&membership=join¬_membership=leave': (var req) => { 'chunk': [ { @@ -1315,7 +1314,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/rooms/!696r7674:example.com/members': (var req) => { + '/client/v3/rooms/!696r7674:example.com/members': (var req) => { 'chunk': [ { 'content': { @@ -1333,7 +1332,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/rooms/!726s6s6q:example.com/members': (var req) => { + '/client/v3/rooms/!726s6s6q:example.com/members': (var req) => { 'chunk': [ { 'content': { @@ -1351,7 +1350,7 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/rooms/!localpart%3Aserver.abc/members': (var req) => { + '/client/v3/rooms/!localpart%3Aserver.abc/members': (var req) => { 'chunk': [ { 'content': { @@ -1369,20 +1368,20 @@ class FakeMatrixApi extends MockClient { } ] }, - '/client/r0/pushrules/global/content/nocake': (var req) => { + '/client/v3/pushrules/global/content/nocake': (var req) => { 'actions': ['dont_notify'], 'pattern': 'cake*lie', 'rule_id': 'nocake', 'enabled': true, 'default': false }, - '/client/r0/pushrules/global/content/nocake/enabled': (var req) => { + '/client/v3/pushrules/global/content/nocake/enabled': (var req) => { 'enabled': true, }, - '/client/r0/pushrules/global/content/nocake/actions': (var req) => { + '/client/v3/pushrules/global/content/nocake/actions': (var req) => { 'actions': ['notify'] }, - '/client/r0/pushrules': (var req) => { + '/client/v3/pushrules': (var req) => { 'global': { 'content': [ { @@ -1527,15 +1526,15 @@ class FakeMatrixApi extends MockClient { ] } }, - '/client/r0/sync?filter=%7B%22room%22%3A%7B%22include_leave%22%3Atrue%2C%22timeline%22%3A%7B%22limit%22%3A10%7D%7D%7D&timeout=0': + '/client/v3/sync?filter=%7B%22room%22%3A%7B%22include_leave%22%3Atrue%2C%22timeline%22%3A%7B%22limit%22%3A10%7D%7D%7D&timeout=0': (var req) => archiveSyncResponse, - '/client/r0/sync?filter=%7B%22room%22%3A%7B%22state%22%3A%7B%22lazy_load_members%22%3Atrue%7D%7D%7D': + '/client/v3/sync?filter=%7B%22room%22%3A%7B%22state%22%3A%7B%22lazy_load_members%22%3Atrue%7D%7D%7D': (var req) => syncResponse, - '/client/r0/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15': + '/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15': (var req) => syncResponse, - '/client/r0/register/available?username=testuser': (var req) => + '/client/v3/register/available?username=testuser': (var req) => {'available': true}, - '/client/r0/user/${Uri.encodeComponent('alice@example.com')}/filter/1234': + '/client/v3/user/${Uri.encodeComponent('alice@example.com')}/filter/1234': (var req) => { 'room': { 'state': { @@ -1566,7 +1565,7 @@ class FakeMatrixApi extends MockClient { 'event_format': 'client', 'event_fields': ['type', 'content', 'sender'] }, - '/client/unstable/room_keys/version': (var req) => { + '/client/v3/room_keys/version': (var req) => { 'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2, 'auth_data': { 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', @@ -1576,7 +1575,7 @@ class FakeMatrixApi extends MockClient { 'etag': '0', 'version': '5', }, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': (var req) => { 'first_message_index': 0, 'forwarded_count': 0, @@ -1588,7 +1587,7 @@ class FakeMatrixApi extends MockClient { 'mac': 'QzKV/fgAs4U', }, }, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': (var req) => { 'sessions': { 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU': { @@ -1605,7 +1604,7 @@ class FakeMatrixApi extends MockClient { }, }, }, - '/client/unstable/room_keys/keys?version=5': (var req) => { + '/client/v3/room_keys/keys?version=5': (var req) => { 'rooms': { '!726s6s6q:example.com': { 'sessions': { @@ -1627,16 +1626,16 @@ class FakeMatrixApi extends MockClient { }, }, 'POST': { - '/client/r0/delete_devices': (var req) => {}, - '/client/r0/account/3pid/add': (var req) => {}, - '/client/r0/account/3pid/bind': (var req) => {}, - '/client/r0/account/3pid/delete': (var req) => + '/client/v3/delete_devices': (var req) => {}, + '/client/v3/account/3pid/add': (var req) => {}, + '/client/v3/account/3pid/bind': (var req) => {}, + '/client/v3/account/3pid/delete': (var req) => {'id_server_unbind_result': 'success'}, - '/client/r0/account/3pid/unbind': (var req) => + '/client/v3/account/3pid/unbind': (var req) => {'id_server_unbind_result': 'success'}, - '/client/r0/account/password': (var req) => {}, - '/client/r0/rooms/1234/report/1234': (var req) => {}, - '/client/r0/search': (var req) => { + '/client/v3/account/password': (var req) => {}, + '/client/v3/rooms/1234/report/1234': (var req) => {}, + '/client/v3/search': (var req) => { 'search_categories': { 'room_events': { 'groups': { @@ -1674,9 +1673,9 @@ class FakeMatrixApi extends MockClient { } } }, - '/client/r0/account/deactivate': (var req) => + '/client/v3/account/deactivate': (var req) => {'id_server_unbind_result': 'success'}, - '/client/r0/user_directory/search': (var req) => { + '/client/v3/user_directory/search': (var req) => { 'results': [ { 'user_id': '@foo:bar.com', @@ -1686,39 +1685,38 @@ class FakeMatrixApi extends MockClient { ], 'limited': false }, - '/client/r0/register/email/requestToken': (var req) => { + '/client/v3/register/email/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/register/msisdn/requestToken': (var req) => { + '/client/v3/register/msisdn/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/account/password/email/requestToken': (var req) => { + '/client/v3/account/password/email/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/account/password/msisdn/requestToken': (var req) => { + '/client/v3/account/password/msisdn/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/account/3pid/email/requestToken': (var req) => { + '/client/v3/account/3pid/email/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/account/3pid/msisdn/requestToken': (var req) => { + '/client/v3/account/3pid/msisdn/requestToken': (var req) => { 'sid': '123abc', 'submit_url': 'https://example.org/path/to/submitToken' }, - '/client/r0/rooms/!localpart%3Aexample.com/receipt/m.read/%241234%3Aexample.com': + '/client/v3/rooms/!localpart%3Aexample.com/receipt/m.read/%241234%3Aexample.com': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/read_markers': (var req) => {}, - '/client/r0/user/${Uri.encodeComponent('alice@example.com')}/filter': + '/client/v3/rooms/!localpart%3Aexample.com/read_markers': (var req) => {}, + '/client/v3/user/${Uri.encodeComponent('alice@example.com')}/filter': (var req) => {'filter_id': '1234'}, - '/client/r0/publicRooms?server=example.com': (var req) => { + '/client/v3/publicRooms?server=example.com': (var req) => { 'chunk': [ { - 'aliases': ['#murrays:cheese.bar'], 'canonical_alias': '#murrays:cheese.bar', 'avatar_url': 'mxc://bleeker.street/CHEDDARandBRIE', 'guest_can_join': false, @@ -1733,7 +1731,7 @@ class FakeMatrixApi extends MockClient { 'prev_batch': 'p1902', 'total_room_count_estimate': 115 }, - '/client/r0/keys/claim': (var req) => { + '/client/v3/keys/claim': (var req) => { 'failures': {}, 'one_time_keys': { if (decodeJson(req)['one_time_keys']['@alice:example.com'] != @@ -1769,25 +1767,25 @@ class FakeMatrixApi extends MockClient { }, } }, - '/client/r0/rooms/!localpart%3Aexample.com/invite': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/leave': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/forget': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/kick': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/kick': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/ban': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/unban': (var req) => {}, - '/client/r0/rooms/!localpart%3Aexample.com/join': (var req) => + '/client/v3/rooms/!localpart%3Aexample.com/invite': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/kick': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/kick': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/ban': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/unban': (var req) => {}, + '/client/v3/rooms/!localpart%3Aexample.com/join': (var req) => {'room_id': '!localpart:example.com'}, - '/client/r0/join/!localpart%3Aexample.com?server_name=example.com&server_name=example.abc': + '/client/v3/join/!localpart%3Aexample.com?server_name=example.com&server_name=example.abc': (var req) => {'room_id': '!localpart:example.com'}, - '/client/r0/keys/upload': (var req) => { + '/client/v3/keys/upload': (var req) => { 'one_time_key_counts': { 'curve25519': 10, 'signed_curve25519': decodeJson(req)['one_time_keys']?.keys?.length ?? 0, } }, - '/client/r0/keys/query': (var req) => { + '/client/v3/keys/query': (var req) => { 'failures': {}, 'device_keys': { '@alice:example.com': { @@ -1970,32 +1968,32 @@ class FakeMatrixApi extends MockClient { }, }, }, - '/client/r0/register': (var req) => { + '/client/v3/register': (var req) => { 'user_id': '@testuser:example.com', 'access_token': '1234', 'device_id': 'ABCD', }, - '/client/r0/register?kind=user': (var req) => + '/client/v3/register?kind=user': (var req) => {'user_id': '@testuser:example.com'}, - '/client/r0/register?kind=guest': (var req) => + '/client/v3/register?kind=guest': (var req) => {'user_id': '@testuser:example.com'}, - '/client/r0/rooms/1234/upgrade': (var req) => { + '/client/v3/rooms/1234/upgrade': (var req) => { 'replacement_room': '!1234:fakeServer.notExisting', }, - '/client/r0/user/1234/openid/request_token': (var req) => { + '/client/v3/user/1234/openid/request_token': (var req) => { 'access_token': 'SomeT0kenHere', 'token_type': 'Bearer', 'matrix_server_name': 'example.com', 'expires_in': 3600 }, - '/client/r0/user/@test:fakeServer.notExisting/openid/request_token': + '/client/v3/user/@test:fakeServer.notExisting/openid/request_token': (var req) => { 'access_token': 'SomeT0kenHere', 'token_type': 'Bearer', 'matrix_server_name': 'example.com', 'expires_in': 3600 }, - '/client/r0/login': (var req) => { + '/client/v3/login': (var req) => { 'user_id': '@test:fakeServer.notExisting', 'access_token': 'abc123', 'device_id': 'GHTYAJCE', @@ -2004,160 +2002,160 @@ class FakeMatrixApi extends MockClient { 'm.identity_server': {'base_url': 'https://id.example.org'} } }, - '/media/r0/upload?filename=file.jpeg': (var req) => + '/media/v3/upload?filename=file.jpeg': (var req) => {'content_uri': 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'}, - '/client/r0/logout': (var reqI) => {}, - '/client/r0/pushers/set': (var reqI) => {}, - '/client/r0/join/1234': (var reqI) => {'room_id': '1234'}, - '/client/r0/logout/all': (var reqI) => {}, - '/client/r0/createRoom': (var reqI) => { + '/client/v3/logout': (var reqI) => {}, + '/client/v3/pushers/set': (var reqI) => {}, + '/client/v3/join/1234': (var reqI) => {'room_id': '1234'}, + '/client/v3/logout/all': (var reqI) => {}, + '/client/v3/createRoom': (var reqI) => { 'room_id': '!1234:fakeServer.notExisting', }, - '/client/r0/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) => {}, - '/client/r0/rooms/!localpart:server.abc/kick': (var reqI) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/ban': (var reqI) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/unban': (var reqI) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/invite': (var reqI) => {}, - '/client/unstable/keys/device_signing/upload': (var reqI) { + '/client/v3/rooms/!localpart%3Aserver.abc/read_markers': (var reqI) => {}, + '/client/v3/rooms/!localpart:server.abc/kick': (var reqI) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/ban': (var reqI) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/unban': (var reqI) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/invite': (var reqI) => {}, + '/client/v3/keys/device_signing/upload': (var reqI) { return {}; }, - '/client/r0/keys/signatures/upload': (var reqI) => {'failures': {}}, - '/client/unstable/room_keys/version': (var reqI) => {'version': '5'}, + '/client/v3/keys/signatures/upload': (var reqI) => {'failures': {}}, + '/client/v3/room_keys/version': (var reqI) => {'version': '5'}, }, 'PUT': { - '/client/r0/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list': + '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list': (var req) => {}, - '/client/r0/presence/${Uri.encodeComponent('@alice:example.com')}/status': + '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status': (var req) => {}, - '/client/r0/pushrules/global/content/nocake/enabled': (var req) => {}, - '/client/r0/pushrules/global/content/nocake/actions': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility': + '/client/v3/pushrules/global/content/nocake/enabled': (var req) => {}, + '/client/v3/pushrules/global/content/nocake/actions': (var req) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.history_visibility': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.join_rules': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.join_rules': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.guest_access': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.guest_access': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.invite/1234': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.answer/1234': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.candidates/1234': (var req) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.call.hangup/1234': (var req) => {}, - '/client/r0/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234': + '/client/v3/rooms/!1234%3Aexample.com/redact/1143273582443PhrSn%3Aexample.org/1234': (var req) => {'event_id': '1234'}, - '/client/r0/pushrules/global/room/!localpart%3Aserver.abc': (var req) => + '/client/v3/pushrules/global/room/!localpart%3Aserver.abc': (var req) => {}, - '/client/r0/pushrules/global/override/.m.rule.master/enabled': + '/client/v3/pushrules/global/override/.m.rule.master/enabled': (var req) => {}, - '/client/r0/pushrules/global/content/nocake?before=1&after=2': + '/client/v3/pushrules/global/content/nocake?before=1&after=2': (var req) => {}, - '/client/r0/devices/QBUAZIFURK': (var req) => {}, - '/client/r0/directory/room/%23testalias%3Aexample.com': (var reqI) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.room.message/testtxid': + '/client/v3/devices/QBUAZIFURK': (var req) => {}, + '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => {}, + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.room.message/testtxid': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.reaction/testtxid': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.reaction/testtxid': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, - '/client/r0/rooms/!localpart%3Aexample.com/typing/%40alice%3Aexample.com': + '/client/v3/rooms/!localpart%3Aexample.com/typing/%40alice%3Aexample.com': (var req) => {}, - '/client/r0/rooms/!1234%3Aexample.com/send/m.room.message/1234': + '/client/v3/rooms/!1234%3Aexample.com/send/m.room.message/1234': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, - '/client/r0/rooms/!1234%3Aexample.com/send/m.room.message/newresend': + '/client/v3/rooms/!1234%3Aexample.com/send/m.room.message/newresend': (var reqI) => { 'event_id': '\$event${FakeMatrixApi.eventCounter++}', }, - '/client/r0/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': + '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': (var req) => {}, - '/client/r0/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': + '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': (var req) => {}, - '/client/r0/user/%40alice%3Aexample.com/account_data/test.account.data': + '/client/v3/user/%40alice%3Aexample.com/account_data/test.account.data': (var req) => {}, - '/client/r0/user/%40test%3AfakeServer.notExisting/account_data/best%20animal': + '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/best%20animal': (var req) => {}, - '/client/r0/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': + '/client/v3/user/%40alice%3Aexample.com/rooms/1234/account_data/test.account.data': (var req) => {}, - '/client/r0/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/account_data/com.famedly.marked_unread': + '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/account_data/com.famedly.marked_unread': (var req) => {}, - '/client/r0/user/%40test%3AfakeServer.notExisting/account_data/m.direct': + '/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct': (var req) => {}, - '/client/r0/user/%40othertest%3AfakeServer.notExisting/account_data/m.direct': + '/client/v3/user/%40othertest%3AfakeServer.notExisting/account_data/m.direct': (var req) => {}, - '/client/r0/profile/%40alice%3Aexample.com/displayname': (var reqI) => {}, - '/client/r0/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => {}, - '/client/r0/profile/%40test%3AfakeServer.notExisting/avatar_url': + '/client/v3/profile/%40alice%3Aexample.com/displayname': (var reqI) => {}, + '/client/v3/profile/%40alice%3Aexample.com/avatar_url': (var reqI) => {}, + '/client/v3/profile/%40test%3AfakeServer.notExisting/avatar_url': (var reqI) => {}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.encryption': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.encryption': (var reqI) => {'event_id': 'YUwRidLecu:example.com'}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.avatar': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.avatar': (var reqI) => {'event_id': 'YUwRidLecu:example.com'}, - '/client/r0/rooms/!localpart%3Aserver.abc/send/m.room.message/1234': + '/client/v3/rooms/!localpart%3Aserver.abc/send/m.room.message/1234': (var reqI) => {'event_id': 'YUwRidLecu:example.com'}, - '/client/r0/rooms/!localpart%3Aserver.abc/redact/1234/1234': (var reqI) => + '/client/v3/rooms/!localpart%3Aserver.abc/redact/1234/1234': (var reqI) => {'event_id': 'YUwRidLecu:example.com'}, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.name': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.name': (var reqI) => { 'event_id': '42', }, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.topic': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.topic': (var reqI) => { 'event_id': '42', }, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.pinned_events': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.pinned_events': (var reqI) => { 'event_id': '42', }, - '/client/r0/rooms/!localpart%3Aserver.abc/state/m.room.power_levels': + '/client/v3/rooms/!localpart%3Aserver.abc/state/m.room.power_levels': (var reqI) => { 'event_id': '42', }, - '/client/r0/directory/list/room/!localpart%3Aexample.com': (var req) => + '/client/v3/directory/list/room/!localpart%3Aexample.com': (var req) => {}, - '/client/unstable/room_keys/version/5': (var req) => {}, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': + '/client/v3/room_keys/version/5': (var req) => {}, + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, - '/client/unstable/room_keys/keys?version=5': (var req) => { + '/client/v3/room_keys/keys?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, }, 'DELETE': { '/unknown/token': (var req) => {'errcode': 'M_UNKNOWN_TOKEN'}, - '/client/r0/devices/QBUAZIFURK': (var req) => {}, - '/client/r0/directory/room/%23testalias%3Aexample.com': (var reqI) => {}, - '/client/r0/pushrules/global/content/nocake': (var req) => {}, - '/client/r0/pushrules/global/override/!localpart%3Aserver.abc': + '/client/v3/devices/QBUAZIFURK': (var req) => {}, + '/client/v3/directory/room/%23testalias%3Aexample.com': (var reqI) => {}, + '/client/v3/pushrules/global/content/nocake': (var req) => {}, + '/client/v3/pushrules/global/override/!localpart%3Aserver.abc': (var req) => {}, - '/client/r0/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': + '/client/v3/user/%40test%3AfakeServer.notExisting/rooms/!localpart%3Aserver.abc/tags/m.favourite': (var req) => {}, - '/client/r0/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': + '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags/testtag': (var req) => {}, - '/client/unstable/room_keys/version/5': (var req) => {}, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': + '/client/v3/room_keys/version/5': (var req) => {}, + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, - '/client/unstable/room_keys/keys?version=5': (var req) => { + '/client/v3/room_keys/keys?version=5': (var req) => { 'etag': 'asdf', 'count': 1, }, diff --git a/lib/src/generated/api.dart b/lib/src/generated/api.dart index 7a898127..66df959e 100644 --- a/lib/src/generated/api.dart +++ b/lib/src/generated/api.dart @@ -42,6 +42,85 @@ class Api { return DiscoveryInformation.fromJson(json); } + /// Queries the server to determine if a given registration token is still + /// valid at the time of request. This is a point-in-time check where the + /// token might still expire by the time it is used. + /// + /// Servers should be sure to rate limit this endpoint to avoid brute force + /// attacks. + /// + /// [token] The token to check validity of. + /// + /// returns `valid`: + /// True if the token is still valid, false otherwise. This should + /// additionally be false if the token is not a recognised token by + /// the server. + Future registrationTokenValidity(String token) async { + final requestUri = Uri( + path: '_matrix/client/v1/register/m.login.registration_token/validity', + queryParameters: { + 'token': token, + }); + final request = Request('GET', baseUri!.resolveUri(requestUri)); + final response = await httpClient.send(request); + final responseBody = await response.stream.toBytes(); + if (response.statusCode != 200) unexpectedResponse(response, responseBody); + final responseString = utf8.decode(responseBody); + final json = jsonDecode(responseString); + return json['valid'] as bool; + } + + /// Paginates over the space tree in a depth-first manner to locate child rooms of a given space. + /// + /// Where a child room is unknown to the local server, federation is used to fill in the details. + /// The servers listed in the `via` array should be contacted to attempt to fill in missing rooms. + /// + /// Only [`m.space.child`](#mspacechild) state events of the room are considered. Invalid child + /// rooms and parent events are not covered by this endpoint. + /// + /// [roomId] The room ID of the space to get a hierarchy for. + /// + /// [suggestedOnly] Optional (default `false`) flag to indicate whether or not the server should only consider + /// suggested rooms. Suggested rooms are annotated in their [`m.space.child`](#mspacechild) event + /// contents. + /// + /// [limit] Optional limit for the maximum number of rooms to include per response. Must be an integer + /// greater than zero. + /// + /// Servers should apply a default value, and impose a maximum value to avoid resource exhaustion. + /// + /// [maxDepth] Optional limit for how far to go into the space. Must be a non-negative integer. + /// + /// When reached, no further child rooms will be returned. + /// + /// Servers should apply a default value, and impose a maximum value to avoid resource exhaustion. + /// + /// [from] A pagination token from a previous result. If specified, `max_depth` and `suggested_only` cannot + /// be changed from the first request. + Future getSpaceHierarchy(String roomId, + {bool? suggestedOnly, + double? limit, + double? maxDepth, + String? from}) async { + final requestUri = Uri( + path: + '_matrix/client/v1/rooms/${Uri.encodeComponent(roomId)}/hierarchy', + queryParameters: { + if (suggestedOnly != null) 'suggested_only': suggestedOnly.toString(), + if (limit != null) 'limit': limit.toString(), + if (maxDepth != null) 'max_depth': maxDepth.toString(), + if (from != null) 'from': from, + }); + final request = Request('GET', baseUri!.resolveUri(requestUri)); + request.headers['authorization'] = 'Bearer ${bearerToken!}'; + final response = await httpClient.send(request); + final responseBody = await response.stream.toBytes(); + if (response.statusCode != 200) unexpectedResponse(response, responseBody); + final responseString = utf8.decode(responseBody); + final json = jsonDecode(responseString); + return GetSpaceHierarchyResponse.fromJson(json); + } + /// Gets a list of the third party identifiers that the homeserver has /// associated with the user's account. /// @@ -53,7 +132,7 @@ class Api { /// /// returns `threepids` Future?> getAccount3PIDs() async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid'); + final requestUri = Uri(path: '_matrix/client/v3/account/3pid'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -78,9 +157,23 @@ class Api { /// than dual-purpose. /// /// [threePidCreds] The third party credentials to associate with the account. + /// + /// returns `submit_url`: + /// An optional field containing a URL where the client must + /// submit the validation token to, with identical parameters + /// to the Identity Service API's `POST + /// /validate/email/submitToken` endpoint (without the requirement + /// for an access token). The homeserver must send this token to the + /// user (if applicable), who should then be prompted to provide it + /// to the client. + /// + /// If this field is not present, the client can assume that + /// verification will happen without the client's involvement + /// provided the homeserver advertises this specification version + /// in the `/versions` response (ie: r0.5.0). @deprecated - Future post3PIDs(ThreePidCredentials threePidCreds) async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid'); + Future post3PIDs(ThreePidCredentials threePidCreds) async { + final requestUri = Uri(path: '_matrix/client/v3/account/3pid'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -92,7 +185,7 @@ class Api { if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return null; + return ((v) => v != null ? Uri.parse(v) : null)(json['submit_url']); } /// This API endpoint uses the [User-Interactive Authentication API](https://spec.matrix.org/unstable/client-server-api/#user-interactive-authentication-api). @@ -111,7 +204,7 @@ class Api { /// [sid] The session identifier given by the homeserver. Future add3PID(String clientSecret, String sid, {AuthenticationData? auth}) async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid/add'); + final requestUri = Uri(path: '_matrix/client/v3/account/3pid/add'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -145,7 +238,7 @@ class Api { /// [sid] The session identifier given by the identity server. Future bind3PID(String clientSecret, String idAccessToken, String idServer, String sid) async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid/bind'); + final requestUri = Uri(path: '_matrix/client/v3/account/3pid/bind'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -189,34 +282,29 @@ class Api { Future delete3pidFromAccount( String address, ThirdPartyIdentifierMedium medium, {String? idServer}) async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid/delete'); + final requestUri = Uri(path: '_matrix/client/v3/account/3pid/delete'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ 'address': address, if (idServer != null) 'id_server': idServer, - 'medium': { - ThirdPartyIdentifierMedium.email: 'email', - ThirdPartyIdentifierMedium.msisdn: 'msisdn' - }[medium]!, + 'medium': medium.name, })); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return { - 'no-support': IdServerUnbindResult.noSupport, - 'success': IdServerUnbindResult.success - }[json['id_server_unbind_result']]!; + return IdServerUnbindResult.values + .fromString(json['id_server_unbind_result'])!; } /// The homeserver must check that the given email address is **not** /// already associated with an account on this homeserver. This API should /// be used to request validation tokens when adding an email address to an /// account. This API's parameters and response are identical to that of - /// the [`/register/email/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0registeremailrequesttoken) + /// the [`/register/email/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3registeremailrequesttoken) /// endpoint. The homeserver should validate /// the email itself, either by sending a validation email itself or by using /// a service it has control over. @@ -258,7 +346,7 @@ class Api { String clientSecret, String email, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/account/3pid/email/requestToken'); + Uri(path: '_matrix/client/v3/account/3pid/email/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -281,7 +369,7 @@ class Api { /// already associated with an account on this homeserver. This API should /// be used to request validation tokens when adding a phone number to an /// account. This API's parameters and response are identical to that of - /// the [`/register/msisdn/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0registermsisdnrequesttoken) + /// the [`/register/msisdn/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3registermsisdnrequesttoken) /// endpoint. The homeserver should validate /// the phone number itself, either by sending a validation message itself or by using /// a service it has control over. @@ -325,7 +413,7 @@ class Api { String clientSecret, String country, String phoneNumber, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/account/3pid/msisdn/requestToken'); + Uri(path: '_matrix/client/v3/account/3pid/msisdn/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -370,27 +458,22 @@ class Api { Future unbind3pidFromAccount( String address, ThirdPartyIdentifierMedium medium, {String? idServer}) async { - final requestUri = Uri(path: '_matrix/client/r0/account/3pid/unbind'); + final requestUri = Uri(path: '_matrix/client/v3/account/3pid/unbind'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ 'address': address, if (idServer != null) 'id_server': idServer, - 'medium': { - ThirdPartyIdentifierMedium.email: 'email', - ThirdPartyIdentifierMedium.msisdn: 'msisdn' - }[medium]!, + 'medium': medium.name, })); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return { - 'no-support': IdServerUnbindResult.noSupport, - 'success': IdServerUnbindResult.success - }[json['id_server_unbind_result']]!; + return IdServerUnbindResult.values + .fromString(json['id_server_unbind_result'])!; } /// Deactivate the user's account, removing all ability for the user to @@ -428,7 +511,7 @@ class Api { /// for the user. Future deactivateAccount( {AuthenticationData? auth, String? idServer}) async { - final requestUri = Uri(path: '_matrix/client/r0/account/deactivate'); + final requestUri = Uri(path: '_matrix/client/v3/account/deactivate'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -441,10 +524,8 @@ class Api { if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return { - 'no-support': IdServerUnbindResult.noSupport, - 'success': IdServerUnbindResult.success - }[json['id_server_unbind_result']]!; + return IdServerUnbindResult.values + .fromString(json['id_server_unbind_result'])!; } /// Changes the password for an account on this homeserver. @@ -472,7 +553,7 @@ class Api { /// [newPassword] The new password for the account. Future changePassword(String newPassword, {AuthenticationData? auth, bool? logoutDevices}) async { - final requestUri = Uri(path: '_matrix/client/r0/account/password'); + final requestUri = Uri(path: '_matrix/client/v3/account/password'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -495,7 +576,7 @@ class Api { /// `/account/password` endpoint. /// /// This API's parameters and response are identical to that of the - /// [`/register/email/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0registeremailrequesttoken) + /// [`/register/email/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3registeremailrequesttoken) /// endpoint, except that /// `M_THREEPID_NOT_FOUND` may be returned if no account matching the /// given email address could be found. The server may instead send an @@ -542,7 +623,7 @@ class Api { String clientSecret, String email, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/account/password/email/requestToken'); + Uri(path: '_matrix/client/v3/account/password/email/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -567,7 +648,7 @@ class Api { /// `/account/password` endpoint. /// /// This API's parameters and response are identical to that of the - /// [`/register/msisdn/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0registermsisdnrequesttoken) + /// [`/register/msisdn/requestToken`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3registermsisdnrequesttoken) /// endpoint, except that /// `M_THREEPID_NOT_FOUND` may be returned if no account matching the /// given phone number could be found. The server may instead send the SMS @@ -616,7 +697,7 @@ class Api { String clientSecret, String country, String phoneNumber, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/account/password/msisdn/requestToken'); + Uri(path: '_matrix/client/v3/account/password/msisdn/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -645,7 +726,7 @@ class Api { /// is registered by the appservice, and return it in the response /// body. Future getTokenOwner() async { - final requestUri = Uri(path: '_matrix/client/r0/account/whoami'); + final requestUri = Uri(path: '_matrix/client/v3/account/whoami'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -665,7 +746,7 @@ class Api { /// [userId] The user to look up. Future getWhoIs(String userId) async { final requestUri = Uri( - path: '_matrix/client/r0/admin/whois/${Uri.encodeComponent(userId)}'); + path: '_matrix/client/v3/admin/whois/${Uri.encodeComponent(userId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -683,7 +764,7 @@ class Api { /// The custom capabilities the server supports, using the /// Java package naming convention. Future getCapabilities() async { - final requestUri = Uri(path: '_matrix/client/r0/capabilities'); + final requestUri = Uri(path: '_matrix/client/v3/capabilities'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -737,9 +818,9 @@ class Api { /// `creation_content`. /// /// [creationContent] Extra keys, such as `m.federate`, to be added to the content - /// of the [`m.room.create`](client-server-api/#mroomcreate) event. The server will clobber the following + /// of the [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate) event. The server will overwrite the following /// keys: `creator`, `room_version`. Future versions of the specification - /// may allow the server to clobber other keys. + /// may allow the server to overwrite other keys. /// /// [initialState] A list of state events to set in the new room. This allows /// the user to override the default state events set in the new @@ -747,7 +828,7 @@ class Api { /// with type, state_key and content keys set. /// /// Takes precedence over events set by `preset`, but gets - /// overriden by `name` and `topic` keys. + /// overridden by `name` and `topic` keys. /// /// [invite] A list of user IDs to invite to the room. This will tell the /// server to invite everyone in the list to the newly created room. @@ -765,7 +846,7 @@ class Api { /// /// [powerLevelContentOverride] The power level content to override in the default power level /// event. This object is applied on top of the generated - /// [`m.room.power_levels`](client-server-api/#mroompower_levels) + /// [`m.room.power_levels`](https://spec.matrix.org/unstable/client-server-api/#mroompower_levels) /// event content prior to it being sent to the room. Defaults to /// overriding nothing. /// @@ -819,7 +900,7 @@ class Api { String? roomVersion, String? topic, Visibility? visibility}) async { - final requestUri = Uri(path: '_matrix/client/r0/createRoom'); + final requestUri = Uri(path: '_matrix/client/v3/createRoom'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -834,20 +915,11 @@ class Api { if (name != null) 'name': name, if (powerLevelContentOverride != null) 'power_level_content_override': powerLevelContentOverride, - if (preset != null) - 'preset': { - CreateRoomPreset.privateChat: 'private_chat', - CreateRoomPreset.publicChat: 'public_chat', - CreateRoomPreset.trustedPrivateChat: 'trusted_private_chat' - }[preset]!, + if (preset != null) 'preset': preset.name, if (roomAliasName != null) 'room_alias_name': roomAliasName, if (roomVersion != null) 'room_version': roomVersion, if (topic != null) 'topic': topic, - if (visibility != null) - 'visibility': { - Visibility.public: 'public', - Visibility.private: 'private' - }[visibility]!, + if (visibility != null) 'visibility': visibility.name, })); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -867,7 +939,7 @@ class Api { /// [devices] The list of device IDs to delete. Future deleteDevices(List devices, {AuthenticationData? auth}) async { - final requestUri = Uri(path: '_matrix/client/r0/delete_devices'); + final requestUri = Uri(path: '_matrix/client/v3/delete_devices'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -888,7 +960,7 @@ class Api { /// returns `devices`: /// A list of all registered devices for this user. Future?> getDevices() async { - final requestUri = Uri(path: '_matrix/client/r0/devices'); + final requestUri = Uri(path: '_matrix/client/v3/devices'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -911,7 +983,7 @@ class Api { /// user-interactive authentication API. Future deleteDevice(String deviceId, {AuthenticationData? auth}) async { final requestUri = - Uri(path: '_matrix/client/r0/devices/${Uri.encodeComponent(deviceId)}'); + Uri(path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}'); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -931,7 +1003,7 @@ class Api { /// [deviceId] The device to retrieve. Future getDevice(String deviceId) async { final requestUri = - Uri(path: '_matrix/client/r0/devices/${Uri.encodeComponent(deviceId)}'); + Uri(path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -950,7 +1022,7 @@ class Api { /// display name is unchanged. Future updateDevice(String deviceId, {String? displayName}) async { final requestUri = - Uri(path: '_matrix/client/r0/devices/${Uri.encodeComponent(deviceId)}'); + Uri(path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -987,15 +1059,12 @@ class Api { String networkId, String roomId, Visibility visibility) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/list/appservice/${Uri.encodeComponent(networkId)}/${Uri.encodeComponent(roomId)}'); + '_matrix/client/v3/directory/list/appservice/${Uri.encodeComponent(networkId)}/${Uri.encodeComponent(roomId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ - 'visibility': { - Visibility.public: 'public', - Visibility.private: 'private' - }[visibility]!, + 'visibility': visibility.name, })); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1014,16 +1083,15 @@ class Api { Future getRoomVisibilityOnDirectory(String roomId) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/list/room/${Uri.encodeComponent(roomId)}'); + '_matrix/client/v3/directory/list/room/${Uri.encodeComponent(roomId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return ((v) => v != null - ? {'public': Visibility.public, 'private': Visibility.private}[v]! - : null)(json['visibility']); + return ((v) => v != null ? Visibility.values.fromString(v)! : null)( + json['visibility']); } /// Sets the visibility of a given room in the server's public room @@ -1041,16 +1109,12 @@ class Api { {Visibility? visibility}) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/list/room/${Uri.encodeComponent(roomId)}'); + '_matrix/client/v3/directory/list/room/${Uri.encodeComponent(roomId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ - if (visibility != null) - 'visibility': { - Visibility.public: 'public', - Visibility.private: 'private' - }[visibility]!, + if (visibility != null) 'visibility': visibility.name, })); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1076,7 +1140,7 @@ class Api { Future deleteRoomAlias(String roomAlias) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/room/${Uri.encodeComponent(roomAlias)}'); + '_matrix/client/v3/directory/room/${Uri.encodeComponent(roomAlias)}'); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1097,7 +1161,7 @@ class Api { Future getRoomIdByAlias(String roomAlias) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/room/${Uri.encodeComponent(roomAlias)}'); + '_matrix/client/v3/directory/room/${Uri.encodeComponent(roomAlias)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1115,7 +1179,7 @@ class Api { Future setRoomAlias(String roomAlias, String roomId) async { final requestUri = Uri( path: - '_matrix/client/r0/directory/room/${Uri.encodeComponent(roomAlias)}'); + '_matrix/client/v3/directory/room/${Uri.encodeComponent(roomAlias)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1134,8 +1198,8 @@ class Api { /// block until an event is received, or until the `timeout` is reached. /// /// This endpoint was deprecated in r0 of this specification. Clients - /// should instead call the [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync) - /// API with a `since` parameter. See + /// should instead call the [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync) + /// endpoint with a `since` parameter. See /// the [migration guide](https://matrix.org/docs/guides/migrating-from-client-server-api-v-1#deprecated-endpoints). /// /// [from] The token to stream from. This token is either from a previous @@ -1143,8 +1207,8 @@ class Api { /// /// [timeout] The maximum time in milliseconds to wait for an event. @deprecated - Future getEvents({String? from, int? timeout}) async { - final requestUri = Uri(path: '_matrix/client/r0/events', queryParameters: { + Future getEvents({String? from, int? timeout}) async { + final requestUri = Uri(path: '_matrix/client/v3/events', queryParameters: { if (from != null) 'from': from, if (timeout != null) 'timeout': timeout.toString(), }); @@ -1155,7 +1219,7 @@ class Api { if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return EventsSyncUpdate.fromJson(json); + return GetEventsResponse.fromJson(json); } /// This will listen for new events related to a particular room and return @@ -1175,9 +1239,9 @@ class Api { /// [timeout] The maximum time in milliseconds to wait for an event. /// /// [roomId] The room ID for which events should be returned. - Future peekEvents( + Future peekEvents( {String? from, int? timeout, String? roomId}) async { - final requestUri = Uri(path: '_matrix/client/r0/events', queryParameters: { + final requestUri = Uri(path: '_matrix/client/v3/events', queryParameters: { if (from != null) 'from': from, if (timeout != null) 'timeout': timeout.toString(), if (roomId != null) 'room_id': roomId, @@ -1189,7 +1253,7 @@ class Api { if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return EventsSyncUpdate.fromJson(json); + return PeekEventsResponse.fromJson(json); } /// Get a single event based on `event_id`. You must have permission to @@ -1197,14 +1261,14 @@ class Api { /// /// This endpoint was deprecated in r0 of this specification. Clients /// should instead call the - /// [/rooms/{roomId}/event/{eventId}](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0roomsroomideventeventid) API - /// or the [/rooms/{roomId}/context/{eventId](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0roomsroomidcontexteventid) API. + /// [/rooms/{roomId}/event/{eventId}](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3roomsroomideventeventid) API + /// or the [/rooms/{roomId}/context/{eventId](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3roomsroomidcontexteventid) API. /// /// [eventId] The event ID to get. @deprecated Future getOneEvent(String eventId) async { final requestUri = - Uri(path: '_matrix/client/r0/events/${Uri.encodeComponent(eventId)}'); + Uri(path: '_matrix/client/v3/events/${Uri.encodeComponent(eventId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1223,8 +1287,8 @@ class Api { /// events associated with the room until the user leaves the room. /// /// After a user has joined a room, the room will appear as an entry in the - /// response of the [`/initialSync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0initialsync) - /// and [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync) APIs. + /// response of the [`/initialSync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3initialsync) + /// and [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync) APIs. /// /// [roomIdOrAlias] The room identifier or alias to join. /// @@ -1245,7 +1309,7 @@ class Api { String? reason, ThirdPartySigned? thirdPartySigned}) async { final requestUri = Uri( - path: '_matrix/client/r0/join/${Uri.encodeComponent(roomIdOrAlias)}', + path: '_matrix/client/v3/join/${Uri.encodeComponent(roomIdOrAlias)}', queryParameters: { if (serverName != null) 'server_name': serverName.map((v) => v).toList(), @@ -1271,7 +1335,7 @@ class Api { /// returns `joined_rooms`: /// The ID of each room in which the user has `joined` membership. Future> getJoinedRooms() async { - final requestUri = Uri(path: '_matrix/client/r0/joined_rooms'); + final requestUri = Uri(path: '_matrix/client/v3/joined_rooms'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1293,18 +1357,18 @@ class Api { /// identity keys, between `from` and `to`. /// /// [from] The desired start point of the list. Should be the `next_batch` field - /// from a response to an earlier call to [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync). Users who have not + /// from a response to an earlier call to [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync). Users who have not /// uploaded new device identity keys since this point, nor deleted /// existing devices with identity keys since then, will be excluded /// from the results. /// /// [to] The desired end point of the list. Should be the `next_batch` - /// field from a recent call to [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync) - typically the most recent + /// field from a recent call to [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync) - typically the most recent /// such call. This may be used by the server as a hint to check its /// caches are up to date. Future getKeysChanges(String from, String to) async { final requestUri = - Uri(path: '_matrix/client/r0/keys/changes', queryParameters: { + Uri(path: '_matrix/client/v3/keys/changes', queryParameters: { 'from': from, 'to': to, }); @@ -1328,7 +1392,7 @@ class Api { Future claimKeys( Map> oneTimeKeys, {int? timeout}) async { - final requestUri = Uri(path: '_matrix/client/r0/keys/claim'); + final requestUri = Uri(path: '_matrix/client/v3/keys/claim'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1369,7 +1433,7 @@ class Api { MatrixCrossSigningKey? selfSigningKey, MatrixCrossSigningKey? userSigningKey}) async { final requestUri = - Uri(path: '_matrix/client/unstable/keys/device_signing/upload'); + Uri(path: '_matrix/client/v3/keys/device_signing/upload'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1402,7 +1466,7 @@ class Api { /// contains the keys advertised by the notification in that sync. Future queryKeys(Map> deviceKeys, {int? timeout, String? token}) async { - final requestUri = Uri(path: '_matrix/client/r0/keys/query'); + final requestUri = Uri(path: '_matrix/client/v3/keys/query'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1432,7 +1496,7 @@ class Api { Future>>?> uploadCrossSigningSignatures( Map>> signatures) async { - final requestUri = Uri(path: '_matrix/client/r0/keys/signatures/upload'); + final requestUri = Uri(path: '_matrix/client/v3/keys/signatures/upload'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1465,7 +1529,7 @@ class Api { /// history visibility to the user. /// /// The knock will appear as an entry in the response of the - /// [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync) API. + /// [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync) API. /// /// [roomIdOrAlias] The room identifier or alias to knock upon. /// @@ -1480,7 +1544,7 @@ class Api { Future knockRoom(String roomIdOrAlias, {List? serverName, String? reason}) async { final requestUri = Uri( - path: '_matrix/client/r0/knock/${Uri.encodeComponent(roomIdOrAlias)}', + path: '_matrix/client/v3/knock/${Uri.encodeComponent(roomIdOrAlias)}', queryParameters: { if (serverName != null) 'server_name': serverName.map((v) => v).toList(), @@ -1505,7 +1569,7 @@ class Api { /// returns `flows`: /// The homeserver's supported login types Future?> getLoginFlows() async { - final requestUri = Uri(path: '_matrix/client/r0/login'); + final requestUri = Uri(path: '_matrix/client/v3/login'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1561,7 +1625,7 @@ class Api { String? password, String? token, String? user}) async { - final requestUri = Uri(path: '_matrix/client/r0/login'); + final requestUri = Uri(path: '_matrix/client/v3/login'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -1573,10 +1637,7 @@ class Api { if (medium != null) 'medium': medium, if (password != null) 'password': password, if (token != null) 'token': token, - 'type': { - LoginType.mLoginPassword: 'm.login.password', - LoginType.mLoginToken: 'm.login.token' - }[type]!, + 'type': type.name, if (user != null) 'user': user, })); final response = await httpClient.send(request); @@ -1591,7 +1652,7 @@ class Api { /// authorization. The device associated with the access token is also deleted. /// [Device keys](https://spec.matrix.org/unstable/client-server-api/#device-keys) for the device are deleted alongside the device. Future logout() async { - final requestUri = Uri(path: '_matrix/client/r0/logout'); + final requestUri = Uri(path: '_matrix/client/v3/logout'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1614,7 +1675,7 @@ class Api { /// the request, and therefore the attacker is unable to take over the account in /// this way. Future logoutAll() async { - final requestUri = Uri(path: '_matrix/client/r0/logout/all'); + final requestUri = Uri(path: '_matrix/client/v3/logout/all'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1628,7 +1689,8 @@ class Api { /// This API is used to paginate through the list of events that the /// user has been, or would have been notified about. /// - /// [from] Pagination token given to retrieve the next set of events. + /// [from] Pagination token to continue from. This should be the `next_token` + /// returned from an earlier call to this endpoint. /// /// [limit] Limit on the number of events to return in this request. /// @@ -1638,7 +1700,7 @@ class Api { Future getNotifications( {String? from, int? limit, String? only}) async { final requestUri = - Uri(path: '_matrix/client/r0/notifications', queryParameters: { + Uri(path: '_matrix/client/v3/notifications', queryParameters: { if (from != null) 'from': from, if (limit != null) 'limit': limit.toString(), if (only != null) 'only': only, @@ -1659,7 +1721,7 @@ class Api { Future getPresence(String userId) async { final requestUri = Uri( path: - '_matrix/client/r0/presence/${Uri.encodeComponent(userId)}/status'); + '_matrix/client/v3/presence/${Uri.encodeComponent(userId)}/status'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1684,16 +1746,12 @@ class Api { {String? statusMsg}) async { final requestUri = Uri( path: - '_matrix/client/r0/presence/${Uri.encodeComponent(userId)}/status'); + '_matrix/client/v3/presence/${Uri.encodeComponent(userId)}/status'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ - 'presence': { - PresenceType.online: 'online', - PresenceType.offline: 'offline', - PresenceType.unavailable: 'unavailable' - }[presence]!, + 'presence': presence.name, if (statusMsg != null) 'status_msg': statusMsg, })); final response = await httpClient.send(request); @@ -1712,7 +1770,7 @@ class Api { /// [userId] The user whose profile information to get. Future getUserProfile(String userId) async { final requestUri = - Uri(path: '_matrix/client/r0/profile/${Uri.encodeComponent(userId)}'); + Uri(path: '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1733,7 +1791,7 @@ class Api { Future getAvatarUrl(String userId) async { final requestUri = Uri( path: - '_matrix/client/r0/profile/${Uri.encodeComponent(userId)}/avatar_url'); + '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}/avatar_url'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1752,7 +1810,7 @@ class Api { Future setAvatarUrl(String userId, Uri? avatarUrl) async { final requestUri = Uri( path: - '_matrix/client/r0/profile/${Uri.encodeComponent(userId)}/avatar_url'); + '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}/avatar_url'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1778,7 +1836,7 @@ class Api { Future getDisplayName(String userId) async { final requestUri = Uri( path: - '_matrix/client/r0/profile/${Uri.encodeComponent(userId)}/displayname'); + '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}/displayname'); final request = Request('GET', baseUri!.resolveUri(requestUri)); final response = await httpClient.send(request); final responseBody = await response.stream.toBytes(); @@ -1797,7 +1855,7 @@ class Api { Future setDisplayName(String userId, String? displayname) async { final requestUri = Uri( path: - '_matrix/client/r0/profile/${Uri.encodeComponent(userId)}/displayname'); + '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}/displayname'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -1829,7 +1887,7 @@ class Api { Future getPublicRooms( {int? limit, String? since, String? server}) async { final requestUri = - Uri(path: '_matrix/client/r0/publicRooms', queryParameters: { + Uri(path: '_matrix/client/v3/publicRooms', queryParameters: { if (limit != null) 'limit': limit.toString(), if (since != null) 'since': since, if (server != null) 'server': server, @@ -1873,7 +1931,7 @@ class Api { String? since, String? thirdPartyInstanceId}) async { final requestUri = - Uri(path: '_matrix/client/r0/publicRooms', queryParameters: { + Uri(path: '_matrix/client/v3/publicRooms', queryParameters: { if (server != null) 'server': server, }); final request = Request('POST', baseUri!.resolveUri(requestUri)); @@ -1901,7 +1959,7 @@ class Api { /// returns `pushers`: /// An array containing the current pushers for the user Future?> getPushers() async { - final requestUri = Uri(path: '_matrix/client/r0/pushers'); + final requestUri = Uri(path: '_matrix/client/v3/pushers'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1922,7 +1980,7 @@ class Api { /// returns `global`: /// The global ruleset. Future getPushRules() async { - final requestUri = Uri(path: '_matrix/client/r0/pushrules'); + final requestUri = Uri(path: '_matrix/client/v3/pushrules'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1946,13 +2004,7 @@ class Api { String scope, PushRuleKind kind, String ruleId) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}'); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -1976,13 +2028,7 @@ class Api { String scope, PushRuleKind kind, String ruleId) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2030,13 +2076,7 @@ class Api { String? pattern}) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}', + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}', queryParameters: { if (before != null) 'before': before, if (after != null) 'after': after, @@ -2075,13 +2115,7 @@ class Api { String scope, PushRuleKind kind, String ruleId) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}/actions'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}/actions'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2108,13 +2142,7 @@ class Api { String ruleId, List actions) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}/actions'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}/actions'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -2146,13 +2174,7 @@ class Api { String scope, PushRuleKind kind, String ruleId) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}/enabled'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}/enabled'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2178,13 +2200,7 @@ class Api { String scope, PushRuleKind kind, String ruleId, bool enabled) async { final requestUri = Uri( path: - '_matrix/client/r0/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent({ - PushRuleKind.override: 'override', - PushRuleKind.underride: 'underride', - PushRuleKind.sender: 'sender', - PushRuleKind.room: 'room', - PushRuleKind.content: 'content' - }[kind]!)}/${Uri.encodeComponent(ruleId)}/enabled'); + '_matrix/client/v3/pushrules/${Uri.encodeComponent(scope)}/${Uri.encodeComponent(kind.name)}/${Uri.encodeComponent(ruleId)}/enabled'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -2271,9 +2287,8 @@ class Api { String? password, String? username}) async { final requestUri = - Uri(path: '_matrix/client/r0/register', queryParameters: { - if (kind != null) - 'kind': {AccountKind.guest: 'guest', AccountKind.user: 'user'}[kind]!, + Uri(path: '_matrix/client/v3/register', queryParameters: { + if (kind != null) 'kind': kind.name, }); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; @@ -2314,7 +2329,7 @@ class Api { /// be `true` when the server replies with 200 OK. Future checkUsernameAvailability(String username) async { final requestUri = - Uri(path: '_matrix/client/r0/register/available', queryParameters: { + Uri(path: '_matrix/client/v3/register/available', queryParameters: { 'username': username, }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -2368,7 +2383,7 @@ class Api { String clientSecret, String email, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/register/email/requestToken'); + Uri(path: '_matrix/client/v3/register/email/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -2431,7 +2446,7 @@ class Api { String clientSecret, String country, String phoneNumber, int sendAttempt, {String? nextLink, String? idAccessToken, String? idServer}) async { final requestUri = - Uri(path: '_matrix/client/r0/register/msisdn/requestToken'); + Uri(path: '_matrix/client/v3/register/msisdn/requestToken'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ @@ -2456,7 +2471,7 @@ class Api { /// [version] The backup from which to delete the key Future deleteRoomKeys(String version) async { final requestUri = - Uri(path: '_matrix/client/unstable/room_keys/keys', queryParameters: { + Uri(path: '_matrix/client/v3/room_keys/keys', queryParameters: { 'version': version, }); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); @@ -2474,7 +2489,7 @@ class Api { /// [version] The backup from which to retrieve the keys. Future getRoomKeys(String version) async { final requestUri = - Uri(path: '_matrix/client/unstable/room_keys/keys', queryParameters: { + Uri(path: '_matrix/client/v3/room_keys/keys', queryParameters: { 'version': version, }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -2495,7 +2510,7 @@ class Api { Future putRoomKeys( String version, RoomKeys backupData) async { final requestUri = - Uri(path: '_matrix/client/unstable/room_keys/keys', queryParameters: { + Uri(path: '_matrix/client/v3/room_keys/keys', queryParameters: { 'version': version, }); final request = Request('PUT', baseUri!.resolveUri(requestUri)); @@ -2518,8 +2533,7 @@ class Api { Future deleteRoomKeysByRoomId( String roomId, String version) async { final requestUri = Uri( - path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}', + path: '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}', queryParameters: { 'version': version, }); @@ -2541,8 +2555,7 @@ class Api { Future getRoomKeysByRoomId( String roomId, String version) async { final requestUri = Uri( - path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}', + path: '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}', queryParameters: { 'version': version, }); @@ -2566,8 +2579,7 @@ class Api { Future putRoomKeysByRoomId( String roomId, String version, RoomKeyBackup backupData) async { final requestUri = Uri( - path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}', + path: '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}', queryParameters: { 'version': version, }); @@ -2590,11 +2602,11 @@ class Api { /// [sessionId] The ID of the megolm session whose key is to be deleted. /// /// [version] The backup from which to delete the key - Future deleteRoomKeysBySessionId( + Future deleteRoomKeyBySessionId( String roomId, String sessionId, String version) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', + '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', queryParameters: { 'version': version, }); @@ -2615,11 +2627,11 @@ class Api { /// [sessionId] The ID of the megolm session whose key is requested. /// /// [version] The backup from which to retrieve the key. - Future getRoomKeysBySessionId( + Future getRoomKeyBySessionId( String roomId, String sessionId, String version) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', + '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', queryParameters: { 'version': version, }); @@ -2642,11 +2654,11 @@ class Api { /// [version] The backup in which to store the key. Must be the current backup. /// /// [data] The key data. - Future putRoomKeysBySessionId(String roomId, + Future putRoomKeyBySessionId(String roomId, String sessionId, String version, KeyBackupData data) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', + '_matrix/client/v3/room_keys/keys/${Uri.encodeComponent(roomId)}/${Uri.encodeComponent(sessionId)}', queryParameters: { 'version': version, }); @@ -2664,7 +2676,7 @@ class Api { /// Get information about the latest backup version. Future getRoomKeysVersionCurrent() async { - final requestUri = Uri(path: '_matrix/client/unstable/room_keys/version'); + final requestUri = Uri(path: '_matrix/client/v3/room_keys/version'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2687,15 +2699,12 @@ class Api { /// The backup version. This is an opaque string. Future postRoomKeysVersion( BackupAlgorithm algorithm, Map authData) async { - final requestUri = Uri(path: '_matrix/client/unstable/room_keys/version'); + final requestUri = Uri(path: '_matrix/client/v3/room_keys/version'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ - 'algorithm': { - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: - 'm.megolm_backup.v1.curve25519-aes-sha2' - }[algorithm]!, + 'algorithm': algorithm.name, 'auth_data': authData, })); final response = await httpClient.send(request); @@ -2711,12 +2720,12 @@ class Api { /// /// [version] The backup version to delete, as returned in the `version` /// parameter in the response of - /// [`POST /_matrix/client/r0/room_keys/version`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0room_keysversion) - /// or [`GET /_matrix/client/r0/room_keys/version/{version}`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0room_keysversionversion). + /// [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3room_keysversion) + /// or [`GET /_matrix/client/v3/room_keys/version/{version}`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3room_keysversionversion). Future deleteRoomKeysVersion(String version) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/version/${Uri.encodeComponent(version)}'); + '_matrix/client/v3/room_keys/version/${Uri.encodeComponent(version)}'); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2731,12 +2740,12 @@ class Api { /// /// [version] The backup version to get, as returned in the `version` parameter /// of the response in - /// [`POST /_matrix/client/r0/room_keys/version`](https://spec.matrix.org/unstable/client-server/#post_matrixclientr0room_keysversion) + /// [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3room_keysversion) /// or this endpoint. Future getRoomKeysVersion(String version) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/version/${Uri.encodeComponent(version)}'); + '_matrix/client/v3/room_keys/version/${Uri.encodeComponent(version)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2751,8 +2760,8 @@ class Api { /// /// [version] The backup version to update, as returned in the `version` /// parameter in the response of - /// [`POST /_matrix/client/r0/room_keys/version`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0room_keysversion) - /// or [`GET /_matrix/client/r0/room_keys/version/{version}`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0room_keysversionversion). + /// [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3room_keysversion) + /// or [`GET /_matrix/client/v3/room_keys/version/{version}`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3room_keysversionversion). /// /// [algorithm] The algorithm used for storing backups. Must be the same as /// the algorithm currently used by the backup. @@ -2760,19 +2769,16 @@ class Api { /// [authData] Algorithm-dependent data. See the documentation for the backup /// algorithms in [Server-side key backups](https://spec.matrix.org/unstable/client-server-api/#server-side-key-backups) for more information on the /// expected format of the data. - Future putRoomKeysVersion(String version, BackupAlgorithm algorithm, - Map authData) async { + Future> putRoomKeysVersion(String version, + BackupAlgorithm algorithm, Map authData) async { final requestUri = Uri( path: - '_matrix/client/unstable/room_keys/version/${Uri.encodeComponent(version)}'); + '_matrix/client/v3/room_keys/version/${Uri.encodeComponent(version)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; request.bodyBytes = utf8.encode(jsonEncode({ - 'algorithm': { - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: - 'm.megolm_backup.v1.curve25519-aes-sha2' - }[algorithm]!, + 'algorithm': algorithm.name, 'auth_data': authData, })); final response = await httpClient.send(request); @@ -2780,7 +2786,7 @@ class Api { if (response.statusCode != 200) unexpectedResponse(response, responseBody); final responseString = utf8.decode(responseBody); final json = jsonDecode(responseString); - return ignore(json); + return json as Map; } /// Get a list of aliases maintained by the local server for the @@ -2806,7 +2812,7 @@ class Api { /// The server's local aliases on the room. Can be empty. Future> getLocalAliases(String roomId) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/aliases'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/aliases'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2830,7 +2836,7 @@ class Api { /// [userId] The fully qualified user ID of the user being banned. Future ban(String roomId, String userId, {String? reason}) async { final requestUri = - Uri(path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/ban'); + Uri(path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/ban'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -2870,7 +2876,7 @@ class Api { {int? limit, String? filter}) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/context/${Uri.encodeComponent(eventId)}', + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/context/${Uri.encodeComponent(eventId)}', queryParameters: { if (limit != null) 'limit': limit.toString(), if (filter != null) 'filter': filter, @@ -2894,7 +2900,7 @@ class Api { Future getOneRoomEvent(String roomId, String eventId) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/event/${Uri.encodeComponent(eventId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/event/${Uri.encodeComponent(eventId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2918,7 +2924,7 @@ class Api { /// [roomId] The room identifier to forget. Future forgetRoom(String roomId) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/forget'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/forget'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -2934,7 +2940,7 @@ class Api { /// identifier of the invitee, and instead relies on third party identifiers. /// The homeserver uses an identity server to perform the mapping from /// third party identifier to a Matrix identifier. The other is documented in the* - /// [joining rooms section](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0roomsroomidinvite). + /// [joining rooms section](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3roomsroomidinvite). /// /// This API invites a user to participate in a particular room. /// They do not start participating in the room until they actually join the @@ -2984,7 +2990,7 @@ class Api { Future inviteBy3PID(String roomId, String address, String idAccessToken, String idServer, String medium) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/invite'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/invite'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3005,7 +3011,7 @@ class Api { /// *Note that there are two forms of this API, which are documented separately. /// This version of the API requires that the inviter knows the Matrix /// identifier of the invitee. The other is documented in the* - /// [third party invites section](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0roomsroomidinvite-1). + /// [third party invites section](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3roomsroomidinvite-1). /// /// This API invites a user to participate in a particular room. /// They do not start participating in the room until they actually join the @@ -3026,7 +3032,7 @@ class Api { Future inviteUser(String roomId, String userId, {String? reason}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/invite'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/invite'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3051,8 +3057,8 @@ class Api { /// events associated with the room until the user leaves the room. /// /// After a user has joined a room, the room will appear as an entry in the - /// response of the [`/initialSync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0initialsync) - /// and [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync) APIs. + /// response of the [`/initialSync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3initialsync) + /// and [`/sync`](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv3sync) APIs. /// /// [roomId] The room identifier (not alias) to join. /// @@ -3068,7 +3074,7 @@ class Api { Future joinRoomById(String roomId, {String? reason, ThirdPartySigned? thirdPartySigned}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/join'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/join'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3094,7 +3100,7 @@ class Api { Future?> getJoinedMembersByRoom(String roomId) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/joined_members'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/joined_members'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3124,7 +3130,7 @@ class Api { /// [userId] The fully qualified user ID of the user being kicked. Future kick(String roomId, String userId, {String? reason}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/kick'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/kick'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3158,7 +3164,7 @@ class Api { /// membership event. Future leaveRoom(String roomId, {String? reason}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/leave'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/leave'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3194,25 +3200,11 @@ class Api { Future?> getMembersByRoom(String roomId, {String? at, Membership? membership, Membership? notMembership}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/members', + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/members', queryParameters: { if (at != null) 'at': at, - if (membership != null) - 'membership': { - Membership.invite: 'invite', - Membership.join: 'join', - Membership.knock: 'knock', - Membership.leave: 'leave', - Membership.ban: 'ban' - }[membership]!, - if (notMembership != null) - 'not_membership': { - Membership.invite: 'invite', - Membership.join: 'join', - Membership.knock: 'knock', - Membership.leave: 'leave', - Membership.ban: 'ban' - }[notMembership]!, + if (membership != null) 'membership': membership.name, + if (notMembership != null) 'not_membership': notMembership.name, }); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; @@ -3235,16 +3227,21 @@ class Api { /// [roomId] The room to get events from. /// /// [from] The token to start returning events from. This token can be obtained - /// from a `prev_batch` token returned for each room by the sync API, - /// or from a `start` or `end` token returned by a previous request - /// to this endpoint. + /// from a `prev_batch` or `next_batch` token returned by the `/sync` endpoint, + /// or from an `end` token returned by a previous request to this endpoint. + /// + /// This endpoint can also accept a value returned as a `start` token + /// by a previous request to this endpoint, though servers are not + /// required to support this. Clients should not rely on the behaviour. /// /// [to] The token to stop returning events at. This token can be obtained from - /// a `prev_batch` token returned for each room by the sync endpoint, - /// or from a `start` or `end` token returned by a previous request to - /// this endpoint. + /// a `prev_batch` or `next_batch` token returned by the `/sync` endpoint, + /// or from an `end` token returned by a previous request to this endpoint. /// - /// [dir] The direction to return events from. + /// [dir] The direction to return events from. If this is set to `f`, events + /// will be returned in chronological order starting at `from`. If it + /// is set to `b`, events will be returned in *reverse* chronological + /// order, again starting at `from`. /// /// [limit] The maximum number of events to return. Default: 10. /// @@ -3253,11 +3250,11 @@ class Api { String roomId, String from, Direction dir, {String? to, int? limit, String? filter}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/messages', + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/messages', queryParameters: { 'from': from, if (to != null) 'to': to, - 'dir': {Direction.b: 'b', Direction.f: 'f'}[dir]!, + 'dir': dir.name, if (limit != null) 'limit': limit.toString(), if (filter != null) 'filter': filter, }); @@ -3286,7 +3283,7 @@ class Api { {String? mRead}) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/read_markers'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/read_markers'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3317,9 +3314,7 @@ class Api { String eventId, Map receipt) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/receipt/${Uri.encodeComponent({ - ReceiptType.mRead: 'm.read' - }[receiptType]!)}/${Uri.encodeComponent(eventId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/receipt/${Uri.encodeComponent(receiptType.name)}/${Uri.encodeComponent(eventId)}'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3359,7 +3354,7 @@ class Api { {String? reason}) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/redact/${Uri.encodeComponent(eventId)}/${Uri.encodeComponent(txnId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/redact/${Uri.encodeComponent(eventId)}/${Uri.encodeComponent(txnId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3389,7 +3384,7 @@ class Api { {String? reason, int? score}) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/report/${Uri.encodeComponent(eventId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/report/${Uri.encodeComponent(eventId)}'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3427,7 +3422,7 @@ class Api { Map body) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/send/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/send/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3445,7 +3440,7 @@ class Api { /// [roomId] The room to look up the state for. Future> getRoomState(String roomId) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/state'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/state'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3471,7 +3466,7 @@ class Api { String roomId, String eventType, String stateKey) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3514,7 +3509,7 @@ class Api { String stateKey, Map body) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/state/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(stateKey)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3544,7 +3539,7 @@ class Api { {int? timeout}) async { final requestUri = Uri( path: - '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/typing/${Uri.encodeComponent(userId)}'); + '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/typing/${Uri.encodeComponent(userId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3573,7 +3568,7 @@ class Api { /// [userId] The fully qualified user ID of the user being unbanned. Future unban(String roomId, String userId, {String? reason}) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/unban'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/unban'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3599,7 +3594,7 @@ class Api { /// The ID of the new room. Future upgradeRoom(String roomId, String newVersion) async { final requestUri = Uri( - path: '_matrix/client/r0/rooms/${Uri.encodeComponent(roomId)}/upgrade'); + path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/upgrade'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3622,7 +3617,7 @@ class Api { /// [searchCategories] Describes which categories to search in and their criteria. Future search(Categories searchCategories, {String? nextBatch}) async { - final requestUri = Uri(path: '_matrix/client/r0/search', queryParameters: { + final requestUri = Uri(path: '_matrix/client/v3/search', queryParameters: { if (nextBatch != null) 'next_batch': nextBatch, }); final request = Request('POST', baseUri!.resolveUri(requestUri)); @@ -3655,7 +3650,7 @@ class Api { Map>> messages) async { final requestUri = Uri( path: - '_matrix/client/r0/sendToDevice/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}'); + '_matrix/client/v3/sendToDevice/${Uri.encodeComponent(eventType)}/${Uri.encodeComponent(txnId)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3703,7 +3698,8 @@ class Api { /// /// See [Filtering](https://spec.matrix.org/unstable/client-server-api/#filtering) for more information. /// - /// [since] A point in time to continue a sync from. + /// [since] A point in time to continue a sync from. This should be the + /// `next_batch` token returned by an earlier call to this endpoint. /// /// [fullState] Controls whether to include the full state for all rooms the user /// is a member of. @@ -3738,16 +3734,11 @@ class Api { bool? fullState, PresenceType? setPresence, int? timeout}) async { - final requestUri = Uri(path: '_matrix/client/r0/sync', queryParameters: { + final requestUri = Uri(path: '_matrix/client/v3/sync', queryParameters: { if (filter != null) 'filter': filter, if (since != null) 'since': since, if (fullState != null) 'full_state': fullState.toString(), - if (setPresence != null) - 'set_presence': { - PresenceType.online: 'online', - PresenceType.offline: 'offline', - PresenceType.unavailable: 'unavailable' - }[setPresence]!, + if (setPresence != null) 'set_presence': setPresence.name, if (timeout != null) 'timeout': timeout.toString(), }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -3766,7 +3757,7 @@ class Api { /// [alias] The Matrix room alias to look up. Future> queryLocationByAlias(String alias) async { final requestUri = - Uri(path: '_matrix/client/r0/thirdparty/location', queryParameters: { + Uri(path: '_matrix/client/v3/thirdparty/location', queryParameters: { 'alias': alias, }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -3796,7 +3787,7 @@ class Api { {String? searchFields}) async { final requestUri = Uri( path: - '_matrix/client/r0/thirdparty/location/${Uri.encodeComponent(protocol)}', + '_matrix/client/v3/thirdparty/location/${Uri.encodeComponent(protocol)}', queryParameters: { if (searchFields != null) 'searchFields': searchFields, }); @@ -3816,7 +3807,7 @@ class Api { Future getProtocolMetadata(String protocol) async { final requestUri = Uri( path: - '_matrix/client/r0/thirdparty/protocol/${Uri.encodeComponent(protocol)}'); + '_matrix/client/v3/thirdparty/protocol/${Uri.encodeComponent(protocol)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3831,7 +3822,7 @@ class Api { /// homeserver. Includes both the available protocols and all fields /// required for queries against each protocol. Future> getProtocols() async { - final requestUri = Uri(path: '_matrix/client/r0/thirdparty/protocols'); + final requestUri = Uri(path: '_matrix/client/v3/thirdparty/protocols'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3848,7 +3839,7 @@ class Api { /// [userid] The Matrix User ID to look up. Future> queryUserByID(String userid) async { final requestUri = - Uri(path: '_matrix/client/r0/thirdparty/user', queryParameters: { + Uri(path: '_matrix/client/v3/thirdparty/user', queryParameters: { 'userid': userid, }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -3871,7 +3862,7 @@ class Api { {String? fields}) async { final requestUri = Uri( path: - '_matrix/client/r0/thirdparty/user/${Uri.encodeComponent(protocol)}', + '_matrix/client/v3/thirdparty/user/${Uri.encodeComponent(protocol)}', queryParameters: { if (fields != null) 'fields...': fields, }); @@ -3897,7 +3888,7 @@ class Api { String userId, String type) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -3923,7 +3914,7 @@ class Api { String userId, String type, Map content) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/account_data/${Uri.encodeComponent(type)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3951,7 +3942,7 @@ class Api { /// declared filter by homeservers on some APIs. Future defineFilter(String userId, Filter filter) async { final requestUri = Uri( - path: '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/filter'); + path: '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/filter'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -3972,7 +3963,7 @@ class Api { Future getFilter(String userId, String filterId) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/filter/${Uri.encodeComponent(filterId)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/filter/${Uri.encodeComponent(filterId)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4000,7 +3991,7 @@ class Api { String userId, Map body) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/openid/request_token'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/openid/request_token'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -4027,7 +4018,7 @@ class Api { String userId, String roomId, String type) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4055,7 +4046,7 @@ class Api { Map content) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/account_data/${Uri.encodeComponent(type)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -4079,7 +4070,7 @@ class Api { Future?> getRoomTags(String userId, String roomId) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4104,7 +4095,7 @@ class Api { Future deleteRoomTag(String userId, String roomId, String tag) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}'); final request = Request('DELETE', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4131,7 +4122,7 @@ class Api { Map additionalProperties = const {}}) async { final requestUri = Uri( path: - '_matrix/client/r0/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}'); + '_matrix/client/v3/user/${Uri.encodeComponent(userId)}/rooms/${Uri.encodeComponent(roomId)}/tags/${Uri.encodeComponent(tag)}'); final request = Request('PUT', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -4163,7 +4154,7 @@ class Api { /// [searchTerm] The term to search for Future searchUserDirectory(String searchTerm, {int? limit}) async { - final requestUri = Uri(path: '_matrix/client/r0/user_directory/search'); + final requestUri = Uri(path: '_matrix/client/v3/user_directory/search'); final request = Request('POST', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; request.headers['content-type'] = 'application/json'; @@ -4182,7 +4173,7 @@ class Api { /// This API provides credentials for the client to use when initiating /// calls. Future getTurnServer() async { - final requestUri = Uri(path: '_matrix/client/r0/voip/turnServer'); + final requestUri = Uri(path: '_matrix/client/v3/voip/turnServer'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4195,10 +4186,9 @@ class Api { /// Gets the versions of the specification supported by the server. /// - /// Values will take the form `rX.Y.Z`. - /// - /// Only the latest `Z` value will be reported for each supported `X.Y` value. - /// i.e. if the server implements `r0.0.0`, `r0.0.1`, and `r1.2.0`, it will report `r0.0.1` and `r1.2.0`. + /// Values will take the form `vX.Y` or `rX.Y.Z` in historical cases. See + /// [the Specification Versioning](../#specification-versions) for more + /// information. /// /// The server may additionally advertise experimental features it supports /// through `unstable_features`. These features should be namespaced and @@ -4234,7 +4224,7 @@ class Api { /// repository APIs, for example, proxies may enforce a lower upload size limit /// than is advertised by the server on this endpoint. Future getConfig() async { - final requestUri = Uri(path: '_matrix/media/r0/config'); + final requestUri = Uri(path: '_matrix/media/v3/config'); final request = Request('GET', baseUri!.resolveUri(requestUri)); request.headers['authorization'] = 'Bearer ${bearerToken!}'; final response = await httpClient.send(request); @@ -4261,7 +4251,7 @@ class Api { {bool? allowRemote}) async { final requestUri = Uri( path: - '_matrix/media/r0/download/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}', + '_matrix/media/v3/download/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}', queryParameters: { if (allowRemote != null) 'allow_remote': allowRemote.toString(), }); @@ -4294,7 +4284,7 @@ class Api { {bool? allowRemote}) async { final requestUri = Uri( path: - '_matrix/media/r0/download/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}/${Uri.encodeComponent(fileName)}', + '_matrix/media/v3/download/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}/${Uri.encodeComponent(fileName)}', queryParameters: { if (allowRemote != null) 'allow_remote': allowRemote.toString(), }); @@ -4322,7 +4312,7 @@ class Api { /// available. Future getUrlPreview(Uri url, {int? ts}) async { final requestUri = - Uri(path: '_matrix/media/r0/preview_url', queryParameters: { + Uri(path: '_matrix/media/v3/preview_url', queryParameters: { 'url': url.toString(), if (ts != null) 'ts': ts.toString(), }); @@ -4362,12 +4352,11 @@ class Api { {Method? method, bool? allowRemote}) async { final requestUri = Uri( path: - '_matrix/media/r0/thumbnail/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}', + '_matrix/media/v3/thumbnail/${Uri.encodeComponent(serverName)}/${Uri.encodeComponent(mediaId)}', queryParameters: { 'width': width.toString(), 'height': height.toString(), - if (method != null) - 'method': {Method.crop: 'crop', Method.scale: 'scale'}[method]!, + if (method != null) 'method': method.name, if (allowRemote != null) 'allow_remote': allowRemote.toString(), }); final request = Request('GET', baseUri!.resolveUri(requestUri)); @@ -4390,7 +4379,7 @@ class Api { /// The [MXC URI](https://spec.matrix.org/unstable/client-server-api/#matrix-content-mxc-uris) to the uploaded content. Future uploadContent(Uint8List content, {String? filename, String? contentType}) async { - final requestUri = Uri(path: '_matrix/media/r0/upload', queryParameters: { + final requestUri = Uri(path: '_matrix/media/v3/upload', queryParameters: { if (filename != null) 'filename': filename, }); final request = Request('POST', baseUri!.resolveUri(requestUri)); diff --git a/lib/src/generated/model.dart b/lib/src/generated/model.dart index edc8d356..db8cb054 100644 --- a/lib/src/generated/model.dart +++ b/lib/src/generated/model.dart @@ -6,6 +6,8 @@ import '../model/sync_update.dart'; import '../model/matrix_event.dart'; import 'internal.dart'; +import 'package:enhanced_enum/enhanced_enum.dart'; +part 'model.g.dart'; class _NameSource { final String source; @@ -82,8 +84,238 @@ class DiscoveryInformation { Map> additionalProperties; } +@_NameSource('spec') +class PublicRoomsChunk { + PublicRoomsChunk({ + this.avatarUrl, + this.canonicalAlias, + required this.guestCanJoin, + this.joinRule, + this.name, + required this.numJoinedMembers, + required this.roomId, + this.topic, + required this.worldReadable, + }); + + PublicRoomsChunk.fromJson(Map json) + : avatarUrl = + ((v) => v != null ? Uri.parse(v) : null)(json['avatar_url']), + canonicalAlias = + ((v) => v != null ? v as String : null)(json['canonical_alias']), + guestCanJoin = json['guest_can_join'] as bool, + joinRule = ((v) => v != null ? v as String : null)(json['join_rule']), + name = ((v) => v != null ? v as String : null)(json['name']), + numJoinedMembers = json['num_joined_members'] as int, + roomId = json['room_id'] as String, + topic = ((v) => v != null ? v as String : null)(json['topic']), + worldReadable = json['world_readable'] as bool; + Map toJson() { + final avatarUrl = this.avatarUrl; + final canonicalAlias = this.canonicalAlias; + final joinRule = this.joinRule; + final name = this.name; + final topic = this.topic; + return { + if (avatarUrl != null) 'avatar_url': avatarUrl.toString(), + if (canonicalAlias != null) 'canonical_alias': canonicalAlias, + 'guest_can_join': guestCanJoin, + if (joinRule != null) 'join_rule': joinRule, + if (name != null) 'name': name, + 'num_joined_members': numJoinedMembers, + 'room_id': roomId, + if (topic != null) 'topic': topic, + 'world_readable': worldReadable, + }; + } + + /// The URL for the room's avatar, if one is set. + Uri? avatarUrl; + + /// The canonical alias of the room, if any. + String? canonicalAlias; + + /// Whether guest users may join the room and participate in it. + /// If they can, they will be subject to ordinary power level + /// rules like any other user. + bool guestCanJoin; + + /// The room's join rule. When not present, the room is assumed to + /// be `public`. + String? joinRule; + + /// The name of the room, if any. + String? name; + + /// The number of members joined to the room. + int numJoinedMembers; + + /// The ID of the room. + String roomId; + + /// The topic of the room, if any. + String? topic; + + /// Whether the room may be viewed by guest users without joining. + bool worldReadable; +} + @_NameSource('rule override generated') -enum ThirdPartyIdentifierMedium { email, msisdn } +class SpaceRoomsChunkBase { + SpaceRoomsChunkBase({ + required this.childrenState, + required this.roomType, + }); + + SpaceRoomsChunkBase.fromJson(Map json) + : childrenState = (json['children_state'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList(), + roomType = json['room_type'] as String; + Map toJson() => { + 'children_state': childrenState.map((v) => v.toJson()).toList(), + 'room_type': roomType, + }; + + /// The [`m.space.child`](#mspacechild) events of the space-room, represented + /// as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key. + /// + /// If the room is not a space-room, this should be empty. + List childrenState; + + /// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any. + String roomType; +} + +@_NameSource('rule override generated') +class SpaceRoomsChunk implements PublicRoomsChunk, SpaceRoomsChunkBase { + SpaceRoomsChunk({ + this.avatarUrl, + this.canonicalAlias, + required this.guestCanJoin, + this.joinRule, + this.name, + required this.numJoinedMembers, + required this.roomId, + this.topic, + required this.worldReadable, + required this.childrenState, + required this.roomType, + }); + + SpaceRoomsChunk.fromJson(Map json) + : avatarUrl = + ((v) => v != null ? Uri.parse(v) : null)(json['avatar_url']), + canonicalAlias = + ((v) => v != null ? v as String : null)(json['canonical_alias']), + guestCanJoin = json['guest_can_join'] as bool, + joinRule = ((v) => v != null ? v as String : null)(json['join_rule']), + name = ((v) => v != null ? v as String : null)(json['name']), + numJoinedMembers = json['num_joined_members'] as int, + roomId = json['room_id'] as String, + topic = ((v) => v != null ? v as String : null)(json['topic']), + worldReadable = json['world_readable'] as bool, + childrenState = (json['children_state'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList(), + roomType = json['room_type'] as String; + Map toJson() { + final avatarUrl = this.avatarUrl; + final canonicalAlias = this.canonicalAlias; + final joinRule = this.joinRule; + final name = this.name; + final topic = this.topic; + return { + if (avatarUrl != null) 'avatar_url': avatarUrl.toString(), + if (canonicalAlias != null) 'canonical_alias': canonicalAlias, + 'guest_can_join': guestCanJoin, + if (joinRule != null) 'join_rule': joinRule, + if (name != null) 'name': name, + 'num_joined_members': numJoinedMembers, + 'room_id': roomId, + if (topic != null) 'topic': topic, + 'world_readable': worldReadable, + 'children_state': childrenState.map((v) => v.toJson()).toList(), + 'room_type': roomType, + }; + } + + /// The URL for the room's avatar, if one is set. + Uri? avatarUrl; + + /// The canonical alias of the room, if any. + String? canonicalAlias; + + /// Whether guest users may join the room and participate in it. + /// If they can, they will be subject to ordinary power level + /// rules like any other user. + bool guestCanJoin; + + /// The room's join rule. When not present, the room is assumed to + /// be `public`. + String? joinRule; + + /// The name of the room, if any. + String? name; + + /// The number of members joined to the room. + int numJoinedMembers; + + /// The ID of the room. + String roomId; + + /// The topic of the room, if any. + String? topic; + + /// Whether the room may be viewed by guest users without joining. + bool worldReadable; + + /// The [`m.space.child`](#mspacechild) events of the space-room, represented + /// as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key. + /// + /// If the room is not a space-room, this should be empty. + List childrenState; + + /// The `type` of room (from [`m.room.create`](https://spec.matrix.org/unstable/client-server-api/#mroomcreate)), if any. + String roomType; +} + +@_NameSource('generated') +class GetSpaceHierarchyResponse { + GetSpaceHierarchyResponse({ + this.nextBatch, + required this.rooms, + }); + + GetSpaceHierarchyResponse.fromJson(Map json) + : nextBatch = ((v) => v != null ? v as String : null)(json['next_batch']), + rooms = (json['rooms'] as List) + .map((v) => SpaceRoomsChunk.fromJson(v)) + .toList(); + Map toJson() { + final nextBatch = this.nextBatch; + return { + if (nextBatch != null) 'next_batch': nextBatch, + 'rooms': rooms.map((v) => v.toJson()).toList(), + }; + } + + /// A token to supply to `from` to keep paginating the responses. Not present when there are + /// no further results. + String? nextBatch; + + /// The rooms for the current page, with the current filters. + List rooms; +} + +@_NameSource('rule override generated') +@EnhancedEnum() +enum ThirdPartyIdentifierMedium { + @EnhancedEnumValue(name: 'email') + email, + @EnhancedEnumValue(name: 'msisdn') + msisdn +} @_NameSource('spec') class ThirdPartyIdentifier { @@ -97,18 +329,12 @@ class ThirdPartyIdentifier { ThirdPartyIdentifier.fromJson(Map json) : addedAt = json['added_at'] as int, address = json['address'] as String, - medium = { - 'email': ThirdPartyIdentifierMedium.email, - 'msisdn': ThirdPartyIdentifierMedium.msisdn - }[json['medium']]!, + medium = ThirdPartyIdentifierMedium.values.fromString(json['medium'])!, validatedAt = json['validated_at'] as int; Map toJson() => { 'added_at': addedAt, 'address': address, - 'medium': { - ThirdPartyIdentifierMedium.email: 'email', - ThirdPartyIdentifierMedium.msisdn: 'msisdn' - }[medium]!, + 'medium': medium.name, 'validated_at': validatedAt, }; @@ -163,7 +389,13 @@ class ThreePidCredentials { } @_NameSource('generated') -enum IdServerUnbindResult { noSupport, success } +@EnhancedEnum() +enum IdServerUnbindResult { + @EnhancedEnumValue(name: 'no-support') + noSupport, + @EnhancedEnumValue(name: 'success') + success +} @_NameSource('spec') class RequestTokenResponse { @@ -206,16 +438,20 @@ class RequestTokenResponse { class TokenOwnerInfo { TokenOwnerInfo({ this.deviceId, + this.isGuest, required this.userId, }); TokenOwnerInfo.fromJson(Map json) : deviceId = ((v) => v != null ? v as String : null)(json['device_id']), + isGuest = ((v) => v != null ? v as bool : null)(json['is_guest']), userId = json['user_id'] as String; Map toJson() { final deviceId = this.deviceId; + final isGuest = this.isGuest; return { if (deviceId != null) 'device_id': deviceId, + if (isGuest != null) 'is_guest': isGuest, 'user_id': userId, }; } @@ -226,6 +462,11 @@ class TokenOwnerInfo { /// Otherwise this is required. String? deviceId; + /// When `true`, the user is a [Guest User](#guest-access). When + /// not present or `false`, the user is presumed to be a non-guest + /// user. + bool? isGuest; + /// The user ID that owns the access token. String userId; } @@ -355,7 +596,13 @@ class ChangePasswordCapability { /// The stability of the room version. @_NameSource('rule override generated') -enum RoomVersionAvailable { stable, unstable } +@EnhancedEnum() +enum RoomVersionAvailable { + @EnhancedEnumValue(name: 'stable') + stable, + @EnhancedEnumValue(name: 'unstable') + unstable +} @_NameSource('spec') class RoomVersionsCapability { @@ -365,21 +612,11 @@ class RoomVersionsCapability { }); RoomVersionsCapability.fromJson(Map json) - : available = (json['available'] as Map).map((k, v) => - MapEntry( - k, - { - 'stable': RoomVersionAvailable.stable, - 'unstable': RoomVersionAvailable.unstable - }[v]!)), + : available = (json['available'] as Map).map( + (k, v) => MapEntry(k, RoomVersionAvailable.values.fromString(v)!)), default$ = json['default'] as String; Map toJson() => { - 'available': available.map((k, v) => MapEntry( - k, - { - RoomVersionAvailable.stable: 'stable', - RoomVersionAvailable.unstable: 'unstable' - }[v]!)), + 'available': available.map((k, v) => MapEntry(k, v.name)), 'default': default$, }; @@ -497,10 +734,24 @@ class Invite3pid { } @_NameSource('rule override generated') -enum CreateRoomPreset { privateChat, publicChat, trustedPrivateChat } +@EnhancedEnum() +enum CreateRoomPreset { + @EnhancedEnumValue(name: 'private_chat') + privateChat, + @EnhancedEnumValue(name: 'public_chat') + publicChat, + @EnhancedEnumValue(name: 'trusted_private_chat') + trustedPrivateChat +} @_NameSource('generated') -enum Visibility { private, public } +@EnhancedEnum() +enum Visibility { + @EnhancedEnumValue(name: 'private') + private, + @EnhancedEnumValue(name: 'public') + public +} /// A client device @_NameSource('spec') @@ -576,15 +827,52 @@ class GetRoomIdByAliasResponse { List? servers; } -@_NameSource('rule override generated') -class EventsSyncUpdate { - EventsSyncUpdate({ +@_NameSource('generated') +class GetEventsResponse { + GetEventsResponse({ this.chunk, this.end, this.start, }); - EventsSyncUpdate.fromJson(Map json) + GetEventsResponse.fromJson(Map json) + : chunk = ((v) => v != null + ? (v as List).map((v) => MatrixEvent.fromJson(v)).toList() + : null)(json['chunk']), + end = ((v) => v != null ? v as String : null)(json['end']), + start = ((v) => v != null ? v as String : null)(json['start']); + Map toJson() { + final chunk = this.chunk; + final end = this.end; + final start = this.start; + return { + if (chunk != null) 'chunk': chunk.map((v) => v.toJson()).toList(), + if (end != null) 'end': end, + if (start != null) 'start': start, + }; + } + + /// An array of events. + List? chunk; + + /// A token which correlates to the end of `chunk`. This + /// token should be used in the next request to `/events`. + String? end; + + /// A token which correlates to the start of `chunk`. This + /// is usually the same token supplied to `from=`. + String? start; +} + +@_NameSource('generated') +class PeekEventsResponse { + PeekEventsResponse({ + this.chunk, + this.end, + this.start, + }); + + PeekEventsResponse.fromJson(Map json) : chunk = ((v) => v != null ? (v as List).map((v) => MatrixEvent.fromJson(v)).toList() : null)(json['chunk']), @@ -727,6 +1015,9 @@ class ClaimKeysResponse { /// /// See the [key algorithms](https://spec.matrix.org/unstable/client-server-api/#key-algorithms) section for information /// on the Key Object format. + /// + /// If necessary, the claimed key might be a fallback key. Fallback + /// keys are re-used by the server until replaced by the device. Map> oneTimeKeys; } @@ -844,7 +1135,13 @@ class LoginFlow { } @_NameSource('rule override generated') -enum LoginType { mLoginPassword, mLoginToken } +@EnhancedEnum() +enum LoginType { + @EnhancedEnumValue(name: 'm.login.password') + mLoginPassword, + @EnhancedEnumValue(name: 'm.login.token') + mLoginToken +} @_NameSource('generated') class LoginResponse { @@ -990,7 +1287,15 @@ class GetNotificationsResponse { } @_NameSource('rule override generated') -enum PresenceType { offline, online, unavailable } +@EnhancedEnum() +enum PresenceType { + @EnhancedEnumValue(name: 'offline') + offline, + @EnhancedEnumValue(name: 'online') + online, + @EnhancedEnumValue(name: 'unavailable') + unavailable +} @_NameSource('generated') class GetPresenceResponse { @@ -1006,11 +1311,7 @@ class GetPresenceResponse { ((v) => v != null ? v as bool : null)(json['currently_active']), lastActiveAgo = ((v) => v != null ? v as int : null)(json['last_active_ago']), - presence = { - 'online': PresenceType.online, - 'offline': PresenceType.offline, - 'unavailable': PresenceType.unavailable - }[json['presence']]!, + presence = PresenceType.values.fromString(json['presence'])!, statusMsg = ((v) => v != null ? v as String : null)(json['status_msg']); Map toJson() { final currentlyActive = this.currentlyActive; @@ -1019,11 +1320,7 @@ class GetPresenceResponse { return { if (currentlyActive != null) 'currently_active': currentlyActive, if (lastActiveAgo != null) 'last_active_ago': lastActiveAgo, - 'presence': { - PresenceType.online: 'online', - PresenceType.offline: 'offline', - PresenceType.unavailable: 'unavailable' - }[presence]!, + 'presence': presence.name, if (statusMsg != null) 'status_msg': statusMsg, }; } @@ -1070,93 +1367,6 @@ class ProfileInformation { String? displayname; } -@_NameSource('spec') -class PublicRoomsChunk { - PublicRoomsChunk({ - this.aliases, - this.avatarUrl, - this.canonicalAlias, - required this.guestCanJoin, - this.joinRule, - this.name, - required this.numJoinedMembers, - required this.roomId, - this.topic, - required this.worldReadable, - }); - - PublicRoomsChunk.fromJson(Map json) - : aliases = ((v) => v != null - ? (v as List).map((v) => v as String).toList() - : null)(json['aliases']), - avatarUrl = - ((v) => v != null ? Uri.parse(v) : null)(json['avatar_url']), - canonicalAlias = - ((v) => v != null ? v as String : null)(json['canonical_alias']), - guestCanJoin = json['guest_can_join'] as bool, - joinRule = ((v) => v != null ? v as String : null)(json['join_rule']), - name = ((v) => v != null ? v as String : null)(json['name']), - numJoinedMembers = json['num_joined_members'] as int, - roomId = json['room_id'] as String, - topic = ((v) => v != null ? v as String : null)(json['topic']), - worldReadable = json['world_readable'] as bool; - Map toJson() { - final aliases = this.aliases; - final avatarUrl = this.avatarUrl; - final canonicalAlias = this.canonicalAlias; - final joinRule = this.joinRule; - final name = this.name; - final topic = this.topic; - return { - if (aliases != null) 'aliases': aliases.map((v) => v).toList(), - if (avatarUrl != null) 'avatar_url': avatarUrl.toString(), - if (canonicalAlias != null) 'canonical_alias': canonicalAlias, - 'guest_can_join': guestCanJoin, - if (joinRule != null) 'join_rule': joinRule, - if (name != null) 'name': name, - 'num_joined_members': numJoinedMembers, - 'room_id': roomId, - if (topic != null) 'topic': topic, - 'world_readable': worldReadable, - }; - } - - /// Aliases of the room. May be empty. - List? aliases; - - /// The URL for the room's avatar, if one is set. - Uri? avatarUrl; - - /// The canonical alias of the room, if any. - String? canonicalAlias; - - /// Whether guest users may join the room and participate in it. - /// If they can, they will be subject to ordinary power level - /// rules like any other user. - bool guestCanJoin; - - /// The room's join rule. When not present, the room is assumed to - /// be `public`. Note that rooms with `invite` join rules are not - /// expected here, but rooms with `knock` rules are given their - /// near-public nature. - String? joinRule; - - /// The name of the room, if any. - String? name; - - /// The number of members joined to the room. - int numJoinedMembers; - - /// The ID of the room. - String roomId; - - /// The topic of the room, if any. - String? topic; - - /// Whether the room may be viewed by guest users without joining. - bool worldReadable; -} - /// A list of the rooms on the server. @_NameSource('generated') class GetPublicRoomsResponse { @@ -1453,9 +1663,7 @@ class PushCondition { String kind; /// Required for `event_match` conditions. The glob-style pattern to - /// match against. Patterns with no special glob characters should be - /// treated as having asterisks prepended and appended when testing the - /// condition. + /// match against. String? pattern; } @@ -1570,10 +1778,28 @@ class PushRuleSet { } @_NameSource('rule override generated') -enum PushRuleKind { content, override, room, sender, underride } +@EnhancedEnum() +enum PushRuleKind { + @EnhancedEnumValue(name: 'content') + content, + @EnhancedEnumValue(name: 'override') + override, + @EnhancedEnumValue(name: 'room') + room, + @EnhancedEnumValue(name: 'sender') + sender, + @EnhancedEnumValue(name: 'underride') + underride +} @_NameSource('rule override generated') -enum AccountKind { guest, user } +@EnhancedEnum() +enum AccountKind { + @EnhancedEnumValue(name: 'guest') + guest, + @EnhancedEnumValue(name: 'user') + user +} @_NameSource('generated') class RegisterResponse { @@ -1725,7 +1951,11 @@ class RoomKeys { } @_NameSource('rule override generated') -enum BackupAlgorithm { mMegolmBackupV1Curve25519AesSha2 } +@EnhancedEnum() +enum BackupAlgorithm { + @EnhancedEnumValue(name: 'm.megolm_backup.v1.curve25519-aes-sha2') + mMegolmBackupV1Curve25519AesSha2 +} @_NameSource('generated') class GetRoomKeysVersionCurrentResponse { @@ -1738,19 +1968,13 @@ class GetRoomKeysVersionCurrentResponse { }); GetRoomKeysVersionCurrentResponse.fromJson(Map json) - : algorithm = { - 'm.megolm_backup.v1.curve25519-aes-sha2': - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2 - }[json['algorithm']]!, + : algorithm = BackupAlgorithm.values.fromString(json['algorithm'])!, authData = json['auth_data'] as Map, count = json['count'] as int, etag = json['etag'] as String, version = json['version'] as String; Map toJson() => { - 'algorithm': { - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: - 'm.megolm_backup.v1.curve25519-aes-sha2' - }[algorithm]!, + 'algorithm': algorithm.name, 'auth_data': authData, 'count': count, 'etag': etag, @@ -1789,19 +2013,13 @@ class GetRoomKeysVersionResponse { }); GetRoomKeysVersionResponse.fromJson(Map json) - : algorithm = { - 'm.megolm_backup.v1.curve25519-aes-sha2': - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2 - }[json['algorithm']]!, + : algorithm = BackupAlgorithm.values.fromString(json['algorithm'])!, authData = json['auth_data'] as Map, count = json['count'] as int, etag = json['etag'] as String, version = json['version'] as String; Map toJson() => { - 'algorithm': { - BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: - 'm.megolm_backup.v1.curve25519-aes-sha2' - }[algorithm]!, + 'algorithm': algorithm.name, 'auth_data': authData, 'count': count, 'etag': etag, @@ -1924,56 +2142,81 @@ class RoomMember { } @_NameSource('(generated, rule override generated)') -enum Membership { ban, invite, join, knock, leave } +@EnhancedEnum() +enum Membership { + @EnhancedEnumValue(name: 'ban') + ban, + @EnhancedEnumValue(name: 'invite') + invite, + @EnhancedEnumValue(name: 'join') + join, + @EnhancedEnumValue(name: 'knock') + knock, + @EnhancedEnumValue(name: 'leave') + leave +} @_NameSource('rule override generated') -enum Direction { b, f } +@EnhancedEnum() +enum Direction { + @EnhancedEnumValue(name: 'b') + b, + @EnhancedEnumValue(name: 'f') + f +} /// A list of messages with a new token to request more. @_NameSource('generated') class GetRoomEventsResponse { GetRoomEventsResponse({ - this.chunk, + required this.chunk, this.end, - this.start, + required this.start, this.state, }); GetRoomEventsResponse.fromJson(Map json) - : chunk = ((v) => v != null - ? (v as List).map((v) => MatrixEvent.fromJson(v)).toList() - : null)(json['chunk']), + : chunk = (json['chunk'] as List) + .map((v) => MatrixEvent.fromJson(v)) + .toList(), end = ((v) => v != null ? v as String : null)(json['end']), - start = ((v) => v != null ? v as String : null)(json['start']), + start = json['start'] as String, state = ((v) => v != null ? (v as List).map((v) => MatrixEvent.fromJson(v)).toList() : null)(json['state']); Map toJson() { - final chunk = this.chunk; final end = this.end; - final start = this.start; final state = this.state; return { - if (chunk != null) 'chunk': chunk.map((v) => v.toJson()).toList(), + 'chunk': chunk.map((v) => v.toJson()).toList(), if (end != null) 'end': end, - if (start != null) 'start': start, + 'start': start, if (state != null) 'state': state.map((v) => v.toJson()).toList(), }; } /// A list of room events. The order depends on the `dir` parameter. /// For `dir=b` events will be in reverse-chronological order, - /// for `dir=f` in chronological order, so that events start - /// at the `from` point. - List? chunk; + /// for `dir=f` in chronological order. (The exact definition of `chronological` + /// is dependent on the server implementation.) + /// + /// Note that an empty `chunk` does not *necessarily* imply that no more events + /// are available. Clients should continue to paginate until no `end` property + /// is returned. + List chunk; - /// The token the pagination ends at. If `dir=b` this token should - /// be used again to request even earlier events. + /// A token corresponding to the end of `chunk`. This token can be passed + /// back to this endpoint to request further events. + /// + /// If no further events are available (either because we have + /// reached the start of the timeline, or because the user does + /// not have permission to see any more events), this property + /// is omitted from the response. String? end; - /// The token the pagination starts from. If `dir=b` this will be - /// the token supplied in `from`. - String? start; + /// A token corresponding to the start of `chunk`. This will be the same as + /// the value given in `from`. + String start; /// A list of state events relevant to showing the `chunk`. For example, if /// `lazy_load_members` is enabled in the filter then this may contain @@ -1987,7 +2230,11 @@ class GetRoomEventsResponse { } @_NameSource('generated') -enum ReceiptType { mRead } +@EnhancedEnum() +enum ReceiptType { + @EnhancedEnumValue(name: 'm.read') + mRead +} @_NameSource('spec') class IncludeEventContext { @@ -2250,7 +2497,13 @@ class SearchFilter implements EventFilter, RoomEventFilter { } @_NameSource('rule override generated') -enum GroupKey { roomId, sender } +@EnhancedEnum() +enum GroupKey { + @EnhancedEnumValue(name: 'room_id') + roomId, + @EnhancedEnumValue(name: 'sender') + sender +} /// Configuration for group. @_NameSource('spec') @@ -2260,14 +2513,12 @@ class Group { }); Group.fromJson(Map json) - : key = ((v) => v != null - ? {'room_id': GroupKey.roomId, 'sender': GroupKey.sender}[v]! - : null)(json['key']); + : key = ((v) => + v != null ? GroupKey.values.fromString(v)! : null)(json['key']); Map toJson() { final key = this.key; return { - if (key != null) - 'key': {GroupKey.roomId: 'room_id', GroupKey.sender: 'sender'}[key]!, + if (key != null) 'key': key.name, }; } @@ -2297,10 +2548,24 @@ class Groupings { } @_NameSource('rule override generated') -enum KeyKind { contentBody, contentName, contentTopic } +@EnhancedEnum() +enum KeyKind { + @EnhancedEnumValue(name: 'content.body') + contentBody, + @EnhancedEnumValue(name: 'content.name') + contentName, + @EnhancedEnumValue(name: 'content.topic') + contentTopic +} @_NameSource('rule override generated') -enum SearchOrder { rank, recent } +@EnhancedEnum() +enum SearchOrder { + @EnhancedEnumValue(name: 'rank') + rank, + @EnhancedEnumValue(name: 'recent') + recent +} @_NameSource('spec') class RoomEventsCriteria { @@ -2325,17 +2590,10 @@ class RoomEventsCriteria { includeState = ((v) => v != null ? v as bool : null)(json['include_state']), keys = ((v) => v != null - ? (v as List) - .map((v) => { - 'content.body': KeyKind.contentBody, - 'content.name': KeyKind.contentName, - 'content.topic': KeyKind.contentTopic - }[v]!) - .toList() + ? (v as List).map((v) => KeyKind.values.fromString(v)!).toList() : null)(json['keys']), - orderBy = ((v) => v != null - ? {'recent': SearchOrder.recent, 'rank': SearchOrder.rank}[v]! - : null)(json['order_by']), + orderBy = ((v) => v != null ? SearchOrder.values.fromString(v)! : null)( + json['order_by']), searchTerm = json['search_term'] as String; Map toJson() { final eventContext = this.eventContext; @@ -2349,19 +2607,8 @@ class RoomEventsCriteria { if (filter != null) 'filter': filter.toJson(), if (groupings != null) 'groupings': groupings.toJson(), if (includeState != null) 'include_state': includeState, - if (keys != null) - 'keys': keys - .map((v) => { - KeyKind.contentBody: 'content.body', - KeyKind.contentName: 'content.name', - KeyKind.contentTopic: 'content.topic' - }[v]!) - .toList(), - if (orderBy != null) - 'order_by': { - SearchOrder.recent: 'recent', - SearchOrder.rank: 'rank' - }[orderBy]!, + if (keys != null) 'keys': keys.map((v) => v.name).toList(), + if (orderBy != null) 'order_by': orderBy.name, 'search_term': searchTerm, }; } @@ -2872,7 +3119,13 @@ class ThirdPartyUser { } @_NameSource('generated') -enum EventFormat { client, federation } +@EnhancedEnum() +enum EventFormat { + @EnhancedEnumValue(name: 'client') + client, + @EnhancedEnumValue(name: 'federation') + federation +} @_NameSource('rule override generated') class StateFilter implements EventFilter, RoomEventFilter { @@ -3065,10 +3318,7 @@ class Filter { ? (v as List).map((v) => v as String).toList() : null)(json['event_fields']), eventFormat = ((v) => v != null - ? { - 'client': EventFormat.client, - 'federation': EventFormat.federation - }[v]! + ? EventFormat.values.fromString(v)! : null)(json['event_format']), presence = ((v) => v != null ? EventFilter.fromJson(v) : null)(json['presence']), @@ -3083,11 +3333,7 @@ class Filter { if (accountData != null) 'account_data': accountData.toJson(), if (eventFields != null) 'event_fields': eventFields.map((v) => v).toList(), - if (eventFormat != null) - 'event_format': { - EventFormat.client: 'client', - EventFormat.federation: 'federation' - }[eventFormat]!, + if (eventFormat != null) 'event_format': eventFormat.name, if (presence != null) 'presence': presence.toJson(), if (room != null) 'room': room.toJson(), }; @@ -3346,4 +3592,10 @@ class GetUrlPreviewResponse { } @_NameSource('generated') -enum Method { crop, scale } +@EnhancedEnum() +enum Method { + @EnhancedEnumValue(name: 'crop') + crop, + @EnhancedEnumValue(name: 'scale') + scale +} diff --git a/lib/src/generated/model.g.dart b/lib/src/generated/model.g.dart new file mode 100644 index 00000000..b5f907e3 --- /dev/null +++ b/lib/src/generated/model.g.dart @@ -0,0 +1,802 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'model.dart'; + +// ************************************************************************** +// EnhancedEnumGenerator +// ************************************************************************** + +extension ThirdPartyIdentifierMediumFromStringExtension + on Iterable { + ThirdPartyIdentifierMedium? fromString(String val) { + final override = { + 'email': ThirdPartyIdentifierMedium.email, + 'msisdn': ThirdPartyIdentifierMedium.msisdn, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension ThirdPartyIdentifierMediumEnhancedEnum on ThirdPartyIdentifierMedium { + @override +// ignore: override_on_non_overriding_member + String get name => { + ThirdPartyIdentifierMedium.email: 'email', + ThirdPartyIdentifierMedium.msisdn: 'msisdn', + }[this]!; + bool get isEmail => this == ThirdPartyIdentifierMedium.email; + bool get isMsisdn => this == ThirdPartyIdentifierMedium.msisdn; + T when({ + required T Function() email, + required T Function() msisdn, + }) => + { + ThirdPartyIdentifierMedium.email: email, + ThirdPartyIdentifierMedium.msisdn: msisdn, + }[this]!(); + T maybeWhen({ + T? Function()? email, + T? Function()? msisdn, + required T Function() orElse, + }) => + { + ThirdPartyIdentifierMedium.email: email, + ThirdPartyIdentifierMedium.msisdn: msisdn, + }[this] + ?.call() ?? + orElse(); +} + +extension IdServerUnbindResultFromStringExtension + on Iterable { + IdServerUnbindResult? fromString(String val) { + final override = { + 'no-support': IdServerUnbindResult.noSupport, + 'success': IdServerUnbindResult.success, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension IdServerUnbindResultEnhancedEnum on IdServerUnbindResult { + @override +// ignore: override_on_non_overriding_member + String get name => { + IdServerUnbindResult.noSupport: 'no-support', + IdServerUnbindResult.success: 'success', + }[this]!; + bool get isNoSupport => this == IdServerUnbindResult.noSupport; + bool get isSuccess => this == IdServerUnbindResult.success; + T when({ + required T Function() noSupport, + required T Function() success, + }) => + { + IdServerUnbindResult.noSupport: noSupport, + IdServerUnbindResult.success: success, + }[this]!(); + T maybeWhen({ + T? Function()? noSupport, + T? Function()? success, + required T Function() orElse, + }) => + { + IdServerUnbindResult.noSupport: noSupport, + IdServerUnbindResult.success: success, + }[this] + ?.call() ?? + orElse(); +} + +extension RoomVersionAvailableFromStringExtension + on Iterable { + RoomVersionAvailable? fromString(String val) { + final override = { + 'stable': RoomVersionAvailable.stable, + 'unstable': RoomVersionAvailable.unstable, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension RoomVersionAvailableEnhancedEnum on RoomVersionAvailable { + @override +// ignore: override_on_non_overriding_member + String get name => { + RoomVersionAvailable.stable: 'stable', + RoomVersionAvailable.unstable: 'unstable', + }[this]!; + bool get isStable => this == RoomVersionAvailable.stable; + bool get isUnstable => this == RoomVersionAvailable.unstable; + T when({ + required T Function() stable, + required T Function() unstable, + }) => + { + RoomVersionAvailable.stable: stable, + RoomVersionAvailable.unstable: unstable, + }[this]!(); + T maybeWhen({ + T? Function()? stable, + T? Function()? unstable, + required T Function() orElse, + }) => + { + RoomVersionAvailable.stable: stable, + RoomVersionAvailable.unstable: unstable, + }[this] + ?.call() ?? + orElse(); +} + +extension CreateRoomPresetFromStringExtension on Iterable { + CreateRoomPreset? fromString(String val) { + final override = { + 'private_chat': CreateRoomPreset.privateChat, + 'public_chat': CreateRoomPreset.publicChat, + 'trusted_private_chat': CreateRoomPreset.trustedPrivateChat, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension CreateRoomPresetEnhancedEnum on CreateRoomPreset { + @override +// ignore: override_on_non_overriding_member + String get name => { + CreateRoomPreset.privateChat: 'private_chat', + CreateRoomPreset.publicChat: 'public_chat', + CreateRoomPreset.trustedPrivateChat: 'trusted_private_chat', + }[this]!; + bool get isPrivateChat => this == CreateRoomPreset.privateChat; + bool get isPublicChat => this == CreateRoomPreset.publicChat; + bool get isTrustedPrivateChat => this == CreateRoomPreset.trustedPrivateChat; + T when({ + required T Function() privateChat, + required T Function() publicChat, + required T Function() trustedPrivateChat, + }) => + { + CreateRoomPreset.privateChat: privateChat, + CreateRoomPreset.publicChat: publicChat, + CreateRoomPreset.trustedPrivateChat: trustedPrivateChat, + }[this]!(); + T maybeWhen({ + T? Function()? privateChat, + T? Function()? publicChat, + T? Function()? trustedPrivateChat, + required T Function() orElse, + }) => + { + CreateRoomPreset.privateChat: privateChat, + CreateRoomPreset.publicChat: publicChat, + CreateRoomPreset.trustedPrivateChat: trustedPrivateChat, + }[this] + ?.call() ?? + orElse(); +} + +extension VisibilityFromStringExtension on Iterable { + Visibility? fromString(String val) { + final override = { + 'private': Visibility.private, + 'public': Visibility.public, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension VisibilityEnhancedEnum on Visibility { + @override +// ignore: override_on_non_overriding_member + String get name => { + Visibility.private: 'private', + Visibility.public: 'public', + }[this]!; + bool get isPrivate => this == Visibility.private; + bool get isPublic => this == Visibility.public; + T when({ + required T Function() private, + required T Function() public, + }) => + { + Visibility.private: private, + Visibility.public: public, + }[this]!(); + T maybeWhen({ + T? Function()? private, + T? Function()? public, + required T Function() orElse, + }) => + { + Visibility.private: private, + Visibility.public: public, + }[this] + ?.call() ?? + orElse(); +} + +extension LoginTypeFromStringExtension on Iterable { + LoginType? fromString(String val) { + final override = { + 'm.login.password': LoginType.mLoginPassword, + 'm.login.token': LoginType.mLoginToken, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension LoginTypeEnhancedEnum on LoginType { + @override +// ignore: override_on_non_overriding_member + String get name => { + LoginType.mLoginPassword: 'm.login.password', + LoginType.mLoginToken: 'm.login.token', + }[this]!; + bool get isMLoginPassword => this == LoginType.mLoginPassword; + bool get isMLoginToken => this == LoginType.mLoginToken; + T when({ + required T Function() mLoginPassword, + required T Function() mLoginToken, + }) => + { + LoginType.mLoginPassword: mLoginPassword, + LoginType.mLoginToken: mLoginToken, + }[this]!(); + T maybeWhen({ + T? Function()? mLoginPassword, + T? Function()? mLoginToken, + required T Function() orElse, + }) => + { + LoginType.mLoginPassword: mLoginPassword, + LoginType.mLoginToken: mLoginToken, + }[this] + ?.call() ?? + orElse(); +} + +extension PresenceTypeFromStringExtension on Iterable { + PresenceType? fromString(String val) { + final override = { + 'offline': PresenceType.offline, + 'online': PresenceType.online, + 'unavailable': PresenceType.unavailable, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension PresenceTypeEnhancedEnum on PresenceType { + @override +// ignore: override_on_non_overriding_member + String get name => { + PresenceType.offline: 'offline', + PresenceType.online: 'online', + PresenceType.unavailable: 'unavailable', + }[this]!; + bool get isOffline => this == PresenceType.offline; + bool get isOnline => this == PresenceType.online; + bool get isUnavailable => this == PresenceType.unavailable; + T when({ + required T Function() offline, + required T Function() online, + required T Function() unavailable, + }) => + { + PresenceType.offline: offline, + PresenceType.online: online, + PresenceType.unavailable: unavailable, + }[this]!(); + T maybeWhen({ + T? Function()? offline, + T? Function()? online, + T? Function()? unavailable, + required T Function() orElse, + }) => + { + PresenceType.offline: offline, + PresenceType.online: online, + PresenceType.unavailable: unavailable, + }[this] + ?.call() ?? + orElse(); +} + +extension PushRuleKindFromStringExtension on Iterable { + PushRuleKind? fromString(String val) { + final override = { + 'content': PushRuleKind.content, + 'override': PushRuleKind.override, + 'room': PushRuleKind.room, + 'sender': PushRuleKind.sender, + 'underride': PushRuleKind.underride, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension PushRuleKindEnhancedEnum on PushRuleKind { + @override +// ignore: override_on_non_overriding_member + String get name => { + PushRuleKind.content: 'content', + PushRuleKind.override: 'override', + PushRuleKind.room: 'room', + PushRuleKind.sender: 'sender', + PushRuleKind.underride: 'underride', + }[this]!; + bool get isContent => this == PushRuleKind.content; + bool get isOverride => this == PushRuleKind.override; + bool get isRoom => this == PushRuleKind.room; + bool get isSender => this == PushRuleKind.sender; + bool get isUnderride => this == PushRuleKind.underride; + T when({ + required T Function() content, + required T Function() override, + required T Function() room, + required T Function() sender, + required T Function() underride, + }) => + { + PushRuleKind.content: content, + PushRuleKind.override: override, + PushRuleKind.room: room, + PushRuleKind.sender: sender, + PushRuleKind.underride: underride, + }[this]!(); + T maybeWhen({ + T? Function()? content, + T? Function()? override, + T? Function()? room, + T? Function()? sender, + T? Function()? underride, + required T Function() orElse, + }) => + { + PushRuleKind.content: content, + PushRuleKind.override: override, + PushRuleKind.room: room, + PushRuleKind.sender: sender, + PushRuleKind.underride: underride, + }[this] + ?.call() ?? + orElse(); +} + +extension AccountKindFromStringExtension on Iterable { + AccountKind? fromString(String val) { + final override = { + 'guest': AccountKind.guest, + 'user': AccountKind.user, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension AccountKindEnhancedEnum on AccountKind { + @override +// ignore: override_on_non_overriding_member + String get name => { + AccountKind.guest: 'guest', + AccountKind.user: 'user', + }[this]!; + bool get isGuest => this == AccountKind.guest; + bool get isUser => this == AccountKind.user; + T when({ + required T Function() guest, + required T Function() user, + }) => + { + AccountKind.guest: guest, + AccountKind.user: user, + }[this]!(); + T maybeWhen({ + T? Function()? guest, + T? Function()? user, + required T Function() orElse, + }) => + { + AccountKind.guest: guest, + AccountKind.user: user, + }[this] + ?.call() ?? + orElse(); +} + +extension BackupAlgorithmFromStringExtension on Iterable { + BackupAlgorithm? fromString(String val) { + final override = { + 'm.megolm_backup.v1.curve25519-aes-sha2': + BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension BackupAlgorithmEnhancedEnum on BackupAlgorithm { + @override +// ignore: override_on_non_overriding_member + String get name => { + BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: + 'm.megolm_backup.v1.curve25519-aes-sha2', + }[this]!; + bool get isMMegolmBackupV1Curve25519AesSha2 => + this == BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2; + T when({ + required T Function() mMegolmBackupV1Curve25519AesSha2, + }) => + { + BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: + mMegolmBackupV1Curve25519AesSha2, + }[this]!(); + T maybeWhen({ + T? Function()? mMegolmBackupV1Curve25519AesSha2, + required T Function() orElse, + }) => + { + BackupAlgorithm.mMegolmBackupV1Curve25519AesSha2: + mMegolmBackupV1Curve25519AesSha2, + }[this] + ?.call() ?? + orElse(); +} + +extension MembershipFromStringExtension on Iterable { + Membership? fromString(String val) { + final override = { + 'ban': Membership.ban, + 'invite': Membership.invite, + 'join': Membership.join, + 'knock': Membership.knock, + 'leave': Membership.leave, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension MembershipEnhancedEnum on Membership { + @override +// ignore: override_on_non_overriding_member + String get name => { + Membership.ban: 'ban', + Membership.invite: 'invite', + Membership.join: 'join', + Membership.knock: 'knock', + Membership.leave: 'leave', + }[this]!; + bool get isBan => this == Membership.ban; + bool get isInvite => this == Membership.invite; + bool get isJoin => this == Membership.join; + bool get isKnock => this == Membership.knock; + bool get isLeave => this == Membership.leave; + T when({ + required T Function() ban, + required T Function() invite, + required T Function() join, + required T Function() knock, + required T Function() leave, + }) => + { + Membership.ban: ban, + Membership.invite: invite, + Membership.join: join, + Membership.knock: knock, + Membership.leave: leave, + }[this]!(); + T maybeWhen({ + T? Function()? ban, + T? Function()? invite, + T? Function()? join, + T? Function()? knock, + T? Function()? leave, + required T Function() orElse, + }) => + { + Membership.ban: ban, + Membership.invite: invite, + Membership.join: join, + Membership.knock: knock, + Membership.leave: leave, + }[this] + ?.call() ?? + orElse(); +} + +extension DirectionFromStringExtension on Iterable { + Direction? fromString(String val) { + final override = { + 'b': Direction.b, + 'f': Direction.f, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension DirectionEnhancedEnum on Direction { + @override +// ignore: override_on_non_overriding_member + String get name => { + Direction.b: 'b', + Direction.f: 'f', + }[this]!; + bool get isB => this == Direction.b; + bool get isF => this == Direction.f; + T when({ + required T Function() b, + required T Function() f, + }) => + { + Direction.b: b, + Direction.f: f, + }[this]!(); + T maybeWhen({ + T? Function()? b, + T? Function()? f, + required T Function() orElse, + }) => + { + Direction.b: b, + Direction.f: f, + }[this] + ?.call() ?? + orElse(); +} + +extension ReceiptTypeFromStringExtension on Iterable { + ReceiptType? fromString(String val) { + final override = { + 'm.read': ReceiptType.mRead, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension ReceiptTypeEnhancedEnum on ReceiptType { + @override +// ignore: override_on_non_overriding_member + String get name => { + ReceiptType.mRead: 'm.read', + }[this]!; + bool get isMRead => this == ReceiptType.mRead; + T when({ + required T Function() mRead, + }) => + { + ReceiptType.mRead: mRead, + }[this]!(); + T maybeWhen({ + T? Function()? mRead, + required T Function() orElse, + }) => + { + ReceiptType.mRead: mRead, + }[this] + ?.call() ?? + orElse(); +} + +extension GroupKeyFromStringExtension on Iterable { + GroupKey? fromString(String val) { + final override = { + 'room_id': GroupKey.roomId, + 'sender': GroupKey.sender, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension GroupKeyEnhancedEnum on GroupKey { + @override +// ignore: override_on_non_overriding_member + String get name => { + GroupKey.roomId: 'room_id', + GroupKey.sender: 'sender', + }[this]!; + bool get isRoomId => this == GroupKey.roomId; + bool get isSender => this == GroupKey.sender; + T when({ + required T Function() roomId, + required T Function() sender, + }) => + { + GroupKey.roomId: roomId, + GroupKey.sender: sender, + }[this]!(); + T maybeWhen({ + T? Function()? roomId, + T? Function()? sender, + required T Function() orElse, + }) => + { + GroupKey.roomId: roomId, + GroupKey.sender: sender, + }[this] + ?.call() ?? + orElse(); +} + +extension KeyKindFromStringExtension on Iterable { + KeyKind? fromString(String val) { + final override = { + 'content.body': KeyKind.contentBody, + 'content.name': KeyKind.contentName, + 'content.topic': KeyKind.contentTopic, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension KeyKindEnhancedEnum on KeyKind { + @override +// ignore: override_on_non_overriding_member + String get name => { + KeyKind.contentBody: 'content.body', + KeyKind.contentName: 'content.name', + KeyKind.contentTopic: 'content.topic', + }[this]!; + bool get isContentBody => this == KeyKind.contentBody; + bool get isContentName => this == KeyKind.contentName; + bool get isContentTopic => this == KeyKind.contentTopic; + T when({ + required T Function() contentBody, + required T Function() contentName, + required T Function() contentTopic, + }) => + { + KeyKind.contentBody: contentBody, + KeyKind.contentName: contentName, + KeyKind.contentTopic: contentTopic, + }[this]!(); + T maybeWhen({ + T? Function()? contentBody, + T? Function()? contentName, + T? Function()? contentTopic, + required T Function() orElse, + }) => + { + KeyKind.contentBody: contentBody, + KeyKind.contentName: contentName, + KeyKind.contentTopic: contentTopic, + }[this] + ?.call() ?? + orElse(); +} + +extension SearchOrderFromStringExtension on Iterable { + SearchOrder? fromString(String val) { + final override = { + 'rank': SearchOrder.rank, + 'recent': SearchOrder.recent, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension SearchOrderEnhancedEnum on SearchOrder { + @override +// ignore: override_on_non_overriding_member + String get name => { + SearchOrder.rank: 'rank', + SearchOrder.recent: 'recent', + }[this]!; + bool get isRank => this == SearchOrder.rank; + bool get isRecent => this == SearchOrder.recent; + T when({ + required T Function() rank, + required T Function() recent, + }) => + { + SearchOrder.rank: rank, + SearchOrder.recent: recent, + }[this]!(); + T maybeWhen({ + T? Function()? rank, + T? Function()? recent, + required T Function() orElse, + }) => + { + SearchOrder.rank: rank, + SearchOrder.recent: recent, + }[this] + ?.call() ?? + orElse(); +} + +extension EventFormatFromStringExtension on Iterable { + EventFormat? fromString(String val) { + final override = { + 'client': EventFormat.client, + 'federation': EventFormat.federation, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension EventFormatEnhancedEnum on EventFormat { + @override +// ignore: override_on_non_overriding_member + String get name => { + EventFormat.client: 'client', + EventFormat.federation: 'federation', + }[this]!; + bool get isClient => this == EventFormat.client; + bool get isFederation => this == EventFormat.federation; + T when({ + required T Function() client, + required T Function() federation, + }) => + { + EventFormat.client: client, + EventFormat.federation: federation, + }[this]!(); + T maybeWhen({ + T? Function()? client, + T? Function()? federation, + required T Function() orElse, + }) => + { + EventFormat.client: client, + EventFormat.federation: federation, + }[this] + ?.call() ?? + orElse(); +} + +extension MethodFromStringExtension on Iterable { + Method? fromString(String val) { + final override = { + 'crop': Method.crop, + 'scale': Method.scale, + }[val]; +// ignore: unnecessary_this + return this.contains(override) ? override : null; + } +} + +extension MethodEnhancedEnum on Method { + @override +// ignore: override_on_non_overriding_member + String get name => { + Method.crop: 'crop', + Method.scale: 'scale', + }[this]!; + bool get isCrop => this == Method.crop; + bool get isScale => this == Method.scale; + T when({ + required T Function() crop, + required T Function() scale, + }) => + { + Method.crop: crop, + Method.scale: scale, + }[this]!(); + T maybeWhen({ + T? Function()? crop, + T? Function()? scale, + required T Function() orElse, + }) => + { + Method.crop: crop, + Method.scale: scale, + }[this] + ?.call() ?? + orElse(); +} diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index 6eccfbac..b359cdd4 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -91,7 +91,7 @@ class MatrixApi extends Api { } dynamic json; (!(data is String)) ? json = jsonEncode(data) : json = data; - if (data is List || action.startsWith('/media/r0/upload')) json = data; + if (data is List || action.startsWith('/media/v3/upload')) json = data; final url = homeserver! .resolveUri(Uri(path: '_matrix$action', queryParameters: query)); @@ -154,7 +154,7 @@ class MatrixApi extends Api { Map? fallbackKeys}) async { final response = await request( RequestType.POST, - '/client/r0/keys/upload', + '/client/v3/keys/upload', data: { if (deviceKeys != null) 'device_keys': deviceKeys.toJson(), if (oneTimeKeys != null) 'one_time_keys': oneTimeKeys, @@ -181,7 +181,7 @@ class MatrixApi extends Api { } await request( RequestType.POST, - '/client/r0/pushers/set', + '/client/v3/pushers/set', data: data, ); return; @@ -195,7 +195,7 @@ class MatrixApi extends Api { data['kind'] = null; await request( RequestType.POST, - '/client/r0/pushers/set', + '/client/v3/pushers/set', data: data, ); return; @@ -205,7 +205,7 @@ class MatrixApi extends Api { /// calls. @override Future getTurnServer() async { - final json = await request(RequestType.GET, '/client/r0/voip/turnServer'); + final json = await request(RequestType.GET, '/client/v3/voip/turnServer'); // fix invalid responses from synapse // https://github.com/matrix-org/synapse/pull/10922 @@ -213,4 +213,22 @@ class MatrixApi extends Api { return TurnServerCredentials.fromJson(json); } + + @Deprecated('Use [deleteRoomKeyBySessionId] instead') + Future deleteRoomKeysBySessionId( + String roomId, String sessionId, String version) async { + return deleteRoomKeyBySessionId(roomId, sessionId, version); + } + + @Deprecated('Use [deleteRoomKeyBySessionId] instead') + Future putRoomKeysBySessionId(String roomId, + String sessionId, String version, KeyBackupData data) async { + return putRoomKeyBySessionId(roomId, sessionId, version, data); + } + + @Deprecated('Use [getRoomKeyBySessionId] instead') + Future getRoomKeysBySessionId( + String roomId, String sessionId, String version) async { + return getRoomKeyBySessionId(roomId, sessionId, version); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 58d86b0b..ac375342 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,9 +9,12 @@ environment: sdk: ">=2.12.0 <3.0.0" dependencies: + enhanced_enum: ^0.1.1 http: ^0.13.0 mime: ^1.0.0 dev_dependencies: + build_runner: ^2.1.8 + enhanced_enum_generator: ^0.1.1 pedantic: ^1.11.0 test: ^1.14.4 diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index af414dea..0090ddcf 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -146,7 +146,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); final loginTypes = await matrixApi.getLoginFlows(); expect(loginTypes?.first.type, 'm.login.password'); - expect(FakeMatrixApi.api['GET']!['/client/r0/login']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/login']({}), {'flows': loginTypes?.map((x) => x.toJson()).toList()}); matrixApi.homeserver = null; }); @@ -156,7 +156,7 @@ void main() { LoginType.mLoginPassword, identifier: AuthenticationUserIdentifier(user: 'username'), ); - expect(FakeMatrixApi.api['POST']!['/client/r0/login']({}), + expect(FakeMatrixApi.api['POST']!['/client/v3/login']({}), loginResponse.toJson()); matrixApi.homeserver = null; }); @@ -176,7 +176,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); final registerResponse = await matrixApi.register(kind: AccountKind.guest, username: 'test'); - expect(FakeMatrixApi.api['POST']!['/client/r0/register?kind=guest']({}), + expect(FakeMatrixApi.api['POST']!['/client/v3/register?kind=guest']({}), registerResponse.toJson()); matrixApi.homeserver = null; }); @@ -193,7 +193,7 @@ void main() { ); expect( FakeMatrixApi - .api['POST']!['/client/r0/register/email/requestToken']({}), + .api['POST']!['/client/v3/register/email/requestToken']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -211,7 +211,7 @@ void main() { ); expect( FakeMatrixApi - .api['POST']!['/client/r0/register/email/requestToken']({}), + .api['POST']!['/client/v3/register/email/requestToken']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -280,7 +280,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final response = await matrixApi.getAccount3PIDs(); - expect(FakeMatrixApi.api['GET']!['/client/r0/account/3pid']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/account/3pid']({}), {'threepids': response?.map((t) => t.toJson()).toList()}); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -362,7 +362,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final response = await matrixApi.getCapabilities(); - expect(FakeMatrixApi.api['GET']!['/client/r0/capabilities']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/capabilities']({}), {'capabilities': response.toJson()}); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -497,7 +497,7 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/r0/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']( + '/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']( {}) as Map?, response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -575,7 +575,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/r0/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']( + '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']( {}) as Map?, timelineHistoryResponse.toJson()); @@ -666,7 +666,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/r0/directory/room/%23testalias%3Aexample.com']({}), + '/client/v3/directory/room/%23testalias%3Aexample.com']({}), roomAliasInformation.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -828,7 +828,7 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/r0/publicRooms?limit=10&since=1234&server=example.com']({}), + '/client/v3/publicRooms?limit=10&since=1234&server=example.com']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -850,7 +850,7 @@ void main() { expect( FakeMatrixApi - .api['POST']!['/client/r0/publicRooms?server=example.com']({}), + .api['POST']!['/client/v3/publicRooms?server=example.com']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -864,7 +864,7 @@ void main() { limit: 10, ); - expect(FakeMatrixApi.api['POST']!['/client/r0/user_directory/search']({}), + expect(FakeMatrixApi.api['POST']!['/client/v3/user_directory/search']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -912,7 +912,7 @@ void main() { final response = await matrixApi.getUserProfile('@alice:example.com'); expect( FakeMatrixApi - .api['GET']!['/client/r0/profile/%40alice%3Aexample.com']({}), + .api['GET']!['/client/v3/profile/%40alice%3Aexample.com']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -922,7 +922,7 @@ void main() { matrixApi.accessToken = '1234'; final response = await matrixApi.getTurnServer(); - expect(FakeMatrixApi.api['GET']!['/client/r0/voip/turnServer']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/voip/turnServer']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -986,7 +986,7 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/r0/presence/${Uri.encodeComponent('@alice:example.com')}/status']({}), + '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status']({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1016,7 +1016,7 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/media/r0/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), + '/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), openGraphData.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1047,7 +1047,7 @@ void main() { matrixApi.accessToken = '1234'; final devices = await matrixApi.getDevices(); - expect(FakeMatrixApi.api['GET']!['/client/r0/devices']({})['devices'], + expect(FakeMatrixApi.api['GET']!['/client/v3/devices']({})['devices'], devices?.map((i) => i.toJson()).toList()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1118,7 +1118,7 @@ void main() { 'Alices mobile phone'); expect( FakeMatrixApi - .api['POST']!['/client/r0/keys/query']({'device_keys': {}}), + .api['POST']!['/client/v3/keys/query']({'device_keys': {}}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1134,7 +1134,7 @@ void main() { timeout: 10, ); expect( - FakeMatrixApi.api['POST']!['/client/r0/keys/claim']({ + FakeMatrixApi.api['POST']!['/client/v3/keys/claim']({ 'one_time_keys': { '@alice:example.com': {'JLAFKJWSCS': 'signed_curve25519'} } @@ -1193,7 +1193,7 @@ void main() { final response = await matrixApi.getPushers(); expect( - FakeMatrixApi.api['GET']!['/client/r0/pushers']({}), + FakeMatrixApi.api['GET']!['/client/v3/pushers']({}), {'pushers': response?.map((i) => i.toJson()).toList()}, ); @@ -1231,7 +1231,7 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/r0/notifications?from=1234&limit=10&only=1234']({}), + '/client/v3/notifications?from=1234&limit=10&only=1234']({}), response.toJson(), ); @@ -1243,7 +1243,7 @@ void main() { final response = await matrixApi.getPushRules(); expect( - FakeMatrixApi.api['GET']!['/client/r0/pushrules']({}), + FakeMatrixApi.api['GET']!['/client/v3/pushrules']({}), {'global': response.toJson()}, ); @@ -1257,7 +1257,7 @@ void main() { await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); expect( FakeMatrixApi - .api['GET']!['/client/r0/pushrules/global/content/nocake']({}), + .api['GET']!['/client/v3/pushrules/global/content/nocake']({}), response.toJson(), ); @@ -1357,7 +1357,7 @@ void main() { from: '1234', roomId: '!1234', timeout: 10); expect( FakeMatrixApi.api['GET']![ - '/client/r0/events?from=1234&timeout=10&room_id=%211234']({}), + '/client/v3/events?from=1234&timeout=10&room_id=%211234']({}), response.toJson(), ); @@ -1371,7 +1371,7 @@ void main() { '@alice:example.com', '!localpart:example.com'); expect( FakeMatrixApi.api['GET']![ - '/client/r0/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']({}), + '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']({}), {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, ); @@ -1457,7 +1457,7 @@ void main() { final response = await matrixApi.getWhoIs('@alice:example.com'); expect( FakeMatrixApi - .api['GET']!['/client/r0/admin/whois/%40alice%3Aexample.com']({}), + .api['GET']!['/client/v3/admin/whois/%40alice%3Aexample.com']({}), response.toJson(), ); @@ -1471,7 +1471,7 @@ void main() { limit: 10, filter: '{}'); expect( FakeMatrixApi.api['GET']![ - '/client/r0/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), + '/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), response.toJson(), ); @@ -1496,7 +1496,7 @@ void main() { final response = await matrixApi.getProtocols(); expect( - FakeMatrixApi.api['GET']!['/client/r0/thirdparty/protocols']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocols']({}), response.map((k, v) => MapEntry(k, v.toJson())), ); @@ -1508,7 +1508,7 @@ void main() { final response = await matrixApi.getProtocolMetadata('irc'); expect( - FakeMatrixApi.api['GET']!['/client/r0/thirdparty/protocol/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocol/irc']({}), response.toJson(), ); @@ -1520,7 +1520,7 @@ void main() { final response = await matrixApi.queryLocationByProtocol('irc'); expect( - FakeMatrixApi.api['GET']!['/client/r0/thirdparty/location/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location/irc']({}), response.map((i) => i.toJson()).toList(), ); @@ -1532,7 +1532,7 @@ void main() { final response = await matrixApi.queryUserByProtocol('irc'); expect( - FakeMatrixApi.api['GET']!['/client/r0/thirdparty/user/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user/irc']({}), response.map((i) => i.toJson()).toList(), ); @@ -1545,7 +1545,7 @@ void main() { final response = await matrixApi.queryLocationByAlias('1234'); expect( FakeMatrixApi - .api['GET']!['/client/r0/thirdparty/location?alias=1234']({}), + .api['GET']!['/client/v3/thirdparty/location?alias=1234']({}), response.map((i) => i.toJson()).toList(), ); @@ -1557,7 +1557,7 @@ void main() { final response = await matrixApi.queryUserByID('1234'); expect( - FakeMatrixApi.api['GET']!['/client/r0/thirdparty/user?userid=1234']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user?userid=1234']({}), response.map((i) => i.toJson()).toList(), ); @@ -1570,7 +1570,7 @@ void main() { final response = await matrixApi.requestOpenIdToken('1234', {}); expect( FakeMatrixApi - .api['POST']!['/client/r0/user/1234/openid/request_token']({}), + .api['POST']!['/client/v3/user/1234/openid/request_token']({}), response.toJson(), ); @@ -1595,8 +1595,8 @@ void main() { }; final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); expect( - FakeMatrixApi.api['POST']!['/client/unstable/room_keys/version']( - {})['version'], + FakeMatrixApi + .api['POST']!['/client/v3/room_keys/version']({})['version'], ret); }); test('getRoomKeysVersionCurrent', () async { @@ -1604,8 +1604,7 @@ void main() { matrixApi.accessToken = '1234'; final ret = await matrixApi.getRoomKeysVersionCurrent(); - expect( - FakeMatrixApi.api['GET']!['/client/unstable/room_keys/version']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/room_keys/version']({}), ret.toJson()); }); test('putRoomKeysVersion', () async { @@ -1625,7 +1624,7 @@ void main() { await matrixApi.deleteRoomKeys('5'); }); - test('putRoomKeysBySessionId', () async { + test('putRoomKeyBySessionId', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; @@ -1642,37 +1641,36 @@ void main() { 'mac': 'QzKV/fgAs4U', }, }); - final ret = await matrixApi.putRoomKeysBySessionId( + final ret = await matrixApi.putRoomKeyBySessionId( roomId, sessionId, '5', session); expect( FakeMatrixApi.api['PUT']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), ret.toJson()); }); - test('getRoomKeysBySessionId', () async { + test('getRoomKeyBySessionId', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final roomId = '!726s6s6q:example.com'; final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU'; - final ret = - await matrixApi.getRoomKeysBySessionId(roomId, sessionId, '5'); + final ret = await matrixApi.getRoomKeyBySessionId(roomId, sessionId, '5'); expect( FakeMatrixApi.api['GET']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), ret.toJson()); }); - test('deleteRoomKeysBySessionId', () async { + test('deleteRoomKeyBySessionId', () async { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final roomId = '!726s6s6q:example.com'; final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU'; final ret = - await matrixApi.deleteRoomKeysBySessionId(roomId, sessionId, '5'); + await matrixApi.deleteRoomKeyBySessionId(roomId, sessionId, '5'); expect( FakeMatrixApi.api['DELETE']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), ret.toJson()); }); test('putRoomKeysByRoomId', () async { @@ -1699,7 +1697,7 @@ void main() { final ret = await matrixApi.putRoomKeysByRoomId(roomId, '5', session); expect( FakeMatrixApi.api['PUT']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), ret.toJson()); }); test('getRoomKeysByRoomId', () async { @@ -1710,7 +1708,7 @@ void main() { final ret = await matrixApi.getRoomKeysByRoomId(roomId, '5'); expect( FakeMatrixApi.api['GET']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), ret.toJson()); }); test('deleteRoomKeysByRoomId', () async { @@ -1721,7 +1719,7 @@ void main() { final ret = await matrixApi.deleteRoomKeysByRoomId(roomId, '5'); expect( FakeMatrixApi.api['DELETE']![ - '/client/unstable/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), ret.toJson()); }); test('putRoomKeys', () async { @@ -1751,8 +1749,7 @@ void main() { }); final ret = await matrixApi.putRoomKeys('5', session); expect( - FakeMatrixApi - .api['PUT']!['/client/unstable/room_keys/keys?version=5']({}), + FakeMatrixApi.api['PUT']!['/client/v3/room_keys/keys?version=5']({}), ret.toJson()); }); test('getRoomKeys', () async { @@ -1761,8 +1758,7 @@ void main() { final ret = await matrixApi.getRoomKeys('5'); expect( - FakeMatrixApi - .api['GET']!['/client/unstable/room_keys/keys?version=5']({}), + FakeMatrixApi.api['GET']!['/client/v3/room_keys/keys?version=5']({}), ret.toJson()); }); test('deleteRoomKeys', () async { @@ -1772,7 +1768,7 @@ void main() { final ret = await matrixApi.deleteRoomKeys('5'); expect( FakeMatrixApi - .api['DELETE']!['/client/unstable/room_keys/keys?version=5']({}), + .api['DELETE']!['/client/v3/room_keys/keys?version=5']({}), ret.toJson()); }); test('AuthenticationData', () {