Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MatrixSDK/Data/MXRoomState.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ Use MXRoomSummary.displayname to get a computed room display name.
*/
- (float)memberNormalizedPowerLevel:(NSString*)userId;

/**
Returns the power level for a given user identifier, this checks also for the creator and additional creators
*/
- (NSInteger)powerLevelOfUserWithUserID:(NSString *)userId;


# pragma mark - Conference call
/**
Expand Down
41 changes: 36 additions & 5 deletions MatrixSDK/Data/MXRoomState.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,30 @@ - (NSString *)creatorUserId

// Check it from the state events
MXEvent *event = [stateEvents objectForKey:kMXEventTypeStringRoomCreate].lastObject;
NSString* sender = [event sender];

if (event && sender)
{
creatorUserId = [sender copy];
}
return creatorUserId;
}

- (NSArray<NSString*> *)additionalCreators
{
NSArray<NSString*> *additionalCreators = @[];

// Check it from the state events
MXEvent *event = [stateEvents objectForKey:kMXEventTypeStringRoomCreate].lastObject;
NSDictionary<NSString *, id> *eventContent = [self contentOfEvent:event];

if (event && eventContent)
{
MXJSONModelSetString(creatorUserId, eventContent[@"creator"]);
creatorUserId = [creatorUserId copy];
MXJSONModelSetArray(additionalCreators, eventContent[@"additional_creators"]);
additionalCreators = [additionalCreators copy];

}
return creatorUserId;
return additionalCreators;
}

- (MXRoomHistoryVisibility)historyVisibility
Expand Down Expand Up @@ -601,13 +616,29 @@ - (float)memberNormalizedPowerLevel:(NSString*)userId
// Ignore banned and left (kicked) members
if (member.membership != MXMembershipLeave && member.membership != MXMembershipBan)
{
float userPowerLevelFloat = [powerLevels powerLevelOfUserWithUserID:userId];
powerLevel = maxPowerLevel ? userPowerLevelFloat / maxPowerLevel : 1;
float userPowerLevelFloat = [self powerLevelOfUserWithUserID:userId];
if (maxPowerLevel && userPowerLevelFloat >= maxPowerLevel)
{
powerLevel = 1;
}
else
{
powerLevel = maxPowerLevel ? userPowerLevelFloat / maxPowerLevel : 1;
}
}

return powerLevel;
}

- (NSInteger)powerLevelOfUserWithUserID:(NSString *)userId
{
if ([userId isEqualToString: [self creatorUserId]] || [[self additionalCreators] containsObject: userId])
{
return NSIntegerMax;
}
return [powerLevels powerLevelOfUserWithUserID:userId];
}

# pragma mark - Conference call
- (BOOL)isOngoingConferenceCall
{
Expand Down
3 changes: 2 additions & 1 deletion MatrixSDK/JSONModels/MXEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ - (MXEvent*)prune

case MXEventTypeRoomCreate:
{
allowedKeys = @[@"creator"];
allowedKeys = @[@"creator",
@"additional_creators"];
break;
}

Expand Down
5 changes: 5 additions & 0 deletions MatrixSDK/JSONModels/MXRoomCreateContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ extern NSString* _Nonnull const MXRoomCreateContentRoomTypeJSONKey;
*/
@property (nonatomic, copy, readonly, nullable) NSString *creatorUserId;

/**
The array of `user_id` of the additional room creators.
*/
@property (nonatomic, copy, readonly, nullable) NSArray<NSString*> *additionalCreators;

/**
Room predecessor information if the current room is a new version of an old room (that has a state event `m.room.tombstone`).
*/
Expand Down
8 changes: 8 additions & 0 deletions MatrixSDK/JSONModels/MXRoomCreateContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// Private

static NSString* const kRoomCreateContentUserIdJSONKey = @"creator";
static NSString* const kRoomCreateContentAdditionalCreatorsJSONKey = @"additional_creators";
static NSString* const kRoomCreateContentPredecessorInfoJSONKey = @"predecessor";
static NSString* const kRoomCreateContentRoomVersionJSONKey = @"room_version";
static NSString* const kRoomCreateContentFederateJSONKey = @"m.federate";
Expand All @@ -34,6 +35,7 @@
@interface MXRoomCreateContent()

@property (nonatomic, copy, readwrite, nullable) NSString *creatorUserId;
@property (nonatomic, copy, readwrite, nullable) NSArray<NSString*> *additionalCreators;
@property (nonatomic, strong, readwrite, nullable) MXRoomPredecessorInfo *roomPredecessorInfo;
@property (nonatomic, copy, readwrite, nullable) NSString *roomVersion;
@property (nonatomic, readwrite) BOOL isFederated;
Expand All @@ -53,6 +55,7 @@ + (id)modelFromJSON:(NSDictionary *)jsonDictionary
roomCreateContent.isFederated = YES;

MXJSONModelSetString(roomCreateContent.creatorUserId, jsonDictionary[kRoomCreateContentUserIdJSONKey]);
MXJSONModelSetArray(roomCreateContent.additionalCreators, jsonDictionary[kRoomCreateContentAdditionalCreatorsJSONKey]);
MXJSONModelSetMXJSONModel(roomCreateContent.roomPredecessorInfo, MXRoomPredecessorInfo, jsonDictionary[kRoomCreateContentPredecessorInfoJSONKey]);
MXJSONModelSetString(roomCreateContent.roomVersion, jsonDictionary[kRoomCreateContentRoomVersionJSONKey]);
MXJSONModelSetBoolean(roomCreateContent.isFederated, jsonDictionary[kRoomCreateContentFederateJSONKey]);
Expand Down Expand Up @@ -94,6 +97,11 @@ - (NSDictionary *)JSONDictionary
jsonDictionary[MXRoomCreateContentRoomTypeJSONKey] = self.roomType;
}

if (self.additionalCreators)
{
jsonDictionary[kRoomCreateContentAdditionalCreatorsJSONKey] = self.additionalCreators;
}

return jsonDictionary;
}

Expand Down