WFCPrivacyFindMeViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // WFCPrivacyFindMeViewController.h
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/6.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCPrivacyFindMeViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <WFChatUIKit/WFChatUIKit.h>
  11. @interface WFCPrivacyFindMeViewController () <UITableViewDataSource, UITableViewDelegate>
  12. @property (nonatomic, strong)UITableView *tableView;
  13. @property (nonatomic, strong)NSMutableArray<NSMutableArray<UITableViewCell *> *> *cells;
  14. @end
  15. @implementation WFCPrivacyFindMeViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = [UIColor whiteColor];
  19. [self createCells];
  20. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
  21. if (@available(iOS 15, *)) {
  22. self.tableView.sectionHeaderTopPadding = 0;
  23. }
  24. self.tableView.delegate = self;
  25. self.tableView.dataSource = self;
  26. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  27. [self.tableView reloadData];
  28. [self.view addSubview:self.tableView];
  29. }
  30. - (void)createCells {
  31. self.cells = [[NSMutableArray alloc] init];
  32. NSMutableArray *section2 = [[NSMutableArray alloc] init];
  33. [self.cells addObject:section2];
  34. int searchableValue = [[[WFCCIMService sharedWFCIMService] getUserSetting:UserSettingScope_Privacy_Searchable key:nil] intValue];
  35. __weak typeof(self)ws = self;
  36. WFCUGeneralSwitchTableViewCell *switchCell2 = [[WFCUGeneralSwitchTableViewCell alloc] init];
  37. switchCell2.textLabel.text = @"账号";
  38. if (searchableValue & DisableSearch_Name_Mask) {
  39. switchCell2.on = NO;
  40. } else {
  41. switchCell2.on = YES;
  42. }
  43. [switchCell2 setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  44. int intvalue = [[[WFCCIMService sharedWFCIMService] getUserSetting:UserSettingScope_Privacy_Searchable key:nil] intValue];
  45. if(value) {
  46. intvalue &= (DisableSearch_DisplayName_Mask | DisableSearch_Mobile_Mask | DisableSearch_UserId_Mask);
  47. } else {
  48. intvalue |= DisableSearch_Name_Mask;
  49. }
  50. [[WFCCIMService sharedWFCIMService] setUserSetting:UserSettingScope_Privacy_Searchable key:nil value:[NSString stringWithFormat:@"%d", intvalue] success:^{
  51. result(YES);
  52. } error:^(int error_code) {
  53. [ws.view makeToast:@"网络错误"];
  54. result(NO);
  55. }];
  56. }];
  57. [section2 addObject:switchCell2];
  58. WFCUGeneralSwitchTableViewCell *switchCell3 = [[WFCUGeneralSwitchTableViewCell alloc] init];
  59. switchCell3.textLabel.text = @"电话号码";
  60. if (searchableValue & DisableSearch_Mobile_Mask) {
  61. switchCell3.on = NO;
  62. } else {
  63. switchCell3.on = YES;
  64. }
  65. [switchCell3 setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  66. int intvalue = [[[WFCCIMService sharedWFCIMService] getUserSetting:UserSettingScope_Privacy_Searchable key:nil] intValue];
  67. if(value) {
  68. intvalue &= (DisableSearch_DisplayName_Mask | DisableSearch_Name_Mask | DisableSearch_UserId_Mask);
  69. } else {
  70. intvalue |= DisableSearch_Mobile_Mask;
  71. }
  72. [[WFCCIMService sharedWFCIMService] setUserSetting:UserSettingScope_Privacy_Searchable key:nil value:[NSString stringWithFormat:@"%d", intvalue] success:^{
  73. result(YES);
  74. } error:^(int error_code) {
  75. [ws.view makeToast:@"网络错误"];
  76. result(NO);
  77. }];
  78. }];
  79. [section2 addObject:switchCell3];
  80. //如果需要按照用户id搜索,可以打开下面这段,正常不用打开
  81. // WFCUGeneralSwitchTableViewCell *switchCell4 = [[WFCUGeneralSwitchTableViewCell alloc] init];
  82. // switchCell4.textLabel.text = @"用户ID";
  83. // if (searchableValue & DisableSearch_UserId_Mask) {
  84. // switchCell4.on = NO;
  85. // } else {
  86. // switchCell4.on = YES;
  87. // }
  88. // [switchCell4 setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  89. // int intvalue = [[[WFCCIMService sharedWFCIMService] getUserSetting:UserSettingScope_Privacy_Searchable key:nil] intValue];
  90. // if(value) {
  91. // intvalue &= (DisableSearch_DisplayName_Mask | DisableSearch_Name_Mask | DisableSearch_Mobile_Mask);
  92. // } else {
  93. // intvalue |= DisableSearch_UserId_Mask;
  94. // }
  95. // [[WFCCIMService sharedWFCIMService] setUserSetting:UserSettingScope_Privacy_Searchable key:nil value:[NSString stringWithFormat:@"%d", intvalue] success:^{
  96. // result(YES);
  97. // } error:^(int error_code) {
  98. // [ws.view makeToast:@"网络错误"];
  99. // result(NO);
  100. // }];
  101. // }];
  102. // [section2 addObject:switchCell4];
  103. }
  104. - (void)didReceiveMemoryWarning {
  105. [super didReceiveMemoryWarning];
  106. // Dispose of any resources that can be recreated.
  107. }
  108. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  109. return 48;
  110. }
  111. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  112. return 36;
  113. }
  114. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  115. return @"可以通过以下方法找到我";
  116. }
  117. //#pragma mark - Table view data source
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  119. return self.cells.count;
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  122. return self.cells[section].count;
  123. }
  124. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  125. return self.cells[indexPath.section][indexPath.row];
  126. }
  127. @end