1
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
#import "KBAIReplyModel.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
#import "KBAIReplyModel.h"
|
||||
|
||||
|
||||
@implementation KBAIReplyModel
|
||||
@@ -40,6 +39,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MJExtension Hook
|
||||
|
||||
/// MJExtension 转换完成后的钩子方法,用于处理空值
|
||||
- (void)mj_didConvertToObjectWithKeyValues:(NSDictionary *)keyValues {
|
||||
// 防止后端返回 null,统一设置空字符串为默认值
|
||||
if (!_replyId) {
|
||||
_replyId = @"";
|
||||
}
|
||||
if (!_userId) {
|
||||
_userId = @"";
|
||||
}
|
||||
if (!_userName) {
|
||||
_userName = @"";
|
||||
}
|
||||
if (!_avatarUrl) {
|
||||
_avatarUrl = @"";
|
||||
}
|
||||
if (!_content) {
|
||||
_content = @"";
|
||||
}
|
||||
if (!_replyToUserName) {
|
||||
_replyToUserName = @"";
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)formattedTime {
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.createTime];
|
||||
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date];
|
||||
@@ -70,7 +94,7 @@
|
||||
CGFloat contentWidth = maxWidth - 68 - 28 - 8 - 50;
|
||||
|
||||
// 用户名高度(可能包含 "回复 @xxx")
|
||||
NSMutableString *userNameText = [NSMutableString stringWithString:self.userName];
|
||||
NSMutableString *userNameText = [NSMutableString stringWithString:self.userName ?: @""];
|
||||
if (self.replyToUserName.length > 0) {
|
||||
[userNameText appendFormat:@" 回复 @%@", self.replyToUserName];
|
||||
}
|
||||
@@ -83,7 +107,8 @@
|
||||
|
||||
// 内容高度
|
||||
UIFont *contentFont = [UIFont systemFontOfSize:14];
|
||||
CGRect contentRect = [self.content boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
|
||||
NSString *contentText = self.content ?: @"";
|
||||
CGRect contentRect = [contentText boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
|
||||
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
||||
attributes:@{NSFontAttributeName: contentFont}
|
||||
context:nil];
|
||||
|
||||
Reference in New Issue
Block a user