Skip to main content

Message Context Menu

When a user long-presses a message in the chat UI, a pop-up window will appear, offering different options based on the current message type and conversation type. You can customize the display name, order, and even add or remove menu options.

Customizing the Menu Options for Long-Press Message Pop-up

When a message is long-pressed in the chat UI RCChatViewController, the following method is called before the menu is displayed. You can override this method to customize the menu:

- (NSArray<RCMessageEditBarItem *> *)willDisplayEditMenu:(NSArray<RCMessageEditBarItem *> *)items forMessageModel:(RCMessageModel *)messageModel {

/// Use super to get the default menu options
NSMutableArray *tempList = [super willDisplayEditMenu:items forMessageModel:messageModel].mutableCopy;

/// Delete
for (RCMessageEditBarItem *item in tempList) {
if (item.tag == RCMessageEditBarItemDelete) {
[tempList removeObject:item];
}
}

/// Add
RCMessageEditBarItem *barItem = [RCMessageEditBarItem itemWithTitle:@"Custom option" image:[UIImage imageNamed:@"voice"] action:^(RCBarItem *item){
/// Click action
}];
barItem.tag = 2003;
[tempList addObject:barItem];

return tempList.copy;
}

The default menu options can be distinguished by their tags, as shown below:

Functiontag
ReadRCMessageEditBarItemRead
ReplyRCMessageEditBarItemReply
ForwardRCMessageEditBarItemForward
CopyRCMessageEditBarItemCopy
DeleteRCMessageEditBarItemDelete
SelectRCMessageEditBarItemSelect

Customizing the Long-Press Event

You can override the following method to customize the long-press event:

- (void)tableViewCell:(UITableViewCell *)cell didLongPressMessage:(RCMessageModel *)messageModel {

}