Skip to content

Commit

Permalink
MXSession: add setAccountData
Browse files Browse the repository at this point in the history
element-hq/element-ios#1860

and create a const for "m.widgets" account data
  • Loading branch information
manuroe committed May 24, 2018
1 parent 0672124 commit 22d9be0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions MatrixSDK/MXRestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ FOUNDATION_EXPORT NSString *const kMXContentPrefixPath;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeDirect;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypePushRules;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeIgnoredUserList;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeUserWidgets;

/**
Account data keys
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
NSString *const kMXAccountDataTypeIgnoredUserList = @"m.ignored_user_list";
NSString *const kMXAccountDataTypePushRules = @"m.push_rules";
NSString *const kMXAccountDataTypeDirect = @"m.direct";
NSString *const kMXAccountDataTypeUserWidgets = @"m.widgets";

/**
Account data keys
Expand Down
18 changes: 18 additions & 0 deletions MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,24 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);
- (NSString*)tagOrderToBeAtIndex:(NSUInteger)index from:(NSUInteger)originIndex withTag:(NSString *)tag;


#pragma mark - User's account data
/**
Set some account data for the user.
@param data the new data to set for this event type.
@param type The event type of the account_data to set (@see kMXAccountDataType* strings)
Custom types should be namespaced to avoid clashes.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setAccountData:(NSDictionary*)data
forType:(NSString*)type
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;


#pragma mark - Crypto
/**
Decrypt an event and update its data.
Expand Down
15 changes: 12 additions & 3 deletions MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ - (MXHTTPOperation*)uploadDirectRooms:(void (^)(void))success
__weak typeof(self) weakSelf = self;

// Push the current direct rooms dictionary to the homeserver.
return [matrixRestClient setAccountData:_directRooms forType:kMXAccountDataTypeDirect success:^{
return [self setAccountData:_directRooms forType:kMXAccountDataTypeDirect success:^{

// Notify a change in direct rooms directory
[[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionDirectRoomsDidChangeNotification
Expand Down Expand Up @@ -2598,7 +2598,7 @@ - (MXHTTPOperation*)ignoreUsers:(NSArray<NSString*>*)userIds
kMXAccountDataKeyIgnoredUser: ignoredUsersDict
};
// __weak __typeof(self)weakSelf = self;
return [matrixRestClient setAccountData:data forType:kMXAccountDataTypeIgnoredUserList success:^{
return [self setAccountData:data forType:kMXAccountDataTypeIgnoredUserList success:^{

// __strong __typeof(weakSelf)strongSelf = weakSelf;

Expand Down Expand Up @@ -2641,7 +2641,7 @@ - (MXHTTPOperation *)unIgnoreUsers:(NSArray<NSString *> *)userIds success:(void
kMXAccountDataKeyIgnoredUser: ignoredUsersDict
};
// __weak __typeof(self)weakSelf = self;
return [matrixRestClient setAccountData:data forType:kMXAccountDataTypeIgnoredUserList success:^{
return [self setAccountData:data forType:kMXAccountDataTypeIgnoredUserList success:^{

// __strong __typeof(weakSelf)strongSelf = weakSelf;

Expand Down Expand Up @@ -2953,6 +2953,15 @@ - (NSString*)tagOrderToBeAtIndex:(NSUInteger)index from:(NSUInteger)originIndex
}


#pragma mark - User's account data
- (MXHTTPOperation*)setAccountData:(NSDictionary*)data
forType:(NSString*)type
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{
return [matrixRestClient setAccountData:data forType:type success:success failure:failure];
}

#pragma mark - Crypto

/**
Expand Down

0 comments on commit 22d9be0

Please sign in to comment.