61 lines
1.9 KiB
Objective-C
61 lines
1.9 KiB
Objective-C
//
|
|
// AgentMessageModel.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2025/2/20.
|
|
//
|
|
|
|
#import "AgentMessageModel.h"
|
|
#import "AttachmentModel.h"
|
|
|
|
@implementation AgentTextStyleMessageModel
|
|
|
|
@end
|
|
|
|
|
|
@implementation AgentMessageModel
|
|
|
|
- (instancetype)initWithMessage:(NIMMessage *)message {
|
|
if (self = [super init]) {
|
|
self.message = message;
|
|
self.isHiddenAvatar = NO;
|
|
self.messageType = SessionMessageType_Custom;
|
|
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
|
|
NSDictionary *data = attachment.data;
|
|
if (data) {
|
|
AgentMessageModel *model = [AgentMessageModel modelWithJSON:data];
|
|
self.url = model.url;
|
|
self.title = model.title;
|
|
self.content = model.content;
|
|
self.titleFontSize = model.titleFontSize;
|
|
self.contentSize = model.contentSize;
|
|
self.layoutType = model.layoutType;
|
|
self.titleStyles = model.titleStyles;
|
|
self.contentStyles = model.contentStyles;
|
|
}
|
|
|
|
|
|
CGSize maxSize = CGSizeMake(260, CGFLOAT_MAX);
|
|
|
|
// 使用 NSString 的 boundingRectWithSize 方法来计算高度
|
|
CGRect textRect = [self.content boundingRectWithSize:maxSize
|
|
options:NSStringDrawingUsesLineFragmentOrigin
|
|
attributes:@{NSFontAttributeName: kFontRegular(14)}
|
|
context:nil];
|
|
|
|
CGFloat titleHeight = 30;
|
|
CGFloat contentHeight = textRect.size.height;
|
|
CGFloat buttonHeight = self.layoutType == 0 ? 0 : 40;
|
|
self.height = titleHeight + contentHeight + buttonHeight + 20;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSString *)cellContent:(MessageBaseModel *)model {
|
|
return @"AgentMessageTableViewCell";
|
|
}
|
|
|
|
@end
|