1
This commit is contained in:
@@ -41,7 +41,7 @@ typedef NS_ENUM(NSInteger, KBAIReplyFooterState) {
|
||||
@property(nonatomic, assign) NSInteger likeCount;
|
||||
|
||||
/// 是否已点赞
|
||||
@property(nonatomic, assign) BOOL isLiked;
|
||||
@property(nonatomic, assign) BOOL liked;
|
||||
|
||||
/// 创建时间(时间戳)
|
||||
@property(nonatomic, assign) NSTimeInterval createTime;
|
||||
|
||||
@@ -26,11 +26,6 @@
|
||||
return @{@"replies" : [KBAIReplyModel class]};
|
||||
}
|
||||
|
||||
- (void)setLiked:(NSInteger)liked {
|
||||
// 后端返回的是 NSInteger (0/1),转换为 BOOL
|
||||
_isLiked = (liked == 1);
|
||||
}
|
||||
|
||||
- (void)setCreatedAt:(NSString *)createdAt {
|
||||
// 后端返回的是字符串时间,转换为时间戳
|
||||
if (createdAt && createdAt.length > 0) {
|
||||
@@ -44,6 +39,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MJExtension Hook
|
||||
|
||||
/// MJExtension 转换完成后的钩子方法,用于处理空值
|
||||
- (void)mj_didConvertToObjectWithKeyValues:(NSDictionary *)keyValues {
|
||||
// 防止后端返回 null,统一设置空字符串为默认值
|
||||
if (!_commentId) {
|
||||
_commentId = @"";
|
||||
}
|
||||
if (!_userId) {
|
||||
_userId = @"";
|
||||
}
|
||||
if (!_userName) {
|
||||
_userName = @"";
|
||||
}
|
||||
if (!_avatarUrl) {
|
||||
_avatarUrl = @"";
|
||||
}
|
||||
if (!_content) {
|
||||
_content = @"";
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
@@ -133,7 +150,8 @@
|
||||
|
||||
// 内容高度(多行)
|
||||
UIFont *contentFont = [UIFont systemFontOfSize:15];
|
||||
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];
|
||||
|
||||
@@ -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