chore: operation names from OpenAPI spec

This commit is contained in:
Lukas Lihotzki 2021-05-07 13:53:35 +02:00
parent 70ee808911
commit c196610998
9 changed files with 63 additions and 64 deletions

View File

@ -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;

View File

@ -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<String> upload(Uint8List file, String fileName,
Future<String> 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<void> sendTypingNotification(
Future<void> 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<void> 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<void> _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<void> setMuteAllPushNotifications(bool muted) async {
await enablePushRule(
await setPushRuleEnabled(
'global',
PushRuleKind.override,
'.m.rule.master',

View File

@ -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<dynamic> redact({String reason, String txid}) =>
Future<dynamic> redactEvent({String reason, String txid}) =>
room.redactEvent(eventId, reason: reason, txid: txid);
/// Searches for the reply event in the given timeline.

View File

@ -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<void> 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<String> setName(String newName) => client.sendState(
Future<String> setName(String newName) => client.setRoomStateWithKey(
id,
EventTypes.RoomName,
{'name': newName},
);
/// Call the Matrix API to change the topic of this room.
Future<String> setDescription(String newName) => client.sendState(
Future<String> setDescription(String newName) => client.setRoomStateWithKey(
id,
EventTypes.RoomTopic,
{'topic': newName},
);
/// Add a tag to the room.
Future<void> addTag(String tag, {double order}) => client.addRoomTag(
Future<void> addTag(String tag, {double order}) => client.setRoomTag(
client.userID,
id,
tag,
@ -441,7 +441,7 @@ class Room {
);
/// Removes a tag from the room.
Future<void> removeTag(String tag) => client.removeRoomTag(
Future<void> 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<String> setPinnedEvents(List<String> 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<void> 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<void> kick(String userID) => client.kickFromRoom(id, userID);
Future<void> kick(String userID) => client.kick(id, userID);
/// Call the Matrix API to ban a user from this room.
Future<void> ban(String userID) => client.banFromRoom(id, userID);
Future<void> ban(String userID) => client.ban(id, userID);
/// Call the Matrix API to unban a banned user from this room.
Future<void> unban(String userID) => client.unbanInRoom(id, userID);
Future<void> 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<void> 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<void> sendReadMarker(String eventId,
Future<void> 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<void> sendReceiptMarker(String eventId) async {
Future<void> 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<void> 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<Event> 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<String> 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 = <String, dynamic>{};
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<void> sendTypingNotification(bool isTyping, {int timeout}) => client
.sendTypingNotification(client.userID, id, isTyping, timeout: timeout);
Future<void> setTyping(bool isTyping, {int timeout}) =>
client.setTyping(client.userID, id, isTyping, timeout: timeout);
@Deprecated('Use sendTypingNotification instead')
Future<void> 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<void> 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<void> 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<void> setHistoryVisibility(HistoryVisibility historyVisibility) async {
await client.sendState(
await client.setRoomStateWithKey(
id,
EventTypes.HistoryVisibility,
{
@ -1739,7 +1739,7 @@ class Room {
Future<void> 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,
{

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -223,7 +223,7 @@ void main() {
});
test('sendReadMarker', () async {
await room.sendReadMarker('§1234:fakeServer.notExisting');
await room.setReadMarker('§1234:fakeServer.notExisting');
});
test('requestParticipants', () async {

View File

@ -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 {