Files
bundesmessenger-ios/bwi/RollsAndRights/MXRoom+sendRoomPowerLevels.m
T
2022-03-17 15:51:23 +01:00

49 lines
2.2 KiB
Objective-C

#import "MXRoom+sendRoomPowerLevels.h"
@implementation MXRoom (BWI)
- (MXHTTPOperation*)sendRoomPowerLevelGeneral:(NSInteger)powerLevelGeneral
powerLevelInvite:(NSInteger)powerLevelInvite
powerLevelBan:(NSInteger)powerLevelBan
powerLevelSend:(NSInteger)powerLevelSend
powerLevelRedact:(NSInteger)powerLevelRedact
success:(void (^)(void))success
failure:(void (^)(NSError *))failure
{
// Create an empty operation that will be mutated later
MXHTTPOperation *operation = [[MXHTTPOperation alloc] init];
MXWeakify(self);
[self state:^(MXRoomState *roomState) {
MXStrongifyAndReturnIfNil(self);
// To set this new value, we have to take the current powerLevels content,
// Update it with expected values and send it to the home server.
NSMutableDictionary *eventContent = [NSMutableDictionary dictionaryWithDictionary:roomState.powerLevels.JSONDictionary];
NSMutableDictionary *eventPowerLevels = [NSMutableDictionary dictionaryWithDictionary:eventContent[@"events"]];
eventPowerLevels[@"m.room.name"] = [NSNumber numberWithInteger:powerLevelGeneral];
eventPowerLevels[@"m.room.topic"] = [NSNumber numberWithInteger:powerLevelGeneral];
eventPowerLevels[@"m.room.avatar"] = [NSNumber numberWithInteger:powerLevelGeneral];
eventContent[@"events"] = eventPowerLevels;
eventContent[@"invite"] = [NSNumber numberWithInteger:powerLevelInvite];
eventContent[@"kick"] = [NSNumber numberWithInteger:powerLevelBan];
eventContent[@"ban"] = [NSNumber numberWithInteger:powerLevelBan];
eventContent[@"redact"] = [NSNumber numberWithInteger:powerLevelRedact];
eventContent[@"events_default"] = [NSNumber numberWithInteger:powerLevelSend];
// Make the request to the HS
MXHTTPOperation *_operation = [self sendStateEventOfType:kMXEventTypeStringRoomPowerLevels content:eventContent stateKey:nil success:^(NSString *eventId) {
success();
} failure:failure];
[operation mutateTo:_operation];
}];
return operation;
}
@end