Conversation List Page
The IMKit SDK generates conversations based on messages in the local database. The conversation list page displays all local conversations on the current user's device. Once the SDK's local message database generates a message, the SDK creates a corresponding conversation and sorts them in reverse chronological order, with pinned conversations appearing first.
If Multi-Device Message Synchronization is enabled, in scenarios such as logging in on a new device or reinstalling the app, the offline compensation mechanism can only retrieve recent one-to-one and group chat messages (default compensation period is 1 day, maximum 7 days). Conversations older than this period cannot be retrieved through offline compensation. As a result, the conversation list after compensation may not match the list on the original device or before uninstallation (you might feel like some conversations are missing).
IMKit provides the conversation page class RCConversationListViewController
, based on UIKit's UITableView
.
The conversation list page generally consists of a title bar and a conversation list.
To display nicknames and avatars in the conversation list, you have two implementation options:
- Set up a user info provider for IMKit, which fetches the required display data. For details, see User Information.
- Use the User Profile Hosting feature. For details, see User Profile Hosting.
Initialization
- When developing with IMKit, it's recommended to subclass
RCConversationListViewController
to create a custom conversation list page. - For troubleshooting or reproducing issues related to the conversation page, you can directly use
RCConversationListViewController
to verify if the issue is caused by subclass overrides.
You can initialize the RCConversationListViewController
class to build the conversation list page and specify the types of conversations to include. Convert RCConversationType
to NSNumber to construct an Array.
Parameter Description
Parameter | Type | Description |
---|---|---|
displayConversationTypeArray | NSArray (NSNumber *) | An array of conversation types to display in the list. Convert RCConversationType to NSNumber to construct the Array. |
collectionConversationTypeArray | NSArray (NSNumber *) | An array of conversation types to aggregate into a single entry. Convert RCConversationType to NSNumber to construct the Array. See Aggregate Conversations by Type. |
Example Code
NSArray *displayConversationTypeArray = @[@(ConversationType_PRIVATE), @(ConversationType_GROUP), @(ConversationType_SYSTEM)];
NSArray *collectionConversationTypeArray = nil;
RCConversationListViewController *conversationListVC = [[RCDChatListViewController alloc] initWithDisplayConversationTypes:displayConversationTypeArray collectionConversationType:collectionConversationTypeArray];
[self.navigationController pushViewController:conversationListVC animated:YES];
Customization
You can customize the style of the IMKit conversation list interface. Refer to the header file of RCConversationListViewController for details on customizable properties.
Custom Title Bar
IMKit's RCConversationListViewController
uses the system navigation bar to display the conversation list title. Set the title via the title
property of UIViewController
.
Modify Conversation Avatar Shape
Each conversation item in the list displays an avatar icon (not the avatar in the chat message list). One-to-one chats show the other user's avatar, group chats show the group avatar, and aggregated conversations show a default avatar or one set by the app.
IMKit supports global configuration to control the avatar style in the conversation list.
The default avatar shape is rectangular but can be changed to circular. The default avatar size is 46*46
. Call the following code after app initialization but before IM connection:
Parameter Description
RCUserAvatarStyle
options:
Type Name | Description |
---|---|
RC_USER_AVATAR_RECTANGLE | Rectangle |
RC_USER_AVATAR_CYCLE | Circle |
Example Code
RCKitConfigCenter.ui.globalConversationAvatarStyle = RC_USER_AVATAR_CYCLE;
The avatar height must be at least 36. Modify the size as follows:
Example Code
RCKitConfigCenter.ui.globalConversationPortraitSize = CGSizeMake(46, 46);
Show/Hide Network Connection Status Prompt
When the connection is lost or reconnecting, IMKit SDK displays a connection status bar at the top of the conversation list. This feature is enabled by default. Disable it via the isShowNetworkIndicatorView
property of RCConversationListViewController
.
@property (nonatomic, assign) BOOL isShowNetworkIndicatorView;
To modify the prompt text, edit the language files in en.lproj
and zh-Hans.lproj
.
Custom Empty View
RCConversationListViewController
provides an empty view emptyConversationView
(displayed when no conversations exist). Assign a custom view to emptyConversationView
if needed.
Example Code
- (void)viewDidLoad {
[super viewDidLoad];
// Set the frame as needed
UIImageView *empty = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
empty.center = self.view.center;
empty.backgroundColor = [UIColor redColor];
self.emptyConversationView = empty;
}
Custom Conversation Cell
The conversation list component displays all conversations in reverse chronological order, with pinned conversations appearing first. IMKit defaults include swipe-to-delete functionality for conversation cells. Each item's view is created and customized in RCConversationCell
.
For reference, check SealTalk (RongCloud's open-source project: GitHub · Gitee). The RCDChatListViewController
class demonstrates custom cell (RCDChatListCell
) implementation, specifically for system conversations (ConversationType_SYSTEM
) with friend request messages (RCContactNotificationMessage
).
-
Override the data source method.
Filter the
dataSource
for specific conversation types and messagemodel
. Setmodel.conversationModelType = RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION
.-(NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource;
-
Override the custom cell.
// Custom cell
-(RCConversationBaseCell *)rcConversationListTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; -
Override the custom cell height method.
// Cell height
-(CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; -
Override the message receipt handler.
Generate a new
model
, insert it into theconversationListDataSource
, and update the page. Setmodel.conversationModelType
toRC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION
.#pragma mark - Message Receipt Notification
-(void)didReceiveMessageNotification:(NSNotification *)notification;
Handling Reinstallation or Device Switching
If users reinstall the app or switch devices, they might find the conversation list empty or perceive missing conversations.
Reasons:
- Uninstallation deletes the local database, leaving no history messages upon reinstallation.
- Switching devices may result in no local message data, causing an empty conversation list.
- If Multi-Device Message Synchronization is enabled for your App Key, the server activates offline message compensation. After SDK reconnection, the server automatically syncs messages from the current day (00:00 onwards). The client SDK generates partial conversations from these messages, which may seem incomplete compared to the original list.
To retrieve the previous conversation list after reinstallation or device switching, consider these solutions:
- Request an extension of the offline compensation period (up to 7 days). Note: Longer periods may cause client-side performance issues for users with high message volumes. Submit a [ticket] if needed.
- Maintain the conversation list on your server and fetch historical messages via API.
[ticket]: https://console.rongcloud.io/agile/formwork/ticket/create