From c1966109984a8104d85e2a52d41cd2f3d4e9ded8 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Fri, 7 May 2021 13:53:35 +0200 Subject: [PATCH] chore: operation names from OpenAPI spec --- lib/encryption/olm_manager.dart | 5 +- lib/src/client.dart | 26 ++++----- lib/src/event.dart | 2 +- lib/src/room.dart | 78 +++++++++++++-------------- lib/src/utils/commands_extension.dart | 6 +-- pubspec.yaml | 2 +- test/client_test.dart | 4 +- test/room_test.dart | 2 +- test/timeline_test.dart | 2 +- 9 files changed, 63 insertions(+), 64 deletions(-) diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 9ad55d7c..a19348bb 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -235,7 +235,7 @@ class OlmManager { if (updateDatabase) { await client.database?.updateClientKeys(pickledOlmAccount, client.id); } - final response = await client.uploadDeviceKeys( + final response = await client.uploadKeys( deviceKeys: uploadDeviceKeys ? MatrixDeviceKeys.fromJson(keysContent['device_keys']) : null, @@ -526,8 +526,7 @@ class OlmManager { requestingKeysFrom[device.userId][device.deviceId] = 'signed_curve25519'; } - final response = - await client.requestOneTimeKeys(requestingKeysFrom, timeout: 10000); + final response = await client.claimKeys(requestingKeysFrom, timeout: 10000); for (final userKeysEntry in response.oneTimeKeys.entries) { final userId = userKeysEntry.key; diff --git a/lib/src/client.dart b/lib/src/client.dart index db8382b3..4bda6522 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -329,7 +329,7 @@ class Client extends MatrixApi { WellKnownInformation wellKnown; if (checkWellKnown) { try { - wellKnown = await requestWellKnownInformation(); + wellKnown = await getWellknown(); homeserverUrl = wellKnown.mHomeserver.baseUrl.trim(); // strip a trailing slash if (homeserverUrl.endsWith('/')) { @@ -343,14 +343,14 @@ class Client extends MatrixApi { } // Check if server supports at least one supported version - final versions = await requestSupportedVersions(); + final versions = await getVersions(); if (!versions.versions .any((version) => supportedVersions.contains(version))) { throw BadServerVersionsException( versions.versions.toSet(), supportedVersions); } - final loginTypes = await requestLoginTypes(); + final loginTypes = await getLoginFlows(); if (!loginTypes.flows.any((f) => supportedLoginTypes.contains(f.type))) { throw BadServerLoginTypesException( loginTypes.flows.map((f) => f.type).toSet(), supportedLoginTypes); @@ -596,7 +596,7 @@ class Client extends MatrixApi { if (cache && _profileCache.containsKey(userId)) { return _profileCache[userId]; } - final profile = await requestProfile(userId); + final profile = await getUserProfile(userId); _profileCache[userId] = profile; return profile; } @@ -646,9 +646,10 @@ class Client extends MatrixApi { /// Uploads a file and automatically caches it in the database, if it is small enough /// and returns the mxc url as a string. @override - Future upload(Uint8List file, String fileName, + Future uploadContent(Uint8List file, String fileName, {String contentType}) async { - final mxc = await super.upload(file, fileName, contentType: contentType); + final mxc = + await super.uploadContent(file, fileName, contentType: contentType); final storeable = database != null && file.length <= database.maxFileSize; if (storeable) { await database.storeFile( @@ -659,14 +660,13 @@ class Client extends MatrixApi { /// Sends a typing notification and initiates a megolm session, if needed @override - Future sendTypingNotification( + Future setTyping( String userId, String roomId, bool typing, { int timeout, }) async { - await super - .sendTypingNotification(userId, roomId, typing, timeout: timeout); + await super.setTyping(userId, roomId, typing, timeout: timeout); final room = getRoomById(roomId); if (typing && room != null && encryptionEnabled && room.encrypted) { unawaited(encryption.keyManager.prepareOutboundGroupSession(roomId)); @@ -675,7 +675,7 @@ class Client extends MatrixApi { /// Uploads a new user avatar for this user. Future setAvatar(MatrixFile file) async { - final uploadResp = await upload(file.bytes, file.name); + final uploadResp = await uploadContent(file.bytes, file.name); await setAvatarUrl(userID, Uri.parse(uploadResp)); return; } @@ -990,7 +990,7 @@ class Client extends MatrixApi { Future _checkSyncFilter() async { if (syncFilterId == null) { - syncFilterId = await uploadFilter(userID, syncFilter); + syncFilterId = await defineFilter(userID, syncFilter); await database?.storeSyncFilterId(syncFilterId, id); } return; @@ -1563,7 +1563,7 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); if (outdatedLists.isNotEmpty) { // Request the missing device key lists from the server. - final response = await requestDeviceKeys(outdatedLists, timeout: 10000); + final response = await queryKeys(outdatedLists, timeout: 10000); if (!isLogged()) return; for (final rawDeviceKeyListEntry in response.deviceKeys.entries) { @@ -1905,7 +1905,7 @@ sort order of ${prevState.sortOrder}. This should never happen...'''); } Future setMuteAllPushNotifications(bool muted) async { - await enablePushRule( + await setPushRuleEnabled( 'global', PushRuleKind.override, '.m.rule.master', diff --git a/lib/src/event.dart b/lib/src/event.dart index f9c5484f..1c72be9b 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -338,7 +338,7 @@ class Event extends MatrixEvent { bool get canRedact => senderId == room.client.userID || room.canRedact; /// Redacts this event. Throws `ErrorResponse` on error. - Future redact({String reason, String txid}) => + Future redactEvent({String reason, String txid}) => room.redactEvent(eventId, reason: reason, txid: txid); /// Searches for the reply event in the given timeline. diff --git a/lib/src/room.dart b/lib/src/room.dart index 939aadd2..e1d8514f 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -254,11 +254,11 @@ class Room { /// Sets the canonical alias. If the [canonicalAlias] is not yet an alias of /// this room, it will create one. Future setCanonicalAlias(String canonicalAlias) async { - final aliases = await client.requestRoomAliases(id); + final aliases = await client.getLocalAliases(id); if (!aliases.contains(canonicalAlias)) { - await client.createRoomAlias(canonicalAlias, id); + await client.setRoomAlias(canonicalAlias, id); } - await client.sendState(id, EventTypes.RoomCanonicalAlias, { + await client.setRoomStateWithKey(id, EventTypes.RoomCanonicalAlias, { 'alias': canonicalAlias, }); } @@ -419,21 +419,21 @@ class Room { /// Call the Matrix API to change the name of this room. Returns the event ID of the /// new m.room.name event. - Future setName(String newName) => client.sendState( + Future setName(String newName) => client.setRoomStateWithKey( id, EventTypes.RoomName, {'name': newName}, ); /// Call the Matrix API to change the topic of this room. - Future setDescription(String newName) => client.sendState( + Future setDescription(String newName) => client.setRoomStateWithKey( id, EventTypes.RoomTopic, {'topic': newName}, ); /// Add a tag to the room. - Future addTag(String tag, {double order}) => client.addRoomTag( + Future addTag(String tag, {double order}) => client.setRoomTag( client.userID, id, tag, @@ -441,7 +441,7 @@ class Room { ); /// Removes a tag from the room. - Future removeTag(String tag) => client.removeRoomTag( + Future removeTag(String tag) => client.deleteRoomTag( client.userID, id, tag, @@ -482,14 +482,14 @@ class Room { ..roomId = id ..type = EventType.markedUnread ]))))); - await client.setRoomAccountData( + await client.setAccountDataPerRoom( client.userID, id, EventType.markedUnread, content, ); if (unread == false && lastEvent != null) { - await sendReadMarker( + await setReadMarker( lastEvent.eventId, readReceiptLocationEventId: lastEvent.eventId, ); @@ -505,7 +505,7 @@ class Room { /// Call the Matrix API to change the pinned events of this room. Future setPinnedEvents(List pinnedEventIds) => - client.sendState( + client.setRoomStateWithKey( id, EventTypes.RoomPinnedEvents, {'pinned': pinnedEventIds}, @@ -674,13 +674,13 @@ class Room { uploadThumbnail = encryptedThumbnail.toMatrixFile(); } } - final uploadResp = await client.upload( + final uploadResp = await client.uploadContent( uploadFile.bytes, uploadFile.name, contentType: uploadFile.mimeType, ); final thumbnailUploadResp = uploadThumbnail != null - ? await client.upload( + ? await client.uploadContent( uploadThumbnail.bytes, uploadThumbnail.name, contentType: uploadThumbnail.mimeType, @@ -881,7 +881,7 @@ class Room { /// automatically be set. Future join({bool leaveIfNotFound = true}) async { try { - await client.joinRoom(id); + await client.joinRoomById(id); final invitation = getState(EventTypes.RoomMember, client.userID); if (invitation != null && invitation.content['is_direct'] is bool && @@ -929,13 +929,13 @@ class Room { } /// Call the Matrix API to kick a user from this room. - Future kick(String userID) => client.kickFromRoom(id, userID); + Future kick(String userID) => client.kick(id, userID); /// Call the Matrix API to ban a user from this room. - Future ban(String userID) => client.banFromRoom(id, userID); + Future ban(String userID) => client.ban(id, userID); /// Call the Matrix API to unban a banned user from this room. - Future unban(String userID) => client.unbanInRoom(id, userID); + Future unban(String userID) => client.unban(id, userID); /// Set the power level of the user with the [userID] to the value [power]. /// Returns the event ID of the new state event. If there is no known @@ -947,7 +947,7 @@ class Room { if (powerMap['users'] == null) powerMap['users'] = {}; powerMap['users'][userID] = power; - return await client.sendState( + return await client.setRoomStateWithKey( id, EventTypes.RoomPowerLevels, powerMap, @@ -962,7 +962,7 @@ class Room { /// the historical events will be published in the onEvent stream. Future requestHistory( {int historyCount = defaultHistoryCount, onHistoryReceived}) async { - final resp = await client.requestMessages( + final resp = await client.getRoomEvents( id, prev_batch, Direction.b, @@ -1030,7 +1030,7 @@ class Room { return; } // Nothing to do here - await client.setRoomAccountData( + await client.setAccountDataPerRoom( client.userID, id, 'm.direct', @@ -1041,13 +1041,13 @@ class Room { /// Sets the position of the read marker for a given room, and optionally the /// read receipt's location. - Future sendReadMarker(String eventId, + Future setReadMarker(String eventId, {String readReceiptLocationEventId}) async { if (readReceiptLocationEventId != null) { notificationCount = 0; await client.database?.resetNotificationCount(client.id, id); } - await client.sendReadMarker( + await client.setReadMarker( id, eventId, readReceiptLocationEventId: readReceiptLocationEventId, @@ -1057,10 +1057,10 @@ class Room { /// This API updates the marker for the given receipt type to the event ID /// specified. - Future sendReceiptMarker(String eventId) async { + Future postReceipt(String eventId) async { notificationCount = 0; await client.database?.resetNotificationCount(client.id, id); - await client.sendReceiptMarker( + await client.postReceipt( id, eventId, ); @@ -1072,7 +1072,7 @@ class Room { Future sendReadReceipt(String eventID) async { notificationCount = 0; await client.database?.resetNotificationCount(client.id, id); - await client.sendReadMarker( + await client.setReadMarker( id, eventID, readReceiptLocationEventId: eventID, @@ -1199,7 +1199,7 @@ class Room { if (_requestedParticipants || participantListComplete) { return getParticipants(); } - final matrixEvents = await client.requestMembers(id); + final matrixEvents = await client.getMembersByRoom(id); final users = matrixEvents.map((e) => Event.fromMatrixEvent(e, this).asUser).toList(); for (final user in users) { @@ -1294,7 +1294,7 @@ class Room { } if (resp == null && requestProfile) { try { - final profile = await client.requestProfile(mxID); + final profile = await client.getUserProfile(mxID); resp = { 'displayname': profile.displayname, 'avatar_url': profile.avatarUrl.toString(), @@ -1340,7 +1340,7 @@ class Room { /// Searches for the event on the server. Returns null if not found. Future getEventById(String eventID) async { try { - final matrixEvent = await client.requestEvent(id, eventID); + final matrixEvent = await client.getOneRoomEvent(id, eventID); final event = Event.fromMatrixEvent(matrixEvent, this); if (event.type == EventTypes.Encrypted && client.encryptionEnabled) { // attempt decryption @@ -1388,8 +1388,8 @@ class Room { /// Uploads a new user avatar for this room. Returns the event ID of the new /// m.room.avatar event. Future setAvatar(MatrixFile file) async { - final uploadResp = await client.upload(file.bytes, file.name); - return await client.sendState( + final uploadResp = await client.uploadContent(file.bytes, file.name); + return await client.setRoomStateWithKey( id, EventTypes.RoomAvatar, {'url': uploadResp}, @@ -1538,7 +1538,7 @@ class Room { } final data = {}; if (reason != null) data['reason'] = reason; - return await client.redact( + return await client.redactEvent( id, eventId, messageID, @@ -1549,12 +1549,12 @@ class Room { /// This tells the server that the user is typing for the next N milliseconds /// where N is the value specified in the timeout key. Alternatively, if typing is false, /// it tells the server that the user has stopped typing. - Future sendTypingNotification(bool isTyping, {int timeout}) => client - .sendTypingNotification(client.userID, id, isTyping, timeout: timeout); + Future setTyping(bool isTyping, {int timeout}) => + client.setTyping(client.userID, id, isTyping, timeout: timeout); @Deprecated('Use sendTypingNotification instead') Future sendTypingInfo(bool isTyping, {int timeout}) => - sendTypingNotification(isTyping, timeout: timeout); + setTyping(isTyping, timeout: timeout); /// This is sent by the caller when they wish to establish a call. /// [callId] is a unique identifier for the call. @@ -1669,7 +1669,7 @@ class Room { /// Changes the join rules. You should check first if the user is able to change it. Future setJoinRules(JoinRules joinRules) async { - await client.sendState( + await client.setRoomStateWithKey( id, EventTypes.RoomJoinRules, { @@ -1691,7 +1691,7 @@ class Room { /// Changes the guest access. You should check first if the user is able to change it. Future setGuestAccess(GuestAccess guestAccess) async { - await client.sendState( + await client.setRoomStateWithKey( id, EventTypes.GuestAccess, { @@ -1714,7 +1714,7 @@ class Room { /// Changes the history visibility. You should check first if the user is able to change it. Future setHistoryVisibility(HistoryVisibility historyVisibility) async { - await client.sendState( + await client.setRoomStateWithKey( id, EventTypes.HistoryVisibility, { @@ -1739,7 +1739,7 @@ class Room { Future enableEncryption({int algorithmIndex = 0}) async { if (encrypted) throw ('Encryption is already enabled!'); final algorithm = Client.supportedGroupEncryptionAlgorithms[algorithmIndex]; - await client.sendState( + await client.setRoomStateWithKey( id, EventTypes.Encryption, { @@ -1836,7 +1836,7 @@ class Room { }) async { if (!isSpace) throw Exception('Room is not a space!'); via ??= [roomId.domain]; - await client.sendState( + await client.setRoomStateWithKey( id, EventTypes.spaceChild, { @@ -1845,7 +1845,7 @@ class Room { if (suggested != null) 'suggested': suggested, }, roomId); - await client.sendState( + await client.setRoomStateWithKey( roomId, EventTypes.spaceParent, { diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index 722fe9d7..828af639 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -124,7 +124,7 @@ extension CommandsClientExtension on Client { return await args.room.sendReaction(args.inReplyTo.eventId, args.msg); }); addCommand('join', (CommandArgs args) async { - await args.room.client.joinRoomOrAlias(args.msg); + await args.room.client.joinRoom(args.msg); return null; }); addCommand('leave', (CommandArgs args) async { @@ -169,7 +169,7 @@ extension CommandsClientExtension on Client { .content .copy(); currentEventJson['displayname'] = args.msg; - return await args.room.client.sendState( + return await args.room.client.setRoomStateWithKey( args.room.id, EventTypes.RoomMember, currentEventJson, @@ -182,7 +182,7 @@ extension CommandsClientExtension on Client { .content .copy(); currentEventJson['avatar_url'] = args.msg; - return await args.room.client.sendState( + return await args.room.client.setRoomStateWithKey( args.room.id, EventTypes.RoomMember, currentEventJson, diff --git a/pubspec.yaml b/pubspec.yaml index 5481a3a5..587393ff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: olm: ^2.0.0 isolate: ^2.0.3 logger: ^1.0.0 - matrix_api_lite: ^0.2.6 + matrix_api_lite: 0.3.0 dev_dependencies: test: ^1.15.7 diff --git a/test/client_test.dart b/test/client_test.dart index 4834cea2..297b7fda 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -92,7 +92,7 @@ void main() { checkWellKnown: false); expect(matrix.homeserver.toString(), 'https://fakeserver.notexisting'); - final available = await matrix.usernameAvailable('testuser'); + final available = await matrix.checkUsernameAvailability('testuser'); expect(available, true); final loginStateFuture = matrix.onLoginStateChanged.stream.first; @@ -589,7 +589,7 @@ void main() { }); test('upload', () async { final client = await getClient(); - final response = await client.upload(Uint8List(0), 'file.jpeg'); + final response = await client.uploadContent(Uint8List(0), 'file.jpeg'); expect(response, 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'); expect(await client.database.getFile(response) != null, true); await client.dispose(closeDatabase: true); diff --git a/test/room_test.dart b/test/room_test.dart index 1ad8355a..0064ce1e 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -223,7 +223,7 @@ void main() { }); test('sendReadMarker', () async { - await room.sendReadMarker('§1234:fakeServer.notExisting'); + await room.setReadMarker('§1234:fakeServer.notExisting'); }); test('requestParticipants', () async { diff --git a/test/timeline_test.dart b/test/timeline_test.dart index ec077bb2..d16764ed 100644 --- a/test/timeline_test.dart +++ b/test/timeline_test.dart @@ -288,7 +288,7 @@ void main() { expect(timeline.events[1].eventId, '2143273582443PhrSn:example.org'); expect(timeline.events[2].eventId, '1143273582443PhrSn:example.org'); expect(room.prev_batch, 't47409-4357353_219380_26003_2265'); - await timeline.events[2].redact(reason: 'test', txid: '1234'); + await timeline.events[2].redactEvent(reason: 'test', txid: '1234'); }); test('Clear cache on limited timeline', () async {