MTXClient: Add support for logging out

FossilOrigin-Name: c29845b7b81229ea7bf062304824a4087c160629216064ae1a647fe8286826bb
This commit is contained in:
Jonathan Schleifer 2020-10-03 16:21:34 +00:00
parent 023ed62f5a
commit 77a2d20fc7
11 changed files with 209 additions and 25 deletions

View file

@ -24,6 +24,7 @@
#import "MTXRequest.h"
#import "MTXLoginFailedException.h"
#import "MTXLogoutFailedException.h"
static void
validateHomeserver(OFURL *homeserver)
@ -76,9 +77,8 @@ validateHomeserver(OFURL *homeserver)
@"password": password
};
[request asyncPerformWithBlock:
^ (OFDictionary<OFString *, id> *response, int statusCode,
id exception) {
[request asyncPerformWithBlock: ^ (mtx_response_t response,
int statusCode, id exception) {
if (exception != nil) {
block(nil, exception);
return;
@ -170,4 +170,38 @@ validateHomeserver(OFURL *homeserver)
@">",
self.class, _userID, _deviceID, _accessToken, _homeserver];
}
- (MTXRequest *)requestWithPath: (OFString *)path
{
return [MTXRequest requestWithPath: path
accessToken: _accessToken
homeserver: _homeserver];
}
- (void)asyncLogOutWithBlock: (mtx_client_logout_block_t)block
{
void *pool = objc_autoreleasePoolPush();
MTXRequest *request =
[self requestWithPath: @"/_matrix/client/r0/logout"];
request.method = OF_HTTP_REQUEST_METHOD_POST;
[request asyncPerformWithBlock: ^ (mtx_response_t response,
int statusCode, id exception) {
if (exception != nil) {
block(exception);
return;
}
if (statusCode != 200) {
block([MTXLogoutFailedException
exceptionWithClient: self
statusCode: statusCode
response: response]);
return;
}
block(nil);
}];
objc_autoreleasePoolPop(pool);
}
@end