GroupEditController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // GroupEditController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/21.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "GroupEditController.h"
  9. #import "GroupNetApi.h"
  10. #import "GroupListCell.h"
  11. #import "FriendNetApi.h"
  12. #import "GWebSocket.h"
  13. #import "UDManager.h"
  14. #import "config.h"
  15. @interface GroupEditController()<UITableViewDelegate,UITableViewDataSource,GroupListCellDelegate>
  16. @property (weak, nonatomic) IBOutlet UILabel *titleLb;
  17. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  18. @property (strong, nonatomic) NSArray *dataList;
  19. @property (strong, nonatomic) NSArray *groupUserList;
  20. @property (strong,nonatomic) NSString *userId;
  21. @end
  22. @implementation GroupEditController
  23. -(void)viewDidLoad{
  24. [super viewDidLoad];
  25. [self.navigationController setNavigationBarHidden:YES animated:NO];
  26. if(self.editType==1){
  27. _titleLb.text = NSLocalizedString(@"EGroupCtr-rqtitle", @"入群审核");
  28. }
  29. if (self.editType==2) {
  30. _titleLb.text = NSLocalizedString(@"EGroupCtr-qunzhuanr", @"转让群");
  31. }
  32. if (self.editType==3) {
  33. _titleLb.text = NSLocalizedString(@"EGroupCtr-yaoqingrq", @"邀请加入群");
  34. }
  35. if (self.editType==4) {
  36. _titleLb.text = NSLocalizedString(@"EGroupCtr-tichuq", @"踢出群");
  37. }
  38. NSDictionary *userinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  39. NSLog(@"userinfo:%@",userinfo);
  40. _userId = userinfo[@"id"];
  41. [self initFrame];
  42. [self initData];
  43. }
  44. - (IBAction)gotoback:(id)sender {
  45. [self dismissViewControllerAnimated:YES completion:nil];
  46. }
  47. -(void)initFrame{
  48. [_tableView registerClass:[GroupListCell class] forCellReuseIdentifier:@"cellT"];
  49. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  50. _tableView.backgroundColor = [UIColor clearColor];
  51. _tableView.delegate=self;
  52. _tableView.dataSource=self;
  53. }
  54. -(void)initData{
  55. if(self.editType==1){
  56. [self getshenheList];
  57. }
  58. else if(self.editType==2){
  59. [self getGroupUserList];
  60. }
  61. else if(self.editType==3){
  62. [self getGroupUserList];
  63. }
  64. else if(self.editType==4){
  65. [self getGroupUserList];
  66. }
  67. }
  68. #pragma mark 获取待审核入群人员
  69. -(void)getshenheList{
  70. [GroupNetApi getshenheList:self.groupId succ:^(int code, NSDictionary * res) {
  71. NSLog(@"res:%@",res);
  72. self.dataList = res[@"data"];
  73. [self->_tableView reloadData];
  74. } fail:^(NSError * _Nonnull error) {
  75. }];
  76. }
  77. #pragma mark 获取群成员
  78. -(void)getGroupUserList{
  79. [GroupNetApi getGroupUserList:self.groupId succ:^(int code, NSDictionary * res) {
  80. if(self.editType == 3){
  81. self.groupUserList = res[@"data"];
  82. [self getFriendList];
  83. }
  84. else{
  85. self.dataList = res[@"data"];
  86. [self->_tableView reloadData];
  87. }
  88. } fail:^(NSError * _Nonnull error) {
  89. }];
  90. }
  91. #pragma mark 获取所有好友
  92. -(void)getFriendList{
  93. [FriendNetApi getfriends:nil succ:^(int code, NSDictionary * res) {
  94. self.dataList = res[@"data"];
  95. //NSLog(@"self.friendlist:%@",self.friendlist);
  96. if(self.dataList){
  97. [self dowithFriendList];
  98. }
  99. } fail:^(NSError * _Nonnull error) {
  100. }];
  101. }
  102. -(void)dowithFriendList{
  103. NSMutableArray *array = [[NSMutableArray alloc] init];
  104. for (NSDictionary *item in self.dataList) {
  105. NSString *fid = item[@"id"];
  106. BOOL mark=YES;
  107. for (NSDictionary *jtem in self.groupUserList) {
  108. NSString *jid = jtem[@"id"];
  109. if(fid.intValue == jid.intValue){
  110. mark=NO;
  111. break;
  112. }
  113. }
  114. if(mark){
  115. [array addObject:item];
  116. }
  117. }
  118. NSLog(@"self.groupUserList:%@",self.groupUserList);
  119. NSLog(@"self.dataList:%@",self.dataList);
  120. self.dataList = array;
  121. [self.tableView reloadData];
  122. }
  123. #pragma mark UITableViewDelegate
  124. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  125. return 1;
  126. }
  127. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  128. return self.dataList.count;
  129. }
  130. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  131. return 70;
  132. }
  133. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. NSDictionary *data=self.dataList[indexPath.row];
  135. NSLog(@"cellForRowAtIndexPath:%@",data);
  136. if(data){
  137. GroupListCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cellT" forIndexPath:indexPath];
  138. if(cell==nil){
  139. cell=[[GroupListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellT"];
  140. }
  141. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  142. cell.backgroundColor = [UIColor clearColor];
  143. [cell fillWithData:data cellType:self.editType];
  144. cell.delegate = self;
  145. return cell;
  146. }
  147. return nil;
  148. }
  149. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  150. }
  151. -(void)GroupListCellAct:(NSString *)actId act:(NSInteger)state{
  152. NSLog(@"GroupListCellAct:%@,%ld",actId,(long)state);
  153. if(self.editType==1){//入群审核
  154. if(state==1){//同意申请
  155. [self tongyiruqunshenqing:actId];
  156. }
  157. else{//拒绝
  158. [self jujueruqunshenqing:actId];
  159. }
  160. }
  161. if(self.editType==2){//转让
  162. [self zhuanrangqun:actId];
  163. }
  164. if(self.editType==3){//邀请
  165. [self yaoqingruqun:actId];
  166. }
  167. if(self.editType==4){//踢出
  168. [self tichuqun:actId];
  169. }
  170. }
  171. #pragma mark net acttion
  172. //
  173. -(void)tongyiruqunshenqing:(NSString *)userid{
  174. [GroupNetApi Checkagree:userid succ:^(int code, NSDictionary * res) {
  175. //发送通知
  176. NSString *coder = res[@"code"];
  177. if(coder.intValue==200){
  178. [self sendNote];
  179. }
  180. //更新列表
  181. [self initData];
  182. } fail:^(NSError * _Nonnull error) {
  183. }];
  184. }
  185. -(void)jujueruqunshenqing:(NSString *)userid{
  186. [GroupNetApi Checkrefuse:userid succ:^(int code, NSDictionary * res) {
  187. //更新列表
  188. [self initData];
  189. } fail:^(NSError * _Nonnull error) {
  190. }];
  191. }
  192. -(void)zhuanrangqun:(NSString *)userid{
  193. // 创建弹框询问
  194. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  195. message:@"是否转让群?"
  196. preferredStyle:UIAlertControllerStyleAlert];
  197. // 创建取消按钮和确定按钮,并添加到弹框中
  198. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  199. NSLog(@"用户点击了取消");
  200. }];
  201. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  202. NSLog(@"用户点击了确定");
  203. [GroupNetApi transferGroup:self.groupId userId:userid succ:^(int code, NSDictionary * res) {
  204. NSString *coder = res[@"code"];
  205. if(coder.intValue==200){
  206. [self dismissViewControllerAnimated:YES completion:nil];
  207. }
  208. } fail:^(NSError * _Nonnull error) {
  209. }];
  210. }];
  211. [alert addAction:cancelAction];
  212. [alert addAction:okAction];
  213. // 显示弹框
  214. [self presentViewController:alert animated:YES completion:nil];
  215. }
  216. -(void)yaoqingruqun:(NSString *)userid{
  217. NSArray *userlds = @[userid];
  218. //NSString *userlds = [NSString stringWithFormat:@"[%@]",userid];
  219. NSDictionary *dic = @{
  220. @"userIds":userlds,
  221. @"groupId":self.groupId
  222. };
  223. [GroupNetApi addUsertoGroup:dic groupId:nil succ:^(int code, NSDictionary * res) {
  224. NSLog(@"res%@",res);
  225. NSString *coder =res[@"code"];
  226. if(coder.intValue==200){
  227. NSMutableArray *array = [[NSMutableArray alloc] init];
  228. for (NSDictionary *item in self.dataList) {
  229. NSString *fid = item[@"id"];
  230. if(userid.intValue!=fid.intValue){
  231. [array addObject:item];
  232. }
  233. }
  234. self.dataList = array;
  235. [self.tableView reloadData];
  236. }
  237. } fail:^(NSError * _Nonnull error) {
  238. NSLog(@"error:%@",error);
  239. }];
  240. }
  241. -(void)tichuqun:(NSString *)userid{
  242. // 创建弹框询问
  243. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  244. message:@"是否剔除用户出群?"
  245. preferredStyle:UIAlertControllerStyleAlert];
  246. // 创建取消按钮和确定按钮,并添加到弹框中
  247. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  248. NSLog(@"用户点击了取消");
  249. }];
  250. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  251. NSLog(@"用户点击了确定");
  252. [GroupNetApi getoutUserGroup:self.groupId userId:userid succ:^(int code, NSDictionary * res) {
  253. [self initData];
  254. } fail:^(NSError * _Nonnull error) {
  255. }];
  256. }];
  257. [alert addAction:cancelAction];
  258. [alert addAction:okAction];
  259. // 显示弹框
  260. [self presentViewController:alert animated:YES completion:nil];
  261. }
  262. -(void)sendNote{
  263. NSDate *now = [NSDate date];
  264. NSTimeInterval trt = [now timeIntervalSince1970];
  265. NSInteger time = trt*1000;
  266. NSString *strtime = [NSString stringWithFormat:@"%ld",(long)time];
  267. NSString *content = @"有新用户入群";
  268. NSDictionary *callMsg = @{
  269. @"code":SendCode_MESSAGE,
  270. @"message": @{
  271. @"chatId":self.groupId,
  272. @"fromId":self.userId,
  273. @"type":@"1",
  274. @"mine":@"ture",
  275. @"content":content,
  276. @"timestamp":strtime,
  277. @"messageType":MessageType_event
  278. }
  279. };
  280. NSError *error;
  281. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:callMsg options:0 error:&error];
  282. if (!jsonData) {
  283. NSLog(@"Got an error: %@", error);
  284. } else {
  285. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  286. NSLog(@"%@", jsonString); // 输出: {"name":"John","age":25}
  287. [GWebSocket.shareInstance sendMsg:jsonString];
  288. }
  289. }
  290. #pragma mark statusBar
  291. - (UIStatusBarStyle)preferredStatusBarStyle{
  292. return UIStatusBarStyleLightContent;
  293. }
  294. @end