169 lines
6.1 KiB
Objective-C
169 lines
6.1 KiB
Objective-C
//
|
|
// NTESSessionMsgHelper.m
|
|
// NIMDemo
|
|
//
|
|
// Created by ght on 15-1-28.
|
|
// Copyright (c) 2015年 Netease. All rights reserved.
|
|
//
|
|
|
|
#import "NTESSessionMsgConverter.h"
|
|
#import "NTESLocationPoint.h"
|
|
#import "NSString+NTES.h"
|
|
#import "NTESJanKenPonAttachment.h"
|
|
#import "NTESSnapchatAttachment.h"
|
|
#import "NTESChartletAttachment.h"
|
|
#import "NTESWhiteboardAttachment.h"
|
|
|
|
|
|
@implementation NTESSessionMsgConverter
|
|
|
|
|
|
+ (NIMMessage*)msgWithText:(NSString*)text
|
|
{
|
|
NIMMessage *textMessage = [[NIMMessage alloc] init];
|
|
textMessage.text = text;
|
|
return textMessage;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithImage:(UIImage*)image
|
|
{
|
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
|
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
|
|
NIMImageObject * imageObject = [[NIMImageObject alloc] initWithImage:image];
|
|
imageObject.displayName = [NSString stringWithFormat:@"图片发送于%@",dateString];
|
|
NIMImageOption *option = [[NIMImageOption alloc] init];
|
|
option.compressQuality = 0.8;
|
|
imageObject.option = option;
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = imageObject;
|
|
message.apnsContent = @"发来了一张图片";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithAudio:(NSString*)filePath
|
|
{
|
|
NIMAudioObject *audioObject = [[NIMAudioObject alloc] initWithSourcePath:filePath];
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = audioObject;
|
|
message.apnsContent = @"发来了一段语音";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithVideo:(NSString*)filePath
|
|
{
|
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
|
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
|
|
NIMVideoObject *videoObject = [[NIMVideoObject alloc] initWithSourcePath:filePath];
|
|
videoObject.displayName = [NSString stringWithFormat:@"视频发送于%@",dateString];
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = videoObject;
|
|
message.apnsContent = @"发来了一段视频";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithLocation:(NTESLocationPoint*)locationPoint{
|
|
NIMLocationObject *locationObject = [[NIMLocationObject alloc] initWithLatitude:locationPoint.coordinate.latitude
|
|
longitude:locationPoint.coordinate.longitude
|
|
title:locationPoint.title];
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = locationObject;
|
|
message.apnsContent = @"发来了一条位置信息";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithJenKenPon:(NTESJanKenPonAttachment *)attachment
|
|
{
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
|
|
customObject.attachment = attachment;
|
|
message.messageObject = customObject;
|
|
message.apnsContent = @"发来了猜拳信息";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithSnapchatAttachment:(NTESSnapchatAttachment *)attachment
|
|
{
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
|
|
customObject.attachment = attachment;
|
|
message.messageObject = customObject;
|
|
message.apnsContent = @"发来了阅后即焚";
|
|
|
|
NIMMessageSetting *setting = [[NIMMessageSetting alloc] init];
|
|
setting.historyEnabled = NO;
|
|
setting.roamingEnabled = NO;
|
|
setting.syncEnabled = NO;
|
|
message.setting = setting;
|
|
|
|
return message;
|
|
}
|
|
|
|
|
|
+ (NIMMessage*)msgWithFilePath:(NSString*)path{
|
|
NIMFileObject *fileObject = [[NIMFileObject alloc] initWithSourcePath:path];
|
|
NSString *displayName = path.lastPathComponent;
|
|
fileObject.displayName = displayName;
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = fileObject;
|
|
message.apnsContent = @"发来了一个文件";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithFileData:(NSData*)data extension:(NSString*)extension{
|
|
NIMFileObject *fileObject = [[NIMFileObject alloc] initWithData:data extension:extension];
|
|
NSString *displayName;
|
|
if (extension.length) {
|
|
displayName = [NSString stringWithFormat:@"%@.%@",[NSUUID UUID].UUIDString.MD5String,extension];
|
|
}else{
|
|
displayName = [NSString stringWithFormat:@"%@",[NSUUID UUID].UUIDString.MD5String];
|
|
}
|
|
fileObject.displayName = displayName;
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
message.messageObject = fileObject;
|
|
message.apnsContent = @"发来了一个文件";
|
|
return message;
|
|
}
|
|
|
|
|
|
+ (NIMMessage*)msgWithChartletAttachment:(NTESChartletAttachment *)attachment{
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
|
|
customObject.attachment = attachment;
|
|
message.messageObject = customObject;
|
|
message.apnsContent = @"[贴图]";
|
|
return message;
|
|
}
|
|
|
|
+ (NIMMessage*)msgWithWhiteboardAttachment:(NTESWhiteboardAttachment *)attachment
|
|
{
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
|
|
customObject.attachment = attachment;
|
|
message.messageObject = customObject;
|
|
|
|
NIMMessageSetting *setting = [[NIMMessageSetting alloc] init];
|
|
setting.apnsEnabled = NO;
|
|
message.setting = setting;
|
|
|
|
return message;
|
|
}
|
|
|
|
|
|
+ (NIMMessage *)msgWithTip:(NSString *)tip
|
|
{
|
|
NIMMessage *message = [[NIMMessage alloc] init];
|
|
NIMTipObject *tipObject = [[NIMTipObject alloc] init];
|
|
message.messageObject = tipObject;
|
|
message.text = tip;
|
|
NIMMessageSetting *setting = [[NIMMessageSetting alloc] init];
|
|
setting.apnsEnabled = NO;
|
|
setting.shouldBeCounted = NO;
|
|
message.setting = setting;
|
|
return message;
|
|
}
|
|
|
|
|
|
@end
|