Browse Source

group manager code

heavyrain2012 5 years ago
parent
commit
13348bdcdd

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

@@ -82,6 +82,8 @@
 		2E6B511F1FAE9B10006B6E31 /* WFCCUserInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E6B50F51FAE9B10006B6E31 /* WFCCUserInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		2E6B51201FAE9B10006B6E31 /* WFCCUserInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E6B50F61FAE9B10006B6E31 /* WFCCUserInfo.m */; };
 		2EE6A4881FB290FC007953BC /* Common.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EE6A4871FB290FC007953BC /* Common.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		2F19723622C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F19723422C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m */; };
+		2F19723722C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2F19723522C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h */; };
 		2F1A931A21B250F5006625CD /* WFCCTypingMessageContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2F1A931821B250F5006625CD /* WFCCTypingMessageContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		2F1A931B21B250F5006625CD /* WFCCTypingMessageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F1A931921B250F5006625CD /* WFCCTypingMessageContent.m */; };
 		2F3223D52144C5FB0016A2C4 /* WFCCVideoMessageContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2F3223D32144C5FB0016A2C4 /* WFCCVideoMessageContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -96,6 +98,10 @@
 		2F8742E0219C4FED00F65EBA /* WFCCChatroomInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F8742DA219C4FED00F65EBA /* WFCCChatroomInfo.m */; };
 		2FEF332621BE93980087B6C2 /* WFCCChannelInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FEF332421BE93980087B6C2 /* WFCCChannelInfo.m */; };
 		2FEF332721BE93980087B6C2 /* WFCCChannelInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2FEF332521BE93980087B6C2 /* WFCCChannelInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		2FF2A45D22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FF2A45B22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.m */; };
+		2FF2A45E22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2FF2A45C22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.h */; };
+		2FF2A46122C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2FF2A45F22C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h */; };
+		2FF2A46222C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FF2A46022C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m */; };
 		6E6C69A720B959F100006628 /* WFCCGroupSearchInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E6C69A520B959F100006628 /* WFCCGroupSearchInfo.m */; };
 		6E6C69A820B959F100006628 /* WFCCGroupSearchInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E6C69A620B959F100006628 /* WFCCGroupSearchInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		6ECFB2C720A84C88001F91CB /* WFCCFileMessageContent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECFB2C520A84C88001F91CB /* WFCCFileMessageContent.m */; };
@@ -187,6 +193,8 @@
 		2E6B50F51FAE9B10006B6E31 /* WFCCUserInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCUserInfo.h; sourceTree = "<group>"; };
 		2E6B50F61FAE9B10006B6E31 /* WFCCUserInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCUserInfo.m; sourceTree = "<group>"; };
 		2EE6A4871FB290FC007953BC /* Common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = "<group>"; };
+		2F19723422C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCGroupSetManagerNotificationContent.m; sourceTree = "<group>"; };
+		2F19723522C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCGroupSetManagerNotificationContent.h; sourceTree = "<group>"; };
 		2F1A931821B250F5006625CD /* WFCCTypingMessageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCTypingMessageContent.h; sourceTree = "<group>"; };
 		2F1A931921B250F5006625CD /* WFCCTypingMessageContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCTypingMessageContent.m; sourceTree = "<group>"; };
 		2F3223D32144C5FB0016A2C4 /* WFCCVideoMessageContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCVideoMessageContent.h; sourceTree = "<group>"; };
@@ -201,6 +209,10 @@
 		2F8742DA219C4FED00F65EBA /* WFCCChatroomInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCChatroomInfo.m; sourceTree = "<group>"; };
 		2FEF332421BE93980087B6C2 /* WFCCChannelInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCChannelInfo.m; sourceTree = "<group>"; };
 		2FEF332521BE93980087B6C2 /* WFCCChannelInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCChannelInfo.h; sourceTree = "<group>"; };
+		2FF2A45B22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCGroupMuteNotificationContent.m; sourceTree = "<group>"; };
+		2FF2A45C22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCGroupMuteNotificationContent.h; sourceTree = "<group>"; };
+		2FF2A45F22C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCGroupPrivateChatNotificationContent.h; sourceTree = "<group>"; };
+		2FF2A46022C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCGroupPrivateChatNotificationContent.m; sourceTree = "<group>"; };
 		6E6C69A520B959F100006628 /* WFCCGroupSearchInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCGroupSearchInfo.m; sourceTree = "<group>"; };
 		6E6C69A620B959F100006628 /* WFCCGroupSearchInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WFCCGroupSearchInfo.h; sourceTree = "<group>"; };
 		6ECFB2C520A84C88001F91CB /* WFCCFileMessageContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WFCCFileMessageContent.m; sourceTree = "<group>"; };
@@ -362,6 +374,12 @@
 				90F584981FFDB39800F7FFA8 /* WFCCChangeGroupPortraitNotificationContent.m */,
 				90B0444C1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.h */,
 				90B0444D1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.m */,
+				2FF2A45C22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.h */,
+				2FF2A45B22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.m */,
+				2FF2A45F22C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h */,
+				2FF2A46022C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m */,
+				2F19723522C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h */,
+				2F19723422C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m */,
 			);
 			path = Messages;
 			sourceTree = "<group>";
@@ -433,7 +451,9 @@
 			buildActionMask = 2147483647;
 			files = (
 				90D1F597208D65B500C2A9CA /* WFCCCallStartMessageContent.h in Headers */,
+				2FF2A46122C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.h in Headers */,
 				2E6B51131FAE9B10006B6E31 /* WFCCConversation.h in Headers */,
+				2F19723722C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.h in Headers */,
 				903EBB8C21357DDF00312C16 /* WFCCStickerMessageContent.h in Headers */,
 				2F1A931A21B250F5006625CD /* WFCCTypingMessageContent.h in Headers */,
 				2F3223D52144C5FB0016A2C4 /* WFCCVideoMessageContent.h in Headers */,
@@ -477,6 +497,7 @@
 				2E6B50C21FAE9B08006B6E31 /* app_callback.h in Headers */,
 				2E6B50B11FAE990D006B6E31 /* interf_enc.h in Headers */,
 				2E6B50C81FAE9B08006B6E31 /* WFCCNetworkStatus.h in Headers */,
+				2FF2A45E22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.h in Headers */,
 				2E6B50B71FAE990D006B6E31 /* wavwriter.h in Headers */,
 				2E6B50B61FAE990D006B6E31 /* wavreader.h in Headers */,
 				2E6B50A01FAE98E6006B6E31 /* WFCChatClient.h in Headers */,
@@ -599,6 +620,7 @@
 				2E6B51121FAE9B10006B6E31 /* WFCCUtilities.m in Sources */,
 				2E6B51041FAE9B10006B6E31 /* WFCCMessage.m in Sources */,
 				2E6B50FC1FAE9B10006B6E31 /* WFCCDismissGroupNotificationContent.m in Sources */,
+				2F19723622C6FC31009F7055 /* WFCCGroupSetManagerNotificationContent.m in Sources */,
 				2F3223D62144C5FB0016A2C4 /* WFCCVideoMessageContent.m in Sources */,
 				2E6B51181FAE9B10006B6E31 /* WFCCConversationSearchInfo.m in Sources */,
 				2E6B50C31FAE9B08006B6E31 /* app_callback.mm in Sources */,
@@ -617,6 +639,7 @@
 				90E4D1E01FFB0AE200B9A4E4 /* WFCCLocationMessageContent.m in Sources */,
 				2E6B51101FAE9B10006B6E31 /* WFCCTransferGroupOwnerNotificationContent.m in Sources */,
 				2E6B50C51FAE9B08006B6E31 /* WFCCIMService.mm in Sources */,
+				2FF2A46222C4DDF5006A6D4C /* WFCCGroupPrivateChatNotificationContent.m in Sources */,
 				2E6B51201FAE9B10006B6E31 /* WFCCUserInfo.m in Sources */,
 				2E6B511C1FAE9B10006B6E31 /* WFCCGroupInfo.m in Sources */,
 				2E6B51161FAE9B10006B6E31 /* WFCCConversationInfo.m in Sources */,
@@ -631,6 +654,7 @@
 				90B0444B1FEFDC1A00AFE79B /* WFCCChangeGroupNameNotificationContent.m in Sources */,
 				90B0444F1FEFDC4D00AFE79B /* WFCCModifyGroupAliasNotificationContent.m in Sources */,
 				2E6B51021FAE9B10006B6E31 /* WFCCMediaMessageContent.m in Sources */,
+				2FF2A45D22C4DBD1006A6D4C /* WFCCGroupMuteNotificationContent.m in Sources */,
 				2F8742DD219C4FED00F65EBA /* WFCCUnreadCount.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 6 - 0
wfclient/WFChatClient/Client/Common.h

@@ -64,6 +64,12 @@
 //修改群头像的通知消息
 #define MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT 112
 
+#define MESSAGE_CONTENT_TYPE_CHANGE_MUTE 113
+#define MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE 114
+#define MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT 115
+#define MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE 116
+#define MESSAGE_CONTENT_TYPE_SET_MANAGER 117
+
 //VoIP开始消息
 #define VOIP_CONTENT_TYPE_START 400
 //VoIP结束消息

+ 23 - 1
wfclient/WFChatClient/Client/WFCCIMService.h

@@ -55,7 +55,11 @@ typedef NS_ENUM(NSInteger, ModifyMyInfoType) {
 typedef NS_ENUM(NSInteger, ModifyGroupInfoType) {
     Modify_Group_Name = 0,
     Modify_Group_Portrait = 1,
-    Modify_Group_Extra = 2
+    Modify_Group_Extra = 2,
+    Modify_Group_Mute = 3,
+    Modify_Group_JoinType = 4,
+    Modify_Group_PrivateChat = 5,
+    Modify_Group_Searchable = 6
 };
 
 
@@ -869,6 +873,24 @@ typedef NS_ENUM(NSInteger, UserSettingScope) {
               success:(void(^)(void))successBlock
                 error:(void(^)(int error_code))errorBlock;
 
+/**
+ 设置群管理
+ 
+ @param groupId 群ID
+ @param isSet    设置或取消
+ @param memberId    成员ID
+ @param notifyLines 默认传 @[@(0)]
+ @param notifyContent 通知消息
+ @param successBlock 成功的回调
+ @param errorBlock 失败的回调
+ */
+- (void)setGroupManager:(NSString *)groupId
+                  isSet:(BOOL)isSet
+              memberIds:(NSArray<NSString *> *)memberId
+            notifyLines:(NSArray<NSNumber *> *)notifyLines
+          notifyContent:(WFCCMessageContent *)notifyContent
+                success:(void(^)(void))successBlock
+                  error:(void(^)(int error_code))errorBlock;
 /**
  获取当前用户收藏的群组
  

+ 28 - 0
wfclient/WFChatClient/Client/WFCCIMService.mm

@@ -898,6 +898,10 @@ WFCCGroupInfo *convertProtoGroupInfo(mars::stn::TGroupInfo tgi) {
     groupInfo.portrait = [NSString stringWithUTF8String:tgi.portrait.c_str()];
     groupInfo.owner = [NSString stringWithUTF8String:tgi.owner.c_str()];
     groupInfo.memberCount = tgi.memberCount;
+    groupInfo.mute = tgi.mute;
+    groupInfo.joinType = tgi.joinType;
+    groupInfo.privateChat = tgi.privateChat;
+    groupInfo.searchable = tgi.searchable;
     return groupInfo;
 }
 
@@ -1371,6 +1375,30 @@ WFCCGroupInfo *convertProtoGroupInfo(mars::stn::TGroupInfo tgi) {
     mars::stn::transferGroup([groupId UTF8String], [newOwner UTF8String], lines, tcontent, new IMGeneralOperationCallback(successBlock, errorBlock));
 }
 
+- (void)setGroupManager:(NSString *)groupId
+                  isSet:(BOOL)isSet
+              memberIds:(NSArray<NSString *> *)memberIds
+            notifyLines:(NSArray<NSNumber *> *)notifyLines
+          notifyContent:(WFCCMessageContent *)notifyContent
+                success:(void(^)(void))successBlock
+                  error:(void(^)(int error_code))errorBlock {
+    
+    mars::stn::TMessageContent tcontent;
+    fillTMessageContent(tcontent, notifyContent);
+    
+    std::list<int> lines;
+    for (NSNumber *number in notifyLines) {
+        lines.push_back([number intValue]);
+    }
+    
+    std::list<std::string> memberList;
+    for (NSString *member in memberIds) {
+        memberList.push_back([member UTF8String]);
+    }
+    
+    mars::stn::SetGroupManager([groupId UTF8String], memberList, isSet, lines, tcontent, new IMGeneralOperationCallback(successBlock, errorBlock));
+}
+
 - (NSArray<NSString *> *)getFavGroups {
     NSDictionary *favGroupDict = [[WFCCIMService sharedWFCIMService] getUserSettings:UserSettingScope_Favourite_Group];
     NSMutableArray *ids = [[NSMutableArray alloc] init];

+ 31 - 0
wfclient/WFChatClient/Messages/WFCCGroupMuteNotificationContent.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 WFCCGroupMuteNotificationContent : WFCCNotificationMessageContent
+
+/**
+ 群组ID
+ */
+@property (nonatomic, strong)NSString *groupId;
+
+/**
+ 创建者ID
+ */
+@property (nonatomic, strong)NSString *creator;
+
+/**
+ 操作
+ */
+@property (nonatomic, strong)NSString *type;
+
+@end

+ 84 - 0
wfclient/WFChatClient/Messages/WFCCGroupMuteNotificationContent.m

@@ -0,0 +1,84 @@
+//
+//  WFCCCreateGroupNotificationContent.m
+//  WFChatClient
+//
+//  Created by heavyrain on 2017/9/19.
+//  Copyright © 2017年 WildFireChat. All rights reserved.
+//
+
+#import "WFCCGroupMuteNotificationContent.h"
+#import "WFCCIMService.h"
+#import "WFCCNetworkService.h"
+#import "Common.h"
+
+@implementation WFCCGroupMuteNotificationContent
+- (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_MUTE;
+}
+
++ (int)getContentFlags {
+    return WFCCPersistFlag_PERSIST;
+}
+
+
+
++ (void)load {
+    [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
+}
+
+- (NSString *)digest:(WFCCMessage *)message {
+    return [self formatNotification:message];
+}
+
+- (NSString *)formatNotification:(WFCCMessage *)message {
+    if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
+        return [self.type isEqualToString:@"1"] ? @"你开启了全员禁言" : @"你关闭了全员禁言";
+    } 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];
+        } else if(userInfo.groupAlias.length > 0) {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了全员禁言" : @"%@关闭了全员禁言", userInfo.groupAlias];
+        } else if (userInfo.displayName.length > 0) {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了全员禁言" : @"%@关闭了全员禁言", userInfo.displayName];
+        } else {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"用户<%@>开启了全员禁言" : @"用户<%@>关闭了全员禁言", self.creator];
+        }
+    }
+}
+@end

+ 31 - 0
wfclient/WFChatClient/Messages/WFCCGroupPrivateChatNotificationContent.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 WFCCGroupPrivateChatNotificationContent : WFCCNotificationMessageContent
+
+/**
+ 群组ID
+ */
+@property (nonatomic, strong)NSString *groupId;
+
+/**
+ 创建者ID
+ */
+@property (nonatomic, strong)NSString *creator;
+
+/**
+ 操作
+ */
+@property (nonatomic, strong)NSString *type;
+
+@end

+ 84 - 0
wfclient/WFChatClient/Messages/WFCCGroupPrivateChatNotificationContent.m

@@ -0,0 +1,84 @@
+//
+//  WFCCCreateGroupNotificationContent.m
+//  WFChatClient
+//
+//  Created by heavyrain on 2017/9/19.
+//  Copyright © 2017年 WildFireChat. All rights reserved.
+//
+
+#import "WFCCGroupPrivateChatNotificationContent.h"
+#import "WFCCIMService.h"
+#import "WFCCNetworkService.h"
+#import "Common.h"
+
+@implementation WFCCGroupPrivateChatNotificationContent
+- (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_PRIVATECHAT;
+}
+
++ (int)getContentFlags {
+    return WFCCPersistFlag_PERSIST;
+}
+
+
+
++ (void)load {
+    [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
+}
+
+- (NSString *)digest:(WFCCMessage *)message {
+    return [self formatNotification:message];
+}
+
+- (NSString *)formatNotification:(WFCCMessage *)message {
+    if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
+        return [self.type isEqualToString:@"1"] ? @"你开启了成员私聊" : @"你关闭了成员私聊";
+    } 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];
+        } else if(userInfo.groupAlias.length > 0) {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.groupAlias];
+        } else if (userInfo.displayName.length > 0) {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"%@开启了成员私聊" : @"%@关闭了成员私聊", userInfo.displayName];
+        } else {
+            return [NSString stringWithFormat:[self.type isEqualToString:@"1"] ? @"用户<%@>开启了成员私聊" : @"用户<%@>关闭了成员私聊", self.creator];
+        }
+    }
+}
+@end

+ 35 - 0
wfclient/WFChatClient/Messages/WFCCGroupSetManagerNotificationContent.h

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

+ 119 - 0
wfclient/WFChatClient/Messages/WFCCGroupSetManagerNotificationContent.m

@@ -0,0 +1,119 @@
+//
+//  WFCCCreateGroupNotificationContent.m
+//  WFChatClient
+//
+//  Created by heavyrain on 2017/9/19.
+//  Copyright © 2017年 WildFireChat. All rights reserved.
+//
+
+#import "WFCCGroupSetManagerNotificationContent.h"
+#import "WFCCIMService.h"
+#import "WFCCNetworkService.h"
+#import "Common.h"
+
+@implementation WFCCGroupSetManagerNotificationContent
+- (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"];
+    }
+    
+    if (self.memberIds) {
+        [dataDict setObject:self.memberIds forKey:@"ms"];
+    }
+    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"];
+        self.memberIds = dictionary[@"ms"];
+    }
+}
+
++ (int)getContentType {
+    return MESSAGE_CONTENT_TYPE_SET_MANAGER;
+}
+
++ (int)getContentFlags {
+    return WFCCPersistFlag_PERSIST;
+}
+
+
+
++ (void)load {
+    [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
+}
+
+- (NSString *)digest:(WFCCMessage *)message {
+    return [self formatNotification:message];
+}
+
+- (NSString *)formatNotification:(WFCCMessage *)message {
+    NSString *from;
+    NSString *targets;
+    if ([[WFCCNetworkService sharedInstance].userId isEqualToString:self.creator]) {
+        from = @"你";
+    } else {
+        WFCCUserInfo *fromUserInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.creator inGroup:self.groupId refresh:NO];
+        if (fromUserInfo.friendAlias.length > 0) {
+            from = fromUserInfo.friendAlias;
+        } else if(fromUserInfo.groupAlias.length > 0) {
+            from = fromUserInfo.groupAlias;
+        } else if (fromUserInfo.displayName.length > 0) {
+            from = fromUserInfo.displayName;
+        } else {
+            from = [NSString stringWithFormat:@"用户<%@>", self.creator];
+        }
+    }
+    
+    for (NSString *memberId in self.memberIds) {
+        NSString *target;
+        if ([[WFCCNetworkService sharedInstance].userId isEqualToString:memberId]) {
+            target = @"你";
+        } else {
+            WFCCUserInfo *memberUserInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:memberId inGroup:self.groupId refresh:NO];
+            if (memberUserInfo.friendAlias.length > 0) {
+                target = memberUserInfo.friendAlias;
+            } else if(memberUserInfo.groupAlias.length > 0) {
+                target = memberUserInfo.groupAlias;
+            } else if (memberUserInfo.displayName.length > 0) {
+                target = memberUserInfo.displayName;
+            } else {
+                target = [NSString stringWithFormat:@"用户<%@>", memberId];
+            }
+        }
+        if (!targets) {
+            targets = target;
+        } else {
+            targets = [NSString stringWithFormat:@"%@,%@", targets, target];
+        }
+    }
+    
+    if ([self.type isEqualToString:@"1"]) {
+        return [NSString stringWithFormat:@"%@ 设置 %@ 为管理员", from, targets];
+    } else {
+        return [NSString stringWithFormat:@"%@ 取消 %@ 管理员权限", from, targets];
+    }
+}
+@end

+ 19 - 0
wfclient/WFChatClient/Model/WFCCGroupInfo.h

@@ -61,4 +61,23 @@ typedef NS_ENUM(NSInteger, WFCCGroupType) {
  */
 @property (nonatomic, strong)NSData *extra;
 
+/**
+ 群禁言状态,0 关闭群禁言;1 开启群禁言
+ */
+@property (nonatomic, assign)int mute;
+
+/**
+ 加群申请状态,0 无需验证;1 需要验证
+ */
+@property (nonatomic, assign)int joinType;
+
+/**
+ 群成员私聊状态,0 允许私聊;1 不允许私聊
+ */
+@property (nonatomic, assign)int privateChat;
+
+/**
+ 群搜索状态,0 群可以被搜索到;1 群不会被搜索到
+ */
+@property (nonatomic, assign)int searchable;
 @end

+ 3 - 0
wfclient/WFChatClient/Proto/mars.framework/Headers/proto/MessageDB.h

@@ -70,6 +70,7 @@ namespace mars {
             
             TUnreadCount GetUnreadCount(const std::list<int> &conversationTypes, const std::list<int> lines);
             bool ClearUnreadStatus(int conversationType, const std::string &target, int line);
+            bool ClearUnreadStatus(const std::list<int> &conversationTypes, const std::list<int> lines);
             bool ClearAllUnreadStatus();
             
             bool FailSendingMessages();
@@ -111,6 +112,8 @@ namespace mars {
             
             long InsertFriendOrReplace(const std::string &friendUid, int state, int64_t timestamp, const std::string &alias);
             
+            bool DeleteFriend(const std::string &friendUid);
+            
             int unreadFriendRequest();
             void clearUnreadFriendRequestStatus();
             int getMessageFlag(int type);

+ 14 - 1
wfclient/WFChatClient/Proto/mars.framework/Headers/proto/proto.h

@@ -34,6 +34,13 @@
 #define MESSAGE_CONTENT_TYPE_MODIFY_GROUP_ALIAS 111
 #define MESSAGE_CONTENT_TYPE_CHANGE_GROUP_PORTRAIT 112
 
+#define MESSAGE_CONTENT_TYPE_CHANGE_MUTE 113
+#define MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE 114
+#define MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT 115
+#define MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE 116
+
+
+
 #if WFCHAT_PROTO_SERIALIZABLE
 #include "rapidjson/rapidjson.h"
 #include "rapidjson/writer.h"
@@ -125,7 +132,7 @@ namespace mars{
         
         class TGroupInfo : public TSerializable {
         public:
-            TGroupInfo() : target(""), type(0), memberCount(0), updateDt(0) {}
+            TGroupInfo() : target(""), type(0), memberCount(0), updateDt(0), mute(0), joinType(0), privateChat(0), searchable(0) {}
             std::string target;
             std::string name;
             std::string portrait;
@@ -134,6 +141,10 @@ namespace mars{
             int memberCount;
             std::string extra;
             int64_t updateDt;
+            int mute;
+            int joinType;
+            int privateChat;
+            int searchable;
             virtual ~TGroupInfo() {}
 #if WFCHAT_PROTO_SERIALIZABLE
             virtual void Serialize(void *writer) const;
@@ -652,6 +663,8 @@ namespace mars{
         
         extern void (*transferGroup)(const std::string &groupId, const std::string &newOwner, const std::list<int> &notifyLines, TMessageContent &content, GeneralOperationCallback *callback);
         
+        extern void SetGroupManager(const std::string &groupId, const std::list<std::string> userIds, int setOrDelete, const std::list<int> &notifyLines, TMessageContent &content, GeneralOperationCallback *callback);
+        
         extern void (*getUserInfo)(const std::list<std::pair<std::string, int64_t>> &userReqList, GetUserInfoCallback *callback);
         
         extern void reloadGroupInfoFromRemote(const std::list<std::pair<std::string, int64_t>> &groupReqList);

+ 44 - 13
wfuikit/WFChatUIKit/ConversationSetting/ViewController/GroupManageTableViewController.m

@@ -32,7 +32,9 @@
     
     [self.view addSubview:self.tableView];
 }
-
+- (BOOL)isGroupOwner {
+    return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
+}
 - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
     if (cell == nil) {
@@ -46,9 +48,18 @@
     cell.detailTextLabel.text = nil;
     if (indexPath.section == 0) {
         if (indexPath.row == 0) {
-            cell.textLabel.text = @"管理员";
+            if ([self isGroupOwner]) {
+                cell.textLabel.text = @"管理员";
+            } else {
+                cell.textLabel.text = @"设置禁言";
+            }
+            
         } else if(indexPath.row == 1) {
-            cell.textLabel.text = @"设置禁言";
+            if ([self isGroupOwner]) {
+                cell.textLabel.text = @"设置禁言";
+            } else {
+                cell.textLabel.text = @"成员权限";
+            }
         } else if(indexPath.row == 2) {
             cell.textLabel.text = @"成员权限";
         }
@@ -67,7 +78,10 @@
 
 - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     if (section == 0) {
-        return 3;//管理员,设置禁言,群成员权限
+        if ([self isGroupOwner]) {
+            return 3; //管理员,设置禁言,群成员权限
+        }
+        return 2;//设置禁言,群成员权限
     } else if(section == 1) {
         return 2;//加群方式,查找权限
     }
@@ -91,20 +105,37 @@
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return 2; //成员管理,加群设置
 }
+- (void)toManagerVC {
+    ManagerTableViewController *mtvc = [[ManagerTableViewController alloc] init];
+    mtvc.groupInfo = self.groupInfo;
+    [self.navigationController pushViewController:mtvc animated:YES];
+}
+- (void)toMuteVC {
+    GroupMuteTableViewController *gmtc = [[GroupMuteTableViewController alloc] init];
+    gmtc.groupInfo = self.groupInfo;
+    [self.navigationController pushViewController:gmtc animated:YES];
+}
+- (void)toMemberControlVC {
+    GroupMemberControlTableViewController *gmcvc = [[GroupMemberControlTableViewController alloc] init];
+    gmcvc.groupInfo = self.groupInfo;
+    [self.navigationController pushViewController:gmcvc animated:YES];
+}
 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     if (indexPath.section == 0) {
         if (indexPath.row == 0) {
-            ManagerTableViewController *mtvc = [[ManagerTableViewController alloc] init];
-            mtvc.groupInfo = self.groupInfo;
-            [self.navigationController pushViewController:mtvc animated:YES];
+            if ([self isGroupOwner]) {
+                [self toManagerVC];
+            } else {
+                [self toMuteVC];
+            }
         } else if(indexPath.row == 1) {
-            GroupMuteTableViewController *gmtc = [[GroupMuteTableViewController alloc] init];
-            gmtc.groupInfo = self.groupInfo;
-            [self.navigationController pushViewController:gmtc animated:YES];
+            if ([self isGroupOwner]) {
+                [self toMuteVC];
+            } else {
+                [self toMemberControlVC];
+            }
         } else if(indexPath.row == 2) {
-            GroupMemberControlTableViewController *gmcvc = [[GroupMemberControlTableViewController alloc] init];
-            gmcvc.groupInfo = self.groupInfo;
-            [self.navigationController pushViewController:gmcvc animated:YES];
+            [self toMemberControlVC];
         }
     } else if(indexPath.section == 1) {
         if (indexPath.row == 0) {

+ 8 - 9
wfuikit/WFChatUIKit/ConversationSetting/ViewController/GroupMemberControlTableViewController.m

@@ -40,24 +40,23 @@
         cell = [[WFCUGeneralTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
     }
     
-    if(indexPath.row == 0) {
-        cell.textLabel.text = @"允许普通群成员邀请好友";
-        cell.onSwitch = ^(BOOL value, void (^onDone)(BOOL success)) {
-            
-        };
-    } else {
+
+        cell.on = !self.groupInfo.privateChat;
         cell.textLabel.text = @"允许普通群成员发起临时会话";
         cell.onSwitch = ^(BOOL value, void (^onDone)(BOOL success)) {
-            
+            [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_PrivateChat newValue:value?@"0":@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
+                onDone(YES);
+            } error:^(int error_code) {
+                onDone(NO);
+            }];
         };
-    }
     
    
     return cell;
 }
 
 - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return 2;
+    return 1;
 }
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

+ 7 - 1
wfuikit/WFChatUIKit/ConversationSetting/ViewController/GroupMuteTableViewController.m

@@ -40,10 +40,16 @@
         cell = [[WFCUGeneralTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
         cell.textLabel.text = @"全员禁言";
         cell.onSwitch = ^(BOOL value, void (^onDone)(BOOL success)) {
-            
+            [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Mute newValue:value?@"1":@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
+                onDone(YES);
+            } error:^(int error_code) {
+                onDone(NO);
+            }];
         };
     }
     
+    cell.on = self.groupInfo.mute;
+    
    
     
     return cell;

+ 5 - 1
wfuikit/WFChatUIKit/ConversationSetting/ViewController/ManagerTableViewController.m

@@ -48,7 +48,11 @@
     pvc.selectContact = YES;
     pvc.multiSelect = YES;
     pvc.selectResult = ^(NSArray<NSString *> *contacts) {
-        
+        [[WFCCIMService sharedWFCIMService] setGroupManager:self.groupInfo.target isSet:YES memberIds:contacts notifyLines:@[@(0)] notifyContent:nil success:^{
+            
+        } error:^(int error_code) {
+            
+        }];
     };
     NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
     NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO];

+ 7 - 1
wfuikit/WFChatUIKit/MessageList/ViewController/WFCUMessageListViewController.m

@@ -26,7 +26,7 @@
 
 #import "WFCUChatInputBar.h"
 
-
+#import "UIView+Toast.h"
 
 #import "WFCUConversationSettingViewController.h"
 #import "SDPhotoBrowser.h"
@@ -987,6 +987,12 @@
 }
 
 - (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;
+        }
+    }
   WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
   vc.userId = model.message.fromUser;
   vc.hidesBottomBarWhenPushed = YES;