|
|
@@ -22,7 +22,6 @@
|
|
|
@interface FriendRequestViewController ()<FriendRequestAction, UISearchBarDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataArr;
|
|
|
-@property (nonatomic, strong) NSMutableArray *systemArr;
|
|
|
|
|
|
@property (nonatomic, strong) UISearchController *searchController;
|
|
|
@property (nonatomic, strong) NSMutableArray *searchArr;
|
|
|
@@ -35,51 +34,6 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
- _systemArr = [[NSMutableArray alloc] init];
|
|
|
-
|
|
|
- id<NIMSystemNotificationManager> systemNotificationManager = [[NIMSDK sharedSDK] systemNotificationManager];
|
|
|
- NSArray *notifications = [systemNotificationManager fetchSystemNotifications:nil
|
|
|
- limit:20];
|
|
|
-
|
|
|
- NSMutableArray *ids = [[NSMutableArray alloc] init];
|
|
|
- if ([notifications count])
|
|
|
- {
|
|
|
- for(int i=0; i<notifications.count; i++)
|
|
|
- {
|
|
|
- NIMSystemNotification *notification = [notifications objectAtIndex:i];
|
|
|
- if(notification.type == NIMSystemNotificationTypeFriendAdd)
|
|
|
- {
|
|
|
- [self deleteNotification:notification];
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- BOOL found = NO;
|
|
|
- for(int j=0; j<_systemArr.count; j++)
|
|
|
- {
|
|
|
- NIMSystemNotification *existNotification = [_systemArr objectAtIndex:j];
|
|
|
- if(existNotification.type == notification.type &&
|
|
|
- [existNotification.targetID isEqualToString:notification.targetID] &&
|
|
|
- [existNotification.sourceID isEqualToString:notification.sourceID])
|
|
|
- {
|
|
|
- [self deleteNotification:notification];
|
|
|
- found = YES;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!found)
|
|
|
- {
|
|
|
- [_systemArr addObject:notification];
|
|
|
- [ids addObject:notification.sourceID];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [[NIMSDK sharedSDK].userManager fetchUserInfos:ids completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
|
|
|
- [self.tableView reloadData];
|
|
|
- }];
|
|
|
-
|
|
|
-
|
|
|
_searchArr = [[NSMutableArray alloc] init];
|
|
|
|
|
|
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
|
|
|
@@ -129,16 +83,6 @@
|
|
|
[_searchArr addObject:data];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- for(int i=0; i<_systemArr.count; i++)
|
|
|
- {
|
|
|
- NIMSystemNotification *notification = [_systemArr objectAtIndex:i];
|
|
|
- NSString *name = [[User sharedInfo] getUserNameById:notification.sourceID];
|
|
|
- if([[name lowercaseString] containsString:[searchText lowercaseString]])
|
|
|
- {
|
|
|
- [_searchArr addObject:notification];
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -166,7 +110,7 @@
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
if(_searchArr.count)
|
|
|
return _searchArr.count;
|
|
|
- return _dataArr.count + _systemArr.count;
|
|
|
+ return _dataArr.count;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -180,14 +124,7 @@
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(indexPath.row < _dataArr.count)
|
|
|
- {
|
|
|
- [cell setData:[_dataArr objectAtIndex:indexPath.row]];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- [cell setData:[_systemArr objectAtIndex:indexPath.row-_dataArr.count]];
|
|
|
- }
|
|
|
+ [cell setData:[_dataArr objectAtIndex:indexPath.row]];
|
|
|
}
|
|
|
return cell;
|
|
|
}
|
|
|
@@ -198,14 +135,10 @@
|
|
|
|
|
|
- (void)friendRequestAccept:(id)data{
|
|
|
|
|
|
- if([data isKindOfClass:[NIMSystemNotification class]])
|
|
|
- {
|
|
|
- [self onAccept:(NIMSystemNotification *)data];
|
|
|
- }
|
|
|
- else
|
|
|
+ FriendRequestData *friendRequestData = (FriendRequestData *)data;
|
|
|
+ __weak typeof(self) wself = self;
|
|
|
+ if(friendRequestData.type == 0)
|
|
|
{
|
|
|
- FriendRequestData *friendRequestData = (FriendRequestData *)data;
|
|
|
- __weak typeof(self) wself = self;
|
|
|
[[HttpRequest shared] addFriend:friendRequestData.requestId targetId:friendRequestData.userId success:^{
|
|
|
[wself.view makeToast:@"添加成功" duration:2.0 position:CSToastPositionCenter];
|
|
|
[wself removeData:friendRequestData.requestId];
|
|
|
@@ -213,52 +146,62 @@
|
|
|
[wself.view makeToast:@"添加失败" duration:2.0 position:CSToastPositionCenter];
|
|
|
}];
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-- (void)friendRequestDelete:(id)data{
|
|
|
-
|
|
|
- if([data isKindOfClass:[NIMSystemNotification class]])
|
|
|
+ else if(friendRequestData.type == 1)
|
|
|
{
|
|
|
- UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"删除", nil];
|
|
|
-
|
|
|
- __weak typeof(self) wself = self;
|
|
|
- [sheet showInView:self.view completionHandler:^(NSInteger index) {
|
|
|
- switch (index) {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- [wself onRefuse:(NIMSystemNotification *)data];
|
|
|
- break;
|
|
|
+ [SVProgressHUD show];
|
|
|
+ [[NIMSDK sharedSDK].teamManager applyToTeam:friendRequestData.extraId message:@"" completion:^(NSError *error, NIMTeamApplyStatus applyStatus) {
|
|
|
+ [SVProgressHUD dismiss];
|
|
|
+ if (!error) {
|
|
|
+ switch (applyStatus) {
|
|
|
+ case NIMTeamApplyStatusAlreadyInTeam:{
|
|
|
+ [wself.view makeToast:@"加入成功" duration:2.0 position:CSToastPositionCenter];
|
|
|
+ [[HttpRequest shared] deleteFriendRequest:friendRequestData.requestId success:^{
|
|
|
+ [wself removeData:friendRequestData.requestId];
|
|
|
+ } failure:^{
|
|
|
+ [wself.view makeToast:@"删除失败" duration:2.0 position:CSToastPositionCenter];
|
|
|
+ }];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- default:
|
|
|
- break;
|
|
|
}
|
|
|
- }];
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"删除", nil];
|
|
|
- FriendRequestData *friendRequestData = data;
|
|
|
- __weak typeof(self) wself = self;
|
|
|
- [sheet showInView:self.view completionHandler:^(NSInteger index) {
|
|
|
- switch (index) {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- [[HttpRequest shared] deleteFriendRequest:friendRequestData.requestId success:^{
|
|
|
- [wself removeData:friendRequestData.requestId];
|
|
|
- } failure:^{
|
|
|
- [wself.view makeToast:@"删除失败" duration:2.0 position:CSToastPositionCenter];
|
|
|
- }];
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- break;
|
|
|
+ else if(error.code == 809)
|
|
|
+ {
|
|
|
+ [wself.view makeToast:@"已经在群里" duration:2.0 position:CSToastPositionCenter];
|
|
|
+ [[HttpRequest shared] deleteFriendRequest:friendRequestData.requestId success:^{
|
|
|
+ [wself removeData:friendRequestData.requestId];
|
|
|
+ } failure:^{
|
|
|
+ [wself.view makeToast:@"删除失败" duration:2.0 position:CSToastPositionCenter];
|
|
|
+ }];
|
|
|
}
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+- (void)friendRequestDelete:(id)data{
|
|
|
+
|
|
|
+ UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"删除", nil];
|
|
|
+ FriendRequestData *friendRequestData = data;
|
|
|
+ __weak typeof(self) wself = self;
|
|
|
+ [sheet showInView:self.view completionHandler:^(NSInteger index) {
|
|
|
+ switch (index) {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ [[HttpRequest shared] deleteFriendRequest:friendRequestData.requestId success:^{
|
|
|
+ [wself removeData:friendRequestData.requestId];
|
|
|
+ } failure:^{
|
|
|
+ [wself.view makeToast:@"删除失败" duration:2.0 position:CSToastPositionCenter];
|
|
|
+ }];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
- (void)removeData:(NSString *)requestId
|
|
|
{
|
|
|
for(int i=0; i<_dataArr.count; i++)
|
|
|
@@ -277,195 +220,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
-- (void)onAccept:(NIMSystemNotification *)notification
|
|
|
-{
|
|
|
- __weak typeof(self) wself = self;
|
|
|
- switch (notification.type) {
|
|
|
- case NIMSystemNotificationTypeTeamApply:{
|
|
|
- [[NIMSDK sharedSDK].teamManager passApplyToTeam:notification.targetID userId:notification.sourceID completion:^(NSError *error, NIMTeamApplyStatus applyStatus) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"同意成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeOk;
|
|
|
- [wself deleteNotification:notification];
|
|
|
- [wself.tableView reloadData];
|
|
|
- }else {
|
|
|
- if(error.code == NIMRemoteErrorCodeTimeoutError) {
|
|
|
- [wself.navigationController.view makeToast:@"网络问题,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- } else {
|
|
|
- notification.handleStatus = NotificationHandleTypeOutOfDate;
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }
|
|
|
- }];
|
|
|
- break;
|
|
|
- }
|
|
|
- case NIMSystemNotificationTypeTeamInvite:{
|
|
|
- [[NIMSDK sharedSDK].teamManager acceptInviteWithTeam:notification.targetID invitorId:notification.sourceID completion:^(NSError *error) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"接受成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeOk;
|
|
|
- [wself deleteNotification:notification];
|
|
|
- [wself.tableView reloadData];
|
|
|
- }else {
|
|
|
- if(error.code == NIMRemoteErrorCodeTimeoutError) {
|
|
|
- [wself.navigationController.view makeToast:@"网络问题,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- else if (error.code == NIMRemoteErrorCodeTeamNotExists) {
|
|
|
- [wself.navigationController.view makeToast:@"群不存在"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- else {
|
|
|
- notification.handleStatus = NotificationHandleTypeOutOfDate;
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
- break;
|
|
|
- case NIMSystemNotificationTypeFriendAdd:
|
|
|
- {
|
|
|
- NIMUserRequest *request = [[NIMUserRequest alloc] init];
|
|
|
- request.userId = notification.sourceID;
|
|
|
- request.operation = NIMUserOperationVerify;
|
|
|
-
|
|
|
- [[[NIMSDK sharedSDK] userManager] requestFriend:request
|
|
|
- completion:^(NSError *error) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"验证成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeOk;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- [wself.navigationController.view makeToast:@"验证失败,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }];
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-- (void)onRefuse:(NIMSystemNotification *)notification
|
|
|
-{
|
|
|
- __weak typeof(self) wself = self;
|
|
|
- switch (notification.type) {
|
|
|
- case NIMSystemNotificationTypeTeamApply:{
|
|
|
- [[NIMSDK sharedSDK].teamManager rejectApplyToTeam:notification.targetID userId:notification.sourceID rejectReason:@"" completion:^(NSError *error) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"拒绝成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeNo;
|
|
|
- [wself deleteNotification:notification];
|
|
|
- [wself.tableView reloadData];
|
|
|
- }else {
|
|
|
- if(error.code == NIMRemoteErrorCodeTimeoutError) {
|
|
|
- [wself.navigationController.view makeToast:@"网络问题,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- } else {
|
|
|
- notification.handleStatus = NotificationHandleTypeOutOfDate;
|
|
|
- [wself deleteNotification:notification];
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case NIMSystemNotificationTypeTeamInvite:{
|
|
|
- [[NIMSDK sharedSDK].teamManager rejectInviteWithTeam:notification.targetID invitorId:notification.sourceID rejectReason:@"" completion:^(NSError *error) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"拒绝成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeNo;
|
|
|
- [wself deleteNotification:notification];
|
|
|
- [wself.tableView reloadData];
|
|
|
- }else {
|
|
|
- if(error.code == NIMRemoteErrorCodeTimeoutError) {
|
|
|
- [wself.navigationController.view makeToast:@"网络问题,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- else if (error.code == NIMRemoteErrorCodeTeamNotExists) {
|
|
|
- [wself.navigationController.view makeToast:@"群不存在"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- else {
|
|
|
- notification.handleStatus = NotificationHandleTypeOutOfDate;
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }
|
|
|
- }];
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- case NIMSystemNotificationTypeFriendAdd:
|
|
|
- {
|
|
|
- NIMUserRequest *request = [[NIMUserRequest alloc] init];
|
|
|
- request.userId = notification.sourceID;
|
|
|
- request.operation = NIMUserOperationReject;
|
|
|
-
|
|
|
- [[[NIMSDK sharedSDK] userManager] requestFriend:request
|
|
|
- completion:^(NSError *error) {
|
|
|
- if (!error) {
|
|
|
- [wself.navigationController.view makeToast:@"拒绝成功"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- notification.handleStatus = NotificationHandleTypeNo;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- [wself.navigationController.view makeToast:@"拒绝失败,请重试"
|
|
|
- duration:2
|
|
|
- position:CSToastPositionCenter];
|
|
|
- }
|
|
|
- [wself.tableView reloadData];
|
|
|
- DDLogDebug(@"%@",error.localizedDescription);
|
|
|
- }];
|
|
|
- }
|
|
|
- break;
|
|
|
- case NIMSystemNotificationTypeTeamApplyReject:
|
|
|
- case NIMSystemNotificationTypeTeamIviteReject:
|
|
|
- {
|
|
|
- [wself deleteNotification:notification];
|
|
|
- [wself.tableView reloadData];
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-- (void)deleteNotification:(NIMSystemNotification *)notification
|
|
|
-{
|
|
|
- id<NIMSystemNotificationManager> systemNotificationManager = [[NIMSDK sharedSDK] systemNotificationManager];
|
|
|
- [systemNotificationManager deleteNotification:notification];
|
|
|
-
|
|
|
- [_systemArr removeObject:notification];
|
|
|
-}
|
|
|
|
|
|
@end
|