71 lines
2.1 KiB
Objective-C
71 lines
2.1 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];
|
||
//#if DEBUG
|
||
// model.url = @"/guildMember/quitAudit?uid\\u003d3456\\u0026";
|
||
//#endif
|
||
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;
|
||
//#if DEBUG
|
||
// contentHeight = 150;
|
||
// self.layoutType = 2;
|
||
//#endif
|
||
CGFloat buttonHeight = self.layoutType == 0 ? 0 : 40;
|
||
self.height = titleHeight + contentHeight + buttonHeight + 20;
|
||
|
||
// TODO: 補充富文本格式 | 補充 API call 邏輯
|
||
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (NSString *)cellContent:(MessageBaseModel *)model {
|
||
return @"AgentMessageTableViewCell";
|
||
}
|
||
|
||
@end
|