QuncyController.m 10 KB

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