Browse Source

添加自动生成9宫格群组代码

heavyrain2012 4 years ago
parent
commit
d89f56d6ba

+ 23 - 1
wfchat/WildFireChat/LBXScan/CreateBarCodeViewController.m

@@ -137,7 +137,20 @@
 
 - (void)setGroupInfo:(WFCCGroupInfo *)groupInfo {
     _groupInfo = groupInfo;
+    
+#if !WFCU_GROUP_GRID_PORTRAIT
     self.qrLogo = groupInfo.portrait;
+#else
+    if (groupInfo.portrait.length) {
+        self.qrLogo = groupInfo.portrait;
+    } else {
+        NSString *filePath = [WFCCUtilities getGroupGridPortrait:groupInfo.target width:50 defaultUserPortrait:^UIImage *(NSString *userId) {
+            return [UIImage imageNamed:@"PersonalChat"];
+        }];
+        self.qrLogo = filePath;
+    }
+#endif
+    
     if (groupInfo.name.length) {
         self.labelStr = groupInfo.name;
     } else {
@@ -158,7 +171,16 @@
     __weak typeof(self)ws = self;
     dispatch_async(dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_DEFAULT), ^{
         CGSize logoSize=CGSizeMake(50, 50);
-        UIImage *logo = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:ws.qrLogo]]];
+        UIImage *logo;
+        if ([NSURL URLWithString:qrLogo].baseURL) {
+            logo = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:ws.qrLogo]]];
+        } else {
+            logo = [UIImage imageWithContentsOfFile:qrLogo];
+        }
+        if (!logo) {
+            logo = [UIImage imageNamed:@"group_default_portrait"];
+        }
+        
         dispatch_async(dispatch_get_main_queue(), ^{
             ws.logoImgView = [ws roundCornerWithImage:logo size:logoSize];
             ws.logoImgView.bounds = CGRectMake(0, 0, logoSize.width, logoSize.height);

+ 33 - 0
wfuikit/WFChatUIKit/ConversationList/Cell/WFCUConversationTableViewCell.m

@@ -56,7 +56,37 @@
 }
 
 - (void)updateGroupInfo:(WFCCGroupInfo *)groupInfo {
+#if !WFCU_GROUP_GRID_PORTRAIT
   [self.potraitView sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
+#else
+    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GroupPortraitChanged" object:nil];
+
+    if (groupInfo.portrait.length) {
+        [self.potraitView sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
+    } else {
+        __weak typeof(self)ws = self;
+        NSString *groupId = groupInfo.target;
+        
+        [[NSNotificationCenter defaultCenter] addObserverForName:@"GroupPortraitChanged" object:groupInfo.target queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
+            NSString *path = [note.userInfo objectForKey:@"path"];
+            if ((ws.info.conversation.type == Group_Type && [ws.info.conversation.target isEqualToString:groupId]) ||
+                (ws.searchInfo.conversation.type == Group_Type  && [ws.searchInfo.conversation.target isEqualToString:groupId])) {
+                [ws.potraitView sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
+            }
+        }];
+        [self.potraitView setImage:[UIImage imageNamed:@"group_default_portrait"]];
+        
+        
+        NSString *path = [WFCCUtilities getGroupGridPortrait:groupInfo.target width:80 defaultUserPortrait:^UIImage *(NSString *userId) {
+            return [UIImage imageNamed:@"PersonalChat"];
+        }];
+        
+        if (path) {
+            [self.potraitView sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
+            [self.potraitView setImage:[UIImage imageWithContentsOfFile:path]];
+        }
+    }
+#endif
   
   if(groupInfo.name.length > 0) {
     self.targetView.text = groupInfo.name;
@@ -305,4 +335,7 @@
     return _bubbleView;
 }
 
+- (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
 @end

+ 0 - 1
wfuikit/WFChatUIKit/ConversationList/ViewController/WFCUConversationSearchTableViewController.m

@@ -8,7 +8,6 @@
 
 #import "WFCUConversationSearchTableViewController.h"
 #import "WFCUContactListViewController.h"
-#import "WFCUCreateGroupViewController.h"
 #import "WFCUFriendRequestViewController.h"
 
 #import "WFCUMessageListViewController.h"

+ 52 - 0
wfuikit/WFChatUIKit/ConversationList/ViewController/WFCUConversationTableViewController.m

@@ -31,6 +31,7 @@
 #import "UIImage+ERCategory.h"
 #import "UIFont+YH.h"
 #import "UIColor+YH.h"
+#import "UIView+Toast.h"
 #import "WFCUSeletedUserViewController.h"
 
 @interface WFCUConversationTableViewController () <UISearchControllerDelegate, UISearchResultsUpdating, UITableViewDelegate, UITableViewDataSource>
@@ -210,6 +211,7 @@
             mvc.hidesBottomBarWhenPushed = YES;
             [ws.navigationController pushViewController:mvc animated:YES];
         } else {
+#if !WFCU_GROUP_GRID_PORTRAIT
             WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
             vc.memberIds = [contacts mutableCopy];
             if (![vc.memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
@@ -217,12 +219,62 @@
             }
             vc.hidesBottomBarWhenPushed = YES;
             [ws.navigationController pushViewController:vc animated:YES];
+#else
+            [self createGroup:contacts];
+#endif
         }
     };
     
     [self.navigationController presentViewController:navi animated:YES completion:nil];
 }
 
+#if WFCU_GROUP_GRID_PORTRAIT
+- (void)createGroup:(NSArray<NSString *> *)contacts {
+    __weak typeof(self) ws = self;
+    NSMutableArray<NSString *> *memberIds = [contacts mutableCopy];
+    if (![memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
+        [memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
+    }
+
+    NSString *name;
+    WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:0]  refresh:NO];
+    name = userInfo.displayName;
+    
+    for (int i = 1; i < MIN(8, memberIds.count); i++) {
+        userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:i]  refresh:NO];
+        if (userInfo.displayName.length > 0) {
+            if (name.length + userInfo.displayName.length + 1 > 16) {
+                name = [name stringByAppendingString:WFCString(@"Etc")];
+                break;
+            }
+            name = [name stringByAppendingFormat:@",%@", userInfo.displayName];
+        }
+    }
+    if (name.length == 0) {
+        name = WFCString(@"GroupChat");
+    }
+    
+    [[WFCCIMService sharedWFCIMService] createGroup:nil name:name portrait:nil type:GroupType_Restricted members:memberIds notifyLines:@[@(0)] notifyContent:nil success:^(NSString *groupId) {
+        NSLog(@"create group success");
+        
+        WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
+        mvc.conversation = [[WFCCConversation alloc] init];
+        mvc.conversation.type = Group_Type;
+        mvc.conversation.target = groupId;
+        mvc.conversation.line = 0;
+        
+        mvc.hidesBottomBarWhenPushed = YES;
+        [ws.navigationController pushViewController:mvc animated:YES];
+    } error:^(int error_code) {
+        NSLog(@"create group failure");
+        [ws.view makeToast:WFCString(@"CreateGroupFailure")
+                    duration:2
+                    position:CSToastPositionCenter];
+
+    }];
+}
+#endif
+
 - (void)addFriendsAction:(id)sender {
     UIViewController *addFriendVC = [[WFCUFriendRequestViewController alloc] init];
     addFriendVC.hidesBottomBarWhenPushed = YES;

+ 60 - 2
wfuikit/WFChatUIKit/ConversationSetting/ViewController/WFCUConversationSettingViewController.m

@@ -17,7 +17,6 @@
 #import "WFCUSwitchTableViewCell.h"
 #import "WFCUCreateGroupViewController.h"
 #import "WFCUProfileTableViewController.h"
-#import "WFCUCreateGroupViewController.h"
 #import "GroupManageTableViewController.h"
 #import "WFCUGroupMemberCollectionViewController.h"
 
@@ -737,6 +736,7 @@
     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
     [self.navigationController presentViewController:nav animated:YES completion:nil];
   } else if ([self isGroupPortraitCell:indexPath]) {
+#if !WFCU_GROUP_GRID_PORTRAIT
       if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
           [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupPortraitHint") duration:1 position:CSToastPositionCenter];
           return;
@@ -750,6 +750,7 @@
     }
     
     [self.navigationController pushViewController:vc animated:YES];
+#endif
   } else if ([self isGroupManageCell:indexPath]) {
       GroupManageTableViewController *gmvc = [[GroupManageTableViewController alloc] init];
       gmvc.groupInfo = self.groupInfo;
@@ -856,6 +857,7 @@
       } else {
         [disabledUser addObject:self.conversation.target];
         pvc.selectResult = ^(NSArray<NSString *> *contacts) {
+#if !WFCU_GROUP_GRID_PORTRAIT
             WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
             vc.memberIds = [contacts mutableCopy];
             if(![vc.memberIds containsObject:self.conversation.target]) {
@@ -881,7 +883,9 @@
                 mvc.hidesBottomBarWhenPushed = YES;
                 [nav pushViewController:mvc animated:YES];
             };
-            
+#else
+            [self createGroup:contacts];
+#endif
         };
         pvc.disableUsersSelected = YES;
       }
@@ -963,6 +967,60 @@
 //        }
     }
 }
+#if WFCU_GROUP_GRID_PORTRAIT
+- (void)createGroup:(NSArray<NSString *> *)contacts {
+    __weak typeof(self) ws = self;
+    NSMutableArray<NSString *> *memberIds = [contacts mutableCopy];
+    
+    if(![memberIds containsObject:self.conversation.target]) {
+      [memberIds insertObject:self.conversation.target atIndex:0];
+    }
+    
+    if (![memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
+        [memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
+    }
+
+    NSString *name;
+    WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:0]  refresh:NO];
+    name = userInfo.displayName;
+    
+    for (int i = 1; i < MIN(8, memberIds.count); i++) {
+        userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:i]  refresh:NO];
+        if (userInfo.displayName.length > 0) {
+            if (name.length + userInfo.displayName.length + 1 > 16) {
+                name = [name stringByAppendingString:WFCString(@"Etc")];
+                break;
+            }
+            name = [name stringByAppendingFormat:@",%@", userInfo.displayName];
+        }
+    }
+    if (name.length == 0) {
+        name = WFCString(@"GroupChat");
+    }
+    
+    [[WFCCIMService sharedWFCIMService] createGroup:nil name:name portrait:nil type:GroupType_Restricted members:memberIds notifyLines:@[@(0)] notifyContent:nil success:^(NSString *groupId) {
+        NSLog(@"create group success");
+        
+        WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
+        mvc.conversation = [[WFCCConversation alloc] init];
+        mvc.conversation.type = Group_Type;
+        mvc.conversation.target = groupId;
+        mvc.conversation.line = 0;
+        
+        mvc.hidesBottomBarWhenPushed = YES;
+        UINavigationController *nav = self.navigationController;
+        [self.navigationController popToRootViewControllerAnimated:NO];
+        [nav pushViewController:mvc animated:YES];
+
+    } error:^(int error_code) {
+        NSLog(@"create group failure");
+        [ws.view makeToast:WFCString(@"CreateGroupFailure")
+                    duration:2
+                    position:CSToastPositionCenter];
+
+    }];
+}
+#endif
 
 - (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];

+ 3 - 0
wfuikit/WFChatUIKit/Predefine.h

@@ -48,4 +48,7 @@ alpha:1.0]
 #define WFCU_SUPPORT_VOIP 1
 
 #define WFCString(key) NSLocalizedStringFromTable(key, @"wfc", nil)
+
+#define WFCU_GROUP_GRID_PORTRAIT 0
+
 #endif /* Predefine_h */