Adjust to ObjFW changes
FossilOrigin-Name: e597cc80e1537bae3544bccd7b55dbdf963bc846184521ac9bd0e2e82aa695f0
This commit is contained in:
parent
96f6425bfc
commit
0166881d65
18 changed files with 106 additions and 128 deletions
|
@ -3,7 +3,7 @@ OBJMATRIX_STATIC_LIB = @OBJMATRIX_STATIC_LIB@
|
||||||
OBJMATRIX_FRAMEWORK = @OBJMATRIX_FRAMEWORK@
|
OBJMATRIX_FRAMEWORK = @OBJMATRIX_FRAMEWORK@
|
||||||
OBJMATRIX_LIB_MAJOR = 0
|
OBJMATRIX_LIB_MAJOR = 0
|
||||||
OBJMATRIX_LIB_MINOR = 0
|
OBJMATRIX_LIB_MINOR = 0
|
||||||
OBJMATRIX_LIB_MAJOR_MINOR = ${OBJMATRIX_LIB_MAJOR_MINOR}.${OBJMATRIX_LIB_MINOR}
|
OBJMATRIX_LIB_MAJOR_MINOR = ${OBJMATRIX_LIB_MAJOR}.${OBJMATRIX_LIB_MINOR}
|
||||||
|
|
||||||
EXCEPTIONS_A = @EXCEPTIONS_A@
|
EXCEPTIONS_A = @EXCEPTIONS_A@
|
||||||
EXCEPTIONS_EXCEPTIONS_A = @EXCEPTIONS_EXCEPTIONS_A@
|
EXCEPTIONS_EXCEPTIONS_A = @EXCEPTIONS_EXCEPTIONS_A@
|
||||||
|
|
|
@ -34,7 +34,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
* @param client If the login succeeded, the newly created client
|
* @param client If the login succeeded, the newly created client
|
||||||
* @param exception If the login failed, an exception
|
* @param exception If the login failed, an exception
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_client_login_block_t)(MTXClient *_Nullable client,
|
typedef void (^MTXClientLoginBlock)(MTXClient *_Nullable client,
|
||||||
id _Nullable exception);
|
id _Nullable exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,14 +42,14 @@ typedef void (^mtx_client_login_block_t)(MTXClient *_Nullable client,
|
||||||
*
|
*
|
||||||
* @param exception `nil` on success, otherwise an exception
|
* @param exception `nil` on success, otherwise an exception
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_client_response_block_t)(id _Nullable exception);
|
typedef void (^MTXClientResponseBlock)(id _Nullable exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A block called when an exception occurred during sync.
|
* @brief A block called when an exception occurred during sync.
|
||||||
*
|
*
|
||||||
* @param exception The exception which occurred during sync
|
* @param exception The exception which occurred during sync
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_sync_exception_handler_block_t)(id exception);
|
typedef void (^MTXSyncExceptionHandlerBlock)(id exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A block called when the room list was fetched.
|
* @brief A block called when the room list was fetched.
|
||||||
|
@ -57,8 +57,8 @@ typedef void (^mtx_sync_exception_handler_block_t)(id exception);
|
||||||
* @param rooms An array of joined rooms, or nil on error
|
* @param rooms An array of joined rooms, or nil on error
|
||||||
* @param exception An exception if fetching the room list failed
|
* @param exception An exception if fetching the room list failed
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_client_room_list_block_t)(
|
typedef void (^MTXClientRoomListBlock)(OFArray<OFString *> *_Nullable rooms,
|
||||||
OFArray<OFString *> *_Nullable rooms, id _Nullable exception);
|
id _Nullable exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A block called when a room was joined.
|
* @brief A block called when a room was joined.
|
||||||
|
@ -67,7 +67,7 @@ typedef void (^mtx_client_room_list_block_t)(
|
||||||
* to get the room ID if a room alias was joined.
|
* to get the room ID if a room alias was joined.
|
||||||
* @param exception An exception if joining the room failed
|
* @param exception An exception if joining the room failed
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
typedef void (^MTXClientRoomJoinBlock)(OFString *_Nullable roomID,
|
||||||
id _Nullable exception);
|
id _Nullable exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,13 +104,12 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
*
|
*
|
||||||
* Defaults to 5 minutes.
|
* Defaults to 5 minutes.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic) of_time_interval_t syncTimeout;
|
@property (nonatomic) OFTimeInterval syncTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A block to handle exceptions that occurred during sync.
|
* @brief A block to handle exceptions that occurred during sync.
|
||||||
*/
|
*/
|
||||||
@property (copy, nonatomic)
|
@property (copy, nonatomic) MTXSyncExceptionHandlerBlock syncExceptionHandler;
|
||||||
mtx_sync_exception_handler_block_t syncExceptionHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new client with the specified access token on the specified
|
* @brief Creates a new client with the specified access token on the specified
|
||||||
|
@ -142,7 +141,7 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
password: (OFString *)password
|
password: (OFString *)password
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
storage: (id <MTXStorage>)storage
|
storage: (id <MTXStorage>)storage
|
||||||
block: (mtx_client_login_block_t)block;
|
block: (MTXClientLoginBlock)block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes an already allocated client with the specified access
|
* @brief Initializes an already allocated client with the specified access
|
||||||
|
@ -182,14 +181,14 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
*
|
*
|
||||||
* @param block A block to call when logging out succeeded or failed
|
* @param block A block to call when logging out succeeded or failed
|
||||||
*/
|
*/
|
||||||
- (void)logOutWithBlock: (mtx_client_response_block_t)block;
|
- (void)logOutWithBlock: (MTXClientResponseBlock)block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetches the list of joined rooms.
|
* @brief Fetches the list of joined rooms.
|
||||||
*
|
*
|
||||||
* @param block A block to call with the list of joined room
|
* @param block A block to call with the list of joined room
|
||||||
*/
|
*/
|
||||||
- (void)fetchRoomListWithBlock: (mtx_client_room_list_block_t)block;
|
- (void)fetchRoomListWithBlock: (MTXClientRoomListBlock)block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Joins the specified room.
|
* @brief Joins the specified room.
|
||||||
|
@ -197,8 +196,7 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
* @param room The room to join. Either a room ID or a room alias.
|
* @param room The room to join. Either a room ID or a room alias.
|
||||||
* @param block A block to call when the room was joined
|
* @param block A block to call when the room was joined
|
||||||
*/
|
*/
|
||||||
- (void)joinRoom: (OFString *)room
|
- (void)joinRoom: (OFString *)room block: (MTXClientRoomJoinBlock)block;
|
||||||
block: (mtx_client_room_join_block_t)block;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Leaves the specified room.
|
* @brief Leaves the specified room.
|
||||||
|
@ -206,8 +204,7 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
* @param roomID The room ID to leave
|
* @param roomID The room ID to leave
|
||||||
* @param block A block to call when the room was left
|
* @param block A block to call when the room was left
|
||||||
*/
|
*/
|
||||||
- (void)leaveRoom: (OFString *)roomID
|
- (void)leaveRoom: (OFString *)roomID block: (MTXClientResponseBlock)block;
|
||||||
block: (mtx_client_response_block_t)block;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends the specified message to the specified room ID.
|
* @brief Sends the specified message to the specified room ID.
|
||||||
|
@ -218,7 +215,7 @@ typedef void (^mtx_client_room_join_block_t)(OFString *_Nullable roomID,
|
||||||
*/
|
*/
|
||||||
- (void)sendMessage: (OFString *)message
|
- (void)sendMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
block: (mtx_client_response_block_t)block;
|
block: (MTXClientResponseBlock)block;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -69,7 +69,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
password: (OFString *)password
|
password: (OFString *)password
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
storage: (id <MTXStorage>)storage
|
storage: (id <MTXStorage>)storage
|
||||||
block: (mtx_client_login_block_t)block
|
block: (MTXClientLoginBlock)block
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
requestWithPath: @"/_matrix/client/r0/login"
|
requestWithPath: @"/_matrix/client/r0/login"
|
||||||
accessToken: nil
|
accessToken: nil
|
||||||
homeserver: homeserver];
|
homeserver: homeserver];
|
||||||
request.method = OF_HTTP_REQUEST_METHOD_POST;
|
request.method = OFHTTPRequestMethodPost;
|
||||||
request.body = @{
|
request.body = @{
|
||||||
@"type": @"m.login.password",
|
@"type": @"m.login.password",
|
||||||
@"identifier": @{
|
@"identifier": @{
|
||||||
|
@ -89,7 +89,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
@"password": password
|
@"password": password
|
||||||
};
|
};
|
||||||
|
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(nil, exception);
|
block(nil, exception);
|
||||||
|
@ -217,7 +217,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
forKey: @"timeout"];
|
forKey: @"timeout"];
|
||||||
query[@"since"] = [_storage nextBatchForDeviceID: _deviceID];
|
query[@"since"] = [_storage nextBatchForDeviceID: _deviceID];
|
||||||
request.query = query;
|
request.query = query;
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
if (_syncExceptionHandler != NULL)
|
if (_syncExceptionHandler != NULL)
|
||||||
|
@ -275,13 +275,13 @@ validateHomeserver(OFURL *homeserver)
|
||||||
_syncing = false;
|
_syncing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)logOutWithBlock: (mtx_client_response_block_t)block
|
- (void)logOutWithBlock: (MTXClientResponseBlock)block
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
MTXRequest *request =
|
MTXRequest *request =
|
||||||
[self requestWithPath: @"/_matrix/client/r0/logout"];
|
[self requestWithPath: @"/_matrix/client/r0/logout"];
|
||||||
request.method = OF_HTTP_REQUEST_METHOD_POST;
|
request.method = OFHTTPRequestMethodPost;
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(exception);
|
block(exception);
|
||||||
|
@ -302,12 +302,12 @@ validateHomeserver(OFURL *homeserver)
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)fetchRoomListWithBlock: (mtx_client_room_list_block_t)block
|
- (void)fetchRoomListWithBlock: (MTXClientRoomListBlock)block
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
MTXRequest *request =
|
MTXRequest *request =
|
||||||
[self requestWithPath: @"/_matrix/client/r0/joined_rooms"];
|
[self requestWithPath: @"/_matrix/client/r0/joined_rooms"];
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(nil, exception);
|
block(nil, exception);
|
||||||
|
@ -341,14 +341,13 @@ validateHomeserver(OFURL *homeserver)
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)joinRoom: (OFString *)room
|
- (void)joinRoom: (OFString *)room block: (MTXClientRoomJoinBlock)block
|
||||||
block: (mtx_client_room_join_block_t)block
|
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
MTXRequest *request = [self requestWithPath:
|
MTXRequest *request = [self requestWithPath:
|
||||||
[OFString stringWithFormat: @"/_matrix/client/r0/join/%@", room]];
|
[OFString stringWithFormat: @"/_matrix/client/r0/join/%@", room]];
|
||||||
request.method = OF_HTTP_REQUEST_METHOD_POST;
|
request.method = OFHTTPRequestMethodPost;
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(nil, exception);
|
block(nil, exception);
|
||||||
|
@ -376,14 +375,13 @@ validateHomeserver(OFURL *homeserver)
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)leaveRoom: (OFString *)roomID
|
- (void)leaveRoom: (OFString *)roomID block: (MTXClientResponseBlock)block
|
||||||
block: (mtx_client_response_block_t)block
|
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
MTXRequest *request = [self requestWithPath: [OFString
|
MTXRequest *request = [self requestWithPath: [OFString
|
||||||
stringWithFormat: @"/_matrix/client/r0/rooms/%@/leave", roomID]];
|
stringWithFormat: @"/_matrix/client/r0/rooms/%@/leave", roomID]];
|
||||||
request.method = OF_HTTP_REQUEST_METHOD_POST;
|
request.method = OFHTTPRequestMethodPost;
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(exception);
|
block(exception);
|
||||||
|
@ -407,18 +405,18 @@ validateHomeserver(OFURL *homeserver)
|
||||||
|
|
||||||
- (void)sendMessage: (OFString *)message
|
- (void)sendMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
block: (mtx_client_response_block_t)block;
|
block: (MTXClientResponseBlock)block;
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
OFString *path = [OFString stringWithFormat:
|
OFString *path = [OFString stringWithFormat:
|
||||||
@"/_matrix/client/r0/rooms/%@/send/m.room.message", roomID];
|
@"/_matrix/client/r0/rooms/%@/send/m.room.message", roomID];
|
||||||
MTXRequest *request = [self requestWithPath: path];
|
MTXRequest *request = [self requestWithPath: path];
|
||||||
request.method = OF_HTTP_REQUEST_METHOD_POST;
|
request.method = OFHTTPRequestMethodPost;
|
||||||
request.body = @{
|
request.body = @{
|
||||||
@"msgtype": @"m.text",
|
@"msgtype": @"m.text",
|
||||||
@"body": message
|
@"body": message
|
||||||
};
|
};
|
||||||
[request performWithBlock: ^ (mtx_response_t response, int statusCode,
|
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
block(exception);
|
block(exception);
|
||||||
|
@ -466,8 +464,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (OFString *roomID in rooms)
|
for (OFString *roomID in rooms)
|
||||||
[_storage addJoinedRoom: roomID
|
[_storage addJoinedRoom: roomID forUser: _userID];
|
||||||
forUser: _userID];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)processInvitedRooms: (OFDictionary<OFString *, id> *)rooms
|
- (void)processInvitedRooms: (OFDictionary<OFString *, id> *)rooms
|
||||||
|
@ -482,7 +479,6 @@ validateHomeserver(OFURL *homeserver)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (OFString *roomID in rooms)
|
for (OFString *roomID in rooms)
|
||||||
[_storage removeJoinedRoom: roomID
|
[_storage removeJoinedRoom: roomID forUser: _userID];
|
||||||
forUser: _userID];
|
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -29,7 +29,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
*
|
*
|
||||||
* This is a typedef for `OFDictionary<OFString *, id> *`.
|
* This is a typedef for `OFDictionary<OFString *, id> *`.
|
||||||
*/
|
*/
|
||||||
typedef OFDictionary<OFString *, id> *mtx_response_t;
|
typedef OFDictionary<OFString *, id> *MTXResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A block called with the response for an MTXRequest.
|
* @brief A block called with the response for an MTXRequest.
|
||||||
|
@ -39,8 +39,8 @@ typedef OFDictionary<OFString *, id> *mtx_response_t;
|
||||||
* @param exception The first exception that occurred during the request,
|
* @param exception The first exception that occurred during the request,
|
||||||
* or `nil` on success
|
* or `nil` on success
|
||||||
*/
|
*/
|
||||||
typedef void (^mtx_request_block_t)(mtx_response_t _Nullable response,
|
typedef void (^MTXRequestBlock)(MTXResponse _Nullable response, int statusCode,
|
||||||
int statusCode, id _Nullable exception);
|
id _Nullable exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief An internal class for performing a request on the Matrix server.
|
* @brief An internal class for performing a request on the Matrix server.
|
||||||
|
@ -63,7 +63,7 @@ typedef void (^mtx_request_block_t)(mtx_response_t _Nullable response,
|
||||||
*
|
*
|
||||||
* Defaults to `OF_HTTP_REQUEST_METHOD_GET`.
|
* Defaults to `OF_HTTP_REQUEST_METHOD_GET`.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic) of_http_request_method_t method;
|
@property (nonatomic) OFHTTPRequestMethod method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The path of the request.
|
* @brief The path of the request.
|
||||||
|
@ -112,7 +112,7 @@ typedef void (^mtx_request_block_t)(mtx_response_t _Nullable response,
|
||||||
*
|
*
|
||||||
* @param block The block to call once the request succeeded or failed
|
* @param block The block to call once the request succeeded or failed
|
||||||
*/
|
*/
|
||||||
- (void)performWithBlock: (mtx_request_block_t)block;
|
- (void)performWithBlock: (MTXRequestBlock)block;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
@implementation MTXRequest
|
@implementation MTXRequest
|
||||||
{
|
{
|
||||||
OFData *_body;
|
OFData *_body;
|
||||||
mtx_request_block_t _block;
|
MTXRequestBlock _block;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)requestWithPath: (OFString *)path
|
+ (instancetype)requestWithPath: (OFString *)path
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
_accessToken = [accessToken copy];
|
_accessToken = [accessToken copy];
|
||||||
_homeserver = [homeserver copy];
|
_homeserver = [homeserver copy];
|
||||||
_path = [path copy];
|
_path = [path copy];
|
||||||
_method = OF_HTTP_REQUEST_METHOD_GET;
|
_method = OFHTTPRequestMethodGet;
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -73,8 +73,7 @@
|
||||||
[_body release];
|
[_body release];
|
||||||
|
|
||||||
OFString *JSONString = [body JSONRepresentation];
|
OFString *JSONString = [body JSONRepresentation];
|
||||||
_body = [[OFData alloc]
|
_body = [[OFData alloc] initWithItems: JSONString.UTF8String
|
||||||
initWithItems: JSONString.UTF8String
|
|
||||||
count: JSONString.UTF8StringLength];
|
count: JSONString.UTF8StringLength];
|
||||||
|
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
|
@ -83,11 +82,10 @@
|
||||||
- (OFDictionary<OFString *, id> *)body
|
- (OFDictionary<OFString *, id> *)body
|
||||||
{
|
{
|
||||||
return [OFString stringWithUTF8String: _body.items
|
return [OFString stringWithUTF8String: _body.items
|
||||||
length: _body.count]
|
length: _body.count].objectByParsingJSON;
|
||||||
.objectByParsingJSON;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performWithBlock: (mtx_request_block_t)block
|
- (void)performWithBlock: (MTXRequestBlock)block
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@
|
||||||
exception = nil;
|
exception = nil;
|
||||||
|
|
||||||
/* Reset to nil first, so that another one can be performed. */
|
/* Reset to nil first, so that another one can be performed. */
|
||||||
mtx_request_block_t block = _block;
|
MTXRequestBlock block = _block;
|
||||||
_block = nil;
|
_block = nil;
|
||||||
|
|
||||||
if (exception == nil) {
|
if (exception == nil) {
|
||||||
|
@ -142,11 +140,10 @@
|
||||||
size_t length = [response readIntoBuffer: buffer
|
size_t length = [response readIntoBuffer: buffer
|
||||||
length: 512];
|
length: 512];
|
||||||
|
|
||||||
[responseData addItems: buffer
|
[responseData addItems: buffer count: length];
|
||||||
count: length];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx_response_t responseJSON = [OFString
|
MTXResponse responseJSON = [OFString
|
||||||
stringWithUTF8String: responseData.items
|
stringWithUTF8String: responseData.items
|
||||||
length: responseData.count]
|
length: responseData.count]
|
||||||
.objectByParsingJSON;
|
.objectByParsingJSON;
|
||||||
|
|
|
@ -106,13 +106,12 @@
|
||||||
@");"];
|
@");"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)transactionWithBlock: (mtx_storage_transaction_block_t)block
|
- (void)transactionWithBlock: (MTXStorageTransactionBlock)block
|
||||||
{
|
{
|
||||||
[_conn transactionWithBlock: block];
|
[_conn transactionWithBlock: block];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setNextBatch: (OFString *)nextBatch
|
- (void)setNextBatch: (OFString *)nextBatch forDeviceID: (OFString *)deviceID
|
||||||
forDeviceID: (OFString *)deviceID
|
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
|
@ -146,8 +145,7 @@
|
||||||
return [nextBatch autorelease];
|
return [nextBatch autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addJoinedRoom: (OFString *)roomID
|
- (void)addJoinedRoom: (OFString *)roomID forUser: (OFString *)userID
|
||||||
forUser: (OFString *)userID
|
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
|
@ -161,8 +159,7 @@
|
||||||
objc_autoreleasePoolPop(pool);
|
objc_autoreleasePoolPop(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeJoinedRoom: (OFString *)roomID
|
- (void)removeJoinedRoom: (OFString *)roomID forUser: (OFString *)userID
|
||||||
forUser: (OFString *)userID
|
|
||||||
{
|
{
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
|
@ -182,9 +179,7 @@
|
||||||
void *pool = objc_autoreleasePoolPush();
|
void *pool = objc_autoreleasePoolPush();
|
||||||
|
|
||||||
[_joinedRoomsGetStatement reset];
|
[_joinedRoomsGetStatement reset];
|
||||||
[_joinedRoomsGetStatement bindWithDictionary: @{
|
[_joinedRoomsGetStatement bindWithDictionary: @{ @"$user_id": userID }];
|
||||||
@"$user_id": userID
|
|
||||||
}];
|
|
||||||
|
|
||||||
while ([_joinedRoomsGetStatement step])
|
while ([_joinedRoomsGetStatement step])
|
||||||
[joinedRooms addObject:
|
[joinedRooms addObject:
|
||||||
|
|
|
@ -30,7 +30,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
* @return Whether the transaction should be committed (`true`) or rolled back
|
* @return Whether the transaction should be committed (`true`) or rolled back
|
||||||
* (`false`).
|
* (`false`).
|
||||||
*/
|
*/
|
||||||
typedef bool (^mtx_storage_transaction_block_t)(void);
|
typedef bool (^MTXStorageTransactionBlock)(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A protocol for a storage to be used by @ref MTXClient.
|
* @brief A protocol for a storage to be used by @ref MTXClient.
|
||||||
|
@ -39,7 +39,7 @@ typedef bool (^mtx_storage_transaction_block_t)(void);
|
||||||
/**
|
/**
|
||||||
* @brief Performs all operations inside the block as a transaction.
|
* @brief Performs all operations inside the block as a transaction.
|
||||||
*/
|
*/
|
||||||
- (void)transactionWithBlock: (mtx_storage_transaction_block_t)block;
|
- (void)transactionWithBlock: (MTXStorageTransactionBlock)block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stores the next batch for the specified device.
|
* @brief Stores the next batch for the specified device.
|
||||||
|
@ -47,8 +47,7 @@ typedef bool (^mtx_storage_transaction_block_t)(void);
|
||||||
* @param nextBatch The next batch for the device
|
* @param nextBatch The next batch for the device
|
||||||
* @param deviceID The device for which to store the next batch
|
* @param deviceID The device for which to store the next batch
|
||||||
*/
|
*/
|
||||||
- (void)setNextBatch: (OFString *)nextBatch
|
- (void)setNextBatch: (OFString *)nextBatch forDeviceID: (OFString *)deviceID;
|
||||||
forDeviceID: (OFString *)deviceID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the next batch for the specified device.
|
* @brief Returns the next batch for the specified device.
|
||||||
|
@ -66,8 +65,7 @@ typedef bool (^mtx_storage_transaction_block_t)(void);
|
||||||
* @param roomID The room ID to add to the list of joined rooms
|
* @param roomID The room ID to add to the list of joined rooms
|
||||||
* @param userID The user ID for which to add the room
|
* @param userID The user ID for which to add the room
|
||||||
*/
|
*/
|
||||||
- (void)addJoinedRoom: (OFString *)roomID
|
- (void)addJoinedRoom: (OFString *)roomID forUser: (OFString *)userID;
|
||||||
forUser: (OFString *)userID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Removes the specified room ID to the list of joined rooms for the
|
* @brief Removes the specified room ID to the list of joined rooms for the
|
||||||
|
@ -76,8 +74,7 @@ typedef bool (^mtx_storage_transaction_block_t)(void);
|
||||||
* @param roomID The room ID to add to the list of joined rooms
|
* @param roomID The room ID to add to the list of joined rooms
|
||||||
* @param userID The user ID for which to add the room
|
* @param userID The user ID for which to add the room
|
||||||
*/
|
*/
|
||||||
- (void)removeJoinedRoom: (OFString *)roomID
|
- (void)removeJoinedRoom: (OFString *)roomID forUser: (OFString *)userID;
|
||||||
forUser: (OFString *)userID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the joined room IDs for the specified user ID.
|
* @brief Returns the joined room IDs for the specified user ID.
|
||||||
|
|
|
@ -30,14 +30,14 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface MTXClientException: OFException
|
@interface MTXClientException: OFException
|
||||||
@property (readonly, nonatomic) int statusCode;
|
@property (readonly, nonatomic) int statusCode;
|
||||||
@property (readonly, nonatomic) mtx_response_t response;
|
@property (readonly, nonatomic) MTXResponse response;
|
||||||
@property (readonly, nonatomic) MTXClient *client;
|
@property (readonly, nonatomic) MTXClient *client;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
- (instancetype)initWithStatusCode: (int)statusCode
|
- (instancetype)initWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)respons
|
response: (MTXResponse)respons
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
OF_DESIGNATED_INITIALIZER;
|
OF_DESIGNATED_INITIALIZER;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
@implementation MTXClientException
|
@implementation MTXClientException
|
||||||
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithStatusCode: statusCode
|
return [[[self alloc] initWithStatusCode: statusCode
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithStatusCode: (int)statusCode
|
- (instancetype)initWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
|
@ -30,18 +30,18 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) OFString *room;
|
@property (readonly, nonatomic) OFString *room;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
+ (instancetype)exceptionWithRoom: (OFString *)room
|
+ (instancetype)exceptionWithRoom: (OFString *)room
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
- (instancetype)initWithStatusCode: (int)statusCode
|
- (instancetype)initWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithRoom: (OFString *)room
|
- (instancetype)initWithRoom: (OFString *)room
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
@implementation MTXJoinRoomFailedException
|
@implementation MTXJoinRoomFailedException
|
||||||
+ (instancetype)exceptionWithRoom: (OFString *)room
|
+ (instancetype)exceptionWithRoom: (OFString *)room
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithRoom: room
|
return [[[self alloc] initWithRoom: room
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
- (instancetype)initWithRoom: (OFString *)room
|
- (instancetype)initWithRoom: (OFString *)room
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
self = [super initWithStatusCode: statusCode
|
self = [super initWithStatusCode: statusCode
|
||||||
|
|
|
@ -30,18 +30,18 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) OFString *roomID;
|
@property (readonly, nonatomic) OFString *roomID;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
+ (instancetype)exceptionWithRoomID: (OFString *)roomID
|
+ (instancetype)exceptionWithRoomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
- (instancetype)initWithStatusCode: (int)statusCode
|
- (instancetype)initWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithRoomID: (OFString *)roomID
|
- (instancetype)initWithRoomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
@implementation MTXLeaveRoomFailedException
|
@implementation MTXLeaveRoomFailedException
|
||||||
+ (instancetype)exceptionWithRoomID: (OFString *)roomID
|
+ (instancetype)exceptionWithRoomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithRoomID: roomID
|
return [[[self alloc] initWithRoomID: roomID
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
- (instancetype)initWithRoomID: (OFString *)roomID
|
- (instancetype)initWithRoomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
self = [super initWithStatusCode: statusCode
|
self = [super initWithStatusCode: statusCode
|
||||||
|
|
|
@ -30,16 +30,16 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) OFString *user;
|
@property (readonly, nonatomic) OFString *user;
|
||||||
@property (readonly, nonatomic) OFURL *homeserver;
|
@property (readonly, nonatomic) OFURL *homeserver;
|
||||||
@property (readonly, nonatomic) int statusCode;
|
@property (readonly, nonatomic) int statusCode;
|
||||||
@property (readonly, nonatomic) mtx_response_t response;
|
@property (readonly, nonatomic) MTXResponse response;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithUser: (OFString *)user
|
+ (instancetype)exceptionWithUser: (OFString *)user
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response;
|
response: (MTXResponse)response;
|
||||||
- (instancetype)initWithUser: (OFString *)user
|
- (instancetype)initWithUser: (OFString *)user
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response;
|
response: (MTXResponse)response;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
+ (instancetype)exceptionWithUser: (OFString *)user
|
+ (instancetype)exceptionWithUser: (OFString *)user
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithUser: user
|
return [[[self alloc] initWithUser: user
|
||||||
homeserver: homeserver
|
homeserver: homeserver
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
- (instancetype)initWithUser: (OFString *)user
|
- (instancetype)initWithUser: (OFString *)user
|
||||||
homeserver: (OFURL *)homeserver
|
homeserver: (OFURL *)homeserver
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
|
|
@ -31,20 +31,20 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) OFString *roomID;
|
@property (readonly, nonatomic) OFString *roomID;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
+ (instancetype)exceptionWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
+ (instancetype)exceptionWithMessage: (OFString *)message
|
+ (instancetype)exceptionWithMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client;
|
client: (MTXClient *)client;
|
||||||
- (instancetype)initWithStatusCode: (int)statusCode
|
- (instancetype)initWithStatusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_UNAVAILABLE;
|
client: (MTXClient *)client OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithMessage: (OFString *)message
|
- (instancetype)initWithMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client OF_DESIGNATED_INITIALIZER;
|
client: (MTXClient *)client OF_DESIGNATED_INITIALIZER;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
+ (instancetype)exceptionWithMessage: (OFString *)message
|
+ (instancetype)exceptionWithMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithMessage: message
|
return [[[self alloc] initWithMessage: message
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
- (instancetype)initWithMessage: (OFString *)message
|
- (instancetype)initWithMessage: (OFString *)message
|
||||||
roomID: (OFString *)roomID
|
roomID: (OFString *)roomID
|
||||||
statusCode: (int)statusCode
|
statusCode: (int)statusCode
|
||||||
response: (mtx_response_t)response
|
response: (MTXResponse)response
|
||||||
client: (MTXClient *)client
|
client: (MTXClient *)client
|
||||||
{
|
{
|
||||||
self = [super initWithStatusCode: statusCode
|
self = [super initWithStatusCode: statusCode
|
||||||
|
|
|
@ -41,7 +41,7 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
if (environment[@"OBJMATRIX_USER"] == nil ||
|
if (environment[@"OBJMATRIX_USER"] == nil ||
|
||||||
environment[@"OBJMATRIX_PASS"] == nil ||
|
environment[@"OBJMATRIX_PASS"] == nil ||
|
||||||
environment[@"OBJMATRIX_HS"] == nil) {
|
environment[@"OBJMATRIX_HS"] == nil) {
|
||||||
[of_stderr writeString: @"Please set OBJMATRIX_USER, "
|
[OFStdErr writeString: @"Please set OBJMATRIX_USER, "
|
||||||
@"OBJMATRIX_PASS and OBJMATRIX_HS in "
|
@"OBJMATRIX_PASS and OBJMATRIX_HS in "
|
||||||
@"the environment!\n"];
|
@"the environment!\n"];
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
|
@ -56,12 +56,12 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
storage: storage
|
storage: storage
|
||||||
block: ^ (MTXClient *client, id exception) {
|
block: ^ (MTXClient *client, id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Error logging in: %@", exception);
|
OFLog(@"Error logging in: %@", exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
_client = [client retain];
|
_client = [client retain];
|
||||||
of_log(@"Logged in client: %@", _client);
|
OFLog(@"Logged in client: %@", _client);
|
||||||
|
|
||||||
[_client startSyncLoop];
|
[_client startSyncLoop];
|
||||||
[self fetchRoomList];
|
[self fetchRoomList];
|
||||||
|
@ -73,11 +73,11 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
[_client fetchRoomListWithBlock: ^ (OFArray<OFString *> *rooms,
|
[_client fetchRoomListWithBlock: ^ (OFArray<OFString *> *rooms,
|
||||||
id exception) {
|
id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Failed to fetch room list: %@", exception);
|
OFLog(@"Failed to fetch room list: %@", exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
of_log(@"Fetched room list: %@", rooms);
|
OFLog(@"Fetched room list: %@", rooms);
|
||||||
|
|
||||||
[self joinRoom];
|
[self joinRoom];
|
||||||
}];
|
}];
|
||||||
|
@ -86,15 +86,14 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
- (void)joinRoom
|
- (void)joinRoom
|
||||||
{
|
{
|
||||||
OFString *room = @"#test:nil.im";
|
OFString *room = @"#test:nil.im";
|
||||||
[_client joinRoom: room
|
[_client joinRoom: room block: ^ (OFString *roomID, id exception) {
|
||||||
block: ^ (OFString *roomID, id exception) {
|
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Failed to join room %@: %@", room, exception);
|
OFLog(@"Failed to join room %@: %@", room, exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
_roomID = [roomID copy];
|
_roomID = [roomID copy];
|
||||||
of_log(@"Joined room %@", _roomID);
|
OFLog(@"Joined room %@", _roomID);
|
||||||
|
|
||||||
[self sendMessage];
|
[self sendMessage];
|
||||||
}];
|
}];
|
||||||
|
@ -106,31 +105,28 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
roomID: _roomID
|
roomID: _roomID
|
||||||
block: ^ (id exception) {
|
block: ^ (id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Failed to send message to room %@: %@",
|
OFLog(@"Failed to send message to room %@: %@",
|
||||||
_roomID, exception);
|
_roomID, exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
of_log(@"Message sent to %@", _roomID);
|
OFLog(@"Message sent to %@", _roomID);
|
||||||
|
|
||||||
of_log(
|
OFLog(@"Waiting 5 seconds before leaving room and logging out");
|
||||||
@"Waiting 5 seconds before leaving room and logging out");
|
|
||||||
|
|
||||||
[self performSelector: @selector(leaveRoom)
|
[self performSelector: @selector(leaveRoom) afterDelay: 5];
|
||||||
afterDelay: 5];
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)leaveRoom
|
- (void)leaveRoom
|
||||||
{
|
{
|
||||||
[_client leaveRoom: _roomID
|
[_client leaveRoom: _roomID block: ^ (id exception) {
|
||||||
block: ^ (id exception) {
|
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Failed to leave room %@: %@", exception);
|
OFLog(@"Failed to leave room %@: %@", exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
of_log(@"Left room %@", _roomID);
|
OFLog(@"Left room %@", _roomID);
|
||||||
|
|
||||||
[self logOut];
|
[self logOut];
|
||||||
}];
|
}];
|
||||||
|
@ -140,11 +136,11 @@ OF_APPLICATION_DELEGATE(Tests)
|
||||||
{
|
{
|
||||||
[_client logOutWithBlock: ^ (id exception) {
|
[_client logOutWithBlock: ^ (id exception) {
|
||||||
if (exception != nil) {
|
if (exception != nil) {
|
||||||
of_log(@"Failed to log out: %@\n", exception);
|
OFLog(@"Failed to log out: %@\n", exception);
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
of_log(@"Logged out client");
|
OFLog(@"Logged out client");
|
||||||
|
|
||||||
[OFApplication terminate];
|
[OFApplication terminate];
|
||||||
}];
|
}];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue