Comment: | Initial support for sync
Only sends the sync, does not do anything with the response yet. Handling the response will be implemented in the next several commits, piece by piece. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
17e299f073f39e55dfe0b8a4bd1b34c8 |
User & Date: | js on 2020-10-03 21:56:23 |
Other Links: | manifest | tags |
2020-10-03
| ||
22:32 | Store next batch check-in: 6ab44895eb user: js tags: trunk | |
21:56 | Initial support for sync check-in: 17e299f073 user: js tags: trunk | |
19:47 | Add support for storage check-in: 3c84d235e5 user: js tags: trunk | |
Modified src/MTXClient.h from [2463af8d3c] to [a9c991a2fb].
︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | + + + + + + + + | - (instancetype)initWithUserID: (OFString *)userID deviceID: (OFString *)deviceID accessToken: (OFString *)accessToken homeserver: (OFURL *)homeserver storage: (id <MTXStorage>)storage OF_DESIGNATED_INITIALIZER; /** * @brief Performs a sync. * * @param block A block to call when a sync was performed */ - (void)syncWithTimeout: (of_time_interval_t)timeout block: (mtx_client_response_block_t)block; /** * @brief Logs out the device and invalidates the access token. * * @warning The client can no longer be used after this succeeded! * * @param block A block to call when logging out succeeded or failed */ |
︙ |
Modified src/MTXClient.m from [a5246fd62c] to [348fd1db0b].
︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | + | #import "MTXFetchRoomListFailedException.h" #import "MTXJoinRoomFailedException.h" #import "MTXLeaveRoomFailedException.h" #import "MTXLoginFailedException.h" #import "MTXLogoutFailedException.h" #import "MTXSendMessageFailedException.h" #import "MTXSyncFailedException.h" static void validateHomeserver(OFURL *homeserver) { if (![homeserver.scheme isEqual: @"http"] && ![homeserver.scheme isEqual: @"https"]) @throw [OFUnsupportedProtocolException |
︙ | |||
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | - (MTXRequest *)requestWithPath: (OFString *)path { return [MTXRequest requestWithPath: path accessToken: _accessToken homeserver: _homeserver]; } - (void)syncWithTimeout: (of_time_interval_t)timeout block: (mtx_client_response_block_t)block { void *pool = objc_autoreleasePoolPush(); MTXRequest *request = [self requestWithPath: @"/_matrix/client/r0/sync"]; unsigned long long timeoutMs = timeout * 1000; request.query = [OFString stringWithFormat: @"timeout=%llu", timeoutMs]; [request performWithBlock: ^ (mtx_response_t response, int statusCode, id exception) { if (exception != nil) { block(exception); return; } if (statusCode != 200) { block([MTXSyncFailedException exceptionWithStatusCode: statusCode response: response client: self]); return; } block(nil); }]; objc_autoreleasePoolPop(pool); } - (void)logOutWithBlock: (mtx_client_response_block_t)block { void *pool = objc_autoreleasePoolPush(); MTXRequest *request = [self requestWithPath: @"/_matrix/client/r0/logout"]; request.method = OF_HTTP_REQUEST_METHOD_POST; |
︙ |
Modified src/MTXRequest.h from [c05bb8879a] to [9c39efc51b].
︙ | |||
66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | + + + + + | @property (nonatomic) of_http_request_method_t method; /** * @brief The path of the request. */ @property (copy, nonatomic) OFString *path; /** * @brief The query for the request. */ @property (copy, nullable, nonatomic) OFString *query; /** * @brief An optional body to send along with the request. * * This is a dictionary that gets serialized to JSON when the request is sent. */ @property (copy, nullable, nonatomic) OFDictionary<OFString *, id> *body; |
︙ |
Modified src/MTXRequest.m from [3b4c617815] to [88ddaafdca].
︙ | |||
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | + | if (_block != nil) /* Not the best exception to indicate it's already in-flight. */ @throw [OFAlreadyConnectedException exception]; OFMutableURL *requestURL = [[_homeserver mutableCopy] autorelease]; requestURL.path = _path; requestURL.query = _query; OFMutableDictionary *headers = [OFMutableDictionary dictionary]; headers[@"User-Agent"] = @"ObjMatrix"; if (_accessToken != nil) headers[@"Authorization"] = [OFString stringWithFormat: @"Bearer %@", _accessToken]; if (_body != nil) |
︙ |
Modified src/ObjMatrix.h from [45c5ea7f4a] to [0c8f4f9aec].
︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | + + + | */ #import "MTXClient.h" #import "MTXRequest.h" #import "MTXSQLite3Storage.h" #import "MTXStorage.h" #import "MTXClientException.h" #import "MTXFetchRoomListFailedException.h" #import "MTXJoinRoomFailedException.h" #import "MTXLeaveRoomFailedException.h" #import "MTXLoginFailedException.h" #import "MTXLogoutFailedException.h" #import "MTXSendMessageFailedException.h" #import "MTXSyncFailedException.h" |
Modified src/exceptions/MTXFetchRoomListFailedException.m from [48606353c7] to [ed85cc2a2b].
︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 30 31 32 33 34 | - - + + | #import "MTXClient.h" @implementation MTXFetchRoomListFailedException - (OFString *)description { return [OFString stringWithFormat: |
Modified src/exceptions/MTXJoinRoomFailedException.m from [f939691250] to [6d2b4b0f4f].
︙ | |||
61 62 63 64 65 66 67 | 61 62 63 64 65 66 67 68 69 70 71 | - - + + | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: |
Modified src/exceptions/MTXLeaveRoomFailedException.m from [4b628c276b] to [1ab07a8b06].
︙ | |||
61 62 63 64 65 66 67 | 61 62 63 64 65 66 67 68 69 70 71 | - - + + | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: |
Modified src/exceptions/MTXLoginFailedException.m from [900a59b5fd] to [9df3447195].
︙ | |||
62 63 64 65 66 67 68 | 62 63 64 65 66 67 68 69 70 71 72 | - - + + | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: |
Modified src/exceptions/MTXLogoutFailedException.m from [6372c5e6df] to [1b0abaa340].
︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 30 31 32 33 34 | - - + + | #import "MTXClient.h" @implementation MTXLogoutFailedException - (OFString *)description { return [OFString stringWithFormat: |
Modified src/exceptions/MTXSendMessageFailedException.m from [2c6af4070c] to [4d0e5a29bd].
︙ | |||
66 67 68 69 70 71 72 | 66 67 68 69 70 71 72 73 74 75 76 | - - + + | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: |
Added src/exceptions/MTXSyncFailedException.h version [f96dda2973].
Added src/exceptions/MTXSyncFailedException.m version [ddf381e4b2].
Modified src/exceptions/Makefile from [21b2ee299e] to [3d8ea75409].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | - + + | include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} SRCS = MTXClientException.m \ MTXFetchRoomListFailedException.m \ MTXJoinRoomFailedException.m \ MTXLeaveRoomFailedException.m \ MTXLoginFailedException.m \ MTXLogoutFailedException.m \ |
Modified tests/tests.m from [9a4477a98b] to [247888a299].
︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | + + + + + + + + + + + + + + + | of_log(@"Error logging in: %@", exception); [OFApplication terminateWithStatus: 1]; } _client = [client retain]; of_log(@"Logged in client: %@", _client); [self sync]; }]; } - (void)sync { [_client syncWithTimeout: 5 block: ^ (id exception) { if (exception != nil) { of_log(@"Failed to sync: %@", exception); [OFApplication terminateWithStatus: 1]; } of_log(@"Synced"); [self fetchRoomList]; }]; } - (void)fetchRoomList { [_client fetchRoomListWithBlock: ^ (OFArray<OFString *> *rooms, |
︙ |