Browse Source

群管理

heavyrain lee 5 years ago
parent
commit
95d93ce49e

+ 8 - 0
wfclient/WFChatClient.xcodeproj/project.pbxproj

@@ -121,6 +121,8 @@
 		90B0444B1FEFDC1A00AFE79B /* WFCCChangeGroupNameNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 90B044491FEFDC1A00AFE79B /* WFCCChangeGroupNameNotificationContent.m */; };
 		90B0444E1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 90B0444C1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		90B0444F1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 90B0444D1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.m */; };
+		90B1373C22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 90B1373A22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.h */; };
+		90B1373D22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 90B1373B22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.m */; };
 		90D1F596208D65B500C2A9CA /* WFCCCallStartMessageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 90D1F594208D65B500C2A9CA /* WFCCCallStartMessageContent.m */; };
 		90D1F597208D65B500C2A9CA /* WFCCCallStartMessageContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 90D1F595208D65B500C2A9CA /* WFCCCallStartMessageContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		90E4D1DF1FFB0AE200B9A4E4 /* WFCCLocationMessageContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 90E4D1DD1FFB0AE200B9A4E4 /* WFCCLocationMessageContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -232,6 +234,8 @@
 		90B044491FEFDC1A00AFE79B /* WFCCChangeGroupNameNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCChangeGroupNameNotificationContent.m; sourceTree = "<group>"; };
 		90B0444C1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCModifyGroupAliasNotificationContent.h; sourceTree = "<group>"; };
 		90B0444D1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCModifyGroupAliasNotificationContent.m; sourceTree = "<group>"; };
+		90B1373A22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCGroupJoinTypeNotificationContent.h; sourceTree = "<group>"; };
+		90B1373B22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCGroupJoinTypeNotificationContent.m; sourceTree = "<group>"; };
 		90D1F594208D65B500C2A9CA /* WFCCCallStartMessageContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCCallStartMessageContent.m; sourceTree = "<group>"; };
 		90D1F595208D65B500C2A9CA /* WFCCCallStartMessageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCCallStartMessageContent.h; sourceTree = "<group>"; };
 		90E4D1DD1FFB0AE200B9A4E4 /* WFCCLocationMessageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCLocationMessageContent.h; sourceTree = "<group>"; };
@@ -380,6 +384,8 @@
 				2FF2A46022C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m */,
 				2F19723522C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h */,
 				2F19723422C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m */,
+				90B1373A22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.h */,
+				90B1373B22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.m */,
 			);
 			path = Messages;
 			sourceTree = "<group>";
@@ -453,6 +459,7 @@
 				90D1F597208D65B500C2A9CA /* WFCCCallStartMessageContent.h in Headers */,
 				2FF2A46122C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h in Headers */,
 				2E6B51131FAE9B10006B6E31 /* WFCCConversation.h in Headers */,
+				90B1373C22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.h in Headers */,
 				2F19723722C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h in Headers */,
 				903EBB8C21357DDF00312C16 /* WFCCStickerMessageContent.h in Headers */,
 				2F1A931A21B250F5006625CD /* WFCCTypingMessageContent.h in Headers */,
@@ -642,6 +649,7 @@
 				2FF2A46222C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m in Sources */,
 				2E6B51201FAE9B10006B6E31 /* WFCCUserInfo.m in Sources */,
 				2E6B511C1FAE9B10006B6E31 /* WFCCGroupInfo.m in Sources */,
+				90B1373D22D9D1CC005F103C /* WFCCGroupJoinTypeNotificationContent.m in Sources */,
 				2E6B51161FAE9B10006B6E31 /* WFCCConversationInfo.m in Sources */,
 				6E6C69A720B959F100006628 /* WFCCGroupSearchInfo.m in Sources */,
 				2E6B50B41FAE990D006B6E31 /* wav_amr.mm in Sources */,

+ 31 - 0
wfclient/WFChatClient/Messages/WFCCGroupJoinTypeNotificationContent.h

@@ -0,0 +1,31 @@
+//
+//  WFCCCreateGroupNotificationContent.h
+//  WFChatClient
+//
+//  Created by heavyrain on 2017/9/19.
+//  Copyright © 2017年 WildFireChat. All rights reserved.
+//
+
+#import "WFCCNotificationMessageContent.h"
+
+/**
+ 建群的通知消息
+ */
+@interface WFCCGroupJoinTypeNotificationContent : WFCCNotificationMessageContent
+
+/**
+ 群组ID
+ */
+@property (nonatomic, strong)NSString *groupId;
+
+/**
+ 创建者ID
+ */
+@property (nonatomic, strong)NSString *creator;
+
+/**
+ 操作
+ */
+@property (nonatomic, strong)NSString *type;
+
+@end

+ 92 - 0
wfclient/WFChatClient/Messages/WFCCGroupJoinTypeNotificationContent.m

@@ -0,0 +1,92 @@
+//
+//  WFCCCreateGroupNotificationContent.m
+//  WFChatClient
+//
+//  Created by heavyrain on 2017/9/19.
+//  Copyright © 2017年 WildFireChat. All rights reserved.
+//
+
+#import "WFCCGroupJoinTypeNotificationContent.h"
+#import "WFCCIMService.h"
+#import "WFCCNetworkService.h"
+#import "Common.h"
+
+@implementation WFCCGroupJoinTypeNotificationContent
+- (WFCCMessagePayload *)encode {
+    WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
+    payload.contentType = [self.class getContentType];
+    
+    NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
+    if (self.creator) {
+        [dataDict setObject:self.creator forKey:@"o"];
+    }
+    if (self.type) {
+        [dataDict setObject:self.type forKey:@"n"];
+    }
+    
+    if (self.groupId) {
+        [dataDict setObject:self.groupId forKey:@"g"];
+    }
+    
+    payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
+                                                                           options:kNilOptions
+                                                                             error:nil];
+    
+    return payload;
+}
+
+- (void)decode:(WFCCMessagePayload *)payload {
+    NSError *__error = nil;
+    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
+                                                               options:kNilOptions
+                                                                 error:&__error];
+    if (!__error) {
+        self.creator = dictionary[@"o"];
+        self.type = dictionary[@"n"];
+        self.groupId = dictionary[@"g"];
+    }
+}
+
++ (int)getContentType {
+    return MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE;
+}
+
++ (int)getContentFlags {
+    return WFCCPersistFlag_PERSIST;
+}
+
+
+
++ (void)load {
+    [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
+}
+
+- (NSString *)digest:(WFCCMessage *)message {
+    return [self formatNotification:message];
+}
+
+- (NSString *)formatNotification:(WFCCMessage *)message {
+    NSString *user = @"你";
+    if (![[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
+        WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator inGroup:self.groupId refresh:NO];
+        if (userInfo.friendAlias.length > 0) {
+            user = userInfo.friendAlias;
+        } else if(userInfo.groupAlias.length > 0) {
+            user = userInfo.groupAlias;
+        } else if (userInfo.displayName.length > 0) {
+            user = userInfo.displayName;
+        } else {
+            user = [NSString stringWithFormat:@"管理员<%@>", self.creator];
+        }
+    }
+    
+    if ([self.type isEqualToString:@"0"]) {
+        return [NSString stringWithFormat:@"%@开放了加入群组功能", user];
+    } else if ([self.type isEqualToString:@"1"]) {
+        return [NSString stringWithFormat:@"%@仅允许群成员邀请加入群组", user];
+    } else {
+        return [NSString stringWithFormat:@"%@关闭了加入群组功能", user];
+    }
+    
+}
+@end

+ 5 - 5
wfclient/WFChatClient/Messages/WFCCGroupPrivateChatNotificationContent.m

@@ -67,17 +67,17 @@
 
 - (NSString *)formatNotification:(WFCCMessage *)message {
     if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
-        return [self.type isEqualToString:@"1"] ? @"你开启了成员私聊" : @"你关闭了成员私聊";
+        return [self.type isEqualToString:@"0"] ? @"你开启了成员私聊" : @"你关闭了成员私聊";
     } else {
         WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator inGroup:self.groupId refresh:NO];
         if (userInfo.friendAlias.length > 0) {
-            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.friendAlias];
+            return [NSString stringWithFormat:[self.type isEqualToString:@"0"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.friendAlias];
         } else if(userInfo.groupAlias.length > 0) {
-            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.groupAlias];
+            return [NSString stringWithFormat:[self.type isEqualToString:@"0"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.groupAlias];
         } else if (userInfo.displayName.length > 0) {
-            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.displayName];
+            return [NSString stringWithFormat:[self.type isEqualToString:@"0"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.displayName];
         } else {
-            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"用户<%@>开启了成员私聊" : @"用户<%@>关闭了成员私聊", self.creator];
+            return [NSString stringWithFormat:[self.type isEqualToString:@"0"] ? @"用户<%@>开启了成员私聊" : @"用户<%@>关闭了成员私聊", self.creator];
         }
     }
 }

+ 15 - 6
wfuikit/WFChatUIKit/ConversationSetting/ViewController/GroupManageTableViewController.m

@@ -32,6 +32,15 @@
     [self.tableView reloadData];
     
     [self.view addSubview:self.tableView];
+    
+    __weak typeof(self)ws = self;
+    [[NSNotificationCenter defaultCenter] addObserverForName:kGroupInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
+        if ([ws.groupInfo.target isEqualToString:note.object]) {
+            ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.groupInfo.target refresh:NO];
+            [ws.tableView reloadData];
+        }
+    }];
+    
 }
 - (BOOL)isGroupOwner {
     return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
@@ -156,8 +165,8 @@
             
             UIAlertAction *openAction = [UIAlertAction actionWithTitle:@"不限制加入" style:self.groupInfo.joinType == 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                 [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
-                    self.groupInfo.joinType = 0;
-                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
+//                    self.groupInfo.joinType = 0;
+//                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
                 } error:^(int error_code) {
                     [self.view makeToast:@"设置失败"];
                 }];
@@ -166,8 +175,8 @@
             
             UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:@"群成员可以拉人" style:self.groupInfo.joinType == 1 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                 [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
-                    self.groupInfo.joinType = 1;
-                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
+//                    self.groupInfo.joinType = 1;
+//                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
                 } error:^(int error_code) {
                     [self.view makeToast:@"设置失败"];
                 }];
@@ -176,8 +185,8 @@
             
             UIAlertAction *normalAction = [UIAlertAction actionWithTitle:@"只能群管理拉人" style:self.groupInfo.joinType == 2 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                 [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"2" notifyLines:@[@(0)] notifyContent:nil success:^{
-                    self.groupInfo.joinType = 2;
-                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
+//                    self.groupInfo.joinType = 2;
+//                    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
                 } error:^(int error_code) {
                     [self.view makeToast:@"设置失败"];
                 }];

+ 8 - 6
wfuikit/WFChatUIKit/ConversationSetting/ViewController/WFCUConversationSettingViewController.m

@@ -144,15 +144,17 @@
     [self.view addSubview:self.tableView];
     
     if(self.conversation.type == Group_Type) {
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onGroupMemberUpdated:) name:kGroupMemberUpdated object:self.conversation.target];
+        __weak typeof(self)ws = self;
+        [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
+            if ([ws.conversation.target isEqualToString:note.object]) {
+                ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.conversation.target refresh:NO];
+                ws.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:NO];
+                [ws.memberCollectionView reloadData];
+            }
+        }];
     }
 }
 
-- (void)onGroupMemberUpdated:(NSNotification *)notification {
-    self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
-    self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
-    [self.memberCollectionView reloadData];
-}
 
 - (void)onTapChannelPortrait:(id)sender {
     WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];

+ 10 - 2
wfuikit/WFChatUIKit/MessageList/ViewController/WFCUMessageListViewController.m

@@ -989,8 +989,16 @@
 - (void)didTapMessagePortrait:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
     if(self.conversation.type == Group_Type) {
         if (self.targetGroup.privateChat) {
-            [self.view makeToast:@"管理员关闭了群组私聊权限" duration:1 position:CSToastPositionCenter];
-            return;
+            if (![self.targetGroup.owner isEqualToString:model.message.fromUser] && ![self.targetGroup.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
+                WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
+                if (gm.type != Member_Type_Manager) {
+                    WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:model.message.fromUser];
+                    if (gm.type != Member_Type_Manager) {
+                        [self.view makeToast:@"管理员关闭了群组私聊权限" duration:1 position:CSToastPositionCenter];
+                        return;
+                    }
+                }
+            }
         }
     }
   WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];