Initial commit
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// CellLayoutConfig.h
|
||||
// DemoApplication
|
||||
//
|
||||
// Created by chris on 15/11/1.
|
||||
// Copyright © 2015年 chris. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "NIMKit.h"
|
||||
|
||||
@interface CellLayoutConfig : NIMCellLayoutConfig<NIMCellLayoutConfig>
|
||||
|
||||
|
||||
@end
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
//
|
||||
// CellLayoutConfig.m
|
||||
// DemoApplication
|
||||
//
|
||||
// Created by chris on 15/11/1.
|
||||
// Copyright © 2015年 chris. All rights reserved.
|
||||
//
|
||||
|
||||
#import "CellLayoutConfig.h"
|
||||
#import "NTESSessionCustomContentConfig.h"
|
||||
#import "NTESChatroomTextContentConfig.h"
|
||||
#import "NTESWhiteboardAttachment.h"
|
||||
|
||||
@interface CellLayoutConfig ()
|
||||
@property (nonatomic,strong) NSArray *types;
|
||||
@property (nonatomic,strong) NTESSessionCustomContentConfig *sessionCustomconfig;
|
||||
@property (nonatomic,strong) NTESChatroomTextContentConfig *chatroomTextConfig;
|
||||
@end
|
||||
|
||||
@implementation CellLayoutConfig
|
||||
|
||||
- (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
|
||||
+14
@@ -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
|
||||
+218
@@ -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
|
||||
+14
@@ -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
|
||||
+59
@@ -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
|
||||
+13
@@ -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
|
||||
+43
@@ -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
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// IfishAttachment.h
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/11.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
//自定义爱鱼奇官方帐号推送消息 在消息扩展中已经做 这个是自定义消息的以后用 可以按需求重新写,下面没用
|
||||
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
@interface IfishAttachment : NSObject<NIMCustomAttachment>
|
||||
|
||||
@property (nonatomic,copy) NSString *pushlink;
|
||||
|
||||
@property (nonatomic,copy) NSString *timestamp;
|
||||
|
||||
@property (nonatomic,copy) NSString *pushType;
|
||||
|
||||
@property (nonatomic,copy) NSString *pushId;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// IfishAttachment.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/11.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IfishAttachment.h"
|
||||
|
||||
@implementation IfishAttachment
|
||||
- (NSString *)encodeAttachment{
|
||||
NSDictionary *dict = @{@"push_link":self.pushlink,@"timestamp":self.timestamp,@"msg_type":self.pushType,@"pushId":self.pushId};
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
|
||||
NSString *encodeString = @"";
|
||||
if (data) {
|
||||
encodeString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
return encodeString;
|
||||
}
|
||||
//其他协议如上传下载托管可根据自己的业务需求选择实现
|
||||
|
||||
|
||||
#pragma mark - Getter
|
||||
- (NSString *)pushTitle{
|
||||
|
||||
if (!_pushlink) {
|
||||
_pushlink = @"";
|
||||
}
|
||||
return _pushlink;
|
||||
}
|
||||
|
||||
- (NSString *)pushContext{
|
||||
|
||||
if (!_timestamp) {
|
||||
_timestamp = @"";
|
||||
}
|
||||
return _timestamp;
|
||||
}
|
||||
|
||||
- (NSString *)pushType{
|
||||
|
||||
if (!_pushType) {
|
||||
_pushType = @"";
|
||||
}
|
||||
return _pushType;
|
||||
}
|
||||
|
||||
- (NSString *)pushId{
|
||||
|
||||
if (!_pushId) {
|
||||
_pushId = @"";
|
||||
}
|
||||
return _pushId;
|
||||
}
|
||||
|
||||
@end
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// IfishPushmassgaeContentView.h
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/12.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NIMSessionMessageContentView.h"
|
||||
//自定义消息用 暂时没用
|
||||
|
||||
@interface IfishPushmassgaeContentView : NIMSessionMessageContentView
|
||||
//消息内容
|
||||
@property (nonatomic,strong) UILabel *messageLabel;
|
||||
|
||||
@end
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// IfishPushmassgaeContentView.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/12.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IfishPushmassgaeContentView.h"
|
||||
#import "IfishAttachment.h"
|
||||
@implementation IfishPushmassgaeContentView
|
||||
|
||||
- (instancetype)initSessionMessageContentView{
|
||||
self = [super initSessionMessageContentView];
|
||||
if (self) {
|
||||
_messageLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_messageLabel.font = [UIFont systemFontOfSize:13.f];
|
||||
[self addSubview:_messageLabel];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refresh:(NIMMessageModel*)data{
|
||||
//务必调用super方法
|
||||
[super refresh:data];
|
||||
|
||||
NIMCustomObject *object = data.message.messageObject;
|
||||
IfishAttachment *attachment = (IfishAttachment *)object.attachment;
|
||||
|
||||
self.messageLabel.text = attachment.pushType;
|
||||
|
||||
|
||||
if (!self.model.message.isOutgoingMsg) {
|
||||
self.messageLabel.textColor = [UIColor blackColor];
|
||||
|
||||
}else{
|
||||
self.messageLabel.textColor = [UIColor whiteColor];
|
||||
|
||||
}
|
||||
|
||||
[_messageLabel sizeToFit];
|
||||
|
||||
}
|
||||
|
||||
- (void)layoutSubviews{
|
||||
|
||||
[super layoutSubviews];
|
||||
CGFloat messageOriginX = 10.f;
|
||||
CGFloat messageOriginY = 10.f;
|
||||
|
||||
CGRect frame = self.messageLabel.frame;
|
||||
frame.origin = CGPointMake(messageOriginX, messageOriginY);
|
||||
self.messageLabel.frame = frame;
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)onTouchUpInside:(id)sender
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// RemoteExtMassageModel.h
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/12.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface RemoteExtMassageModel : NSObject
|
||||
|
||||
@property (nonatomic,copy) NSString *pushlink;
|
||||
|
||||
@property (nonatomic,copy) NSString *timestamp;
|
||||
|
||||
@property (nonatomic,copy) NSString *pushType;
|
||||
|
||||
@property (nonatomic,copy) NSString *pushId;
|
||||
|
||||
@property (nonatomic,copy) NSString *pushTitle;
|
||||
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// RemoteExtMassageModel.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 16/10/12.
|
||||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RemoteExtMassageModel.h"
|
||||
|
||||
@implementation RemoteExtMassageModel
|
||||
|
||||
@end
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SessionConfig.h
|
||||
// DemoApplication
|
||||
//
|
||||
// Created by chris on 15/11/1.
|
||||
// Copyright © 2015年 chris. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "NIMKit.h"
|
||||
#import "NIMSessionConfig.h"
|
||||
|
||||
@interface SessionConfig : NSObject<NIMSessionConfig>
|
||||
|
||||
@property (nonatomic,strong) NIMSession *session;
|
||||
|
||||
@end
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// SessionConfig.m
|
||||
// DemoApplication
|
||||
//
|
||||
// Created by chris on 15/11/1.
|
||||
// Copyright © 2015年 chris. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SessionConfig.h"
|
||||
#import "NIMMediaItem.h"
|
||||
#import "CellLayoutConfig.h"
|
||||
#import "NTESBundleSetting.h"
|
||||
#import "NTESSnapchatAttachment.h"
|
||||
#import "NTESWhiteboardAttachment.h"
|
||||
#import "NTESBundleSetting.h"
|
||||
#import "NIMKitUIConfig.h"
|
||||
|
||||
@implementation SessionConfig
|
||||
|
||||
- (NSArray *)mediaItems
|
||||
{
|
||||
|
||||
NSArray *defaultMediaItems = [NIMKitUIConfig sharedConfig].defaultMediaItems;
|
||||
|
||||
// NIMMediaItem *janKenPon = [NIMMediaItem item:@"onTapMediaItemJanKenPon:"
|
||||
// normalImage:[UIImage imageNamed:@"icon_jankenpon_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"icon_jankenpon_pressed"]
|
||||
// title:@"石头剪刀布"];
|
||||
|
||||
// NIMMediaItem *fileTrans = [NIMMediaItem item:@"onTapMediaItemFileTrans:"
|
||||
// normalImage:[UIImage imageNamed:@"icon_file_trans_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"icon_file_trans_pressed"]
|
||||
// title:@"文件传输"];
|
||||
|
||||
//NIMMediaItem *tip = [NIMMediaItem item:@"onTapMediaItemTip:"
|
||||
// normalImage:[UIImage imageNamed:@"bk_media_tip_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"bk_media_tip_pressed"]
|
||||
// title:@"提醒消息"];
|
||||
|
||||
// NIMMediaItem *audioChat = [NIMMediaItem item:@"onTapMediaItemAudioChat:"
|
||||
// normalImage:[UIImage imageNamed:@"btn_media_telphone_message_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"btn_media_telphone_message_pressed"]
|
||||
// title:@"实时语音"];
|
||||
|
||||
// NIMMediaItem *videoChat = [NIMMediaItem item:@"onTapMediaItemVideoChat:"
|
||||
// normalImage:[UIImage imageNamed:@"btn_bk_media_video_chat_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"btn_bk_media_video_chat_pressed"]
|
||||
// title:@"视频聊天"];
|
||||
|
||||
// NIMMediaItem *snapChat = [NIMMediaItem item:@"onTapMediaItemSnapChat:"
|
||||
// normalImage:[UIImage imageNamed:@"bk_media_snap_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"bk_media_snap_pressed"]
|
||||
// title:@"阅后即焚"];
|
||||
|
||||
//NIMMediaItem *whiteBoard = [NIMMediaItem item:@"onTapMediaItemWhiteBoard:"
|
||||
// normalImage:[UIImage imageNamed:@"btn_whiteboard_invite_normal"]
|
||||
// selectedImage:[UIImage imageNamed:@"btn_whiteboard_invite_pressed"]
|
||||
// title:@"白板"];
|
||||
|
||||
|
||||
// BOOL isMe = _session.sessionType == NIMSessionTypeP2P
|
||||
// && [_session.sessionId isEqualToString:[[NIMSDK sharedSDK].loginManager currentAccount]];
|
||||
// NSArray *items = @[];
|
||||
// if (_session.sessionType != NIMSessionTypeTeam && !isMe)
|
||||
// {
|
||||
// items = @[janKenPon,audioChat,videoChat,fileTrans,snapChat,whiteBoard,tip];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// items = @[janKenPon,fileTrans,tip];
|
||||
// }
|
||||
|
||||
// return [defaultMediaItems arrayByAddingObjectsFromArray:items];
|
||||
|
||||
return defaultMediaItems ;
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)shouldHandleReceipt{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)shouldHandleReceiptForMessage:(NIMMessage *)message
|
||||
{
|
||||
//文字,语音,图片,视频,文件,地址位置和自定义消息都支持已读回执,其他的不支持
|
||||
NIMMessageType type = message.messageType;
|
||||
if (type == NIMMessageTypeCustom) {
|
||||
NIMCustomObject *object = (NIMCustomObject *)message.messageObject;
|
||||
id attachment = object.attachment;
|
||||
|
||||
if ([attachment isKindOfClass:[NTESWhiteboardAttachment class]]) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return type == NIMMessageTypeText ||
|
||||
type == NIMMessageTypeAudio ||
|
||||
type == NIMMessageTypeImage ||
|
||||
type == NIMMessageTypeVideo ||
|
||||
type == NIMMessageTypeFile ||
|
||||
type == NIMMessageTypeLocation ||
|
||||
type == NIMMessageTypeCustom;
|
||||
}
|
||||
|
||||
- (BOOL)disableProximityMonitor{
|
||||
return [[NTESBundleSetting sharedConfig] disableProximityMonitor];
|
||||
}
|
||||
|
||||
- (NIMAudioType)recordType
|
||||
{
|
||||
return [[NTESBundleSetting sharedConfig] usingAmr] ? NIMAudioTypeAMR : NIMAudioTypeAAC;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user