Friend Request List Page
This feature is supported starting from version 5.12.0.
The friend request list page displays all friend requests on the current user's device. Upon entering this page, the IMKit SDK automatically retrieves friend request data from the database and sorts it chronologically.
Friend request lists expire after 7 days. Expired requests require reinitiation and won't sync across multiple devices.
IMKit provides RCApplyFriendListViewController
, a friend list page class based on UIKit's UITableView
.
This page typically consists of a navigation bar and a friend request list section.


Initialization
Initialize the friend list page by calling the RCApplyFriendListViewController
constructor. Note: You need to create an RCApplyFriendListViewModel object as the business logic handler for RCApplyFriendListViewController
.
RCApplyFriendSectionItem objects are used to group friend requests by time intervals.
Parameters
Parameter | Type | Description |
---|---|---|
viewModel | RCApplyFriendListViewModel | Business logic handler for RCApplyFriendListViewController . Manages UI configuration and data retrieval. |
items | NSArray <RCApplyFriendSectionItem *>* | Grouping model for friend requests. Creates different RCApplyFriendSectionItem objects to categorize data by time intervals. |
option | RCPagingQueryOption | Query configuration. |
types | NSArray<NSNumber *> * | List of friend request types RCFriendApplicationType. Example: @[@(RCFriendApplicationTypeSent),@(RCFriendApplicationTypeReceived)] |
status | NSArray<NSNumber *> * | List of friend request statuses RCFriendApplicationStatus. Example: @[@(RCFriendApplicationStatusUnHandled),@(RCFriendApplicationStatusAccepted),@(RCFriendApplicationStatusRefused),@(RCFriendApplicationStatusExpired)] . |
Sample Code
- (void)showFriendApplyWithController:(UIViewController *)controller {
NSMutableArray *sections = [NSMutableArray array];
RCFriendApplyItemFilterBlock block = ^BOOL(RCApplyFriendCellViewModel *obj, NSInteger start, NSInteger end, BOOL * _Nonnull stop) {
if (obj.application.operationTime >= start && obj.application.operationTime < end) {
return YES;
}
return NO;
};
RCApplyFriendSectionItem *justNow = [[RCApplyFriendSectionItem alloc] initWithFilterBlock:block compareBlock:nil];
justNow.title = @"Just now";
justNow.timeStart = [self startOfToday];
justNow.timeEnd = [[NSDate date]timeIntervalSince1970] * 1000;
[sections addObject:justNow];
RCApplyFriendSectionItem *oneDays = [[RCApplyFriendSectionItem alloc] initWithFilterBlock:block compareBlock:nil];
oneDays.title = @"Last 24 hours";
oneDays.timeStart = [self startTimeOfDaysBefore:-1];
oneDays.timeEnd = [self startOfToday];
[sections addObject:oneDays];
RCApplyFriendSectionItem *threeDays = [[RCApplyFriendSectionItem alloc] initWithFilterBlock:block compareBlock:nil];
threeDays.title = @"Last 3 days";
threeDays.timeStart = [self startTimeOfDaysBefore:-4];
threeDays.timeEnd = [self startTimeOfDaysBefore:-1];
[sections addObject:threeDays];
RCApplyFriendSectionItem *longAgo = [[RCApplyFriendSectionItem alloc] initWithFilterBlock:block compareBlock:nil];
longAgo.title = @"Older than 3 days";
longAgo.timeStart = 0;
longAgo.timeEnd = [self startTimeOfDaysBefore:-4];
[sections addObject:longAgo];
RCApplyFriendListViewModel *vm = [[RCApplyFriendListViewModel alloc] initWithSectionItems:sections option:nil types:@[] status:@[]];
RCApplyFriendListViewController *listVC = [[RCApplyFriendListViewController alloc] initWithViewModel:vm];
[self.navigationController pushViewController:listVC animated:YES];
}
- (NSInteger)startOfToday {
NSDate *now = [NSDate date];
NSDate *date = [[NSCalendar currentCalendar] startOfDayForDate:[NSDate date]];
return [date timeIntervalSince1970] * 1000;
}
- (NSInteger)timeOfDaysBefore:(NSInteger)dayDiff start:(BOOL)start {
NSDate *now = [NSDate date];
NSDate *date = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay
value:dayDiff
toDate:now options:NSCalendarMatchStrictly];
NSDate *dateStart = [[NSCalendar currentCalendar] startOfDayForDate:date];
if (start) {
return [dateStart timeIntervalSince1970] * 1000;
} else {
NSDate *dateEnd = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay
value:1
toDate:dateStart options:NSCalendarWrapComponents];
return [dateEnd timeIntervalSince1970] * 1000 - 1;
}
}
- (NSInteger)startTimeOfDaysBefore:(NSInteger)dayDiff {
return [self timeOfDaysBefore:dayDiff start:YES];;
}
- (NSInteger)endTimeOfDaysBefore:(NSInteger)dayDiff {
return [self timeOfDaysBefore:dayDiff start:NO];;
}
Time intervals in multiple RCApplyFriendSectionItem objects must not overlap to prevent duplicate data display.
Customization
IMKit allows customization of the friend request list interface.
Custom Navigation Bar
RCApplyFriendListViewController
uses the system navigation bar to display the page title. Subclass RCApplyFriendListViewController
and set the title
property in viewDidLoad
:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Custom Title";
}
Custom Friend Request List Cell
RCApplyFriendListViewController
supports cell customization. Set the delegate
property of RCApplyFriendListViewModel
to modify cell styles and displayed content.
1. Create RCCustomCell
@interface RCCustomCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@end
@implementation
// Cell rendering
@end
2. Create RCCustomCellViewModel
Custom CellViewModel must subclass RCApplyFriendCellViewModel.
typedef void(^RCPermanentCellViewModelBlock)(UIViewController *);
@interface RCCustomCellViewModel : RCApplyFriendCellViewModel
/// Constructor
- (instancetype)initWithTitle:(NSString *)title
portrait:(UIImage *)portrait
touchBlock:(RCPermanentCellViewModelBlock)touchBlock;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) UIImage *portrait;
@property (nonatomic, copy) RCPermanentCellViewModelBlock touchBlock;
@end
@implementation RCCustomCellViewModel
- (instancetype)initWithTitle:(NSString *)title
portrait:(UIImage *)portrait
touchBlock:(RCPermanentCellViewModelBlock)touchBlock{
self = [super init];
if (self) {
self.title = title;
self.portrait = portrait;
self.touchBlock = touchBlock;
}
return self;
}
// Register and customize cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"RCCustomCellIdentifier";
// Register cell
[tableView registerClass:RCCustomCell.class forCellReuseIdentifier:cellIdentifier];
// Return cell
RCCustomCellViewModel *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
// Modify UI
cell.titleLabel.text = self.title;
cell.contentLabel.text = self.detail;
return cell;
}
@end
3. Set Delegate
Initialize RCApplyFriendListViewModel
with its delegate:
RCApplyFriendListViewModel *viewModel = [[RCApplyFriendListViewModel alloc] initWithSectionItems:sections option:nil types:@[] status:@[]];
viewModel.delegate = self;
4. Modify Data Source
Implement delegate methods:
- (NSArray <RCApplyFriendCellViewModel *> *_Nullable)applyFriendListViewModel:(RCApplyFriendListViewModel *)viewModel
willLoadItemsInDataSource:(NSArray *_Nullable)dataSource{
NSMutableArray *list = dataSource.mutableCopy;
RCCustomCellViewModel *customCellVM = [[RCCustomCellViewModel alloc] initWithTitle:@"title" portrait:[UIImage imageNamed:@"newFriend"] touchBlock:^(UIViewController * vc) {
// Handle tap event
}];
[list addObject:@[customCellVM]];
return list;
}
5. Custom Cell Tap Handling
/// Configure custom tap events. Returns: Whether the app handles the event [YES: SDK skips processing, NO: SDK handles internally]
- (BOOL)applyFriendListViewModel:(RCApplyFriendListViewModel *)viewModel
viewController:(UIViewController*)viewController
tableView:(UITableView *)tableView
didSelectRow:(NSIndexPath *)indexPath
cellViewModel:(RCApplyFriendCellViewModel *)viewModel {
}