Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/SesssionModel/AgentMessageModel.m
2025-02-28 19:04:09 +08:00

71 lines
2.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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