1.设置会话类型
//设置需要显示哪些类型的会话,由于楼主只需要单聊功能,所以只设置ConversationType_PRIVATE
[self setDisplayConversationTypes:@[@(ConversationType_PRIVATE),@(ConversationType_SYSTEM)
]];
2.依据文本消息的附加信息判断是否是好友添加类型消息
//重写RCConversationListViewController的onSelectedTableRow事件
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
conversationModel:(RCConversationModel *)model
atIndexPath:(NSIndexPath *)indexPath {
UIMConversationController *conversationVC = [[UIMConversationController alloc]init];
conversationVC.displayUserNameInCell = YES;
//聊天界面的聊天类型
conversationVC.conversationType = model.conversationType;
//需要打开和谁聊天的会话界面,和谁聊天其实是通过TargetId来联系的。
conversationVC.targetId = model.targetId;
conversationVC.title = model.targetId;
RCTextMessage *msg = [RCTextMessage new];
msg = model.lastestMessage;
NSString *extra = msg.extra;
if ([extra isEqualToString:@"ConversationType_SYSTEM"]) {
NSLog(extra);
// push时隐藏
self.hidesBottomBarWhenPushed = YES;
// 进入到是否确认好友请求页面
UIMAddressBookViewController *addressBookVC = [UIMAddressBookViewController addressBookViewController];
UIMFriendModel *user = [UIMFriendModel new];
user.userId = model.targetId;
user.name = model.targetId;
user.icon = @"http://img4.duitang.com/uploads/item/201511/26/20151126112617_vUaQf.jpeg";
[self postGetfriendstatus:[RCIM sharedRCIM].currentUserInfo.userId friendid:model.targetId success:^(id responseObject) {
// NSLog(responseObject);
user.status = responseObject[@"m_status"];
} failure:^(NSError *error) {
NSLog(error);
}];
addressBookVC.friendInfo = user;
[self.navigationController pushViewController:addressBookVC animated:YES];
} else {
[self.navigationController pushViewController:conversationVC animated:YES];
};
}
附:
向客户端服务器发送添加好友的申请
image.png
#pragma mark - 请求添加好友
- (void)postAddfriendrequest: (NSString *)userid friendid:(NSString *)friendid success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{
NSURL *url = [NSURL URLWithString:@".......url......."];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
// 数据体
NSString *str = [NSString stringWithFormat:@"fromuser=%@&touser=%@&message=%@&messagetype=%@",userid,friendid,@"请求添加好友",@"ConversationType_SYSTEM"];
// 将字符串转换成数据
request.HTTPBody = [str dataUsingEncoding:NSUTF8StringEncoding];
// 3. 连接,异步
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError == nil) {
// 网络请求结束之后执行!
// 将Data转换成字符串
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
success(str);
}else{
failure(connectionError);
}
}];
// num = 1
NSLog(@"come here %@", [NSThread currentThread]);
}