WFCUProfileTableViewController.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. //
  2. // WFCUProfileTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/22.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUProfileTableViewController.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUMessageListViewController.h"
  12. #import "MBProgressHUD.h"
  13. #import "WFCUMyPortraitViewController.h"
  14. #import "WFCUVerifyRequestViewController.h"
  15. #import "WFCUGeneralModifyViewController.h"
  16. #import "WFCUVideoViewController.h"
  17. #import "WFCUMultiVideoViewController.h"
  18. #if WFCU_SUPPORT_VOIP
  19. #import <WFAVEngineKit/WFAVEngineKit.h>
  20. #endif
  21. #import "UIFont+YH.h"
  22. #import "UIColor+YH.h"
  23. #import "WFCUConfigManager.h"
  24. #import "WFCUUserMessageListViewController.h"
  25. #import "WFCUImage.h"
  26. #import "WFCUProfileMoreTableViewController.h"
  27. #import "MWPhotoBrowser.h"
  28. #import "WFCUOrganizationViewController.h"
  29. #import "WFCUOrganizationCache.h"
  30. #import "WFCUOrganization.h"
  31. #import "WFCUEmployee.h"
  32. #import "WFCUOrgRelationship.h"
  33. #import "WFCUUtilities.h"
  34. #import "WFCUEmployeeEx.h"
  35. @interface WFCUProfileTableViewController () <UITableViewDelegate, UITableViewDataSource, MWPhotoBrowserDelegate>
  36. @property (strong, nonatomic)UIImageView *portraitView;
  37. @property (strong, nonatomic)UILabel *aliasLabel;
  38. @property (strong, nonatomic)UILabel *displayNameLabel;
  39. @property (strong, nonatomic)UILabel *userNameLabel;
  40. @property (strong, nonatomic)UILabel *domainLabel;
  41. @property (strong, nonatomic)UILabel *starLabel;
  42. @property (strong, nonatomic)UITableViewCell *headerCell;
  43. @property (strong, nonatomic)UITableViewCell *sendMessageCell;
  44. @property (strong, nonatomic)UITableViewCell *voipCallCell;
  45. @property (strong, nonatomic)UITableViewCell *addFriendCell;
  46. @property (strong, nonatomic)UITableViewCell *momentCell;
  47. @property (strong, nonatomic)UITableViewCell *moreCell;
  48. @property (nonatomic, strong)UITableViewCell *userMessagesCell;
  49. @property (nonatomic, strong)UITableViewCell *groupSourceCell;
  50. @property (nonatomic, strong)UITableView *tableView;
  51. @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *cells;
  52. @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *headerCells;
  53. @property (nonatomic, strong)WFCCUserInfo *userInfo;
  54. @property(nonatomic, strong)NSArray<NSNumber *> *organizationIds;
  55. @property(nonatomic, assign)WFCCGroupMemberSourceType groupSourceType;
  56. @property (nonatomic, strong)NSString *groupSourceTargetId;
  57. @end
  58. @implementation WFCUProfileTableViewController
  59. - (void)viewDidLoad {
  60. [super viewDidLoad];
  61. self.title = WFCString(@"UserInfomation");
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:nil];
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEmployeeExUpdated:) name:kEmployeeExUpdated object:nil];
  64. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrganizationUpdated:) name:kOrganizationUpdated object:nil];
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFriendListUpdated:) name:kFriendListUpdated object:nil];
  66. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.userId refresh:YES];
  67. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  68. [self.view addSubview:self.tableView];
  69. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  70. self.tableView.delegate = self;
  71. self.tableView.dataSource = self;
  72. if (@available(iOS 15, *)) {
  73. self.tableView.sectionHeaderTopPadding = 0;
  74. }
  75. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"..." style:UIBarButtonItemStyleDone target:self action:@selector(onRightBtn:)];
  76. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];
  77. [self loadOrganizationData:YES];
  78. [self loadData];
  79. }
  80. - (void)loadOrganizationData:(BOOL)refresh {
  81. WFCUEmployeeEx *employeeEx = [[WFCUOrganizationCache sharedCache] getEmployeeEx:self.userId refresh:refresh];
  82. if(employeeEx.relationships.count) {
  83. NSMutableArray<NSNumber *> *arr = [[NSMutableArray alloc] init];
  84. [employeeEx.relationships enumerateObjectsUsingBlock:^(WFCUOrgRelationship * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  85. if(obj.bottom) {
  86. [arr addObject:@(obj.organizationId)];
  87. }
  88. }];
  89. self.organizationIds = [arr mutableCopy];
  90. }
  91. }
  92. - (void)onFriendListUpdated:(NSNotification *)notification {
  93. [self loadData];
  94. }
  95. - (void)onUserInfoUpdated:(NSNotification *)notification {
  96. NSArray<WFCCUserInfo *> *userInfoList = notification.userInfo[@"userInfoList"];
  97. for (WFCCUserInfo *userInfo in userInfoList) {
  98. if ([self.userId isEqualToString:userInfo.userId]) {
  99. self.userInfo = userInfo;
  100. [self loadData];
  101. break;
  102. }
  103. }
  104. }
  105. - (void)onEmployeeExUpdated:(NSNotification *)notification {
  106. NSString *employeeId = notification.object;
  107. if([employeeId isEqualToString:self.userId]) {
  108. [self loadOrganizationData:NO];
  109. [self.tableView reloadData];
  110. }
  111. }
  112. - (void)onOrganizationUpdated:(NSNotification *)notification {
  113. [self.tableView reloadData];
  114. }
  115. - (void)viewWillAppear:(BOOL)animated {
  116. [super viewWillAppear:animated];
  117. UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
  118. keyWindow.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
  119. [keyWindow tintColorDidChange];
  120. }
  121. - (void)viewWillDisappear:(BOOL)animated {
  122. [super viewWillDisappear:animated];
  123. }
  124. - (void)onRightBtn:(id)sender {
  125. __weak typeof(self)ws = self;
  126. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  127. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  128. }];
  129. [actionSheet addAction:actionCancel];
  130. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  131. UIAlertAction *deleteFriendAction = [UIAlertAction actionWithTitle:WFCString(@"DeleteFriend") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  132. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  133. hud.label.text = WFCString(@"Processing");
  134. [hud showAnimated:YES];
  135. [[WFCCIMService sharedWFCIMService] deleteFriend:ws.userId success:^{
  136. dispatch_async(dispatch_get_main_queue(), ^{
  137. [hud hideAnimated:YES];
  138. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  139. hud.mode = MBProgressHUDModeText;
  140. hud.label.text = WFCString(@"ProcessDone");
  141. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  142. [hud hideAnimated:YES afterDelay:1.f];
  143. });
  144. } error:^(int error_code) {
  145. dispatch_async(dispatch_get_main_queue(), ^{
  146. [hud hideAnimated:YES];
  147. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  148. hud.mode = MBProgressHUDModeText;
  149. hud.label.text = WFCString(@"ProcessFailure");
  150. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  151. [hud hideAnimated:YES afterDelay:1.f];
  152. });
  153. }];
  154. }];
  155. [actionSheet addAction:deleteFriendAction];
  156. } else {
  157. UIAlertAction *addFriendAction = [UIAlertAction actionWithTitle:WFCString(@"AddFriend") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  158. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  159. vc.userId = ws.userId;
  160. vc.sourceType = ws.sourceType;
  161. vc.sourceTargetId = ws.sourceTargetId;
  162. [ws.navigationController pushViewController:vc animated:YES];
  163. }];
  164. [actionSheet addAction:addFriendAction];
  165. }
  166. if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
  167. UIAlertAction *addFriendAction = [UIAlertAction actionWithTitle:WFCString(@"RemoveFromBlacklist") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  168. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  169. hud.label.text = WFCString(@"Processing");
  170. [hud showAnimated:YES];
  171. [[WFCCIMService sharedWFCIMService] setBlackList:ws.userId isBlackListed:NO success:^{
  172. [hud hideAnimated:YES];
  173. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  174. hud.mode = MBProgressHUDModeText;
  175. hud.label.text = WFCString(@"ProcessDone");
  176. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  177. [hud hideAnimated:YES afterDelay:1.f];
  178. } error:^(int error_code) {
  179. [hud hideAnimated:YES];
  180. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  181. hud.mode = MBProgressHUDModeText;
  182. hud.label.text = WFCString(@"ProcessFailure");
  183. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  184. [hud hideAnimated:YES afterDelay:1.f];
  185. }];
  186. }];
  187. [actionSheet addAction:addFriendAction];
  188. } else if (self.userInfo.type == 0) { //Only normal user can add to blacklist, robot user not allowed.
  189. UIAlertAction *addFriendAction = [UIAlertAction actionWithTitle:WFCString(@"Add2Blacklist") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  190. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  191. hud.label.text = WFCString(@"Processing");
  192. [hud showAnimated:YES];
  193. [[WFCCIMService sharedWFCIMService] setBlackList:ws.userId isBlackListed:YES success:^{
  194. [hud hideAnimated:YES];
  195. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  196. hud.mode = MBProgressHUDModeText;
  197. hud.label.text = WFCString(@"ProcessDone");
  198. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  199. [hud hideAnimated:YES afterDelay:1.f];
  200. } error:^(int error_code) {
  201. [hud hideAnimated:YES];
  202. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  203. hud.mode = MBProgressHUDModeText;
  204. hud.label.text = WFCString(@"ProcessFailure");
  205. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  206. [hud hideAnimated:YES afterDelay:1.f];
  207. }];
  208. }];
  209. [actionSheet addAction:addFriendAction];
  210. }
  211. UIAlertAction *aliasAction = [UIAlertAction actionWithTitle:WFCString(@"SetAlias") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  212. [ws setFriendNote];
  213. }];
  214. [actionSheet addAction:aliasAction];
  215. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  216. if ([[WFCCIMService sharedWFCIMService] isFavUser:self.userId]) {
  217. UIAlertAction *cancelStarAction = [UIAlertAction actionWithTitle:WFCString(@"Unstar") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  218. [ws setFavUser];
  219. }];
  220. [actionSheet addAction:cancelStarAction];
  221. } else {
  222. UIAlertAction *setStarAction = [UIAlertAction actionWithTitle:WFCString(@"Star") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  223. [ws setFavUser];
  224. }];
  225. [actionSheet addAction:setStarAction];
  226. }
  227. }
  228. [self presentViewController:actionSheet animated:YES completion:nil];
  229. }
  230. - (void)loadData {
  231. self.cells = [[NSMutableArray alloc] init];
  232. self.sendMessageCell = nil;
  233. self.voipCallCell = nil;
  234. self.addFriendCell = nil;
  235. self.momentCell = nil;
  236. self.moreCell = nil;
  237. self.userMessagesCell = nil;
  238. self.headerCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  239. for (UIView *subView in self.headerCell.contentView.subviews) {
  240. [subView removeFromSuperview];
  241. }
  242. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  243. self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 14, 58, 58)];
  244. self.portraitView.layer.cornerRadius = 10;
  245. self.portraitView.layer.masksToBounds = YES;
  246. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewPortrait:)];
  247. [self.portraitView addGestureRecognizer:tap];
  248. self.portraitView.userInteractionEnabled = YES;
  249. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[self.userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
  250. NSString *alias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
  251. CGFloat startPos = 8;
  252. if (alias.length) {
  253. self.aliasLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 8, width - 64 - 8, 21)];
  254. self.aliasLabel.text = alias;
  255. startPos += 24;
  256. }
  257. self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, startPos, width - 94 - 8, 21)];
  258. self.displayNameLabel.text = self.userInfo.displayName;
  259. startPos += 24;
  260. self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, startPos, width - 94 - 8, 11)];
  261. self.userNameLabel.text = [NSString stringWithFormat:@"野火号:%@", self.userInfo.name];
  262. self.userNameLabel.font = [UIFont systemFontOfSize:12];
  263. self.userNameLabel.textColor = [UIColor grayColor];
  264. startPos += 16;
  265. if([WFCCUtilities isExternalTarget:self.userId]) {
  266. NSString *domainId = [WFCCUtilities getExternalDomain:self.userId];
  267. self.domainLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, startPos, width - 94 - 8, 11)];
  268. self.domainLabel.attributedText = [WFCCUtilities getExternal:domainId withName:nil withColor:[WFCUConfigManager globalManager].externalNameColor];
  269. self.domainLabel.font = [UIFont systemFontOfSize:12];
  270. startPos += 16;
  271. }
  272. if ([[WFCCIMService sharedWFCIMService] isFavUser:self.userId]) {
  273. self.starLabel = [[UILabel alloc] initWithFrame:CGRectMake(width - 16 - 20, self.displayNameLabel.frame.origin.y, 20, 20)];
  274. self.starLabel.text = @"☆";
  275. self.starLabel.font = [UIFont systemFontOfSize:18];
  276. self.starLabel.textColor = [UIColor yellowColor];
  277. [self.headerCell.contentView addSubview:self.starLabel];
  278. }
  279. [self.headerCell.contentView addSubview:self.portraitView];
  280. [self.headerCell.contentView addSubview:self.displayNameLabel];
  281. [self.headerCell.contentView addSubview:self.userNameLabel];
  282. if(self.aliasLabel) {
  283. [self.headerCell.contentView addSubview:self.aliasLabel];
  284. }
  285. if(self.domainLabel) {
  286. [self.headerCell.contentView addSubview:self.domainLabel];
  287. }
  288. self.headerCells = [NSMutableArray new];
  289. [self.headerCells addObject:self.headerCell];
  290. if (self.userInfo.type == 1) {
  291. [self setupSendMessageCell:width];
  292. } else {
  293. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  294. UITableViewCell *alisaCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"setAlisa"];
  295. alisaCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  296. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16 - 60, 50)];
  297. [btn setTitle:WFCString(@"ModifyNickname") forState:UIControlStateNormal];
  298. [btn setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
  299. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  300. [btn addTarget:self action:@selector(setFriendNote) forControlEvents:UIControlEventTouchUpInside];
  301. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  302. [alisaCell.contentView addSubview:btn];
  303. [self showSeparatorLine:alisaCell];
  304. [self.headerCells addObject:alisaCell];
  305. }
  306. if (self.fromConversation.type == Group_Type) {
  307. WFCCGroupMember * groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.fromConversation.target memberId:self.userId];
  308. NSMutableString *targetId = [[NSMutableString alloc] init];
  309. self.groupSourceType = [WFCCUtilities getGroupMemberSourceType:groupMember.extra sourceTargetId:targetId];
  310. if(self.groupSourceType > 0) {
  311. if(targetId.length) {
  312. self.sourceTargetId = [targetId copy];
  313. }
  314. if(self.groupSourceType == GroupMemberSource_Invite) {
  315. if([self.userId isEqualToString:self.sourceTargetId]) {
  316. //可能是当前用户创建的群组,忽略。
  317. NSLog(@"Maybe the creator of the group!");
  318. } else {
  319. if(self.sourceTargetId.length) {
  320. self.groupSourceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  321. self.groupSourceCell.textLabel.text = @"进群方式";
  322. self.groupSourceCell.detailTextLabel.text = [NSString stringWithFormat:@"%@ 邀请入群", [WFCCUtilities getUserDisplayName:self.sourceTargetId inGroup:self.fromConversation.target]];
  323. [self.cells addObject:self.groupSourceCell];
  324. }
  325. }
  326. } else if(self.groupSourceType == GroupMemberSource_QrCode) {
  327. if(self.sourceTargetId.length) {
  328. self.groupSourceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  329. self.groupSourceCell.textLabel.text = @"进群方式";
  330. self.groupSourceCell.detailTextLabel.text = [NSString stringWithFormat:@"扫描 %@ 分享的二维码入群", [WFCCUtilities getUserDisplayName:self.sourceTargetId inGroup:self.fromConversation.target]];
  331. [self.cells addObject:self.groupSourceCell];
  332. }
  333. } else if(self.groupSourceType == GroupMemberSource_Card) {
  334. if(self.sourceTargetId.length) {
  335. self.groupSourceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  336. self.groupSourceCell.textLabel.text = @"进群方式";
  337. self.groupSourceCell.detailTextLabel.text = [NSString stringWithFormat:@"通过 %@ 分享的名片入群", [WFCCUtilities getUserDisplayName:self.sourceTargetId inGroup:self.fromConversation.target]];
  338. [self.cells addObject:self.groupSourceCell];
  339. }
  340. } else if(self.groupSourceType == GroupMemberSource_Search) {
  341. self.groupSourceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  342. self.groupSourceCell.textLabel.text = @"进群方式";
  343. self.groupSourceCell.detailTextLabel.text = @"通过搜索入群";
  344. [self.cells addObject:self.groupSourceCell];
  345. }
  346. }
  347. self.userMessagesCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  348. self.userMessagesCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  349. if([self.userId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  350. self.userMessagesCell.textLabel.text = WFCString(@"MyMessages");
  351. } else {
  352. self.userMessagesCell.textLabel.text = WFCString(@"He`sMessages");
  353. }
  354. [self.cells addObject:self.userMessagesCell];
  355. }
  356. if (self.userInfo.type == 0) {
  357. if(NSClassFromString(@"SDTimeLineTableViewController")) {
  358. self.momentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"momentCell"];
  359. for (UIView *subView in self.momentCell.subviews) {
  360. [subView removeFromSuperview];
  361. }
  362. UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 100, 70)];
  363. [momentButton setTitle: @"朋友圈" forState:UIControlStateNormal];
  364. [momentButton setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
  365. momentButton.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  366. momentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  367. [momentButton addTarget:self action:@selector(momentClick) forControlEvents:UIControlEventTouchUpInside];
  368. if (@available(iOS 14, *)) {
  369. [self.momentCell.contentView addSubview:momentButton];
  370. } else {
  371. [self.momentCell addSubview:momentButton];
  372. }
  373. self.momentCell.selectionStyle = UITableViewCellSelectionStyleNone;
  374. self.momentCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  375. }
  376. }
  377. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  378. [self setupSendMessageCell:width];
  379. [self showSeparatorLine:self.sendMessageCell];
  380. #if WFCU_SUPPORT_VOIP
  381. self.voipCallCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  382. for (UIView *subView in self.voipCallCell.subviews) {
  383. [subView removeFromSuperview];
  384. }
  385. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  386. [btn setImage:[WFCUImage imageNamed:@"video"] forState:UIControlStateNormal];
  387. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  388. [btn setTitle:WFCString(@"VOIPCall") forState:UIControlStateNormal];
  389. [btn addTarget:self action:@selector(onVoipCallBtn:) forControlEvents:UIControlEventTouchDown];
  390. [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
  391. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  392. if (@available(iOS 14, *)) {
  393. [self.voipCallCell.contentView addSubview:btn];
  394. } else {
  395. [self.voipCallCell addSubview:btn];
  396. }
  397. #endif
  398. } else if([[WFCCNetworkService sharedInstance].userId isEqualToString:self.userId]) {
  399. } else {
  400. self.addFriendCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  401. for (UIView *subView in self.addFriendCell.subviews) {
  402. [subView removeFromSuperview];
  403. }
  404. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  405. [btn setTitle:WFCString(@"AddFriend") forState:UIControlStateNormal];
  406. [btn setBackgroundColor:[UIColor greenColor]];
  407. [btn addTarget:self action:@selector(onAddFriendBtn:) forControlEvents:UIControlEventTouchDown];
  408. btn.layer.cornerRadius = 5.f;
  409. btn.layer.masksToBounds = YES;
  410. if (@available(iOS 14, *)) {
  411. [self.addFriendCell.contentView addSubview:btn];
  412. } else {
  413. [self.addFriendCell addSubview:btn];
  414. }
  415. if(self.fromConversation.type == Group_Type) {
  416. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.fromConversation.target refresh:NO];
  417. if(!groupInfo.privateChat) {
  418. [self setupSendMessageCell:width];
  419. }
  420. }
  421. }
  422. }
  423. [self.tableView reloadData];
  424. }
  425. - (void)setupSendMessageCell:(CGFloat)width {
  426. self.sendMessageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  427. for (UIView *subView in self.sendMessageCell.subviews) {
  428. [subView removeFromSuperview];
  429. }
  430. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  431. [btn setImage:[WFCUImage imageNamed:@"message"] forState:UIControlStateNormal];
  432. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  433. [btn setTitle:WFCString(@"SendMessage") forState:UIControlStateNormal];
  434. [btn setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
  435. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  436. [btn addTarget:self action:@selector(onSendMessageBtn:) forControlEvents:UIControlEventTouchDown];
  437. if (@available(iOS 14, *)) {
  438. [self.sendMessageCell.contentView addSubview:btn];
  439. } else {
  440. [self.sendMessageCell addSubview:btn];
  441. }
  442. }
  443. - (UITableViewCell *)moreCell {
  444. if(!_moreCell) {
  445. _moreCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"more_cell"];
  446. _moreCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  447. _moreCell.textLabel.text = WFCString(@"More");
  448. }
  449. return _moreCell;
  450. }
  451. - (UIEdgeInsets)hiddenSeparatorLine:(UITableViewCell *)cell {
  452. return cell.separatorInset = UIEdgeInsetsMake(self.view.frame.size.width, 0, 0, 0);
  453. }
  454. - (void)showSeparatorLine:(UITableViewCell *)cell {
  455. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  456. }
  457. - (void)onViewPortrait:(id)sender {
  458. MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  459. browser.displayActionButton = YES;
  460. browser.displayNavArrows = NO;
  461. browser.displaySelectionButtons = NO;
  462. browser.alwaysShowControls = NO;
  463. browser.zoomPhotosToFill = YES;
  464. browser.enableGrid = NO;
  465. browser.startOnGrid = NO;
  466. browser.enableSwipeToDismiss = NO;
  467. browser.autoPlayOnAppear = NO;
  468. [browser setCurrentPhotoIndex:0];
  469. [self.navigationController pushViewController:browser animated:YES];
  470. }
  471. - (void)momentClick {
  472. Class cls = NSClassFromString(@"SDTimeLineTableViewController");
  473. UIViewController *vc = [[cls alloc] init];
  474. [vc performSelector:@selector(setUserId:) withObject:self.userId];
  475. [self.navigationController pushViewController:vc animated:YES];
  476. }
  477. - (void)onSendMessageBtn:(id)sender {
  478. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  479. mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:self.userId line:0];
  480. for (UIViewController *vc in self.navigationController.viewControllers) {
  481. if ([vc isKindOfClass:[WFCUMessageListViewController class]]) {
  482. WFCUMessageListViewController *old = (WFCUMessageListViewController*)vc;
  483. if (old.conversation.type == Single_Type && [old.conversation.target isEqualToString:self.userId]) {
  484. [self.navigationController popToViewController:vc animated:YES];
  485. return;
  486. }
  487. }
  488. }
  489. UINavigationController *nav = self.navigationController;
  490. [self.navigationController popToRootViewControllerAnimated:NO];
  491. mvc.hidesBottomBarWhenPushed = YES;
  492. [nav pushViewController:mvc animated:YES];
  493. }
  494. - (void)onVoipCallBtn:(id)sender {
  495. #if WFCU_SUPPORT_VOIP
  496. __weak typeof(self)ws = self;
  497. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  498. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  499. }];
  500. UIAlertAction *actionVoice = [UIAlertAction actionWithTitle:WFCString(@"VoiceCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  501. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  502. [self startCall:@[ws.userInfo.userId] isMulti:NO conversation:conversation audioOnly:YES];
  503. }];
  504. UIAlertAction *actionVideo = [UIAlertAction actionWithTitle:WFCString(@"VideoCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  505. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  506. [self startCall:@[ws.userInfo.userId] isMulti:NO conversation:conversation audioOnly:NO];
  507. }];
  508. //把action添加到actionSheet里
  509. [actionSheet addAction:actionVoice];
  510. [actionSheet addAction:actionVideo];
  511. [actionSheet addAction:actionCancel];
  512. //相当于之前的[actionSheet show];
  513. [self presentViewController:actionSheet animated:YES completion:nil];
  514. #endif
  515. }
  516. #if WFCU_SUPPORT_VOIP
  517. - (void)startCall:(NSArray<NSString *> *)targetIds isMulti:(BOOL)isMulti conversation:(WFCCConversation *)conversation audioOnly:(BOOL)isAudioOnly {
  518. [WFCUUtilities checkRecordOrCameraPermission:YES complete:^(BOOL granted) {
  519. if(granted) {
  520. if(isAudioOnly) {
  521. UIViewController *videoVC;
  522. if(isMulti) {
  523. videoVC = [[WFCUMultiVideoViewController alloc] initWithTargets:targetIds conversation:conversation audioOnly:isAudioOnly];
  524. } else {
  525. videoVC = [[WFCUVideoViewController alloc] initWithTargets:targetIds conversation:conversation audioOnly:isAudioOnly];
  526. }
  527. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  528. } else {
  529. [WFCUUtilities checkRecordOrCameraPermission:NO complete:^(BOOL granted) {
  530. if(granted) {
  531. UIViewController *videoVC;
  532. if(isMulti) {
  533. videoVC = [[WFCUMultiVideoViewController alloc] initWithTargets:targetIds conversation:conversation audioOnly:isAudioOnly];
  534. } else {
  535. videoVC = [[WFCUVideoViewController alloc] initWithTargets:targetIds conversation:conversation audioOnly:isAudioOnly];
  536. }
  537. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  538. }
  539. } viewController:self];
  540. }
  541. }
  542. } viewController:self];
  543. }
  544. #endif
  545. - (void)onAddFriendBtn:(id)sender {
  546. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  547. vc.userId = self.userId;
  548. vc.sourceType = self.sourceType;
  549. vc.sourceTargetId = self.sourceTargetId;
  550. [self.navigationController pushViewController:vc animated:YES];
  551. }
  552. - (void)didReceiveMemoryWarning {
  553. [super didReceiveMemoryWarning];
  554. // Dispose of any resources that can be recreated.
  555. }
  556. #pragma mark - UITableViewDataSource<NSObject>
  557. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  558. if (section == 0) {
  559. return self.headerCells.count;
  560. } else if (section == 1) {
  561. int count = 1;//more
  562. if (self.momentCell) {
  563. count++;
  564. }
  565. count+= self.organizationIds.count;
  566. return count;
  567. } else if(section == 2) {
  568. return self.cells.count;
  569. } else {
  570. if (self.sendMessageCell) {
  571. int i = 1;
  572. if (self.voipCallCell) {
  573. i++;
  574. }
  575. if(self.addFriendCell) {
  576. i++;
  577. }
  578. return i;
  579. } else {
  580. return 1;
  581. }
  582. }
  583. }
  584. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  585. NSLog(@"section:%ld",(long)indexPath.section);
  586. if (indexPath.section == 0) {
  587. return self.headerCells[indexPath.row];
  588. } else if (indexPath.section == 1) {
  589. if(self.momentCell && indexPath.row == 0) {
  590. return self.momentCell;
  591. }
  592. int index = indexPath.row;
  593. if(self.momentCell)
  594. index--;
  595. if(index < self.organizationIds.count) {
  596. NSInteger orgId = [self.organizationIds[index] integerValue];
  597. WFCUOrganization *org = [[WFCUOrganizationCache sharedCache] getOrganization:orgId refresh:NO];
  598. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"org_cell"];
  599. if(!cell) {
  600. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"org_cell"];
  601. }
  602. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  603. cell.textLabel.text = @"部门";
  604. cell.detailTextLabel.text = org.name;
  605. return cell;
  606. } else {
  607. return self.moreCell;
  608. }
  609. } else if (indexPath.section == 2) {
  610. return self.cells[indexPath.row];
  611. } else {
  612. if (self.sendMessageCell) {
  613. if (indexPath.row == 0) {
  614. return self.sendMessageCell;
  615. } else if(indexPath.row == 1) {
  616. if(self.voipCallCell) {
  617. return self.voipCallCell;
  618. }
  619. }
  620. return self.addFriendCell;
  621. } else {
  622. return self.addFriendCell;
  623. }
  624. }
  625. }
  626. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  627. if (self.sendMessageCell || self.voipCallCell || self.addFriendCell) {
  628. return 4;
  629. } else {
  630. if(self.cells.count > 0)
  631. return 3;
  632. return 2;
  633. }
  634. }
  635. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  636. if (section != 0) {
  637. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
  638. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  639. return view;
  640. } else {
  641. return nil;
  642. }
  643. }
  644. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  645. if (section == 0) {
  646. return 0;
  647. } else {
  648. return 10;
  649. }
  650. }
  651. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  652. return @" ";
  653. }
  654. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  655. if([tableView cellForRowAtIndexPath:indexPath] == self.userMessagesCell) {
  656. WFCUUserMessageListViewController *vc = [[WFCUUserMessageListViewController alloc] init];
  657. vc.userId = self.userId;
  658. vc.conversation = self.fromConversation;
  659. [self.navigationController pushViewController:vc animated:YES];
  660. } else if([tableView cellForRowAtIndexPath:indexPath] == self.moreCell) {
  661. WFCUProfileMoreTableViewController *moreVC = [[WFCUProfileMoreTableViewController alloc] init];
  662. moreVC.userId = self.userId;
  663. [[WFCCIMService sharedWFCIMService] getCommonGroups:self.userId success:^(NSArray<NSString *> *groupIds) {
  664. moreVC.commonGroupIds = groupIds;
  665. } error:^(int error_code) {
  666. }];
  667. [self.navigationController pushViewController:moreVC animated:YES];
  668. } else if(indexPath.section == 1) {
  669. if(self.momentCell && indexPath.row == 0) {
  670. //click momentCell
  671. }
  672. int index = (int)indexPath.row;
  673. if(self.momentCell)
  674. index--;
  675. if(index < self.organizationIds.count) {
  676. NSInteger orgId = [self.organizationIds[index] integerValue];
  677. NSArray<WFCUOrgRelationship *> *rs = [[WFCUOrganizationCache sharedCache] getRelationship:self.userId refresh:YES];
  678. __block NSInteger index = orgId;
  679. NSMutableArray *ids = [[NSMutableArray alloc] init];
  680. while (index) {
  681. [ids insertObject:@(index) atIndex:0];
  682. [rs enumerateObjectsUsingBlock:^(WFCUOrgRelationship * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  683. if(obj.organizationId == index) {
  684. index = obj.parentOrganizationId;
  685. *stop = YES;
  686. }
  687. }];
  688. }
  689. WFCUOrganizationViewController *orgVC = [[WFCUOrganizationViewController alloc] init];
  690. orgVC.organizationIds = ids;
  691. orgVC.hidesBottomBarWhenPushed = YES;
  692. orgVC.isPushed = YES;
  693. [self.navigationController pushViewController:orgVC animated:YES];
  694. }
  695. }
  696. }
  697. #pragma mark - UITableViewDelegate
  698. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  699. if (indexPath.section == 0) {
  700. if (indexPath.row == 0) {
  701. return 100;
  702. } else {
  703. return 50;
  704. }
  705. } else if(indexPath.section == 1) {
  706. return 50;
  707. } else if(indexPath.section == 2) {
  708. if (self.momentCell) {
  709. return 120;
  710. } else {
  711. return 50;
  712. }
  713. } else {
  714. return 50;
  715. }
  716. }
  717. - (void)setFriendNote {
  718. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  719. NSString *previousAlias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
  720. gmvc.defaultValue = previousAlias;
  721. gmvc.titleText = @"设置备注";
  722. gmvc.canEmpty = YES;
  723. __weak typeof(self)ws = self;
  724. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  725. if (![newValue isEqualToString:previousAlias]) {
  726. [[WFCCIMService sharedWFCIMService] setFriend:self.userId alias:newValue success:^{
  727. result(YES);
  728. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  729. [ws loadData];
  730. });
  731. } error:^(int error_code) {
  732. result(NO);
  733. }];
  734. }
  735. };
  736. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  737. [self.navigationController presentViewController:nav animated:YES completion:nil];
  738. }
  739. - (void)setFavUser {
  740. BOOL isFav = [[WFCCIMService sharedWFCIMService] isFavUser:self.userId];
  741. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  742. hud.label.text = WFCString(@"Processing");
  743. [hud showAnimated:YES];
  744. __weak typeof(self)ws = self;
  745. [[WFCCIMService sharedWFCIMService] setFavUser:self.userId fav:!isFav success:^{
  746. dispatch_async(dispatch_get_main_queue(), ^{
  747. [hud hideAnimated:YES];
  748. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  749. hud.mode = MBProgressHUDModeText;
  750. hud.label.text = WFCString(@"ProcessDone");
  751. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  752. [hud hideAnimated:YES afterDelay:1.f];
  753. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  754. [ws loadData];
  755. });
  756. });
  757. } error:^(int errorCode) {
  758. dispatch_async(dispatch_get_main_queue(), ^{
  759. [hud hideAnimated:YES];
  760. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  761. hud.mode = MBProgressHUDModeText;
  762. hud.label.text = WFCString(@"ProcessFailure");
  763. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  764. [hud hideAnimated:YES afterDelay:1.f];
  765. });
  766. }];
  767. }
  768. #pragma mark - MWPhotoBrowserDelegate
  769. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
  770. return 1;
  771. }
  772. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
  773. MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:self.userInfo.portrait]];
  774. return photo;
  775. }
  776. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index {
  777. return nil;
  778. }
  779. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index {
  780. NSLog(@"Did start viewing photo at index %lu", (unsigned long)index);
  781. }
  782. - (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index {
  783. return NO;
  784. }
  785. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected {
  786. NSLog(@"Photo at index %lu selected %@", (unsigned long)index, selected ? @"YES" : @"NO");
  787. }
  788. - (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser {
  789. // If we subscribe to this method we must dismiss the view controller ourselves
  790. NSLog(@"Did finish modal presentation");
  791. [self dismissViewControllerAnimated:YES completion:nil];
  792. }
  793. - (void)dealloc {
  794. [[NSNotificationCenter defaultCenter] removeObserver:self];
  795. }
  796. @end