Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,14 @@
//
// NTESCellLayoutConfig.h
// NIM
//
// Created by amao on 2016/11/22.
// Copyright © 2016年 Netease. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "NIMKit.h"
@interface NTESCellLayoutConfig : NIMCellLayoutConfig<NIMCellLayoutConfig>
@end
@@ -0,0 +1,218 @@
//
// NTESCellLayoutConfig.m
// NIM
//
// Created by amao on 2016/11/22.
// Copyright © 2016年 Netease. All rights reserved.
//
#import "NTESCellLayoutConfig.h"
#import "NTESSessionCustomContentConfig.h"
#import "NTESChatroomTextContentConfig.h"
#import "NTESWhiteboardAttachment.h"
@interface NTESCellLayoutConfig ()
@property (nonatomic,strong) NSArray *types;
@property (nonatomic,strong) NTESSessionCustomContentConfig *sessionCustomconfig;
@property (nonatomic,strong) NTESChatroomTextContentConfig *chatroomTextConfig;
@end
@implementation NTESCellLayoutConfig
- (instancetype)init
{
if (self = [super init])
{
_types = @[
@"NTESJanKenPonAttachment",
@"NTESSnapchatAttachment",
@"NTESChartletAttachment",
@"NTESWhiteboardAttachment"
];
_sessionCustomconfig = [[NTESSessionCustomContentConfig alloc] init];
_chatroomTextConfig = [[NTESChatroomTextContentConfig alloc] init];
}
return self;
}
#pragma mark - NIMCellLayoutConfig
- (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
NIMMessage *message = model.message;
//检查是不是当前支持的自定义消息类型
if ([self isSupportedCustomMessage:message]) {
return [_sessionCustomconfig contentSize:width message:message];
}
//检查是不是聊天室文本消息
if ([self isChatroomTextMessage:message]) {
return [_chatroomTextConfig contentSize:width message:message];
}
//如果没有特殊需求,就走默认处理流程
return [super contentSize:model
cellWidth:width];
}
- (NSString *)cellContent:(NIMMessageModel *)model{
NIMMessage *message = model.message;
//检查是不是当前支持的自定义消息类型
if ([self isSupportedCustomMessage:message]) {
return [_sessionCustomconfig cellContent:message];
}
//检查是不是聊天室文本消息
if ([self isChatroomTextMessage:message]) {
return [_chatroomTextConfig cellContent:message];
}
//如果没有特殊需求,就走默认处理流程
return [super cellContent:model];
}
- (UIEdgeInsets)contentViewInsets:(NIMMessageModel *)model
{
NIMMessage *message = model.message;
//检查是不是当前支持的自定义消息类型
if ([self isSupportedCustomMessage:message]) {
return [_sessionCustomconfig contentViewInsets:message];
}
//检查是不是聊天室文本消息
if ([self isChatroomTextMessage:message]) {
return [_chatroomTextConfig contentViewInsets:message];
}
//如果没有特殊需求,就走默认处理流程
return [super contentViewInsets:model];
}
- (UIEdgeInsets)cellInsets:(NIMMessageModel *)model
{
NIMMessage *message = model.message;
//检查是不是聊天室消息
if (message.session.sessionType == NIMSessionTypeChatroom) {
return UIEdgeInsetsZero;
}
//如果没有特殊需求,就走默认处理流程
return [super cellInsets:model];
}
- (BOOL)shouldShowAvatar:(NIMMessageModel *)model
{
if ([self isSupportedChatroomMessage:model.message]) {
return NO;
}
if ([self isWhiteboardCloseNotificationMessage:model.message]){
return NO;
}
return [super shouldShowAvatar:model];
}
- (BOOL)shouldShowLeft:(NIMMessageModel *)model{
if ([self isSupportedChatroomMessage:model.message]) {
return YES;
}
return [super shouldShowLeft:model];
}
- (BOOL)shouldShowNickName:(NIMMessageModel *)model{
if ([self isSupportedChatroomMessage:model.message]) {
return YES;
}
return [super shouldShowNickName:model];
}
- (CGFloat)nickNameMargin:(NIMMessageModel *)model{
if ([self isSupportedChatroomMessage:model.message]) {
NSDictionary *ext = model.message.remoteExt;
NIMChatroomMemberType type = [ext[@"type"] integerValue];
switch (type) {
case NIMChatroomMemberTypeManager:
case NIMChatroomMemberTypeCreator:
return 50.f;
default:
break;
}
return 15.f;
}
return [super nickNameMargin:model];
}
- (NSArray *)customViews:(NIMMessageModel *)model
{
if ([self isSupportedChatroomMessage:model.message]) {
NSDictionary *ext = model.message.remoteExt;
NIMChatroomMemberType type = [ext[@"type"] integerValue];
NSString *imageName;
switch (type) {
case NIMChatroomMemberTypeManager:
imageName = @"chatroom_role_manager";
break;
case NIMChatroomMemberTypeCreator:
imageName = @"chatroom_role_master";
break;
default:
break;
}
UIImageView *imageView;
if (imageName.length) {
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
CGFloat leftMargin = 15.f;
CGFloat topMatgin = 0.f;
CGRect frame = imageView.frame;
frame.origin = CGPointMake(leftMargin, topMatgin);
imageView.frame = frame;
}
return imageView ? @[imageView] : nil;
}
return [super customViews:model];
}
#pragma mark - misc
- (BOOL)isSupportedCustomMessage:(NIMMessage *)message
{
NIMCustomObject *object = message.messageObject;
return [object isKindOfClass:[NIMCustomObject class]] &&
[_types indexOfObject:NSStringFromClass([object.attachment class])] != NSNotFound;
}
- (BOOL)isSupportedChatroomMessage:(NIMMessage *)message
{
return message.session.sessionType == NIMSessionTypeChatroom &&
(message.messageType == NIMMessageTypeText || [self isSupportedCustomMessage:message]);
}
- (BOOL)isChatroomTextMessage:(NIMMessage *)message
{
return message.session.sessionType == NIMSessionTypeChatroom &&
message.messageObject == NIMMessageTypeText;
}
- (BOOL)isWhiteboardCloseNotificationMessage:(NIMMessage *)message
{
if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *object = message.messageObject;
if ([object.attachment isKindOfClass:[NTESWhiteboardAttachment class]]) {
return [(NTESWhiteboardAttachment *)object.attachment flag] == CustomWhiteboardFlagClose;
}
}
return NO;
}
@end
@@ -0,0 +1,14 @@
//
// NTESChatroomTextContentConfig.h
// NIM
//
// Created by chris on 16/1/13.
// Copyright © 2016年 Netease. All rights reserved.
//
#import "NIMBaseSessionContentConfig.h"
@interface NTESChatroomTextContentConfig : NSObject<NIMSessionContentConfig>
@end
@@ -0,0 +1,59 @@
//
// NTESChatroomTextContentConfig.m
// NIM
//
// Created by chris on 16/1/13.
// Copyright © 2016年 Netease. All rights reserved.
//
#import "NTESChatroomTextContentConfig.h"
#import "M80AttributedLabel+NIMKit.h"
#import "NIMGlobalMacro.h"
@interface NTESChatroomTextContentConfig()
@property (nonatomic, strong) M80AttributedLabel *label;
@end
@implementation NTESChatroomTextContentConfig
- (instancetype)init{
self = [super init];
if (self) {
}
return self;
}
- (CGSize)contentSize:(CGFloat)cellWidth message:(NIMMessage *)message
{
NSString *text = message.text;
[self.label nim_setText:text];
CGFloat msgBubbleMaxWidth = (cellWidth - 130);
CGFloat bubbleLeftToContent = 15;
CGFloat contentRightToBubble = 0;
CGFloat msgContentMaxWidth = (msgBubbleMaxWidth - contentRightToBubble - bubbleLeftToContent);
return [self.label sizeThatFits:CGSizeMake(msgContentMaxWidth, CGFLOAT_MAX)];
}
- (NSString *)cellContent:(NIMMessage *)message
{
return @"NTESChatroomTextContentView";
}
- (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
{
return UIEdgeInsetsMake(20,15,10,0);
}
- (M80AttributedLabel *)label
{
if (!_label) {
_label = [[M80AttributedLabel alloc] initWithFrame:CGRectZero];
_label.font = [UIFont systemFontOfSize:Chatroom_Message_Font_Size];
}
return _label;
}
@end
@@ -0,0 +1,13 @@
//
// NTESSessionCustomContentConfig.h
// NIM
//
// Created by chris on 16/1/14.
// Copyright © 2016年 Netease. All rights reserved.
//
#import "NIMBaseSessionContentConfig.h"
@interface NTESSessionCustomContentConfig : NSObject<NIMSessionContentConfig>
@end
@@ -0,0 +1,43 @@
//
// NTESSessionCustomContentConfig.m
// NIM
//
// Created by chris on 16/1/14.
// Copyright © 2016年 Netease. All rights reserved.
//
#import "NTESSessionCustomContentConfig.h"
#import "NTESCustomAttachmentDefines.h"
@interface NTESSessionCustomContentConfig()
@end
@implementation NTESSessionCustomContentConfig
- (CGSize)contentSize:(CGFloat)cellWidth message:(NIMMessage *)message
{
NIMCustomObject *object = message.messageObject;
NSAssert([object isKindOfClass:[NIMCustomObject class]], @"message must be custom");
id<NTESCustomAttachmentInfo> info = (id<NTESCustomAttachmentInfo>)object.attachment;
return [info contentSize:message cellWidth:cellWidth];
}
- (NSString *)cellContent:(NIMMessage *)message
{
NIMCustomObject *object = message.messageObject;
NSAssert([object isKindOfClass:[NIMCustomObject class]], @"message must be custom");
id<NTESCustomAttachmentInfo> info = (id<NTESCustomAttachmentInfo>)object.attachment;
return [info cellContent:message];
}
- (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
{
NIMCustomObject *object = message.messageObject;
NSAssert([object isKindOfClass:[NIMCustomObject class]], @"message must be custom");
id<NTESCustomAttachmentInfo> info = (id<NTESCustomAttachmentInfo>)object.attachment;
return [info contentViewInsets:message];
}
@end