68 lines
2.6 KiB
Objective-C
68 lines
2.6 KiB
Objective-C
//
|
|
// MessageTextClickModel.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2023/1/30.
|
|
//
|
|
|
|
#import "MessageTextClickModel.h"
|
|
#import "AttachmentModel.h"
|
|
@implementation MessageTextClickModel
|
|
|
|
- (instancetype)initWithMessage:(NIMMessage *)message {
|
|
if (self = [super initWithMessage:message]) {
|
|
self.messageType = SessionMessageType_Custom;
|
|
|
|
NSString * messageText = message.text;
|
|
if (message.messageType == NIMMessageTypeCustom) {
|
|
NIMCustomObject *obj = (NIMCustomObject *) message.messageObject;
|
|
AttachmentModel *attachment = (AttachmentModel *) obj.attachment;
|
|
if (attachment.first == CustomMessageType_Secretary) {
|
|
if (attachment.second == Custom_Message_Sub_Secretary_Router) {
|
|
messageText = attachment.data[@"msg"];
|
|
self.contentInfo = [ContentSecretaryModel modelWithJSON:attachment.data];
|
|
}
|
|
} else if (attachment.first == CustomMessageType_Car_Notify) {
|
|
if (attachment.second == Custom_Message_Sub_Car_OutDate) {
|
|
messageText = attachment.data[@"msg"];
|
|
self.contentInfo = [ContentSecretaryModel modelWithJSON:attachment.data];
|
|
self.contentInfo.routerType = SecretaryRouterType_Car;
|
|
}
|
|
}
|
|
}
|
|
if (!messageText) {
|
|
// messageText = YMLocalizedString(@"MessageContentText0");
|
|
messageText = [NSString stringWithFormat:@"%@\n%@",
|
|
YMLocalizedString(@"MessageContentText0"),
|
|
message.rawAttachContent];
|
|
}
|
|
CGSize dstRect = CGSizeMake(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, MAXFLOAT);
|
|
|
|
CGSize msgSize = [messageText boundingRectWithSize:dstRect options:NSStringDrawingUsesLineFragmentOrigin attributes:[self messageTextAttibutes] context:nil].size;
|
|
if(self.contentInfo.routerType > 0){
|
|
msgSize = CGSizeMake(msgSize.width, msgSize.height+35);
|
|
}
|
|
self.attributedText = [[NSAttributedString alloc] initWithString:messageText attributes:[self messageTextAttibutes]];
|
|
self.height = msgSize.height + MESSAGE_PADDING * 2 + CONTENT_PADDING_V_TOTAL;
|
|
self.contentSize = CGSizeMake(msgSize.width + MESSAGE_PADDING * 2, msgSize.height + MESSAGE_PADDING * 2);
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSDictionary<NSAttributedStringKey, id> *)messageTextAttibutes {
|
|
UIFont *font = [UIFont systemFontOfSize:13.f];
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
[paragraphStyle setLineSpacing:2.5];
|
|
return @{
|
|
NSFontAttributeName:font,
|
|
NSParagraphStyleAttributeName: paragraphStyle
|
|
};
|
|
}
|
|
|
|
- (NSString *)cellContent:(MessageBaseModel *)model {
|
|
return @"MessageContentTextClickable";
|
|
}
|
|
|
|
@end
|