620 lines
25 KiB
Mathematica
620 lines
25 KiB
Mathematica
|
|
//
|
|||
|
|
// ChatViewController.m
|
|||
|
|
// Youth
|
|||
|
|
//
|
|||
|
|
// Created by mambaxie on 2022/1/2.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import "ChatViewController.h"
|
|||
|
|
#import "TUIC2CChatViewController.h"
|
|||
|
|
#import "TUIPatch.h"
|
|||
|
|
#import "TUIGroupChatViewController.h"
|
|||
|
|
#import "C2CChatSetttingsViewController.h"
|
|||
|
|
#import "TUIMessageDataProvider.h"
|
|||
|
|
#import "V2TIMMessage+TUIPatch.h"
|
|||
|
|
#import "TUIBaseMessageController+TUIPatch.h"
|
|||
|
|
#import "C2CChatViewController.h"
|
|||
|
|
#import "ProfileCardViewController.h"
|
|||
|
|
#import "VIPViewController.h"
|
|||
|
|
|
|||
|
|
//#import "MyVIPCardData.h"
|
|||
|
|
//#import "MyVipCarDatas.h"
|
|||
|
|
//#import "MyVIPCardCell.h"
|
|||
|
|
#import "THGiveVipMessageCell.h"
|
|||
|
|
|
|||
|
|
@interface TUIBaseChatViewController () <TUIBaseMessageControllerDelegate>
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
@interface ChatViewController () <TUIBaseMessageControllerDelegate, V2TIMSimpleMsgListener, V2TIMAdvancedMsgListener>
|
|||
|
|
@property (nonatomic, strong) TUIBaseChatViewController *chatVC;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIButton *followButton;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UserOtherInfo *otherInfo;
|
|||
|
|
|
|||
|
|
@property (nonatomic, weak) id observe;
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
@implementation ChatViewController
|
|||
|
|
|
|||
|
|
- (BOOL)isGroup {
|
|||
|
|
return self.convData.groupID.length > 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (BOOL)enableAutoToolbar {
|
|||
|
|
return NO;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (BOOL)mt_nagationBarTransparent {
|
|||
|
|
return NO;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)viewDidLayoutSubviews {
|
|||
|
|
[super viewDidLayoutSubviews];
|
|||
|
|
|
|||
|
|
self.chatVC.view.frame = self.view.bounds;
|
|||
|
|
self.chatVC.messageController.tableView.backgroundColor = [UIColor clearColor];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)dealloc {
|
|||
|
|
NSLog(@"ChatViewController dealloc");
|
|||
|
|
|
|||
|
|
// [[NSNotificationCenter defaultCenter] removeObserver:self name:@"sendVipMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:_observe];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedVipMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"sendLocationMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|||
|
|
[super viewWillDisappear:animated];
|
|||
|
|
|
|||
|
|
if ([self isMovingFromParentViewController]) { // 页面销毁
|
|||
|
|
[self markReaded];
|
|||
|
|
[[V2TIMManager sharedInstance] removeSimpleMsgListener:self];
|
|||
|
|
[[V2TIMManager sharedInstance] removeAdvancedMsgListener:self];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|||
|
|
[super viewWillAppear:animated];
|
|||
|
|
|
|||
|
|
if ([self isMovingToParentViewController]) { // 初次进入页面
|
|||
|
|
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
|
|||
|
|
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
|
|||
|
|
}
|
|||
|
|
self.title = self.convData.title;
|
|||
|
|
self.chatVC.messageController.tableView.backgroundColor = [UIColor clearColor];
|
|||
|
|
[self updateFollowButton];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)markReaded {
|
|||
|
|
[[V2TIMManager sharedInstance] markC2CMessageAsRead:self.convData.userID succ:^{
|
|||
|
|
;
|
|||
|
|
} fail:^(int code, NSString *desc) {
|
|||
|
|
;
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)updateFollowButton {
|
|||
|
|
BOOL isFollowing = [self.otherInfo isFollowing];
|
|||
|
|
self.followButton.selected = isFollowing;
|
|||
|
|
self.followButton.backgroundColor = isFollowing ? [UIColor clearColor] : COLOR_WITH_RGB(0xFFBE00);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)viewDidLoad {
|
|||
|
|
[super viewDidLoad];
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
[UserService loadUserOtherInfosWithUserIDs:@[self.convData.userID] userCache:YES comoletion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
[self setupUI];
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
// WeakSelf(self);
|
|||
|
|
[[V2TIMManager sharedInstance] getTotalUnreadMessageCount:^(UInt64 totalCount) {
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 获取成功,totalCount 为未读消息总数
|
|||
|
|
// 更新 UI 上的未读数
|
|||
|
|
// [weakself.customTabbar setNumAtIndex:1 num:totalCount];
|
|||
|
|
|
|||
|
|
[UIApplication sharedApplication].applicationIconBadgeNumber = totalCount;
|
|||
|
|
} fail:^(int code, NSString *desc) {
|
|||
|
|
// 获取失败
|
|||
|
|
// [weakself.tabBarController.tabBar setNumAtIndex:1 num:0];
|
|||
|
|
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sengVipMsg:) name:@"sendVipMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sengLocationMsg:) name:@"sendLocationMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
//接收支付后消息
|
|||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveVipMsg:) name:@"receivedVipMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
|
|||
|
|
// _observe = [[NSNotificationCenter defaultCenter] addObserverForName:@"sendVipMsgnotifi" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
|||
|
|
//
|
|||
|
|
// NSLog(@"收到了通知");
|
|||
|
|
// [PYAppService sendVipVC:@"vip_page" forUserID:self.convData.userID];
|
|||
|
|
//
|
|||
|
|
// [[NSNotificationCenter defaultCenter] removeObserver:self. observe];
|
|||
|
|
//
|
|||
|
|
//
|
|||
|
|
// }];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)sengLocationMsg:(NSNotification *)noti
|
|||
|
|
{
|
|||
|
|
[ToastUtil showToast:@"工程师疯狂打码中......"];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)sengVipMsg:(NSNotification *)noti
|
|||
|
|
{
|
|||
|
|
//测试
|
|||
|
|
/*
|
|||
|
|
// 创建自定义消息,设置消息的 businessID、展示文本、跳转链接(以下代码需要您自己实现)
|
|||
|
|
NSError *error;
|
|||
|
|
NSString *businessID = @"custom_message_vip";
|
|||
|
|
NSString *title_name = @"test会员";
|
|||
|
|
NSDictionary *param = @{@"businessID": businessID, @"title_name":title_name};
|
|||
|
|
NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:&error];
|
|||
|
|
V2TIMMessage *message = [[V2TIMManager sharedInstance] createCustomMessage:data];
|
|||
|
|
[self.chatVC sendMessage:message];
|
|||
|
|
return;
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
if ([UserService currentUser].isVIP) {
|
|||
|
|
|
|||
|
|
[PYAppService sendVipVC:@"vip_page" forUserID:self.convData.userID];
|
|||
|
|
|
|||
|
|
|
|||
|
|
// [[NSNotificationCenter defaultCenter] removeObserver:self name:@"sendVipMsgnotifi" object:nil];
|
|||
|
|
|
|||
|
|
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sengVipMsg:) name:@"sendVipMsgnotifi" object:nil];
|
|||
|
|
}else {
|
|||
|
|
[ToastUtil showToast:@"需要成为会员才可以赠送VIP哦~"];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)receiveVipMsg:(NSNotification *)noti
|
|||
|
|
{
|
|||
|
|
NSString *vipType = noti.object;
|
|||
|
|
|
|||
|
|
// NSLog(@"vipType==%@",vipType);
|
|||
|
|
NSString *text = vipType;
|
|||
|
|
// NSString *link = @"https://cloud.tencent.com/document/product/269/3794";
|
|||
|
|
NSError *error = nil;
|
|||
|
|
NSDictionary *param = @{BussinessID: BussinessID_TextLink, @"text":text};
|
|||
|
|
NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:&error];
|
|||
|
|
if(error)
|
|||
|
|
{
|
|||
|
|
NSLog(@"[%@] Post Json Error", [self class]);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
V2TIMMessage *message = [TUIMessageDataProvider getCustomMessageWithJsonData:data];
|
|||
|
|
|
|||
|
|
[self.chatVC sendMessage:message];
|
|||
|
|
|
|||
|
|
//发送消息成功后退出VipView控制器
|
|||
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"vipViewClosenotifi" object:vipType];
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)setupUI {
|
|||
|
|
|
|||
|
|
|
|||
|
|
// UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
|
|||
|
|
// [back setTitle:@"12" forState:UIControlStateNormal];
|
|||
|
|
//// back addTarget:self action:@selector(<#selector#>) forControlEvents:<#(UIControlEvents)#>
|
|||
|
|
// back.titleLabel.font = [UIFont systemFontOfSize:16];
|
|||
|
|
|
|||
|
|
// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:back];
|
|||
|
|
|
|||
|
|
self.otherInfo = [UserService userOtherInfoForUserID:self.convData.userID];
|
|||
|
|
UIButton *followButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|||
|
|
followButton.size = CGSizeMake(49, 26);
|
|||
|
|
followButton.layer.cornerRadius = 10;
|
|||
|
|
[followButton setTitle:@"已关注" forState:UIControlStateSelected];
|
|||
|
|
[followButton setTitleColor:COLOR_WITH_RGB(0xB3B3B3) forState:UIControlStateSelected];
|
|||
|
|
[followButton setTitle:@"关注" forState:UIControlStateNormal];
|
|||
|
|
[followButton setTitleColor:COLOR_WITH_RGB(0x040000) forState:UIControlStateNormal];
|
|||
|
|
followButton.backgroundColor = COLOR_WITH_RGB(0xFFBE00);
|
|||
|
|
followButton.titleLabel.font = MT_FONT_REGULAR_NO_SCALE_SIZE(13);
|
|||
|
|
self.followButton = followButton;
|
|||
|
|
WeakSelf(self);
|
|||
|
|
[followButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
InputStatus status = weakself.chatVC.inputController.status;
|
|||
|
|
if (status == Input_Status_Input_Talk) {
|
|||
|
|
// [weakself.chatVC.inputController.inputBar performSelector:@selector(clickKeyboardBtn:) withObject:weakself.chatVC.inputController.inputBar.keyboardButton];
|
|||
|
|
}
|
|||
|
|
[weakself.chatVC.inputController reset]; // 收起键盘
|
|||
|
|
|
|||
|
|
int userID = [UserService userIDFromIMUserID:weakself.convData.userID].intValue;
|
|||
|
|
if (button.isSelected) {
|
|||
|
|
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|||
|
|
config.message = @"是否取消关注";
|
|||
|
|
config.cancelTitle = @"取消";
|
|||
|
|
config.otherTitle = @"是的";
|
|||
|
|
config.otherHandler = ^(MTAlertButton *btn) {
|
|||
|
|
[UserService unfollowUserWIthUserID:userID completion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
if (!error) {
|
|||
|
|
[weakself.otherInfo updateFollowState:!button.isSelected];
|
|||
|
|
[weakself updateFollowButton];
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
};
|
|||
|
|
}];
|
|||
|
|
} else {
|
|||
|
|
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|||
|
|
config.title = @"防骚扰提醒";
|
|||
|
|
config.message = @"若两人互相认可(互关),双方发送的内容将不再有鉴黄暴力等检查";
|
|||
|
|
config.cancelTitle = @"取消";
|
|||
|
|
config.otherTitle = @"关注";
|
|||
|
|
config.otherHandler = ^(MTAlertButton *btn) {
|
|||
|
|
[UserService followUserWIthUserID:userID completion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
if (!error) {
|
|||
|
|
[weakself.otherInfo updateFollowState:!button.isSelected];
|
|||
|
|
[weakself updateFollowButton];
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
};
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
UIView *followButtonContainer = [[UIView alloc] initWithFrame:followButton.bounds];
|
|||
|
|
[followButtonContainer addSubview:followButton];
|
|||
|
|
UIBarButtonItem *followItem = [[UIBarButtonItem alloc] initWithCustomView:followButtonContainer];
|
|||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|||
|
|
followButton.centerY = followButtonContainer.height * 0.5;
|
|||
|
|
});
|
|||
|
|
UIBarButtonItem *settingsItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"chat_settings") style:UIBarButtonItemStylePlain target:self action:@selector(openSettingVC)];
|
|||
|
|
self.navigationItem.rightBarButtonItems = @[settingsItem, followItem];
|
|||
|
|
|
|||
|
|
// 创建会话信息
|
|||
|
|
TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init];
|
|||
|
|
data.groupID = self.convData.groupID;
|
|||
|
|
data.groupType = self.convData.groupType;
|
|||
|
|
data.userID = self.convData.userID;
|
|||
|
|
|
|||
|
|
data.conversationID = self.convData.conversationID;
|
|||
|
|
TUIBaseChatViewController *vc = nil;
|
|||
|
|
if ([self isGroup]) {
|
|||
|
|
vc = [[TUIGroupChatViewController alloc] init];
|
|||
|
|
} else {
|
|||
|
|
// 创建 TUIC2CChatViewController
|
|||
|
|
vc = [[C2CChatViewController alloc] init];
|
|||
|
|
}
|
|||
|
|
[vc setConversationData:data];
|
|||
|
|
if (self.isInActivityRoom) {
|
|||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|||
|
|
[vc.messageController patch_setIsInActivityRoom:YES];
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
// 把 TUIC2CChatViewController 添加到自己的 ViewController
|
|||
|
|
[self addChildViewController:vc];
|
|||
|
|
[self.view addSubview:vc.view];
|
|||
|
|
|
|||
|
|
self.view.backgroundColor = BG_COLOR;
|
|||
|
|
vc.view.backgroundColor = [UIColor clearColor];
|
|||
|
|
UIImageView *bgImageView = [[UIImageView alloc] init];
|
|||
|
|
bgImageView.image = ImageNamed(@"TH_chat_bg");
|
|||
|
|
bgImageView.x = FIX_SIZE(37.5);
|
|||
|
|
bgImageView.width = self.view.width - bgImageView.x * 2;
|
|||
|
|
CGSize imageSize = bgImageView.image.size;
|
|||
|
|
bgImageView.height = bgImageView.width * imageSize.height / imageSize.width;
|
|||
|
|
// bgImageView.image = UIImageMake(@"TH_BaseLocalBg");
|
|||
|
|
// bgImageView.frame = self.view.bounds;
|
|||
|
|
[self.view insertSubview:bgImageView atIndex:0];
|
|||
|
|
bgImageView.centerY = self.view.height * 0.5;
|
|||
|
|
vc.messageController.delegate = self;
|
|||
|
|
self.chatVC = vc;
|
|||
|
|
[TUIPatch patchChatVC:vc];
|
|||
|
|
|
|||
|
|
//服务器处理此逻辑
|
|||
|
|
// TUIInputBar *inpuBar = vc.inputController.inputBar;
|
|||
|
|
// [inpuBar.moreButton removeTarget:inpuBar action:@selector(clickMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
|
|||
|
|
// WeakSelf(inpuBar);
|
|||
|
|
// [inpuBar.moreButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
// if ([UserService currentUser].isVIP || weakself.otherInfo.relation == RelationTypeFriends) {
|
|||
|
|
// [weakinpuBar performSelector:@selector(clickMoreBtn:) withObject:button];
|
|||
|
|
// } else {
|
|||
|
|
// [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|||
|
|
// config.title = @"双方互关后才可以发送图片和语音";
|
|||
|
|
// config.message = @"开通VIP后也可向陌生人发送图片和语音\n28元即可开通90天VIP";
|
|||
|
|
// config.cancelTitle = @"下次";
|
|||
|
|
// config.otherTitle = @"开通VIP";
|
|||
|
|
// config.otherHandler = ^(MTAlertButton *button) {
|
|||
|
|
// [PYAppService showFastVipToBuy:@"chat_pic"];
|
|||
|
|
// };
|
|||
|
|
// }];
|
|||
|
|
// }
|
|||
|
|
// }];
|
|||
|
|
//
|
|||
|
|
// [inpuBar.micButton removeTarget:inpuBar action:@selector(clickVoiceBtn:) forControlEvents:UIControlEventTouchUpInside];
|
|||
|
|
// [inpuBar.micButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
// if ([UserService currentUser].isVIP || weakself.otherInfo.relation == RelationTypeFriends) {
|
|||
|
|
// [weakinpuBar performSelector:@selector(clickVoiceBtn:) withObject:button];
|
|||
|
|
// } else {
|
|||
|
|
// [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|||
|
|
// config.title = @"双方互关后才可以发送图片和语音";
|
|||
|
|
// config.message = @"开通VIP后也可向陌生人发送图片和语音\n28元即可开通90天VIP";
|
|||
|
|
// config.cancelTitle = @"下次";
|
|||
|
|
// config.otherTitle = @"开通VIP";
|
|||
|
|
// config.otherHandler = ^(MTAlertButton *button) {
|
|||
|
|
// [PYAppService showFastVipToBuy:@"chat_voice"];
|
|||
|
|
// };
|
|||
|
|
// }];
|
|||
|
|
// }
|
|||
|
|
// }];
|
|||
|
|
|
|||
|
|
UIView *titleView = [[UIView alloc] init];
|
|||
|
|
titleView.height = 44.0;
|
|||
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|||
|
|
titleLabel.font = MT_FONT_MEDIUM_SIZE(15);
|
|||
|
|
titleLabel.textColor = [self.otherInfo isVIP] ? COLOR_WITH_RGB(0xFDCF7F) : [UIColor whiteColor];
|
|||
|
|
titleLabel.text = self.convData.title;
|
|||
|
|
UIImageView *genderIcon = [[UIImageView alloc] init];
|
|||
|
|
genderIcon.size = [User genderSize];
|
|||
|
|
genderIcon.backgroundColor = [UIColor clearColor];
|
|||
|
|
genderIcon.image = [_otherInfo genderImage];
|
|||
|
|
if (!genderIcon.image) {
|
|||
|
|
genderIcon.width = 0;
|
|||
|
|
}
|
|||
|
|
[titleView addSubview:genderIcon];
|
|||
|
|
PYImageView *vipTageImageView = [[PYImageView alloc] init];
|
|||
|
|
vipTageImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|||
|
|
vipTageImageView.size = CGSizeMake(FIX_SIZE(12), FIX_SIZE(12));
|
|||
|
|
[titleView addSubview:vipTageImageView];
|
|||
|
|
vipTageImageView.hidden = ![self.otherInfo isVIP];
|
|||
|
|
vipTageImageView.image = ImageNamed(@"vip_tag");
|
|||
|
|
// vipTageImageView.imageUrl = self.otherInfo.vip_flag_img;
|
|||
|
|
genderIcon.centerY = vipTageImageView.centerY = titleView.height * 0.5;
|
|||
|
|
|
|||
|
|
CGFloat maxLabelWidth = self.view.width - 110 * 2 - 4 - (vipTageImageView.hidden ? 0 : (vipTageImageView.width + 4) - genderIcon.width - FIX_SIZE(6));
|
|||
|
|
[titleLabel sizeToFit];
|
|||
|
|
titleLabel.width = MIN(maxLabelWidth, titleLabel.width);
|
|||
|
|
[titleView addSubview:titleLabel];
|
|||
|
|
titleLabel.height = titleView.height;
|
|||
|
|
genderIcon.x = titleLabel.right + 2;
|
|||
|
|
vipTageImageView.x = genderIcon.right + 4;
|
|||
|
|
titleView.width = vipTageImageView.right;
|
|||
|
|
|
|||
|
|
if (self.otherInfo.is_manager) {
|
|||
|
|
UIView* managerView = [[UIView alloc]initWithFrame:CGRectMake(genderIcon.right + 8, genderIcon.y + (genderIcon.height - 16)/2.0, 34, 16)];
|
|||
|
|
if(self.otherInfo.isVIP){
|
|||
|
|
managerView.left = vipTageImageView.right + 2;
|
|||
|
|
}else{
|
|||
|
|
managerView.left = genderIcon.right + 2;
|
|||
|
|
}
|
|||
|
|
managerView.layer.cornerRadius = 8;
|
|||
|
|
managerView.layer.masksToBounds = YES;
|
|||
|
|
// gradient
|
|||
|
|
CAGradientLayer *gl = [CAGradientLayer layer];
|
|||
|
|
gl.frame = CGRectMake(0,0,managerView.width,managerView.height);
|
|||
|
|
gl.startPoint = CGPointMake(0, 0.5);
|
|||
|
|
gl.endPoint = CGPointMake(1, 0.5);
|
|||
|
|
gl.colors = @[(__bridge id)HEX_COLOR(0xE4B18B).CGColor, (__bridge id)HEX_COLOR(0xFFF4EC).CGColor, (__bridge id)HEX_COLOR(0xE4B18B).CGColor];
|
|||
|
|
gl.locations = @[@(0), @(0.5f), @(1.0f)];
|
|||
|
|
[managerView.layer addSublayer:gl];
|
|||
|
|
UILabel* managerLab = [[UILabel alloc]initWithFrame:managerView.bounds];
|
|||
|
|
managerLab.text = @"官方";
|
|||
|
|
managerLab.textColor = HEX_COLOR(0x000000);
|
|||
|
|
managerLab.textAlignment = NSTextAlignmentCenter;
|
|||
|
|
managerLab.font = MT_FONT_MEDIUM_SIZE(10);
|
|||
|
|
[managerView addSubview:managerLab];
|
|||
|
|
// [nianVipLab bringSubviewToFront:nianVipLab.text];
|
|||
|
|
[titleView addSubview:managerView];
|
|||
|
|
titleView.width = managerView.right;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
self.navigationItem.titleView = titleView;
|
|||
|
|
[titleView addTapWithAction:^{
|
|||
|
|
[PYAppService showUserCardVCWithUserID:[UserService userIDFromIMUserID:self.convData.userID].intValue];
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
[self updateFollowButton];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)openSettingVC {
|
|||
|
|
if ([self isGroup]) {
|
|||
|
|
} else {
|
|||
|
|
[self.navigationController pushViewController:[[C2CChatSetttingsViewController alloc] initWithConversationData:self.chatVC.conversationData] animated:YES];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - TUIBaseMessageControllerDelegate
|
|||
|
|
/**
|
|||
|
|
* 收到新消息的函数委托
|
|||
|
|
* 您可以通过该回调实现:根据传入的 data 初始化新消息并进行新消息提醒。
|
|||
|
|
*
|
|||
|
|
* @param controller 委托者,消息控制器
|
|||
|
|
* @param message 新消息
|
|||
|
|
*
|
|||
|
|
* @return 返回需要显示的新消息单元。该消息单元的信息与数据,来自于参数中的 data 参数。
|
|||
|
|
*/
|
|||
|
|
- (TUIMessageCellData *)messageController:(TUIBaseMessageController *)controller onNewMessage:(V2TIMMessage *)msg
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// 当在活动房间时,设置为MsgDirectionIncoming使得头像均在左侧
|
|||
|
|
if (self.isInActivityRoom) {
|
|||
|
|
[msg patch_setIsInActivityRoom:YES];
|
|||
|
|
}
|
|||
|
|
// if (self.onNewMessage) {
|
|||
|
|
// self.onNewMessage(msg);
|
|||
|
|
// }
|
|||
|
|
if (msg.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
|
|||
|
|
if (msg.customElem.data) {
|
|||
|
|
NSDictionary *param = [NSJSONSerialization JSONObjectWithData:msg.customElem.data options:NSJSONReadingAllowFragments error:nil];
|
|||
|
|
if ([param isKindOfClass:NSDictionary.class]) {
|
|||
|
|
NSString *typeIdStr = param[@"businessID"];
|
|||
|
|
if ([typeIdStr isEqualToString:@"custom_message_vip"]) {
|
|||
|
|
return [THGiveVipMessageCellData getCellData:msg];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onNewMessage:)]) {
|
|||
|
|
return [self.chatVC messageController:controller onNewMessage:msg];
|
|||
|
|
}
|
|||
|
|
return nil;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onSelectMessageAvatar:(TUIMessageCell *)cell {
|
|||
|
|
int userID = [UserService userIDFromIMUserID:cell.messageData.identifier].intValue;
|
|||
|
|
if (userID > 0) {
|
|||
|
|
[PYAppService pushViewControllerAnimated:[[ProfileCardViewController alloc] initWithUserID:userID]];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 显示消息数据委托
|
|||
|
|
* 您可以通过该回调实现:根据传入的 data 初始化消息气泡并进行显示
|
|||
|
|
*
|
|||
|
|
* @param controller 委托者,消息控制器
|
|||
|
|
* @param data 需要显示的消息数据
|
|||
|
|
*
|
|||
|
|
* @return 返回需要显示的消息单元。该消息单元的信息与数据,来自于参数中的 data 参数。
|
|||
|
|
*/
|
|||
|
|
- (TUIMessageCell *)messageController:(TUIBaseMessageController *)controller onShowMessageData:(TUIMessageCellData *)cellData {
|
|||
|
|
|
|||
|
|
NSLog(@"cellData===%@",cellData);
|
|||
|
|
|
|||
|
|
if (self.isInActivityRoom) {
|
|||
|
|
cellData.showName = YES;
|
|||
|
|
}
|
|||
|
|
if ([cellData isKindOfClass:THGiveVipMessageCellData.class]) {
|
|||
|
|
THGiveVipMessageCell *giveVipCell = [[THGiveVipMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"THGiveVipMessageCell"];
|
|||
|
|
[giveVipCell fillWithData:cellData];
|
|||
|
|
return giveVipCell;
|
|||
|
|
}
|
|||
|
|
//末班添加
|
|||
|
|
// if ([cellData isKindOfClass:NSClassFromString(@"MyVipCarDatas")]) {
|
|||
|
|
// MyVIPCardCell *myCell = [[MyVIPCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyVIPCardCell"];
|
|||
|
|
// [myCell fillWithData:(MyVIPCardData *)cellData];
|
|||
|
|
// return myCell;
|
|||
|
|
// }
|
|||
|
|
//
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onShowMessageData:)]) {
|
|||
|
|
return [self.chatVC messageController:controller onShowMessageData:cellData];
|
|||
|
|
}
|
|||
|
|
return nil;
|
|||
|
|
}
|
|||
|
|
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
|
|||
|
|
|
|||
|
|
if (msg.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
|
|||
|
|
V2TIMTextElem *textElem = msg.textElem;
|
|||
|
|
NSString *text = textElem.text;
|
|||
|
|
NSLog(@"文本信息 : %@", text);
|
|||
|
|
// 查看 textElem 后面还有没更多 Elem
|
|||
|
|
V2TIMElem *elem = textElem.nextElem;
|
|||
|
|
while (elem != nil) {
|
|||
|
|
// 判断 elem 类型
|
|||
|
|
if ([elem isKindOfClass:[V2TIMCustomElem class]]) {
|
|||
|
|
V2TIMCustomElem *customElem = (V2TIMCustomElem *)elem;
|
|||
|
|
NSData *customData = customElem.data;
|
|||
|
|
NSLog(@"自定义信息 : %@",customData);
|
|||
|
|
}
|
|||
|
|
// 继续查看当前 elem 后面还有没更多 elem
|
|||
|
|
elem = elem.nextElem;
|
|||
|
|
}
|
|||
|
|
// elem 如果为 nil,表示所有 elem 都已经解析完
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ([msg.sender isEqualToString:self.convData.userID]) {
|
|||
|
|
[self markReaded];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)onRecvC2CTextMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info text:(NSString *)text {
|
|||
|
|
if ([info.userID isEqualToString:self.convData.userID]) {
|
|||
|
|
[self markReaded];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)didTapInMessageController:(TUIBaseMessageController *)controller {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(didTapInMessageController:)]) {
|
|||
|
|
[self.chatVC didTapInMessageController:controller];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
- (void)didHideMenuInMessageController:(TUIBaseMessageController *)controller {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(didHideMenuInMessageController:)]) {
|
|||
|
|
[self.chatVC didHideMenuInMessageController:controller];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
- (BOOL)messageController:(TUIBaseMessageController *)controller willShowMenuInCell:(UIView *)view {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:willShowMenuInCell:)]) {
|
|||
|
|
return [self.chatVC messageController:controller willShowMenuInCell:view];
|
|||
|
|
}
|
|||
|
|
return NO;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller willDisplayCell:(TUIMessageCell *)cell withData:(TUIMessageCellData *)cellData {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:willDisplayCell:withData:)]) {
|
|||
|
|
[self.chatVC messageController:controller willDisplayCell:cell withData:cellData];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onSelectMessageContent:(TUIMessageCell *)cell {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onSelectMessageContent:)]) {
|
|||
|
|
[self.chatVC messageController:controller onSelectMessageContent:cell];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onSelectMessageMenu:(NSInteger)menuType withData:(TUIMessageCellData *)data {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onSelectMessageMenu:withData:)]) {
|
|||
|
|
[self.chatVC messageController:controller onSelectMessageMenu:menuType withData:data];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onRelyMessage:(TUIMessageCellData *)data {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onRelyMessage:)]) {
|
|||
|
|
[self.chatVC messageController:controller onRelyMessage:data];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onReferenceMessage:(TUIMessageCellData *)data {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onReferenceMessage:)]) {
|
|||
|
|
[self.chatVC messageController:controller onReferenceMessage:data];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller modifyMessage:(nonnull TUIMessageCellData *)cellData reactEmoji:(NSString *)emojiName {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:modifyMessage:reactEmoji:)]) {
|
|||
|
|
[self.chatVC messageController:controller modifyMessage:cellData reactEmoji:emojiName];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)messageController:(TUIBaseMessageController *)controller onReEditMessage:(TUIMessageCellData *)data {
|
|||
|
|
if ([self.chatVC respondsToSelector:@selector(messageController:onReEditMessage:)]) {
|
|||
|
|
[self.chatVC messageController:controller onReEditMessage:data];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - V2TIMSimpleMsgListener
|
|||
|
|
- (void)onRecvC2CCustomMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info customData:(NSData *)data {
|
|||
|
|
|
|||
|
|
NSString *notifyMsg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|||
|
|
if ([notifyMsg isEqual:@"follow_relation_refresh"]) {
|
|||
|
|
//废弃
|
|||
|
|
//之前互关后,才可以发图片语音,交给服务器处理即可,此处不再需要处理
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@end
|