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
@@ -29,7 +29,7 @@
#import "GeneratedInterface-Swift.h"
@implementation MXKRoomBubbleCellData
@synthesize senderId, targetId, roomId, senderDisplayName, senderAvatarUrl, senderAvatarPlaceholder, targetDisplayName, targetAvatarUrl, targetAvatarPlaceholder, isEncryptedRoom, isPaginationFirstBubble, shouldHideSenderInformation, date, isIncoming, isAttachmentWithThumbnail, isAttachmentWithIcon, attachment, senderFlair;
@synthesize senderId, targetId, roomId, senderDisplayName, senderAvatarUrl, senderAvatarPlaceholder, targetDisplayName, targetAvatarUrl, targetAvatarPlaceholder, isEncryptedRoom, isPaginationFirstBubble, shouldHideSenderInformation, date, isIncoming, isAttachmentWithThumbnail, isAttachmentWithIcon, attachment;
@synthesize textMessage, attributedTextMessage, attributedTextMessageWithoutPositioningSpace;
@synthesize shouldHideSenderName, isTyping, showBubbleDateTime, showBubbleReceipts, useCustomDateTimeLabel, useCustomReceipts, useCustomUnsentButton, hasNoDisplay;
@synthesize tag;
@@ -122,9 +122,6 @@
- (void)dealloc
{
// Reset any observer on publicised groups by user.
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];
roomDataSource = nil;
bubbleComponents = nil;
}
@@ -450,58 +447,6 @@
- (void)setShouldHideSenderInformation:(BOOL)inShouldHideSenderInformation
{
shouldHideSenderInformation = inShouldHideSenderInformation;
if (!shouldHideSenderInformation)
{
// Refresh the flair
[self refreshSenderFlair];
}
}
- (void)refreshSenderFlair
{
// Reset by default any observer on publicised groups by user.
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];
// Check first whether the room enabled the flair for some groups
NSArray<NSString *> *roomRelatedGroups = roomDataSource.roomState.relatedGroups;
if (roomRelatedGroups.count && senderId)
{
NSArray<NSString *> *senderPublicisedGroups;
senderPublicisedGroups = [self.mxSession publicisedGroupsForUser:senderId];
if (senderPublicisedGroups.count)
{
// Cross the 2 arrays to keep only the common group ids
NSMutableArray *flair = [NSMutableArray arrayWithCapacity:roomRelatedGroups.count];
for (NSString *groupId in roomRelatedGroups)
{
if ([senderPublicisedGroups indexOfObject:groupId] != NSNotFound)
{
MXGroup *group = [roomDataSource groupWithGroupId:groupId];
[flair addObject:group];
}
}
if (flair.count)
{
self.senderFlair = flair;
}
else
{
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];
}
}
- (BOOL)hasThreadRoot
@@ -1042,18 +987,4 @@
}
}
- (void)didMXSessionUpdatePublicisedGroupsForUsers:(NSNotification *)notif
{
// Retrieved the list of the concerned users
NSArray<NSString*> *userIds = notif.userInfo[kMXSessionNotificationUserIdsArrayKey];
if (userIds.count && self.senderId)
{
// Check whether the current sender is concerned.
if ([userIds indexOfObject:self.senderId] != NSNotFound)
{
[self refreshSenderFlair];
}
}
}
@end
@@ -91,11 +91,6 @@
*/
@property (nonatomic) UIImage *targetAvatarPlaceholder;
/**
The current sender flair (list of the publicised groups in the sender profile which matches the room flair settings)
*/
@property (nonatomic) NSArray<MXGroup*> *senderFlair;
/**
Tell whether the room is encrypted.
*/
@@ -304,11 +299,6 @@ Update the event because its sent state changed or it is has been redacted.
foregroundColor:(UIColor*)foregroundColor
andFont:(UIFont*)patternFont;
/**
Refresh the sender flair information
*/
- (void)refreshSenderFlair;
/**
Indicate that the current text message layout is no longer valid and should be recomputed
before presentation in a bubble cell. This could be due to the content changing, or the
@@ -100,11 +100,6 @@ extern NSString *const kMXKRoomDataSourceTimelineErrorErrorKey;
The queue of events that need to be processed in order to compute their display.
*/
NSMutableArray<MXKQueuedEvent*> *eventsToProcess;
/**
The dictionary of the related groups that the current user did not join.
*/
NSMutableDictionary<NSString*, MXGroup*> *externalRelatedGroups;
}
/**
@@ -777,17 +772,6 @@ 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;
#pragma mark - Reactions
/**
@@ -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