关于sdk:融云-SDK-如何实现群组操作

48次阅读

共计 4018 个字符,预计需要花费 11 分钟才能阅读完成。

背景

在集成融云 SDK 后,须要实现群组操作的音讯告诉。包含:

  • 群创立、销毁告诉
  • 群布告告诉
  • 群人员退出、退出告诉
  • 群昵称批改告诉

融云现有的 SDK 仅提供了 RCGroupNotificationMessage,外部封装了几种简略的类型操作,且扩展性不强,无奈实现现有的操作。

解决方案:

应用自定义音讯从新来构建群组告诉音讯。

参考 sealtlak 中的 RCDGroupNotificationMessage,也是独自对群组操作内容,从新进行了封装解决。

/*!
 群组告诉音讯
 */
@interface RCDGroupNotificationMessage : RCMessageContent
​
// 操作名
@property (nonatomic, copy) NSString *operation;
​
// 操作人
@property (nonatomic, copy) NSString *operatorUserId;
​
// 操作对象
@property (nonatomic, strong) NSArray<NSString *> *targetUserIds;
​
// 内容
@property (nonatomic, copy) NSString *message;
​
// 获取摘要
- (NSString *)getDigest:(NSString *)groupId;
@end

这个类预约义了上面几种操作类型音讯, 具体内容可参考名字定义

extern NSString *const RCDGroupCreate;
extern NSString *const RCDGroupMemberAdd;
extern NSString *const RCDGroupMemberQuit;
extern NSString *const RCDGroupMemberKicked;
extern NSString *const RCDGroupRename;
extern NSString *const RCDGroupBulletin;
extern NSString *const RCDGroupOwnerTransfer;
extern NSString *const RCDGroupDismiss;
extern NSString *const RCDGroupMemberJoin;
extern NSString *const RCDGroupMemberManagerSet;
extern NSString *const RCDGroupMemberManagerRemove;
extern NSString *const RCDGroupMemberProtectionOpen;
extern NSString *const RCDGroupMemberProtectionClose;

.m 的实现还是依照自定义音讯的实现进行解决。惟一有区别的是在获取摘要的办法,在这个办法中对音讯内容进行了解决,依据操作名的不同,来对显示的内容进行各种适配。此处依据依据本人的业务进行批改。


- (NSString *)getDigest:(NSString *)groupId {
​
 NSString *content;
​
 // 获取用户信息
 NSString *operationName = [self getDisplayNames:@[ self.operatorUserId?self.operatorUserId:@""] groupId:groupId];
 NSString *targetNames = [self getDisplayNames:self.targetUserIds groupId:groupId];
​
 // 是否以后用户操作
 BOOL isMeOperate = NO;
 if ([self.operatorUserId isEqualToString:[RCIMClient sharedRCIMClient].currentUserInfo.userId]) {isMeOperate = YES;}
​
 // 判断操作类型
 if ([self.operation isEqualToString:RCDGroupCreate]) {
 content =
 [NSString stringWithFormat:NSLocalizedStringFromTable(isMeOperate ? @"GroupHaveCreated" : @"GroupCreated",
 @"RongCloudKit", nil),
 operationName];
 } else if ([self.operation isEqualToString:RCDGroupMemberAdd]) {if (self.targetUserIds.count == 1 && [self.targetUserIds containsObject:self.operatorUserId]) {
 content = [NSString
 stringWithFormat:NSLocalizedStringFromTable(@"GroupJoin", @"RongCloudKit", nil), operationName];
 } else {
 content = [NSString
 stringWithFormat:NSLocalizedStringFromTable(isMeOperate ? @"GroupHaveInvited" : @"GroupInvited",
 @"RongCloudKit", nil),
 operationName, targetNames];
 }
 } else if ([self.operation isEqualToString:RCDGroupMemberJoin]) {
 content =
 [NSString stringWithFormat:NSLocalizedStringFromTable(@"GroupJoin", @"RongCloudKit", nil), operationName];
 } else if ([self.operation isEqualToString:RCDGroupMemberQuit]) {
 content = [NSString stringWithFormat:NSLocalizedStringFromTable(isMeOperate ? @"GroupHaveQuit" : @"GroupQuit",
 @"RongCloudKit", nil),
 operationName];
 } else if ([self.operation isEqualToString:RCDGroupMemberKicked]) {
 content =
 [NSString stringWithFormat:NSLocalizedStringFromTable(isMeOperate ? @"GroupHaveRemoved" : @"GroupRemoved",
 @"RongCloudKit", nil),
 operationName, targetNames];
 } else if ([self.operation isEqualToString:RCDGroupRename]) {content = [NSString stringWithFormat:NSLocalizedStringFromTable(@"GroupChanged", @"RongCloudKit", nil),
 operationName, self.targetGroupName];
 } else if ([self.operation isEqualToString:RCDGroupDismiss]) {
 content =
 [NSString stringWithFormat:NSLocalizedStringFromTable(isMeOperate ? @"GroupHaveDismiss" : @"GroupDismiss",
 @"RongCloudKit", nil),
 operationName];
 } else if ([self.operation isEqualToString:RCDGroupOwnerTransfer]) {content = [NSString stringWithFormat:RCDLocalizedString(@"GroupHasNewOwner"), targetNames];
 } else if ([self.operation isEqualToString:RCDGroupMemberManagerSet]) {content = [NSString stringWithFormat:RCDLocalizedString(@"GroupSetManagerMessage"), targetNames];
 } else if ([self.operation isEqualToString:RCDGroupMemberProtectionOpen]) {content = RCDLocalizedString(@"openMemberProtection");
 } else if ([self.operation isEqualToString:RCDGroupMemberProtectionClose]) {content = [NSString stringWithFormat:RCDLocalizedString(@"closeMemberProtection"), operationName];
 } else {content = NSLocalizedStringFromTable(@"unknown_message_cell_tip", @"RongCloudKit", nil);
 }
 return content;
}

此外,还有一个获取名称的办法,用来保护用户信息。

- (NSString *)getDisplayNames:(NSArray<NSString *> *)userIds groupId:(NSString *)groupId

正文完
 0