This commit is contained in:
2026-01-28 13:43:36 +08:00
parent 51b744ecd7
commit 7d583ceb1d
14 changed files with 152 additions and 36 deletions

View File

@@ -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;

View File

@@ -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];

View File

@@ -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];