Initial skeleton for handling sync

FossilOrigin-Name: 4df5567c11f971e1ea5422bb00f70468d3d1f92bdeb4f9cc39c047c1ac424f3b
This commit is contained in:
Jonathan Schleifer 2020-10-06 20:48:14 +00:00
parent 328d6dd529
commit 962fc15935
2 changed files with 60 additions and 15 deletions

View file

@ -230,8 +230,20 @@ validateHomeserver(OFURL *homeserver)
} }
@try { @try {
[_storage setNextBatch: nextBatch [_storage transactionWithBlock: ^ {
forDeviceID: _deviceID]; [_storage setNextBatch: nextBatch
forDeviceID: _deviceID];
[self processRoomsSync: response[@"rooms"]];
[self processPresenceSync:
response[@"presence"]];
[self processAccountDataSync:
response[@"account_data"]];
[self processToDeviceSync:
response[@"to_device"]];
return true;
}];
} @catch (id e) { } @catch (id e) {
block(e); block(e);
return; return;
@ -408,4 +420,20 @@ validateHomeserver(OFURL *homeserver)
objc_autoreleasePoolPop(pool); objc_autoreleasePoolPop(pool);
} }
- (void)processRoomsSync: (OFDictionary<OFString *, id> *)rooms
{
}
- (void)processPresenceSync: (OFDictionary<OFString *, id> *)presence
{
}
- (void)processAccountDataSync: (OFDictionary<OFString *, id> *)accountData
{
}
- (void)processToDeviceSync: (OFDictionary<OFString *, id> *)toDevice
{
}
@end @end

View file

@ -32,6 +32,7 @@ OF_APPLICATION_DELEGATE(Tests)
@implementation Tests @implementation Tests
{ {
MTXClient *_client; MTXClient *_client;
OFString *_roomID;
} }
- (void)applicationDidFinishLaunching - (void)applicationDidFinishLaunching
@ -106,39 +107,55 @@ OF_APPLICATION_DELEGATE(Tests)
[OFApplication terminateWithStatus: 1]; [OFApplication terminateWithStatus: 1];
} }
of_log(@"Joined room %@", roomID); _roomID = [roomID copy];
of_log(@"Joined room %@", _roomID);
[self sendMessage: roomID]; [self sync2];
}]; }];
} }
- (void)sendMessage: (OFString *)roomID - (void)sync2
{ {
[_client sendMessage: @"ObjMatrix test successful!" [_client syncWithTimeout: 5
roomID: roomID block: ^ (id exception) {
block: ^ (id exception) {
if (exception != nil) { if (exception != nil) {
of_log(@"Failed to send message to room %@: %@", of_log(@"Failed to sync: %@", exception);
roomID, exception);
[OFApplication terminateWithStatus: 1]; [OFApplication terminateWithStatus: 1];
} }
of_log(@"Message sent to %@", roomID); of_log(@"Synced");
[self leaveRoom: roomID]; [self sendMessage];
}]; }];
} }
- (void)leaveRoom: (OFString *)roomID - (void)sendMessage
{ {
[_client leaveRoom: roomID [_client sendMessage: @"ObjMatrix test successful!"
roomID: _roomID
block: ^ (id exception) {
if (exception != nil) {
of_log(@"Failed to send message to room %@: %@",
_roomID, exception);
[OFApplication terminateWithStatus: 1];
}
of_log(@"Message sent to %@", _roomID);
[self leaveRoom];
}];
}
- (void)leaveRoom
{
[_client leaveRoom: _roomID
block: ^ (id exception) { block: ^ (id exception) {
if (exception != nil) { if (exception != nil) {
of_log(@"Failed to leave room %@: %@", exception); of_log(@"Failed to leave room %@: %@", exception);
[OFApplication terminateWithStatus: 1]; [OFApplication terminateWithStatus: 1];
} }
of_log(@"Left room %@", roomID); of_log(@"Left room %@", _roomID);
[self logOut]; [self logOut];
}]; }];