Skip to content

Commit

Permalink
Remove flairs and related groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Aug 9, 2022
1 parent 5f21b5c commit 33a7c27
Show file tree
Hide file tree
Showing 21 changed files with 5 additions and 723 deletions.
1 change: 0 additions & 1 deletion Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ final class BuildSettings: NSObject {
static let roomSettingsScreenAllowChangingAccessSettings: Bool = true
static let roomSettingsScreenAllowChangingHistorySettings: Bool = true
static let roomSettingsScreenShowAddressSettings: Bool = true
static let roomSettingsScreenShowFlairSettings: Bool = true
static let roomSettingsScreenShowAdvancedSettings: Bool = true
static let roomSettingsScreenAdvancedShowEncryptToVerifiedOption: Bool = true

Expand Down
3 changes: 0 additions & 3 deletions Riot/Managers/Settings/RiotSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ final class RiotSettings: NSObject {
@UserDefault(key: "roomSettingsScreenShowAddressSettings", defaultValue: BuildSettings.roomSettingsScreenShowAddressSettings, storage: defaults)
var roomSettingsScreenShowAddressSettings

@UserDefault(key: "roomSettingsScreenShowFlairSettings", defaultValue: BuildSettings.roomSettingsScreenShowFlairSettings, storage: defaults)
var roomSettingsScreenShowFlairSettings

@UserDefault(key: "roomSettingsScreenShowAdvancedSettings", defaultValue: BuildSettings.roomSettingsScreenShowAdvancedSettings, storage: defaults)
var roomSettingsScreenShowAdvancedSettings

Expand Down
7 changes: 0 additions & 7 deletions Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,6 @@ - (void)applicationWillEnterForeground:(UIApplication *)application

[MXSDKOptions.sharedInstance.profiler resume];

// Force each session to refresh here their publicised groups by user dictionary.
// When these publicised groups are retrieved for a user, they are cached and reused until the app is backgrounded and enters in the foreground again
for (MXSession *session in mxSessionArray)
{
[session markOutdatedPublicisedGroupsByUserData];
}

_isAppForeground = YES;
}

Expand Down
1 change: 0 additions & 1 deletion Riot/Modules/MatrixKit/Models/MXKAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ -(instancetype)init
kMXEventTypeStringRoomMessageFeedback,
kMXEventTypeStringRoomRedaction,
kMXEventTypeStringRoomThirdPartyInvite,
kMXEventTypeStringRoomRelatedGroups,
kMXEventTypeStringReaction,
kMXEventTypeStringCallInvite,
kMXEventTypeStringCallAnswer,
Expand Down
71 changes: 1 addition & 70 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,9 +122,6 @@ - (instancetype)initWithEvent:(MXEvent *)event andRoomState:(MXRoomState *)roomS

- (void)dealloc
{
// Reset any observer on publicised groups by user.
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionDidUpdatePublicisedGroupsForUsersNotification object:self.mxSession];

roomDataSource = nil;
bubbleComponents = nil;
}
Expand Down Expand Up @@ -450,58 +447,6 @@ - (void)highlightPatternInTextMessage:(NSString*)pattern
- (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
Expand Down Expand Up @@ -1042,18 +987,4 @@ - (void)highlightPattern
}
}

- (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
10 changes: 0 additions & 10 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleCellDataStoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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

/**
Expand Down
127 changes: 0 additions & 127 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ Current pagination request (if any)
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.
Expand Down Expand Up @@ -318,8 +313,6 @@ - (instancetype)initWithRoomId:(NSString *)roomId andMatrixSession:(MXSession *)
eventsToProcess = [NSMutableArray array];
eventIdToBubbleMap = [NSMutableDictionary dictionary];

externalRelatedGroups = [NSMutableDictionary dictionary];

_filterMessagesWithURL = NO;

emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", kMXKSlashCmdEmote];
Expand Down Expand Up @@ -471,8 +464,6 @@ - (void)reset

- (void)resetNotifying:(BOOL)notify
{
[externalRelatedGroups removeAllObjects];

if (roomDidFlushDataNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver];
Expand Down Expand Up @@ -515,9 +506,6 @@ - (void)resetNotifying:(BOOL)notify

[_timeline removeListener:receiptsListener];
receiptsListener = nil;

[_timeline removeListener:relatedGroupsListener];
relatedGroupsListener = nil;
}

if (_secondaryRoom && secondaryLiveEventsListener)
Expand Down Expand Up @@ -601,8 +589,6 @@ - (void)destroy
[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];
Expand Down Expand Up @@ -638,8 +624,6 @@ - (void)destroy
[_timeline destroy];
[_secondaryTimeline destroy];

externalRelatedGroups = nil;

[super destroy];
}

Expand Down Expand Up @@ -824,52 +808,6 @@ - (void)initializeTimelineForRoom
[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
Expand Down Expand Up @@ -1008,7 +946,6 @@ - (void)refreshEventListeners:(NSArray *)liveEventTypesFilterForMessages
[_timeline removeListener:liveEventsListener];
[_timeline removeListener:redactionListener];
[_timeline removeListener:receiptsListener];
[_timeline removeListener:relatedGroupsListener];
}

// Listen to live events only for live timeline
Expand Down Expand Up @@ -1071,16 +1008,6 @@ - (void)refreshEventListeners:(NSArray *)liveEventTypesFilterForMessages
[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
Expand Down Expand Up @@ -2693,32 +2620,6 @@ - (void)didMXRoomInitialSynced:(NSNotification *)notif
}
}

- (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;
Expand Down Expand Up @@ -3993,34 +3894,6 @@ - (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) {

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

}];
}

return group;
}

#pragma mark - MXScanManager notifications

- (void)registerScanManagerNotifications
Expand Down
Loading

0 comments on commit 33a7c27

Please sign in to comment.