Remove flairs and related groups.

This commit is contained in:
Doug
2022-08-05 15:09:56 +01:00
committed by Doug
parent 85db4e22a0
commit 57f92307f2
21 changed files with 5 additions and 723 deletions
@@ -87,11 +87,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
The listener to receipts events in the room.
*/
id receiptsListener;
/**
The listener to the related groups state events in the room.
*/
id relatedGroupsListener;
/**
The listener to reactions changed in the room.
@@ -318,8 +313,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
eventsToProcess = [NSMutableArray array];
eventIdToBubbleMap = [NSMutableDictionary dictionary];
externalRelatedGroups = [NSMutableDictionary dictionary];
_filterMessagesWithURL = NO;
emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", kMXKSlashCmdEmote];
@@ -471,8 +464,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
- (void)resetNotifying:(BOOL)notify
{
[externalRelatedGroups removeAllObjects];
if (roomDidFlushDataNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver];
@@ -515,9 +506,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[_timeline removeListener:receiptsListener];
receiptsListener = nil;
[_timeline removeListener:relatedGroupsListener];
relatedGroupsListener = nil;
}
if (_secondaryRoom && secondaryLiveEventsListener)
@@ -601,8 +589,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[self unregisterScanManagerNotifications];
[self unregisterReactionsChangeListener];
[self unregisterEventEditsListener];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXEventDidChangeSentStateNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXEventDidDecryptNotification object:nil];
@@ -638,8 +624,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[_timeline destroy];
[_secondaryTimeline destroy];
externalRelatedGroups = nil;
[super destroy];
}
@@ -824,52 +808,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[self setState:MXKDataSourceStateFailed];
}
}
if (_room && MXSessionStateRunning == self.mxSession.state)
{
// Flair handling: observe the update in the publicised groups by users when the flair is enabled in the room.
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];
[self.room state:^(MXRoomState *roomState) {
if (roomState.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 = roomState.relatedGroups.count;
for (NSString *groupId in roomState.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];
[self->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) {
MXLogDebug(@"[MXKRoomDataSource][%p] group profile update failed %@", self, groupId);
if (self.delegate && !(--count))
{
// All the requests have been done.
[self.delegate dataSource:self didCellChange:nil];
}
}];
}
}
}];
}
}
- (void)initializeTimelineForThread
@@ -1008,7 +946,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[_timeline removeListener:liveEventsListener];
[_timeline removeListener:redactionListener];
[_timeline removeListener:receiptsListener];
[_timeline removeListener:relatedGroupsListener];
}
// Listen to live events only for live timeline
@@ -1071,16 +1008,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[self didReceiveReceiptEvent:event roomState:roomState];
}
}];
// Flair handling: register a listener for the related groups state event in this room.
relatedGroupsListener = [_timeline listenToEventsOfTypes:@[kMXEventTypeStringRoomRelatedGroups] onEvent:^(MXEvent *event, MXTimelineDirection direction, MXRoomState *roomState) {
if (MXTimelineDirectionForwards == direction)
{
// The flair settings have been updated: flush the current bubble data and rebuild them.
[self reload];
}
}];
}
// Register a listener to handle redaction which can affect live and past timelines
@@ -2693,32 +2620,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
}
}
- (void)didMXSessionUpdatePublicisedGroupsForUsers:(NSNotification *)notif
{
// Retrieved the list of the concerned users
NSArray<NSString*> *userIds = notif.userInfo[kMXSessionNotificationUserIdsArrayKey];
if (userIds.count)
{
// Check whether at least one listed user is a room member.
for (NSString* userId in userIds)
{
MXRoomMember * roomMember = [self.roomState.members memberWithUserId:userId];
if (roomMember)
{
// Inform the delegate to refresh the bubble display
// We dispatch here this action in order to let each bubble data update their sender flair.
if (self.delegate)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate dataSource:self didCellChange:nil];
});
}
break;
}
}
}
}
- (void)eventDidChangeSentState:(NSNotification *)notif
{
MXEvent *event = notif.object;
@@ -3993,34 +3894,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
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) {
MXLogDebug(@"[MXKRoomDataSource][%p] groupWithGroupId: group profile update failed %@", self, groupId);
}];
}
return group;
}
#pragma mark - MXScanManager notifications
- (void)registerScanManagerNotifications