element-ios/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m

1789 lines
66 KiB
Mathematica
Raw Normal View History

/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "RecentsDataSource.h"
#import "RecentCellData.h"
#import "SectionHeaderView.h"
#import "ThemeService.h"
#import "MXRoom+Riot.h"
#import "MXSession+Riot.h"
#import "NSArray+Element.h"
#import "GeneratedInterface-Swift.h"
@import DesignKit;
#define RECENTSDATASOURCE_SECTION_DIRECTORY 0x01
#define RECENTSDATASOURCE_SECTION_INVITES 0x02
#define RECENTSDATASOURCE_SECTION_FAVORITES 0x04
#define RECENTSDATASOURCE_SECTION_CONVERSATIONS 0x08
#define RECENTSDATASOURCE_SECTION_LOWPRIORITY 0x10
#define RECENTSDATASOURCE_SECTION_SERVERNOTICE 0x20
#define RECENTSDATASOURCE_SECTION_PEOPLE 0x40
#define RECENTSDATASOURCE_SECTION_SUGGESTED 0x80
#define RECENTSDATASOURCE_SECTION_BREADCRUMBS 0x100
#define RECENTSDATASOURCE_SECTION_ALL_CHATS 0x101
#define RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT 30.0
#define RECENTSDATASOURCE_ALL_CHATS_SECTION_BOTTOM_VIEW_HEIGHT 38.0
NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSourceTapOnDirectoryServerChange";
2021-10-04 14:28:21 +00:00
@interface RecentsDataSource() <SecureBackupBannerCellDelegate, CrossSigningSetupBannerCellDelegate, RecentsListServiceDelegate>
{
dispatch_queue_t processingQueue;
NSInteger shrinkedSectionsBitMask;
NSMutableDictionary<NSString*, id> *roomTagsListenerByUserId;
// Timer to not refresh publicRoomsDirectoryDataSource on every keystroke.
NSTimer *publicRoomsTriggerTimer;
}
2019-01-31 18:52:32 +00:00
2022-04-04 08:24:22 +00:00
@property (nonatomic, strong, readwrite) RecentsDataSourceSections *sections;
2020-06-25 15:52:36 +00:00
@property (nonatomic, assign, readwrite) SecureBackupBannerDisplay secureBackupBannerDisplay;
2020-06-30 19:46:10 +00:00
@property (nonatomic, assign, readwrite) CrossSigningBannerDisplay crossSigningBannerDisplay;
2021-10-04 14:28:21 +00:00
@property (nonatomic, readwrite) id<RecentsListServiceProtocol> recentsListService;
2020-06-30 19:46:10 +00:00
@property (nonatomic, strong) CrossSigningService *crossSigningService;
2019-01-31 18:52:32 +00:00
@property (nonatomic, strong) AllChatsFilterOptions *allChatsFilterOptions;
@property (nonatomic, strong) UIView *allChatsOptionsView;
@end
@implementation RecentsDataSource
@synthesize hiddenCellIndexPath, droppingCellIndexPath, droppingCellBackGroundView;
2021-10-04 14:28:21 +00:00
- (instancetype)initWithMatrixSession:(MXSession *)mxSession
recentsListService:(id<RecentsListServiceProtocol>)theRecentsListService
{
2021-10-04 14:28:21 +00:00
if (self = [super initWithMatrixSession:mxSession])
{
processingQueue = dispatch_queue_create("RecentsDataSource", DISPATCH_QUEUE_SERIAL);
2022-04-04 08:24:22 +00:00
_sections = [[RecentsDataSourceSections alloc] initWithSectionTypes:@[]];
2020-06-30 19:46:10 +00:00
_crossSigningBannerDisplay = CrossSigningBannerDisplayNone;
2020-06-25 15:52:36 +00:00
_secureBackupBannerDisplay = SecureBackupBannerDisplayNone;
_areSectionsShrinkable = !BuildSettings.newAppLayoutEnabled;
shrinkedSectionsBitMask = 0;
roomTagsListenerByUserId = [[NSMutableDictionary alloc] init];
2020-06-30 19:46:10 +00:00
_crossSigningService = [CrossSigningService new];
// Set default data and view classes
[self registerCellDataClass:RecentCellData.class forCellIdentifier:kMXKRecentCellIdentifier];
[self registerSpaceServiceDidBuildGraphNotification];
2021-10-04 14:28:21 +00:00
self.recentsListService = theRecentsListService;
[self.recentsListService addDelegate:self];
[self registerAllChatsSettingsUpdateNotification];
self.allChatsFilterOptions = [AllChatsFilterOptions new];
}
return self;
}
- (void)dealloc
{
[self unregisterSpaceServiceDidBuildGraphNotification];
[self unregisterAllChatsSettingsUpdateNotification];
}
#pragma mark - Properties
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)invitesCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.invitedRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)favoriteCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.favoritedRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)peopleCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.peopleRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)conversationCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.conversationRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)lowPriorityCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.lowPriorityRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)serverNoticeCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.serverNoticeRoomListData.rooms;
}
2021-10-12 18:25:15 +00:00
- (NSArray<id<MXRoomSummaryProtocol>> *)suggestedRoomCellDataArray
{
2021-10-12 18:25:15 +00:00
return self.recentsListService.suggestedRoomListData.rooms;
}
- (NSArray<id<MXRoomSummaryProtocol>> *)breadcrumbsRoomCellDataArray
{
return self.recentsListService.breadcrumbsRoomListData.rooms;
}
- (NSArray<id<MXRoomSummaryProtocol>> *)allChatsRoomCellDataArray
{
return self.recentsListService.allChatsRoomListData.rooms;
}
2021-10-04 14:28:21 +00:00
- (NSInteger)totalVisibleItemCount
{
2021-10-04 14:28:21 +00:00
return self.recentsListService.totalVisibleItemCount;
}
2021-10-04 14:28:21 +00:00
- (DiscussionsCount *)favoriteMissedDiscussionsCount
{
2021-10-04 14:28:21 +00:00
return self.recentsListService.favoritedMissedDiscussionsCount;
}
2021-10-04 14:28:21 +00:00
- (DiscussionsCount *)directMissedDiscussionsCount
{
2021-10-04 14:28:21 +00:00
return self.recentsListService.peopleMissedDiscussionsCount;
}
2021-10-04 14:28:21 +00:00
- (DiscussionsCount *)groupMissedDiscussionsCount
{
2021-10-04 14:28:21 +00:00
return self.recentsListService.conversationMissedDiscussionsCount;
}
2022-04-04 08:24:22 +00:00
#pragma mark - Sections
- (RecentsDataSourceSections *)makeDataSourceSections
{
NSMutableArray *types = [NSMutableArray array];
if (self.crossSigningBannerDisplay != CrossSigningBannerDisplayNone)
{
[types addObject:@(RecentsDataSourceSectionTypeCrossSigningBanner)];
}
else if (self.secureBackupBannerDisplay != SecureBackupBannerDisplayNone)
{
[types addObject:@(RecentsDataSourceSectionTypeSecureBackupBanner)];
}
2022-04-04 08:24:22 +00:00
if (self.invitesCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeInvites)];
}
if (self.breadcrumbsRoomCellDataArray.count > 0 && _recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
AllChatsLayoutSettings *settings = AllChatsLayoutSettingsManager.shared.allChatLayoutSettings;
if ((settings.sections & AllChatsLayoutSectionTypeRecents) == AllChatsLayoutSectionTypeRecents)
{
[types addObject:@(RecentsDataSourceSectionTypeBreadcrumbs)];
}
}
2022-04-04 08:24:22 +00:00
if (self.favoriteCellDataArray.count > 0)
{
if (_recentsDataSourceMode != RecentsDataSourceModeAllChats)
{
[types addObject:@(RecentsDataSourceSectionTypeFavorites)];
}
else
{
AllChatsLayoutSettings *settings = AllChatsLayoutSettingsManager.shared.allChatLayoutSettings;
if ((settings.sections & AllChatsLayoutSectionTypeFavourites) == AllChatsLayoutSectionTypeFavourites)
{
[types addObject:@(RecentsDataSourceSectionTypeFavorites)];
}
}
2022-04-04 08:24:22 +00:00
}
if (self.peopleCellDataArray.count > 0 && _recentsDataSourceMode != RecentsDataSourceModeAllChats)
2022-04-04 08:24:22 +00:00
{
[types addObject:@(RecentsDataSourceSectionTypePeople)];
}
// Keep visible the main rooms section even if it is empty, except on favourites screen.
if (self.conversationCellDataArray.count > 0 || _recentsDataSourceMode == RecentsDataSourceModeHome)
{
[types addObject:@(RecentsDataSourceSectionTypeConversation)];
}
if (self.allChatsRoomCellDataArray.count > 0 || _recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
[types addObject:@(RecentsDataSourceSectionTypeAllChats)];
}
if (self.suggestedRoomCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeSuggestedRooms)];
}
2022-04-04 08:24:22 +00:00
if (self.lowPriorityCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeLowPriority)];
}
if (self.serverNoticeCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeServerNotice)];
}
return [[RecentsDataSourceSections alloc] initWithSectionTypes:types.copy];
}
#pragma mark -
- (void)setDelegate:(id<MXKDataSourceDelegate>)delegate andRecentsDataSourceMode:(RecentsDataSourceMode)recentsDataSourceMode
{
// Update the configuration, the recentsDataSourceMode setter will force a refresh.
self.delegate = delegate;
self.recentsDataSourceMode = recentsDataSourceMode;
}
- (void)setRecentsDataSourceMode:(RecentsDataSourceMode)recentsDataSourceMode
{
_recentsDataSourceMode = recentsDataSourceMode;
2019-01-31 18:52:32 +00:00
// Register to key backup state changes only on in home mode.
if (recentsDataSourceMode == RecentsDataSourceModeHome)
{
[self registerKeyBackupStateDidChangeNotification];
}
else
{
[self unregisterKeyBackupStateDidChangeNotification];
}
2020-06-26 11:07:53 +00:00
[self updateSecureBackupBanner];
2020-06-30 19:46:10 +00:00
[self refreshCrossSigningBannerDisplay];
2021-10-04 14:28:21 +00:00
[self.recentsListService updateMode:_recentsDataSourceMode];
}
2021-09-29 12:10:41 +00:00
- (void)setCurrentSpace:(MXSpace *)currentSpace
{
super.currentSpace = currentSpace;
2021-10-04 14:28:21 +00:00
[self.recentsListService updateSpace:currentSpace];
2021-09-29 12:10:41 +00:00
}
2022-02-10 00:19:00 +00:00
- (UIView *)viewForStickyHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView*)tableView
{
UIView *stickyHeader;
NSInteger savedShrinkedSectionsBitMask = shrinkedSectionsBitMask;
2022-04-04 08:24:22 +00:00
if ([self.sections sectionTypeForSectionIndex:section] == RecentsDataSourceSectionTypeDirectory)
{
// Return the section header used when the section is shrinked
shrinkedSectionsBitMask = RECENTSDATASOURCE_SECTION_DIRECTORY;
}
2022-02-10 00:19:00 +00:00
stickyHeader = [self viewForHeaderInSection:section withFrame:frame inTableView:tableView];
shrinkedSectionsBitMask = savedShrinkedSectionsBitMask;
return stickyHeader;
}
- (void)registerAllChatsSettingsUpdateNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(allChatSettingsWillUpdateNotification:) name:AllChatsLayoutSettingsManager.willUpdateSettings object:nil];
}
- (void)allChatSettingsWillUpdateNotification:(NSNotification*)notification
{
self.allChatsOptionsView = nil;
}
- (void)unregisterAllChatsSettingsUpdateNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:AllChatsLayoutSettingsManager.willUpdateSettings object:nil];
}
#pragma mark - Space Service notifications
- (void)registerSpaceServiceDidBuildGraphNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(spaceServiceDidBuildGraphNotification:) name:MXSpaceService.didBuildSpaceGraph object:nil];
}
- (void)spaceServiceDidBuildGraphNotification:(NSNotification*)notification
{
[self forceRefresh];
}
- (void)unregisterSpaceServiceDidBuildGraphNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MXSpaceService.didBuildSpaceGraph object:nil];
}
2019-01-31 18:52:32 +00:00
#pragma mark - Key backup setup banner
- (void)registerKeyBackupStateDidChangeNotification
{
// Check homeserver update in background
[self.mxSession.crypto.backup forceRefresh:nil failure:nil];
2019-01-31 18:52:32 +00:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBackupStateDidChangeNotification:) name:kMXKeyBackupDidStateChangeNotification object:nil];
}
- (void)unregisterKeyBackupStateDidChangeNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXKeyBackupDidStateChangeNotification object:nil];
}
- (void)keyBackupStateDidChangeNotification:(NSNotification*)notification
{
2020-06-26 11:07:53 +00:00
if ([self updateSecureBackupBanner])
{
[self forceRefresh];
}
2019-01-31 18:52:32 +00:00
}
2020-06-26 11:07:53 +00:00
- (BOOL)updateSecureBackupBanner
2019-01-31 18:52:32 +00:00
{
2020-06-26 11:07:53 +00:00
SecureBackupBannerDisplay secureBackupBanner = SecureBackupBannerDisplayNone;
if (self.recentsDataSourceMode == RecentsDataSourceModeHome)
2019-01-31 18:52:32 +00:00
{
2020-06-26 11:07:53 +00:00
SecureBackupBannerPreferences *secureBackupBannersPreferences = SecureBackupBannerPreferences.shared;
2019-01-31 18:52:32 +00:00
// Display the banner only if we can set up 4S, if there are messages keys to backup and key backup is disabled
if (!secureBackupBannersPreferences.hideSetupBanner
&& [self.mxSession vc_canSetupSecureBackup]
&& self.mxSession.crypto.backup.hasKeysToBackup
&& self.mxSession.crypto.backup.state == MXKeyBackupStateDisabled)
{
MXLogDebug(@"[RecentsDataSource] updateSecureBackupBanner: Secure backup should be shown (crypto.backup.state = %lu)", (unsigned long)self.mxSession.crypto.backup.state);
2020-06-26 11:07:53 +00:00
secureBackupBanner = SecureBackupBannerDisplaySetup;
2019-01-31 18:52:32 +00:00
}
}
2020-06-26 11:07:53 +00:00
BOOL updated = (self.secureBackupBannerDisplay != secureBackupBanner);
2020-06-26 11:07:53 +00:00
self.secureBackupBannerDisplay = secureBackupBanner;
return updated;
2019-01-31 18:52:32 +00:00
}
2020-06-26 12:11:58 +00:00
- (void)hideKeyBackupBannerWithDisplay:(SecureBackupBannerDisplay)secureBackupBannerDisplay
2019-01-31 18:52:32 +00:00
{
2020-06-26 11:07:53 +00:00
SecureBackupBannerPreferences *keyBackupBannersPreferences = SecureBackupBannerPreferences.shared;
2019-01-31 18:52:32 +00:00
2020-06-26 12:11:58 +00:00
switch (secureBackupBannerDisplay) {
2020-06-25 15:52:36 +00:00
case SecureBackupBannerDisplaySetup:
2019-01-31 18:52:32 +00:00
keyBackupBannersPreferences.hideSetupBanner = YES;
break;
default:
break;
}
2020-06-26 11:07:53 +00:00
[self updateSecureBackupBanner];
2019-01-31 18:52:32 +00:00
[self forceRefresh];
}
2020-06-30 19:46:10 +00:00
#pragma mark - Cross-signing setup banner
2020-06-30 19:46:10 +00:00
- (void)refreshCrossSigningBannerDisplay
{
if (self.recentsDataSourceMode == RecentsDataSourceModeHome)
{
2020-06-30 19:46:10 +00:00
CrossSigningBannerPreferences *crossSigningBannerPreferences = CrossSigningBannerPreferences.shared;
2020-06-30 19:46:10 +00:00
if (!crossSigningBannerPreferences.hideSetupBanner)
{
2020-06-30 19:46:10 +00:00
[self.crossSigningService canSetupCrossSigningFor:self.mxSession success:^(BOOL canSetupCrossSigning) {
2020-06-30 19:46:10 +00:00
CrossSigningBannerDisplay crossSigningBannerDisplay = canSetupCrossSigning ? CrossSigningBannerDisplaySetup : CrossSigningBannerDisplayNone;
2020-06-30 19:46:10 +00:00
[self updateCrossSigningBannerDisplay:crossSigningBannerDisplay];
} failure:^(NSError * _Nonnull error) {
MXLogDebug(@"[RecentsDataSource] refreshCrossSigningBannerDisplay: Fail to verify if cross signing banner can be displayed");
}];
}
else
{
2020-06-30 19:46:10 +00:00
[self updateCrossSigningBannerDisplay:CrossSigningBannerDisplayNone];
}
}
else
{
2020-06-30 19:46:10 +00:00
[self updateCrossSigningBannerDisplay:CrossSigningBannerDisplayNone];
}
}
2020-06-30 19:46:10 +00:00
- (void)updateCrossSigningBannerDisplay:(CrossSigningBannerDisplay)crossSigningBannerDisplay
{
2020-06-30 19:46:10 +00:00
if (self.crossSigningBannerDisplay == crossSigningBannerDisplay)
{
return;
}
2020-06-30 19:46:10 +00:00
self.crossSigningBannerDisplay = crossSigningBannerDisplay;
[self forceRefresh];
}
2020-06-30 19:46:10 +00:00
- (void)hideCrossSigningBannerWithDisplay:(CrossSigningBannerDisplay)crossSigningBannerDisplay
{
2020-06-30 19:46:10 +00:00
CrossSigningBannerPreferences *crossSigningBannerPreferences = CrossSigningBannerPreferences.shared;
2020-06-30 19:46:10 +00:00
switch (crossSigningBannerDisplay) {
case CrossSigningBannerDisplaySetup:
crossSigningBannerPreferences.hideSetupBanner = YES;
break;
default:
break;
}
2020-06-30 19:46:10 +00:00
[self refreshCrossSigningBannerDisplay];
}
#pragma mark -
- (MXKSessionRecentsDataSource *)addMatrixSession:(MXSession *)mxSession
{
MXKSessionRecentsDataSource *recentsDataSource = [super addMatrixSession:mxSession];
// Initialise the public room directory data source
// Note that it is single matrix session only for now
if (!_publicRoomsDirectoryDataSource)
{
_publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession];
_publicRoomsDirectoryDataSource.showNSFWRooms = RiotSettings.shared.showNSFWPublicRooms;
_publicRoomsDirectoryDataSource.delegate = self;
}
return recentsDataSource;
}
- (void)removeMatrixSession:(MXSession*)matrixSession
{
[super removeMatrixSession:matrixSession];
// sanity check
if (matrixSession.myUser && matrixSession.myUser.userId)
{
id roomTagListener = roomTagsListenerByUserId[matrixSession.myUser.userId];
if (roomTagListener)
{
[matrixSession removeListener:roomTagListener];
[roomTagsListenerByUserId removeObjectForKey:matrixSession.myUser.userId];
}
}
if (_publicRoomsDirectoryDataSource.mxSession == matrixSession)
{
[_publicRoomsDirectoryDataSource destroy];
_publicRoomsDirectoryDataSource = nil;
}
}
- (void)dataSource:(MXKDataSource*)dataSource didStateChange:(MXKDataSourceState)aState
{
if (dataSource == _publicRoomsDirectoryDataSource)
{
2022-04-04 08:24:22 +00:00
if ([self.sections contains:RecentsDataSourceSectionTypeDirectory] && !self.droppingCellIndexPath)
{
// TODO: We should only update the directory section
[self.delegate dataSource:self didCellChange:nil];
}
}
else
{
[super dataSource:dataSource didStateChange:aState];
if ((aState == MXKDataSourceStateReady) && dataSource.mxSession.myUser.userId)
{
// Register the room tags updates to refresh the favorites order
MXWeakify(self);
id roomTagsListener = [dataSource.mxSession listenToEventsOfTypes:@[kMXEventTypeStringRoomTag]
onEvent:^(MXEvent *event, MXTimelineDirection direction, id customObject) {
MXStrongifyAndReturnIfNil(self);
// Consider only live event
if (direction == MXTimelineDirectionForwards)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self forceRefresh];
});
}
}];
roomTagsListenerByUserId[dataSource.mxSession.myUser.userId] = roomTagsListener;
}
}
}
- (void)forceRefresh
{
// Refresh is disabled during drag&drop animation"
if (!self.droppingCellIndexPath)
{
2021-10-04 14:28:21 +00:00
[self.recentsListService refresh];
}
}
- (void)didMXSessionInviteRoomUpdate:(NSNotification *)notif
{
MXSession *mxSession = notif.object;
if ([self.mxSessions indexOfObject:mxSession] != NSNotFound)
{
[self forceRefresh];
}
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Sanity check
if (tableView.tag != self.recentsDataSourceMode)
{
// The view controller of this table view is not the current selected one in the tab bar controller.
return 0;
}
// Check whether all data sources are ready before rendering recents
2022-04-04 08:24:22 +00:00
if (self.state != MXKDataSourceStateReady)
{
2022-04-04 08:24:22 +00:00
return 0;
}
2022-04-04 08:24:22 +00:00
self.sections = [self makeDataSourceSections];
return self.sections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Sanity check
if (tableView.tag != self.recentsDataSourceMode)
{
// The view controller of this table view is not the current selected one in the tab bar controller.
return 0;
}
NSUInteger count = 0;
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeCrossSigningBanner && self.crossSigningBannerDisplay != CrossSigningBannerDisplayNone)
{
count = 1;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner && self.secureBackupBannerDisplay != SecureBackupBannerDisplayNone)
2019-01-31 18:52:32 +00:00
{
count = 1;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeFavorites && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_FAVORITES))
{
count = self.favoriteCellDataArray.count;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_PEOPLE))
{
count = self.peopleCellDataArray.count ? self.peopleCellDataArray.count : 1;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_CONVERSATIONS))
{
count = self.conversationCellDataArray.count ? self.conversationCellDataArray.count : 1;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeDirectory && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_DIRECTORY))
{
2017-04-07 13:44:29 +00:00
count = [_publicRoomsDirectoryDataSource tableView:tableView numberOfRowsInSection:0];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_LOWPRIORITY))
{
count = self.lowPriorityCellDataArray.count;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SERVERNOTICE))
{
count = self.serverNoticeCellDataArray.count;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeInvites && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_INVITES))
{
count = self.invitesCellDataArray.count;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SUGGESTED))
{
count = self.suggestedRoomCellDataArray.count;
}
else if (sectionType == RecentsDataSourceSectionTypeBreadcrumbs && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_BREADCRUMBS))
{
count = self.breadcrumbsRoomCellDataArray.count;
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_ALL_CHATS))
{
count = self.allChatsRoomCellDataArray.count;
}
// Adjust this count according to the potential dragged cell.
if ([self isMovingCellSection:section])
{
count++;
}
if (count && [self isHiddenCellSection:section])
{
count--;
}
return count;
}
- (CGFloat)heightForHeaderInSection:(NSInteger)section
{
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner ||
sectionType == RecentsDataSourceSectionTypeCrossSigningBanner ||
sectionType == RecentsDataSourceSectionTypeBreadcrumbs ||
(sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsFilterOptions.optionsCount))
2019-01-31 18:52:32 +00:00
{
return 0.0;
}
if (sectionType == RecentsDataSourceSectionTypeAllChats && _recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
if (self.allChatsFilterOptions.optionsCount)
{
return RECENTSDATASOURCE_ALL_CHATS_SECTION_BOTTOM_VIEW_HEIGHT;
}
}
return RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT;
}
2017-05-09 08:03:55 +00:00
- (NSAttributedString *)attributedStringForHeaderTitleInSection:(NSInteger)section
{
NSAttributedString *sectionTitle;
NSString *title;
NSUInteger count = 0;
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.favoritedRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsFavouritesSection];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.peopleRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsPeopleSection];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.conversationRoomListData.counts.total.numberOfRooms;
if (_recentsDataSourceMode == RecentsDataSourceModePeople)
{
title = [VectorL10n peopleConversationSection];
}
else
{
title = [VectorL10n roomRecentsConversationsSection];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeDirectory)
{
title = [VectorL10n roomRecentsDirectorySection];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.lowPriorityRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsLowPrioritySection];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.serverNoticeRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsServerNoticeSection];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeInvites)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.invitedRoomListData.counts.total.numberOfRooms;
if (_recentsDataSourceMode == RecentsDataSourceModePeople)
{
title = [VectorL10n peopleInvitesSection];
}
else
{
title = [VectorL10n roomRecentsInvitesSection];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms)
{
2022-01-04 01:29:26 +00:00
count = self.recentsListService.suggestedRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsSuggestedRoomsSection];
}
else if (sectionType == RecentsDataSourceSectionTypeBreadcrumbs)
{
count = self.recentsListService.breadcrumbsRoomListData.counts.total.numberOfRooms;
title = [VectorL10n roomRecentsRecentlyViewedSection];
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats)
{
count = self.recentsListService.allChatsRoomListData.counts.total.numberOfRooms;
title = [VectorL10n allChatsSectionTitle];
}
if (count && !(sectionType == RecentsDataSourceSectionTypeInvites) && !BuildSettings.newAppLayoutEnabled)
{
NSString *roomCount = [NSString stringWithFormat:@" %tu", count];
NSMutableAttributedString *mutableSectionTitle = [[NSMutableAttributedString alloc] initWithString:title
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.headerTextPrimaryColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:15.0]}];
[mutableSectionTitle appendAttributedString:[[NSMutableAttributedString alloc] initWithString:roomCount
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.headerTextSecondaryColor,
NSFontAttributeName: [UIFont boldSystemFontOfSize:15.0]}]];
sectionTitle = mutableSectionTitle;
}
else if (title)
{
sectionTitle = [[NSAttributedString alloc] initWithString:[title capitalizedString]
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.headerTextPrimaryColor,
NSFontAttributeName: [ThemeService shared].theme.fonts.calloutSB}];
}
return sectionTitle;
}
- (UIView *)badgeViewForHeaderTitleInSection:(NSInteger)section
{
// Prepare a badge to display the total of missed notifications in this section.
2021-10-04 14:28:21 +00:00
id<MXRoomListDataCounts> counts = nil;
UIView *missedNotifAndUnreadBadgeBgView = nil;
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeInvites)
{
counts = self.recentsListService.invitedRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.favoritedRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.peopleRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.conversationRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.lowPriorityRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.serverNoticeRoomListData.counts;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms)
{
2021-10-04 14:28:21 +00:00
counts = self.recentsListService.suggestedRoomListData.counts;
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats)
{
counts = self.recentsListService.allChatsRoomListData.counts;
}
// Invites are counted as highlights for the badge view display.
NSUInteger numberOfNotifications = counts.total.numberOfNotifications + counts.total.numberOfInvitedRooms;
NSUInteger numberOfHighlights = counts.total.numberOfHighlights + counts.total.numberOfInvitedRooms;
2022-01-04 01:29:26 +00:00
if (numberOfNotifications)
{
UILabel *missedNotifAndUnreadBadgeLabel = [[UILabel alloc] init];
missedNotifAndUnreadBadgeLabel.textColor = ThemeService.shared.theme.baseTextPrimaryColor;
missedNotifAndUnreadBadgeLabel.font = [UIFont boldSystemFontOfSize:14];
2022-01-04 01:29:26 +00:00
if (numberOfNotifications > 1000)
{
2022-01-04 01:29:26 +00:00
CGFloat value = numberOfNotifications / 1000.0;
missedNotifAndUnreadBadgeLabel.text = [VectorL10n largeBadgeValueKFormat:value];
}
else
{
2022-01-04 01:29:26 +00:00
missedNotifAndUnreadBadgeLabel.text = [NSString stringWithFormat:@"%tu", numberOfNotifications];
}
[missedNotifAndUnreadBadgeLabel sizeToFit];
CGFloat bgViewWidth = missedNotifAndUnreadBadgeLabel.frame.size.width + 18;
2022-01-04 01:29:26 +00:00
BOOL highlight = numberOfHighlights > 0;
missedNotifAndUnreadBadgeBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bgViewWidth, 20)];
[missedNotifAndUnreadBadgeBgView.layer setCornerRadius:10];
missedNotifAndUnreadBadgeBgView.backgroundColor = highlight ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor;
[missedNotifAndUnreadBadgeBgView addSubview:missedNotifAndUnreadBadgeLabel];
missedNotifAndUnreadBadgeLabel.center = missedNotifAndUnreadBadgeBgView.center;
[missedNotifAndUnreadBadgeLabel.centerXAnchor constraintEqualToAnchor:missedNotifAndUnreadBadgeBgView.centerXAnchor
constant:0].active = YES;
[missedNotifAndUnreadBadgeLabel.centerYAnchor constraintEqualToAnchor:missedNotifAndUnreadBadgeBgView.centerYAnchor
constant:0].active = YES;
}
return missedNotifAndUnreadBadgeBgView;
}
2022-02-10 00:19:00 +00:00
- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView*)tableView
{
// No header view in key backup banner section, in cross signing banner section, in recent section, nor in all chats section if flters are disabled
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner ||
sectionType == RecentsDataSourceSectionTypeCrossSigningBanner ||
sectionType == RecentsDataSourceSectionTypeBreadcrumbs ||
(sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsFilterOptions.optionsCount))
2019-01-31 18:52:32 +00:00
{
return nil;
}
2022-02-10 00:19:00 +00:00
SectionHeaderView *sectionHeader = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionHeaderView.defaultReuseIdentifier];
if (sectionHeader == nil)
{
sectionHeader = [[SectionHeaderView alloc] initWithReuseIdentifier:SectionHeaderView.defaultReuseIdentifier];
}
sectionHeader.backgroundView = [UIView new];
sectionHeader.frame = frame;
sectionHeader.backgroundView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
sectionHeader.topPadding = 0;
sectionHeader.topViewHeight = RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT;
NSInteger sectionBitwise = 0;
if (_areSectionsShrinkable)
{
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_FAVORITES;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_PEOPLE;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_CONVERSATIONS;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeDirectory)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_CONVERSATIONS;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_LOWPRIORITY;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_SERVERNOTICE;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeInvites)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_INVITES;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_SUGGESTED;
}
else if (sectionType == RecentsDataSourceSectionTypeBreadcrumbs)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_BREADCRUMBS;
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_ALL_CHATS;
}
}
if (sectionBitwise)
{
// Add shrink button
UIButton *shrinkButton = [UIButton buttonWithType:UIButtonTypeCustom];
shrinkButton.backgroundColor = [UIColor clearColor];
[shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
shrinkButton.tag = sectionBitwise;
sectionHeader.topSpanningView = shrinkButton;
sectionHeader.userInteractionEnabled = YES;
// Add shrink icon
UIImage *chevron;
if (shrinkedSectionsBitMask & sectionBitwise)
{
chevron = AssetImages.disclosureIcon.image;
}
else
{
chevron = AssetImages.shrinkIcon.image;
}
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.tintColor = ThemeService.shared.theme.textSecondaryColor;
chevronView.contentMode = UIViewContentModeCenter;
sectionHeader.accessoryView = chevronView;
}
if (_recentsDataSourceMode == RecentsDataSourceModeHome
|| _recentsDataSourceMode == RecentsDataSourceModePeople
|| _recentsDataSourceMode == RecentsDataSourceModeRooms)
{
// Add a badge to display the total of missed notifications by section.
UIView *badgeView = [self badgeViewForHeaderTitleInSection:section];
if (badgeView)
{
sectionHeader.rightAccessoryView = badgeView;
}
}
if (_recentsDataSourceMode == RecentsDataSourceModeAllChats && sectionType == RecentsDataSourceSectionTypeAllChats) {
if (!self.allChatsOptionsView) {
self.allChatsOptionsView = [self.allChatsFilterOptions createFilterListView];
}
if (self.allChatsOptionsView)
{
return self.allChatsOptionsView;
}
}
else
{
sectionHeader.bottomView = nil;
}
if (!BuildSettings.newAppLayoutEnabled || !sectionHeader.bottomView)
{
// Add label
frame.size.height = RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT - 10;
UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.attributedText = [self attributedStringForHeaderTitleInSection:section];
sectionHeader.headerLabel = headerLabel;
}
else
{
sectionHeader.headerLabel = nil;
}
return sectionHeader;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Sanity check
if (tableView.tag != self.recentsDataSourceMode)
{
// The view controller of this table view is not the current selected one in the tab bar controller.
// Return a fake cell to prevent app from crashing
return [[UITableViewCell alloc] init];
}
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:indexPath.section];
if (sectionType == RecentsDataSourceSectionTypeCrossSigningBanner)
{
2020-06-30 19:46:10 +00:00
CrossSigningSetupBannerCell* crossSigningSetupBannerCell = [tableView dequeueReusableCellWithIdentifier:CrossSigningSetupBannerCell.defaultReuseIdentifier forIndexPath:indexPath];
crossSigningSetupBannerCell.delegate = self;
return crossSigningSetupBannerCell;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner)
2019-01-31 18:52:32 +00:00
{
2020-06-26 11:07:53 +00:00
SecureBackupBannerCell* keyBackupBannerCell = [tableView dequeueReusableCellWithIdentifier:SecureBackupBannerCell.defaultReuseIdentifier forIndexPath:indexPath];
2020-06-25 15:52:36 +00:00
[keyBackupBannerCell configureFor:self.secureBackupBannerDisplay];
keyBackupBannerCell.delegate = self;
return keyBackupBannerCell;
2019-01-31 18:52:32 +00:00
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeDirectory)
{
NSIndexPath *indexPathInPublicRooms = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
return [_publicRoomsDirectoryDataSource tableView:tableView cellForRowAtIndexPath:indexPathInPublicRooms];
}
else if (self.droppingCellIndexPath && [indexPath isEqual:self.droppingCellIndexPath])
{
static NSString* cellIdentifier = @"RiotRecentsMovingCell";
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RiotRecentsMovingCell"];
// add an imageview of the cell.
// The image is a shot of the genuine cell.
// Thus, this cell has the same look as the genuine cell without computing it.
UIImageView* imageView = [cell viewWithTag:[cellIdentifier hash]];
if (!imageView || (imageView != self.droppingCellBackGroundView))
{
if (imageView)
{
[imageView removeFromSuperview];
}
self.droppingCellBackGroundView.tag = [cellIdentifier hash];
[cell.contentView addSubview:self.droppingCellBackGroundView];
}
self.droppingCellBackGroundView.frame = self.droppingCellBackGroundView.frame;
cell.contentView.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
2022-04-04 08:24:22 +00:00
else if ((sectionType == RecentsDataSourceSectionTypeConversation && !self.conversationCellDataArray.count)
|| (sectionType == RecentsDataSourceSectionTypePeople && !self.peopleCellDataArray.count)
|| (sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsRoomCellDataArray.count))
{
MXKTableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
if (!tableViewCell)
{
tableViewCell = [[MXKTableViewCell alloc] init];
2019-01-11 10:45:27 +00:00
tableViewCell.textLabel.textColor = ThemeService.shared.theme.textSecondaryColor;
tableViewCell.textLabel.font = [UIFont systemFontOfSize:15.0];
tableViewCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Check whether a search session is in progress
2017-05-05 13:30:35 +00:00
if (self.searchPatternsList)
{
tableViewCell.textLabel.text = [VectorL10n searchNoResult];
}
2022-04-04 08:24:22 +00:00
else if (_recentsDataSourceMode == RecentsDataSourceModePeople || sectionType == RecentsDataSourceSectionTypePeople)
{
tableViewCell.textLabel.text = [VectorL10n peopleNoConversation];
}
else
{
tableViewCell.textLabel.text = [VectorL10n roomRecentsNoConversation];
}
return tableViewCell;
}
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
- (id<MXKRecentCellDataStoring>)cellDataAtIndexPath:(NSIndexPath *)indexPath
{
2021-10-12 18:25:15 +00:00
id<MXRoomSummaryProtocol> summary = nil;
NSUInteger cellDataIndex = indexPath.row;
NSInteger tableSection = indexPath.section;
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:tableSection];
// Compute the actual cell data index by taking into account the current droppingCellIndexPath and hiddenCellIndexPath (if any).
if ([self isMovingCellSection:tableSection] && (cellDataIndex > self.droppingCellIndexPath.row))
{
cellDataIndex --;
}
if ([self isHiddenCellSection:tableSection] && (cellDataIndex >= self.hiddenCellIndexPath.row))
{
cellDataIndex ++;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
if (cellDataIndex < self.favoriteCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.favoriteCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople)
{
if (cellDataIndex < self.peopleCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.peopleCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation)
{
if (cellDataIndex < self.conversationCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.conversationCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
if (cellDataIndex < self.lowPriorityCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.lowPriorityCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
if (cellDataIndex < self.serverNoticeCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.serverNoticeCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeInvites)
{
if (cellDataIndex < self.invitesCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.invitesCellDataArray[cellDataIndex];
}
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms)
{
if (cellDataIndex < self.suggestedRoomCellDataArray.count)
{
2021-10-12 18:25:15 +00:00
summary = self.suggestedRoomCellDataArray[cellDataIndex];
}
}
else if (sectionType == RecentsDataSourceSectionTypeBreadcrumbs)
{
if (cellDataIndex < self.breadcrumbsRoomCellDataArray.count)
{
summary = self.breadcrumbsRoomCellDataArray[cellDataIndex];
}
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats)
{
if (cellDataIndex < self.allChatsRoomCellDataArray.count)
{
summary = self.allChatsRoomCellDataArray[cellDataIndex];
}
}
2021-10-12 18:25:15 +00:00
if (summary)
{
return [[MXKRecentCellData alloc] initWithRoomSummary:summary dataSource:self];
}
return nil;
}
- (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath
{
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:indexPath.section];
if (sectionType == RecentsDataSourceSectionTypeDirectory)
{
return [_publicRoomsDirectoryDataSource cellHeightAtIndexPath:indexPath];
}
if (self.droppingCellIndexPath && [indexPath isEqual:self.droppingCellIndexPath])
{
return self.droppingCellBackGroundView.frame.size.height;
}
2022-04-04 08:24:22 +00:00
if ((sectionType == RecentsDataSourceSectionTypeConversation && !self.conversationCellDataArray.count)
|| (sectionType == RecentsDataSourceSectionTypePeople && !self.peopleCellDataArray.count))
{
return 50.0;
}
// Override this method here to use our own cellDataAtIndexPath
id<MXKRecentCellDataStoring> cellData = [self cellDataAtIndexPath:indexPath];
if (cellData && self.delegate)
{
Class<MXKCellRendering> class = [self.delegate cellViewClassForCellData:cellData];
return [class heightForCellData:cellData withMaximumWidth:0];
}
return 0;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Sanity check
if (tableView.tag != self.recentsDataSourceMode)
{
// The view controller of this table view is not the current selected one in the tab bar controller.
return NO;
}
// Invited rooms are not editable.
2022-04-04 08:24:22 +00:00
return ([self.sections sectionTypeForSectionIndex:indexPath.section] != RecentsDataSourceSectionTypeInvites);
}
#pragma mark -
2021-10-12 18:25:15 +00:00
- (NSInteger)cellIndexPosWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession within:(NSArray<id<MXRoomSummaryProtocol>> *)summaries
{
2021-10-12 18:25:15 +00:00
if (!roomId || !matrixSession || !summaries.count || self.mxSession != matrixSession)
{
2021-10-12 18:25:15 +00:00
return NSNotFound;
}
2021-10-12 18:25:15 +00:00
return [summaries indexOfObjectPassingTest:^BOOL(id<MXRoomSummaryProtocol> _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
return [obj.roomId isEqualToString:roomId];
}];
}
- (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession
{
NSIndexPath *indexPath = nil;
NSInteger index;
2022-04-04 08:24:22 +00:00
if ([self.sections contains:RecentsDataSourceSectionTypeInvites])
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.invitesCellDataArray];
2022-04-04 08:24:22 +00:00
if (index != NSNotFound)
{
// Check whether the invitations are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_INVITES)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeInvites];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeFavorites]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.favoriteCellDataArray];
2022-04-04 08:24:22 +00:00
if (index != NSNotFound)
{
// Check whether the favorites are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_FAVORITES)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeFavorites];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypePeople]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.peopleCellDataArray];
2022-04-04 08:24:22 +00:00
if (index != NSNotFound)
{
// Check whether the favorites are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_PEOPLE)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypePeople];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeConversation]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.conversationCellDataArray];
2022-04-04 08:24:22 +00:00
if (index != NSNotFound)
{
// Check whether the conversations are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_CONVERSATIONS)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeConversation];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeLowPriority]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.lowPriorityCellDataArray];
2022-04-04 08:24:22 +00:00
if (index != NSNotFound)
{
// Check whether the low priority rooms are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_LOWPRIORITY)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeLowPriority];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeServerNotice]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.serverNoticeCellDataArray];
if (index != NSNotFound)
{
// Check whether the low priority rooms are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SERVERNOTICE)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeServerNotice];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
2022-04-04 08:24:22 +00:00
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeSuggestedRooms]))
{
2022-04-04 08:24:22 +00:00
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.suggestedRoomCellDataArray];
if (index != NSNotFound)
{
// Check whether the low priority rooms are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SUGGESTED)
{
return nil;
}
2022-04-04 08:24:22 +00:00
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeSuggestedRooms];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeBreadcrumbs]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.breadcrumbsRoomCellDataArray];
if (index != NSNotFound)
{
// Check whether the recent rooms are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_BREADCRUMBS)
{
return nil;
}
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeBreadcrumbs];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
if (!indexPath && ([self.sections contains:RecentsDataSourceSectionTypeAllChats]))
{
index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:self.allChatsRoomCellDataArray];
if (index != NSNotFound)
{
// Check whether the all chats rooms are shrinked
if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_ALL_CHATS)
{
return nil;
}
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:RecentsDataSourceSectionTypeAllChats];
indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex];
}
}
return indexPath;
}
#pragma mark - MXKDataSourceDelegate
2015-12-02 16:38:10 +00:00
- (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes
{
// Refresh is disabled during drag&drop animation
if (self.droppingCellIndexPath)
{
return;
}
// FIXME : manage multi accounts
// to manage multi accounts
// this method in MXKInterleavedRecentsDataSource must be split in two parts
// 1 - the intervealing cells method
// 2 - [super dataSource:dataSource didCellChange:changes] call.
// the [self refreshRoomsSections] call should be done at the end of the 1- method
// so a dedicated method must be implemented in MXKInterleavedRecentsDataSource
// this class will inherit of this new method
// 1 - call [super thisNewMethod]
// 2 - call [self refreshRoomsSections]
// Call super to keep update readyRecentsDataSourceArray.
[super dataSource:dataSource didCellChange:changes];
}
#pragma mark - Drag & Drop handling
- (BOOL)isMovingCellSection:(NSInteger)section
{
return self.droppingCellIndexPath && (self.droppingCellIndexPath.section == section);
}
- (BOOL)isHiddenCellSection:(NSInteger)section
{
return self.hiddenCellIndexPath && (self.hiddenCellIndexPath.section == section);
}
#pragma mark - Action
- (IBAction)onButtonPressed:(id)sender
{
if ([sender isKindOfClass:[UIButton class]])
{
UIButton *shrinkButton = (UIButton*)sender;
NSInteger selectedSectionBit = shrinkButton.tag;
if (shrinkedSectionsBitMask & selectedSectionBit)
{
// Disclose the section
shrinkedSectionsBitMask &= ~selectedSectionBit;
}
else
{
// Shrink this section
shrinkedSectionsBitMask |= selectedSectionBit;
}
// Inform the delegate about the update
[self.delegate dataSource:self didCellChange:nil];
}
}
- (IBAction)onPublicRoomsSearchPatternUpdate:(id)sender
{
if (publicRoomsTriggerTimer)
{
NSString *searchPattern = publicRoomsTriggerTimer.userInfo;
[publicRoomsTriggerTimer invalidate];
publicRoomsTriggerTimer = nil;
_publicRoomsDirectoryDataSource.searchPattern = searchPattern;
[_publicRoomsDirectoryDataSource paginate:nil failure:nil];
}
}
#pragma mark - Action
- (IBAction)onDirectoryServerPickerTap:(UITapGestureRecognizer*)sender
{
[self.delegate dataSource:self didRecognizeAction:kRecentsDataSourceTapOnDirectoryServerChange inCell:nil userInfo:nil];
}
#pragma mark - Override MXKDataSource
- (void)destroy
{
[super destroy];
[publicRoomsTriggerTimer invalidate];
publicRoomsTriggerTimer = nil;
2021-10-04 14:28:21 +00:00
[self.recentsListService stop];
}
2015-12-16 15:29:34 +00:00
#pragma mark - Override MXKRecentsDataSource
2015-12-16 15:29:34 +00:00
- (void)searchWithPatterns:(NSArray *)patternsList
{
[super searchWithPatterns:patternsList];
NSString *searchPattern = [patternsList componentsJoinedByString:@" "];
2021-10-04 14:28:21 +00:00
[self.recentsListService updateQuery:searchPattern];
2015-12-16 15:29:34 +00:00
if (_publicRoomsDirectoryDataSource)
2015-12-16 15:29:34 +00:00
{
// Do not send a /publicRooms request for every keystroke
// Let user finish typing
[publicRoomsTriggerTimer invalidate];
publicRoomsTriggerTimer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(onPublicRoomsSearchPatternUpdate:) userInfo:searchPattern repeats:NO];
2015-12-16 15:29:34 +00:00
}
}
#pragma mark - drag and drop managemenent
- (BOOL)isDraggableCellAt:(NSIndexPath*)path
{
if (_recentsDataSourceMode == RecentsDataSourceModePeople || _recentsDataSourceMode == RecentsDataSourceModeRooms)
{
return NO;
}
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:path.section];
return (path && ((sectionType == RecentsDataSourceSectionTypeFavorites)
|| (sectionType == RecentsDataSourceSectionTypePeople)
|| (sectionType == RecentsDataSourceSectionTypeLowPriority)
|| (sectionType == RecentsDataSourceSectionTypeServerNotice)
|| (sectionType == RecentsDataSourceSectionTypeConversation)));
}
- (BOOL)canCellMoveFrom:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath
{
BOOL res = [self isDraggableCellAt:oldPath] && [self isDraggableCellAt:newPath];
// the both index pathes are movable
if (res)
{
// only the favorites cell can be moved within the same section
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:oldPath.section];
res &= (sectionType == RecentsDataSourceSectionTypeFavorites) || (newPath.section != oldPath.section);
// other cases ?
}
return res;
}
- (NSString*)roomTagAt:(NSIndexPath*)path
{
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:path.section];
if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
return kMXRoomTagFavourite;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
return kMXRoomTagLowPriority;
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
return kMXRoomTagServerNotice;
}
return nil;
}
- (void)paginateInSection:(NSInteger)section
{
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeInvites)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionInvited];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeFavorites)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionFavorited];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypePeople)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionPeople];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeConversation)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionConversation];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeLowPriority)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionLowPriority];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeServerNotice)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionServerNotice];
}
2022-04-04 08:24:22 +00:00
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionSuggested];
}
else if (sectionType == RecentsDataSourceSectionTypeAllChats)
{
[self.recentsListService paginateInSection:RecentsListServiceSectionAllChats];
}
}
- (void)moveRoomCell:(MXRoom*)room from:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath success:(void (^)(void))moveSuccess failure:(void (^)(NSError *error))moveFailure;
{
MXLogDebug(@"[RecentsDataSource] moveCellFrom (%tu, %tu) to (%tu, %tu)", oldPath.section, oldPath.row, newPath.section, newPath.row);
2015-12-11 11:03:05 +00:00
if ([self canCellMoveFrom:oldPath to:newPath] && ![newPath isEqual:oldPath])
{
2022-04-04 08:24:22 +00:00
if ([self.sections sectionTypeForSectionIndex:newPath.section] == RecentsDataSourceSectionTypePeople)
{
[room setIsDirect:YES
withUserId:nil
success:moveSuccess
failure:^(NSError *error) {
MXLogDebug(@"[RecentsDataSource] Failed to mark as direct");
if (moveFailure)
{
moveFailure(error);
}
[self forceRefresh];
// Notify user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
else
{
NSString* oldRoomTag = [self roomTagAt:oldPath];
NSString* dstRoomTag = [self roomTagAt:newPath];
NSUInteger oldPos = (oldPath.section == newPath.section) ? oldPath.row : NSNotFound;
NSString* tagOrder = [room.mxSession tagOrderToBeAtIndex:newPath.row from:oldPos withTag:dstRoomTag];
MXLogDebug(@"[RecentsDataSource] Update the room %@ [%@] tag from %@ to %@ with tag order %@", room.roomId, room.summary.displayname, oldRoomTag, dstRoomTag, tagOrder);
[room replaceTag:oldRoomTag
byTag:dstRoomTag
withOrder:tagOrder
success: ^{
MXLogDebug(@"[RecentsDataSource] move is done");
if (moveSuccess)
{
moveSuccess();
}
// wait the server echo to reload the tableview.
} failure:^(NSError *error) {
MXLogDebug(@"[RecentsDataSource] Failed to update the tag %@ of room (%@)", dstRoomTag, room.roomId);
if (moveFailure)
{
moveFailure(error);
}
[self forceRefresh];
// Notify user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
}
2015-12-11 11:03:05 +00:00
else
{
MXLogDebug(@"[RecentsDataSource] cannot move this cell");
if (moveFailure)
{
moveFailure(nil);
}
[self forceRefresh];
2015-12-11 11:03:05 +00:00
}
}
#pragma mark - SecureBackupSetupBannerCellDelegate
2019-01-31 18:52:32 +00:00
2020-06-26 11:07:53 +00:00
- (void)secureBackupBannerCellDidTapCloseAction:(SecureBackupBannerCell * _Nonnull)cell
2019-01-31 18:52:32 +00:00
{
2020-06-25 15:52:36 +00:00
[self hideKeyBackupBannerWithDisplay:self.secureBackupBannerDisplay];
2019-01-31 18:52:32 +00:00
}
2020-06-30 19:46:10 +00:00
#pragma mark - CrossSigningSetupBannerCellDelegate
2020-06-30 19:46:10 +00:00
- (void)crossSigningSetupBannerCellDidTapCloseAction:(CrossSigningSetupBannerCell *)cell
{
2020-06-30 19:46:10 +00:00
[self hideCrossSigningBannerWithDisplay:self.crossSigningBannerDisplay];
}
2021-10-04 14:28:21 +00:00
#pragma mark - RecentsListServiceDelegate
- (void)recentsListServiceDidChangeData:(id<RecentsListServiceProtocol>)service
totalCountsChanged:(BOOL)totalCountsChanged
{
[[AppDelegate theDelegate].masterTabBarController refreshTabBarBadges];
}
- (void)recentsListServiceDidChangeData:(id<RecentsListServiceProtocol>)service
forSection:(RecentsListServiceSection)section
totalCountsChanged:(BOOL)totalCountsChanged
{
RecentsDataSourceSections *updatedSections = [self makeDataSourceSections];
BOOL hasChangedSections = ![self.sections isEqual:updatedSections];
2022-04-07 09:47:06 +00:00
if (hasChangedSections)
{
// If the number or order of sections has changed, we reload all of the data
[self.delegate dataSource:self didCellChange:nil];
return;
}
RecentsDataSourceSectionType sectionType = [self sectionTypeForServiceSection:section];
NSInteger sectionIndex = [self.sections sectionIndexForSectionType:sectionType];
2022-04-07 09:47:06 +00:00
if (sectionIndex >= 0)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:(NSUInteger)sectionIndex];
[self.delegate dataSource:self didCellChange:indexPath];
}
}
- (RecentsDataSourceSectionType)sectionTypeForServiceSection:(RecentsListServiceSection)serviceSection
{
switch (serviceSection)
{
case RecentsListServiceSectionInvited:
return RecentsDataSourceSectionTypeInvites;
case RecentsListServiceSectionFavorited:
return RecentsDataSourceSectionTypeFavorites;
case RecentsListServiceSectionPeople:
return RecentsDataSourceSectionTypePeople;
case RecentsListServiceSectionConversation:
return RecentsDataSourceSectionTypeConversation;
case RecentsListServiceSectionLowPriority:
return RecentsDataSourceSectionTypeLowPriority;
case RecentsListServiceSectionServerNotice:
return RecentsDataSourceSectionTypeServerNotice;
case RecentsListServiceSectionSuggested:
return RecentsDataSourceSectionTypeSuggestedRooms;
case RecentsListServiceSectionBreadcrumbs:
return RecentsDataSourceSectionTypeBreadcrumbs;
case RecentsListServiceSectionAllChats:
return RecentsDataSourceSectionTypeAllChats;
}
}
#pragma mark - Shrinkable
- (BOOL)isSectionShrinkedAt:(NSInteger)section
{
if (_areSectionsShrinkable == NO)
{
return NO;
}
2022-04-04 08:24:22 +00:00
RecentsDataSourceSectionType sectionType = [self.sections sectionTypeForSectionIndex:section];
if (sectionType == RecentsDataSourceSectionTypeFavorites && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_FAVORITES))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypePeople && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_PEOPLE))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeConversation && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_CONVERSATIONS))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeDirectory && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_DIRECTORY))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeLowPriority && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_LOWPRIORITY))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeServerNotice && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SERVERNOTICE))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeInvites && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_INVITES))
{
return YES;
}
2022-04-04 08:24:22 +00:00
if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SUGGESTED))
{
return YES;
}
if (sectionType == RecentsDataSourceSectionTypeBreadcrumbs && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_BREADCRUMBS))
{
return YES;
}
if (sectionType == RecentsDataSourceSectionTypeAllChats && (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_ALL_CHATS))
{
return YES;
}
return NO;
}
@end