1、首先,EaseConversationListViewController是消息列表的.m文件
在该文件的tableViewDidTriggerHeaderRefresh方法里面添加数组:
#warning 当sorted数组为空的时候添加admin到数组中;当sorted中没有admin的时候,添加一个;
if (sorted.count==0) {
EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:@"admin" type:EMConversationTypeChat createIfNotExist:YES];
[sorted addObject:conversation];
}
BOOL existAdmin = NO;
for (EMConversation *conversation in sorted) {
if ([conversation.conversationId isEqualToString:@"admin"]) {
existAdmin = YES;
}
}
if (!existAdmin) {
EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:@"admin" type:EMConversationTypeChat createIfNotExist:YES];
[sorted insertObject:conversation atIndex:0];
}
#warning end
2、其次,在我们自己的MessageListViewController里面,添加逻辑:
conversationListViewController:didSelectConversationModel:方法中添加如下判断:
if (conversationModel) {
EMConversation *conversation = conversationModel.conversation;
if (conversation) {
ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:conversation.conversationId conversationType:conversation.type];
chatController.title = conversationModel.title;
chatController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:chatController animated:YES];
// }
}
}else{
#warning 情感客服
ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:@"admin" conversationType:EMConversationTypeChat];
chatController.title = conversationModel.title;
chatController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:chatController animated:YES];
#warning end}
3、返回EaseConversationListViewController中在tableView的didSelect代理方法中添加
if (_delegate && [_delegate respondsToSelector:@selector(conversationListViewController:didSelectConversationModel:)]) {
// EaseConversationModel *model = [self.dataArray objectAtIndex:indexPath.row];
// [_delegate conversationListViewController:self didSelectConversationModel:model];
#warning 修改cell的策略
if (indexPath.row == 0) {
[_delegate conversationListViewController:self didSelectConversationModel:nil];
}else{
EaseConversationModel *model = [self.dataArray objectAtIndex:indexPath.row];
[_delegate conversationListViewController:self didSelectConversationModel:model];
}
}
网友评论