89 lines
3.5 KiB
Objective-C
89 lines
3.5 KiB
Objective-C
//
|
||
// NIMMessageUtils.m
|
||
// xplan-ios
|
||
//
|
||
// Created by zu on 2021/11/26.
|
||
//
|
||
|
||
#import "NIMMessageUtils.h"
|
||
#import "AttachmentModel.h"
|
||
#import "UserGameInfoVo.h"
|
||
|
||
@implementation NIMMessageUtils
|
||
|
||
+ (NSString *)messageContent:(NIMMessage*)message {
|
||
NSString *text = @"";
|
||
switch (message.messageType) {
|
||
case NIMMessageTypeText:
|
||
text = message.text;
|
||
break;
|
||
case NIMMessageTypeAudio:
|
||
text = @"[语音]";
|
||
break;
|
||
case NIMMessageTypeImage:
|
||
text = @"[图片]";
|
||
break;
|
||
case NIMMessageTypeVideo:
|
||
text = @"[视频]";
|
||
break;
|
||
case NIMMessageTypeLocation:
|
||
text = @"[位置]";
|
||
break;
|
||
case NIMMessageTypeFile:
|
||
text = @"[文件]";
|
||
break;
|
||
case NIMMessageTypeTip:
|
||
text = message.text;
|
||
break;
|
||
case NIMMessageTypeCustom: {
|
||
NIMCustomObject *obj = (NIMCustomObject *) message.messageObject;
|
||
if (![obj.attachment isKindOfClass:[AttachmentModel class]]) {
|
||
text = @"";
|
||
break;
|
||
}
|
||
AttachmentModel *attachment = (AttachmentModel *) obj.attachment;
|
||
if (attachment.first == CustomMessageType_Secretary) {
|
||
if (attachment.second == Custom_Message_Sub_Secretary_Router) {
|
||
text = attachment.data[@"title"];
|
||
}
|
||
} else if(attachment.first == CustomMessageType_Gift) {
|
||
if (attachment.second == Custom_Message_Sub_Gift_Send) {
|
||
text = @"[礼物]";
|
||
}
|
||
} else if(attachment.first == CustomMessageType_Hall) {
|
||
text = @"[您收到一条公会消息]";
|
||
} else if(attachment.first == CustomMessageType_Member_Online && attachment.second == Custom_Message_Type_Attention_Member_Online) {
|
||
return @"您关注的TA上线了,快去围观吧~~~";
|
||
} else if(attachment.first == CustomMessageType_Application_Share && attachment.second == Custom_Message_Sub_Application_Share_Room) {
|
||
return @"[分享房间]";
|
||
}else if(attachment.first == CustomMessageType_User_UpGrade && (attachment.second == Custom_Message_Sub_User_UpGrade_Charm || attachment.second == Custom_Message_Sub_User_UpGrade_Exper)) {
|
||
return @"[升级消息]";
|
||
} else if(attachment.first == CustomMessageType_Tweet && attachment.second == Custom_Message_Sub_Tweet_News) {
|
||
return @"[推文消息]";
|
||
} else if(attachment.first == CustomMessageType_FindNew && attachment.second == Custom_Message_Find_New_Greet_New_User) {
|
||
NSString * text = attachment.data[@"message"];
|
||
return text.length > 0 ? text : @"[消息]";
|
||
} else if(attachment.first == CustomMessageType_Monents && attachment.second == Custom_Message_Sub_Monents_Share) {
|
||
return @"[分享了一条动态]";
|
||
} else if(attachment.first == CustomMessageType_RedPacket && attachment.second == Custom_Message_Sub_AllDiamandRedPacket) {
|
||
return @"[你收到一个全服红包]";
|
||
}else if(attachment.first == CustomMessageType_Initiat_Invitation && attachment.second == Custom_Message_Sub_Initiat_Invitation_Initiating_User) {
|
||
UserGameInfoVo *gameInfo = [UserGameInfoVo modelWithDictionary:attachment.data];
|
||
return [gameInfo.fromUid isEqualToString:[AccountInfoStorage instance].getUid] ? @"你发送一条开黑邀请":@"你收到一条开黑邀请";
|
||
} else {
|
||
text = @"[消息]";
|
||
}
|
||
if (!text) {
|
||
text = message.text;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
text = @"[未知消息]";
|
||
break;
|
||
}
|
||
return text;
|
||
}
|
||
|
||
@end
|