cdts/xdts-ios 3/TreeHole/Code/Features/Chat/ViewController/C2CChatSetttingsViewController.m
2023-07-27 09:20:00 +08:00

139 lines
5.0 KiB
Objective-C

//
// C2CChatSetttingsViewController.m
// Youth
//
// Created by mambaxie on 2022/1/3.
//
#import "C2CChatSetttingsViewController.h"
#import <TUIChatConversationModel.h>
#import <TUIGroupInfoDataProvider.h>
#import "ReportViewController.h"
@interface C2CChatSetttingsViewController ()
//@property (nonatomic, strong) User *user;
@property (nonatomic) TUIChatConversationModel *conversationData;
@property (nonatomic, strong) V2TIMConversation *conversation;
@property (nonatomic, assign) BOOL isBlack;
@end
@implementation C2CChatSetttingsViewController
- (instancetype)initWithConversationData:(TUIChatConversationModel *)conversationData {
if (self = [super init]) {
_conversationData = conversationData;
}
return self;
}
- (BOOL)mt_nagationBarTransparent {
return NO;
}
- (int)userID {
return [UserService userIDFromIMUserID:self.conversationData.userID].intValue;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self startLoading];
int shouldHandleCount = 2;
__block int handledCount = 0;
void (^handleRsp)(void) = ^{
handledCount++;
if (handledCount >= shouldHandleCount) {
[self endLoading:nil];
[self reloadData];
}
};
// [UserService getUserInfoWithUserID:[self userID] completion:^(User * _Nonnull user) {
// if (user) {
// self.user = user;
// }
// handleRsp();
// }];
[[V2TIMManager sharedInstance] getConversation:self.conversationData.conversationID succ:^(V2TIMConversation *conv) {
self.conversation = conv;
handleRsp();
} fail:^(int code, NSString *desc) {
handleRsp();
}];
[UserService getUserBlackWithUserID:[self userID] completion:^(BOOL isBlack) {
self.isBlack = isBlack;
handleRsp();
}];
UILabel *reportLabel = [[UILabel alloc] init];
reportLabel.width = SCREEN_WIDTH;
reportLabel.height = FIX_SIZE(80);
reportLabel.textColor = THEME_COLOR;
reportLabel.textAlignment = NSTextAlignmentCenter;
[reportLabel addTapWithAction:^{
ReportViewController *vc = [[ReportViewController alloc] init];
User *user = [[User alloc] init];
user.ID = [self userID];
vc.user = user;
[PYAppService pushViewControllerAnimated:vc];
}];
reportLabel.text = @"举报";
reportLabel.font = MT_FONT_REGULAR_SIZE(13);
reportLabel.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = reportLabel;
}
- (MTCommonListTableConfig *)tableConfigForTableViewContorller
{
MTCommonListTableConfig *config = [MTCommonListTableConfig defaultConfigWithCellStyle:MTCommonListTableCellStyleSwitch rowsCountForSections:@[@(3)]];
config.cellTitles = @[@"置顶聊天", @"消息免打扰", @"拉黑此人"];
config.cellTitleFont = MT_FONT_MEDIUM_SIZE(13);
config.cellTitleColor = TITLE_COLOR;
config.tableTitle = @"聊天详情";
WeakSelf(self);
[config resetCellConfigForSection:0 row:0 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.style = MTCommonListTableCellStyleSwitch;
[cellConfig.switchButton setOn:weakself.conversation.isPinned animated:NO];
cellConfig.switchButtonAction = ^(UISwitch *switchButton, MTCommonListTableViewCell *cell) {
[[V2TIMManager sharedInstance] pinConversation:weakself.conversationData.conversationID isPinned:switchButton.isOn succ:^{
} fail:^(int code, NSString *desc) {
[SVProgressHUD showErrorWithStatus:desc ?: @"未知错误"];
[switchButton setOn:!switchButton.on animated:YES];
}];
};
}];
[config resetCellConfigForSection:0 row:1 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.style = MTCommonListTableCellStyleSwitch;
[cellConfig.switchButton setOn:weakself.conversation.recvOpt == V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE animated:NO];
cellConfig.switchButtonAction = ^(UISwitch *switchButton, MTCommonListTableViewCell *cell) {
[[V2TIMManager sharedInstance] setC2CReceiveMessageOpt:@[weakself.conversation.userID ?: @""] opt:switchButton.isOn ? V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : V2TIM_RECEIVE_MESSAGE succ:nil fail:^(int code, NSString *desc) {
[SVProgressHUD showErrorWithStatus:desc ?: @"未知错误"];
[switchButton setOn:!switchButton.on animated:YES];
}];
};
}];
[config resetCellConfigForSection:0 row:2 config:^(MTCommonListTableCellConfig *cellConfig) {
cellConfig.style = MTCommonListTableCellStyleSwitch;
[cellConfig.switchButton setOn:weakself.isBlack animated:NO];
cellConfig.switchButtonAction = ^(UISwitch *switchButton, MTCommonListTableViewCell *cell) {
[UserService setUserBlackWithUserID:[weakself userID] isBlack:switchButton.isOn completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
[switchButton setOn:!switchButton.isOn animated:YES];
}
}];
};
}];
return config;
}
@end