Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Enhance the flair handling,
Browse files Browse the repository at this point in the history
by managing the related groups of a room at the RoomDataSource level instead of at the bubble level

element-hq/riot-meta#118
  • Loading branch information
giomfo committed Feb 6, 2018
1 parent 7f854e2 commit 5db5c0d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
20 changes: 5 additions & 15 deletions MatrixKit/Models/Room/MXKRoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,8 @@ - (void)refreshSenderFlair
{
if ([senderPublicisedGroups indexOfObject:groupId] != NSNotFound)
{
MXGroup *group = [self.mxSession groupWithGroupId:groupId];
if (!group)
{
// The current user doesn't belong to this group.
// Create a group instance.
group = [[MXGroup alloc] initWithGroupId:groupId];
}

MXGroup *group = [roomDataSource groupWithGroupId:groupId];
[flair addObject:group];

// Refresh the group profile from server.
[self.mxSession updateGroupProfile:group success:nil failure:^(NSError *error) {

NSLog(@"[MXKRoomBubbleCellData] refreshSenderFlair: group profile update failed %@", groupId);

}];
}
}

Expand All @@ -412,6 +398,10 @@ - (void)refreshSenderFlair
self.senderFlair = nil;
}
}
else
{
self.senderFlair = nil;
}

// Observe any change on publicised groups for the message sender
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionUpdatePublicisedGroupsForUsers:) name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];
Expand Down
17 changes: 16 additions & 1 deletion MatrixKit/Models/Room/MXKRoomDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
The queue of events that need to be processed in order to compute their display.
*/
NSMutableArray *eventsToProcess;

/**
The dictionary of the related groups that the current user did not join.
*/
NSMutableDictionary<NSString*, MXGroup*> *externalRelatedGroups;
}

/**
Expand Down Expand Up @@ -142,7 +147,6 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
*/
@property (nonatomic) NSString *partialTextMessage;


#pragma mark - Configuration
/**
The text formatter applied on the events.
Expand Down Expand Up @@ -480,4 +484,15 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
*/
- (void)collapseRoomBubble:(id<MXKRoomBubbleCellDataStoring>)bubbleData collapsed:(BOOL)collapsed;

#pragma mark - Groups

/**
Get a MXGroup instance for a group.
This method is used by the bubble to retrieve a related groups of the room.
@param groupId The identifier to the group.
@return the MXGroup instance.
*/
- (MXGroup *)groupWithGroupId:(NSString*)groupId;

@end
68 changes: 68 additions & 0 deletions MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ - (instancetype)initWithRoomId:(NSString *)roomId andMatrixSession:(MXSession *)
bubbles = [NSMutableArray array];
eventsToProcess = [NSMutableArray array];
eventIdToBubbleMap = [NSMutableDictionary dictionary];

externalRelatedGroups = [NSMutableDictionary dictionary];

// Set default data and view classes
// Cell data
Expand Down Expand Up @@ -280,6 +282,8 @@ - (void)limitMemoryUsage:(NSInteger)maxBubbleNb

- (void)reset
{
[externalRelatedGroups removeAllObjects];

if (roomDidFlushDataNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver];
Expand Down Expand Up @@ -406,6 +410,8 @@ - (void)destroy

[_timeline destroy];

externalRelatedGroups = nil;

[super destroy];
}

Expand Down Expand Up @@ -520,6 +526,40 @@ - (void)didMXSessionStateChange
if (_room.state.relatedGroups.count)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionUpdatePublicisedGroupsForUsers:) name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];

// Get a fresh profile for all the related groups. Trigger a table refresh when all requests are done.
__block NSUInteger count = _room.state.relatedGroups.count;
for (NSString *groupId in _room.state.relatedGroups)
{
MXGroup *group = [self.mxSession groupWithGroupId:groupId];
if (!group)
{
// Create a group instance for the groups that the current user did not join.
group = [[MXGroup alloc] initWithGroupId:groupId];
[externalRelatedGroups setObject:group forKey:groupId];
}

// Refresh the group profile from server.
[self.mxSession updateGroupProfile:group success:^{

if (self.delegate && !(--count))
{
// All the requests have been done.
[self.delegate dataSource:self didCellChange:nil];
}

} failure:^(NSError *error) {

NSLog(@"[MXKRoomDataSource] group profile update failed %@", groupId);

if (self.delegate && !(--count))
{
// All the requests have been done.
[self.delegate dataSource:self didCellChange:nil];
}

}];
}
}
}
else
Expand Down Expand Up @@ -2557,4 +2597,32 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

#pragma mark - Groups

- (MXGroup *)groupWithGroupId:(NSString*)groupId
{
MXGroup *group = [self.mxSession groupWithGroupId:groupId];
if (!group)
{
// Check whether an instance has been already created.
group = [externalRelatedGroups objectForKey:groupId];
}

if (!group)
{
// Create a new group instance.
group = [[MXGroup alloc] initWithGroupId:groupId];
[externalRelatedGroups setObject:group forKey:groupId];

// Retrieve at least the group profile
[self.mxSession updateGroupProfile:group success:nil failure:^(NSError *error) {

NSLog(@"[MXKRoomDataSource] groupWithGroupId: group profile update failed %@", groupId);

}];
}

return group;
}

@end

0 comments on commit 5db5c0d

Please sign in to comment.