Fenix Wang 8 éve
szülő
commit
f478cc90de

BIN
NIMDemo/NIM.xcworkspace/xcuserdata/Fenix.xcuserdatad/UserInterfaceState.xcuserstate


+ 0 - 6
NIMDemo/NIMDemo.xcodeproj/project.pbxproj

@@ -211,7 +211,6 @@
 		C482C30D1F0B923300EF2B71 /* NTESSessionGiftContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C30C1F0B923300EF2B71 /* NTESSessionGiftContentView.m */; };
 		C482C3101F0CAE7300EF2B71 /* TradeTopBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C30F1F0CAE7300EF2B71 /* TradeTopBarItem.m */; };
 		C482C3131F0CD37E00EF2B71 /* SocialTopTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3121F0CD37E00EF2B71 /* SocialTopTableViewCell.m */; };
-		C482C3161F0DD21500EF2B71 /* GroupCardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3151F0DD21500EF2B71 /* GroupCardViewController.m */; };
 		C482C3191F10A00900EF2B71 /* GroupInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C3181F10A00900EF2B71 /* GroupInfoViewController.m */; };
 		C482C31D1F13354600EF2B71 /* GroupNameTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C31C1F13354600EF2B71 /* GroupNameTableViewCell.m */; };
 		C482C3201F13534700EF2B71 /* GroupDescTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C482C31F1F13534700EF2B71 /* GroupDescTableViewCell.m */; };
@@ -650,8 +649,6 @@
 		C482C30F1F0CAE7300EF2B71 /* TradeTopBarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TradeTopBarItem.m; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/TradeTopBarItem.m; sourceTree = "<group>"; };
 		C482C3111F0CD37E00EF2B71 /* SocialTopTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocialTopTableViewCell.h; sourceTree = "<group>"; };
 		C482C3121F0CD37E00EF2B71 /* SocialTopTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SocialTopTableViewCell.m; sourceTree = "<group>"; };
-		C482C3141F0DD21500EF2B71 /* GroupCardViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupCardViewController.h; sourceTree = "<group>"; };
-		C482C3151F0DD21500EF2B71 /* GroupCardViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupCardViewController.m; sourceTree = "<group>"; };
 		C482C3171F10A00900EF2B71 /* GroupInfoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupInfoViewController.h; sourceTree = "<group>"; };
 		C482C3181F10A00900EF2B71 /* GroupInfoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupInfoViewController.m; sourceTree = "<group>"; };
 		C482C31B1F13354600EF2B71 /* GroupNameTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupNameTableViewCell.h; path = ../../../../../fenix/XCode_Project/NIM_iOS_Demo_v3/NIMDemo/NIMDemo/SectionGroup/GroupNameTableViewCell.h; sourceTree = "<group>"; };
@@ -1877,8 +1874,6 @@
 				C4A7345F1EE6BBD300D6489D /* GroupMoreTableViewController.m */,
 				C4A734611EE6D4DE00D6489D /* GroupMoreTableViewCell.h */,
 				C4A734621EE6D4DE00D6489D /* GroupMoreTableViewCell.m */,
-				C482C3141F0DD21500EF2B71 /* GroupCardViewController.h */,
-				C482C3151F0DD21500EF2B71 /* GroupCardViewController.m */,
 				C482C3171F10A00900EF2B71 /* GroupInfoViewController.h */,
 				C482C3181F10A00900EF2B71 /* GroupInfoViewController.m */,
 				C482C3211F13577200EF2B71 /* GroupIntroViewController.h */,
@@ -2213,7 +2208,6 @@
 				C482C3201F13534700EF2B71 /* GroupDescTableViewCell.m in Sources */,
 				61E471191B7D963E00F4A1BF /* NTESContactUtilCell.m in Sources */,
 				61E471661B7D963E00F4A1BF /* NTESSettingPortraitCell.m in Sources */,
-				C482C3161F0DD21500EF2B71 /* GroupCardViewController.m in Sources */,
 				61E471131B7D963E00F4A1BF /* NTESGroupedContacts.m in Sources */,
 				C4D8F12F1ED48657002F9F3A /* AFURLRequestSerialization.m in Sources */,
 				61E4718D1B7D96AA00F4A1BF /* NTESDemoConfig.m in Sources */,

+ 1 - 1
NIMDemo/NIMDemo/Classes/Sections/Session/ViewController/NTESSessionViewController.m

@@ -1100,7 +1100,7 @@ NIMInputDelegate>
 
 - (void)updateGiftTopItem{
     
-    NSLog(@"updateGiftTopItem");
+    //NSLog(@"updateGiftTopItem");
     
     int hideTimeCount = 2;
 

+ 0 - 13
NIMDemo/NIMDemo/GroupCardViewController.h

@@ -1,13 +0,0 @@
-//
-//  GroupCardViewController.h
-//  NIMDemo
-//
-//  Created by Fenix Wang on 2017/7/6.
-//  Copyright © 2017年 Netease. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface GroupCardViewController : UIViewController
-
-@end

+ 0 - 37
NIMDemo/NIMDemo/GroupCardViewController.m

@@ -1,37 +0,0 @@
-//
-//  GroupCardViewController.m
-//  NIMDemo
-//
-//  Created by Fenix Wang on 2017/7/6.
-//  Copyright © 2017年 Netease. All rights reserved.
-//
-
-#import "GroupCardViewController.h"
-
-@interface GroupCardViewController ()
-
-@end
-
-@implementation GroupCardViewController
-
-- (void)viewDidLoad {
-    [super viewDidLoad];
-    // Do any additional setup after loading the view.
-}
-
-- (void)didReceiveMemoryWarning {
-    [super didReceiveMemoryWarning];
-    // Dispose of any resources that can be recreated.
-}
-
-/*
-#pragma mark - Navigation
-
-// In a storyboard-based application, you will often want to do a little preparation before navigation
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
-    // Get the new view controller using [segue destinationViewController].
-    // Pass the selected object to the new view controller.
-}
-*/
-
-@end

+ 213 - 57
NIMDemo/NIMDemo/GroupInfoViewController.m

@@ -16,22 +16,34 @@
 #import "GroupMenberTableViewCell.h"
 #import "GroupToogleTableViewCell.h"
 #import "User.h"
+#import "NIMTeamMemberListViewController.h"
+#import "NTESSessionLocalHistoryViewController.h"
+#import "NIMKit.h"
+#import "UIActionSheet+NTESBlock.h"
+#import "NTESBundleSetting.h"
 
 
 @interface GroupInfoViewController () <UIAlertViewDelegate>
 
 @property (nonatomic, strong) UITableView           *tableView;
+@property (nonatomic, strong) NIMSession            *session;
 @property (nonatomic, strong) NIMTeam               *team;
 @property (nonatomic, strong) NSMutableArray        *sectionArr;
 
+@property (nonatomic, strong) NSMutableDictionary   *teamNameData;
+@property (nonatomic, strong) NSMutableDictionary   *teamIntroData;
+@property (nonatomic, strong) NSMutableDictionary   *teamMemberCountData;
+@property (nonatomic, strong) NSMutableDictionary   *teamMenberData;
+
 @property(nonatomic,strong) NIMTeamMember *myTeamInfo;
 @property(nonatomic,copy) NSArray *bodyData;
 @property(nonatomic,copy) NSArray *memberData;
-@property(nonatomic,copy) NSArray *teamMembers;
 
 
 @property (nonatomic, strong) UIButton              *quitBtn;
 
+@property (nonatomic, strong) UIAlertView           *updateTeamNameAlertView;
+@property (nonatomic, strong) UIAlertView           *updateTeamIntroAlertView;
 @property (nonatomic, strong) UIAlertView           *quitTeamAlertView;
 @property (nonatomic, strong) UIAlertView           *dismissTeamAlertView;
 
@@ -44,6 +56,7 @@
     self = [super initWithNibName:nil bundle:nil];
     if (self) {
         _team = team;
+        _session = [NIMSession session:team.teamId type:NIMSessionTypeTeam];
     }
     return self;
 }
@@ -55,7 +68,7 @@
     self.view.backgroundColor = User.tinyGrayColor;
     
     [self.view addSubview:self.tableView];
-    [self setUpSectionData];
+    [self buildBodyData];
 }
 
 - (void)didReceiveMemoryWarning {
@@ -63,44 +76,88 @@
     // Dispose of any resources that can be recreated.
 }
 
+- (void)reloadData{
+    self.myTeamInfo = [[NIMSDK sharedSDK].teamManager teamMember:self.myTeamInfo.userId inTeam:self.myTeamInfo.teamId];
+    [self buildBodyData];
+    [self.tableView reloadData];
+}
+
+- (void)requestData:(void(^)(NSError *error)) handler{
+    __weak typeof(self) wself = self;
+    [[NIMSDK sharedSDK].teamManager fetchTeamMembers:self.team.teamId completion:^(NSError *error, NSArray *members) {
+        if (!error) {
+            for (NIMTeamMember *member in members) {
+                if ([member.userId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) {
+                    wself.myTeamInfo = member;
+                    break;
+                }
+            }
+            wself.memberData = members;
+        }else if(error.code == NIMRemoteErrorCodeTeamNotMember){
+            [wself.view makeToast:@"你已经不在群里" duration:2
+                         position:CSToastPositionCenter];
+        }else{
+            [wself.view makeToast:[NSString stringWithFormat:@"拉好友失败 error: %zd",error.code] duration:2
+                         position:CSToastPositionCenter];
+        }
+        handler(error);
+    }];
+}
+
 
-- (void)setUpSectionData{
+- (void)buildBodyData{
     
-    _sectionArr = [[NSMutableArray alloc] init];
+    if(_sectionArr)
+    {
+        [_sectionArr removeAllObjects];
+    }
+    else
+    {
+        _sectionArr = [[NSMutableArray alloc] init];
+    }
     
     NSMutableArray *infoArr = [[NSMutableArray alloc] init];
-    [infoArr addObject:@{@"key":@"name",
-                         @"value":_team.teamName ? _team.teamName : @"",
-                         @"title":@"群聊名称",
-                         @"height":@(44)}];
-    [infoArr addObject:@{@"key":@"intro",
-                         @"value":_team,
-                         @"title":@"群公告",
-                         @"height":@(132)}];
+    _teamNameData = [[NSMutableDictionary alloc] init];
+    [_teamNameData setValue:@"name" forKey:@"key"];
+    [_teamNameData setValue:_team.teamName ? _team.teamName : @"" forKey:@"value"];
+    [_teamNameData setValue:@"群聊名称" forKey:@"title"];
+    [_teamNameData setValue:@(44) forKey:@"height"];
+    [infoArr addObject:_teamNameData];
+    
+    _teamIntroData = [[NSMutableDictionary alloc] init];
+    [_teamIntroData setValue:@"intro" forKey:@"key"];
+    [_teamIntroData setValue:_team forKey:@"value"];
+    [_teamIntroData setValue:@"群公告" forKey:@"title"];
+    [_teamIntroData setValue:@(132) forKey:@"height"];
+    [infoArr addObject:_teamIntroData];
+    
     [_sectionArr addObject:infoArr];
     
     
     
     NSMutableArray *memberArr = [[NSMutableArray alloc] init];
-    [memberArr addObject:@{@"key":@"menberCount",
-                           @"value":[NSString stringWithFormat:@"%ld人", (long)_team.memberNumber],
-                           @"title":@"群聊成员",
-                           @"height":@(44)}];
     
-    NSMutableDictionary *menberDict = [[NSMutableDictionary alloc] init];
-    [menberDict setValue:@"member" forKey:@"key"];
-    [menberDict setValue:@"群聊成员" forKey:@"title"];
-    [menberDict setValue:@(88) forKey:@"height"];
+    _teamMemberCountData = [[NSMutableDictionary alloc] init];
+    [_teamMemberCountData setValue:@"memberCount" forKey:@"key"];
+    [_teamMemberCountData setValue:[NSString stringWithFormat:@"%ld人", (long)_team.memberNumber] forKey:@"value"];
+    [_teamMemberCountData setValue:@"群聊成员" forKey:@"title"];
+    [_teamMemberCountData setValue:@(44) forKey:@"height"];
+    [memberArr addObject:_teamMemberCountData];
+    
+    _teamNameData = [[NSMutableDictionary alloc] init];
+    [_teamNameData setValue:@"member" forKey:@"key"];
+    [_teamNameData setValue:@"群聊成员" forKey:@"title"];
+    [_teamNameData setValue:@(88) forKey:@"height"];
     
     __weak typeof(self) wself = self;
-    [self requestData:^(NSError *error, NSArray *data) {
-        [menberDict setValue:data forKey:@"list"];
+    [self requestData:^(NSError *error) {
+        [wself.teamNameData setValue:wself.memberData forKey:@"list"];
         [wself.tableView reloadData];
     }];
-    [memberArr addObject:menberDict];
+    [memberArr addObject:_teamNameData];
     
     [_sectionArr addObject:memberArr];
-
+    
     
     
     NSMutableArray *actionArr = [[NSMutableArray alloc] init];
@@ -125,35 +182,6 @@
                            @"height":@(44)}];
     
     [_sectionArr addObject:actionArr];
-    
-    
-}
-
-- (void)requestData:(void(^)(NSError *error,NSArray *data)) handler{
-    __weak typeof(self) wself = self;
-    [[NIMSDK sharedSDK].teamManager fetchTeamMembers:self.team.teamId completion:^(NSError *error, NSArray *members) {
-        NSMutableArray *array = nil;
-        if (!error) {
-            NSString *myAccount = [[NIMSDK sharedSDK].loginManager currentAccount];
-            for (NIMTeamMember *item in members) {
-                if ([item.userId isEqualToString:myAccount]) {
-                    wself.myTeamInfo = item;
-                }
-            }
-            array = [[NSMutableArray alloc]init];
-            for (NIMTeamMember *member in members) {
-                NIMTeamCardMemberItem *item = [[NIMTeamCardMemberItem alloc] initWithMember:member];
-                [array addObject:item];
-            }
-            wself.teamMembers = members;
-        }else if(error.code == NIMRemoteErrorCodeTeamNotMember){
-            [wself.view makeToast:@"你已经不在讨论组里"];
-        }else{
-            [wself.view makeToast:@"拉好友失败"];
-        }
-        wself.memberData = array;
-        handler(error,array);
-    }];
 }
 
 
@@ -199,9 +227,9 @@
         [_quitBtn addTarget:self action:@selector(onTouchQuit:) forControlEvents:UIControlEventTouchUpInside];
         
         if([[User sharedInfo] isTeamOwner:_team])
-            [_quitBtn setTitle:@"退出该房间" forState:UIControlStateNormal];
-        else
             [_quitBtn setTitle:@"解散本群" forState:UIControlStateNormal];
+        else
+            [_quitBtn setTitle:@"退出该房间" forState:UIControlStateNormal];
         
         [footer addSubview:_quitBtn];
         
@@ -263,7 +291,7 @@
         }
         baseCell = cell;
     }
-    else if([key isEqualToString:@"menberCount"] || [key isEqualToString:@"record"])
+    else if([key isEqualToString:@"memberCount"] || [key isEqualToString:@"record"])
     {
         GroupMenberCountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"count"];
         if(!cell)
@@ -320,6 +348,78 @@
     return 0.01;//把高度设置很小,效果可以看成footer的高度等于0
 }
 
+-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    NSMutableArray *arr = [_sectionArr objectAtIndex:indexPath.section];
+    NSDictionary *dataObj = [arr objectAtIndex:indexPath.row];
+    NSString *key = [dataObj objectForKey:@"key"];
+    
+    if([key isEqualToString:@"name"])
+    {
+        [self updateTeamName];
+    }
+    else if([key isEqualToString:@"intro"])
+    {
+        [self updateTeamIntro];
+    }
+    else if([key isEqualToString:@"memberCount"])
+    {
+        [self enterMemberCard];
+    }
+    else if([key isEqualToString:@"record"])
+    {
+        [self enterHistory];
+    }
+    else if([key isEqualToString:@"clear"])
+    {
+        [self clearHistory];
+    }
+}
+
+
+
+- (void)updateTeamName{
+    
+    if([[User sharedInfo] isTeamOwner:_team])
+    {
+        _updateTeamNameAlertView = [[UIAlertView alloc] initWithTitle:@"" message:@"修改群名称" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
+        _updateTeamNameAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
+        [_updateTeamNameAlertView show];
+    }
+    
+}
+
+- (void)updateTeamIntro{
+    
+    if([[User sharedInfo] isTeamOwner:_team])
+    {
+        _updateTeamIntroAlertView = [[UIAlertView alloc] initWithTitle:@"" message:@"修改群介绍" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
+        _updateTeamIntroAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
+        [_updateTeamIntroAlertView show];
+    }
+}
+
+- (void)enterMemberCard{
+    NIMTeamMemberListViewController *vc = [[NIMTeamMemberListViewController alloc] initTeam:self.team members:self.memberData];
+    [self.navigationController pushViewController:vc animated:YES];
+}
+
+- (void)enterHistory{
+    NTESSessionLocalHistoryViewController *vc = [[NTESSessionLocalHistoryViewController alloc] initWithSession:self.session];
+    [self.navigationController pushViewController:vc animated:YES];
+}
+
+- (void)clearHistory{
+    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"确定清空聊天记录?" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
+    __weak UIActionSheet *wSheet;
+    [sheet showInView:self.view completionHandler:^(NSInteger index) {
+        if (index == wSheet.destructiveButtonIndex) {
+            BOOL removeRecentSession = [NTESBundleSetting sharedConfig].removeSessionWheDeleteMessages;
+            [[NIMSDK sharedSDK].conversationManager deleteAllmessagesInSession:self.session removeRecentSession:removeRecentSession];
+        }
+    }];
+}
+
 
 - (void)onTouchQuit:(id)sender{
     
@@ -345,7 +445,14 @@
 }
 
 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
-    if (alertView == _quitTeamAlertView) {
+    
+    if (alertView == _updateTeamNameAlertView) {
+        [self updateTeamNameAlert:buttonIndex];
+    }
+    else if (alertView == _updateTeamIntroAlertView) {
+        [self updateTeamIntroAlert:buttonIndex];
+    }
+    else if (alertView == _quitTeamAlertView) {
         [self quitTeamAlert:buttonIndex];
     }
     else if (alertView == _dismissTeamAlertView) {
@@ -353,6 +460,55 @@
     }
 }
 
+- (void)updateTeamNameAlert:(NSInteger)index{
+    switch (index) {
+        case 0://取消
+            break;
+        case 1:{
+            NSString *name = [_updateTeamNameAlertView textFieldAtIndex:0].text;
+            if (name.length) {
+                
+                [[NIMSDK sharedSDK].teamManager updateTeamName:name teamId:self.team.teamId completion:^(NSError *error) {
+                    if (!error) {
+                        self.team.teamName = name;
+                        [self.view makeToast:@"修改成功" duration:2
+                                    position:CSToastPositionCenter];
+                        [self reloadData];
+                    }else{
+                        [self.view makeToast:[NSString stringWithFormat:@"修改失败 code:%zd",error.code] duration:2
+                                    position:CSToastPositionCenter];
+                    }
+                }];
+            }
+            break;
+        }
+        default:
+            break;
+    }
+}
+
+- (void)updateTeamIntroAlert:(NSInteger)index{
+    switch (index) {
+        case 0://取消
+            break;
+        case 1:{
+            NSString *intro = [_updateTeamIntroAlertView textFieldAtIndex:0].text;
+            [[NIMSDK sharedSDK].teamManager updateTeamIntro:intro teamId:self.team.teamId completion:^(NSError *error) {
+                if (!error) {
+                    self.team.intro = intro;
+                    [self.view makeToast:@"修改成功"];
+                    [self reloadData];
+                }else{
+                    [self.view makeToast:[NSString stringWithFormat:@"修改失败 code:%zd",error.code]];
+                }
+            }];
+            break;
+        }
+        default:
+            break;
+    }
+}
+
 - (void)quitTeamAlert:(NSInteger)index{
     switch (index) {
         case 0://取消

+ 5 - 3
NIMDemo/NIMDemo/SectionGroup/GroupDescTableViewCell.m

@@ -34,9 +34,11 @@
     _titleLabel.textColor = UIColor.blackColor;
     [self addSubview:_titleLabel];
     
-    _descTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom+7, width-20-50, 60)];
+    _descTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom, width-20-10, 68)];
     _descTextView.textColor = UIColor.lightGrayColor;
-    _descTextView.editable = NO;
+    _descTextView.font = [UIFont systemFontOfSize:16];
+    _descTextView.textAlignment = NSTextAlignmentLeft;
+    _descTextView.userInteractionEnabled = NO;
     [self addSubview:_descTextView];
     
     UIImageView *arrow = [[UIImageView alloc] init];
@@ -52,7 +54,7 @@
     
     _titleLabel.text = [data objectForKey:@"title"];
     NIMTeam *team = [data objectForKey:@"value"];
-    _descTextView.text = [data objectForKey:team.intro ? team.intro : @""];
+    _descTextView.text = team.intro ? team.intro : @"";
     
 }
 

+ 1 - 0
NIMDemo/NIMDemo/SectionGroup/GroupNameTableViewCell.m

@@ -47,4 +47,5 @@
     
 }
 
+
 @end