添加评论
This commit is contained in:
100
keyBoard/Class/AiTalk/M/KBAICommentModel.m
Normal file
100
keyBoard/Class/AiTalk/M/KBAICommentModel.m
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// KBAICommentModel.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/16.
|
||||
//
|
||||
|
||||
#import "KBAICommentModel.h"
|
||||
#import "KBAIReplyModel.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
|
||||
@implementation KBAICommentModel
|
||||
|
||||
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
|
||||
return @{
|
||||
@"commentId" : @"id",
|
||||
@"userName" : @[ @"userName", @"nickname", @"name" ],
|
||||
@"avatarUrl" : @[ @"avatarUrl", @"avatar" ],
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)mj_objectClassInArray {
|
||||
return @{@"replies" : [KBAIReplyModel class]};
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_displayedReplies = [NSMutableArray array];
|
||||
_isRepliesExpanded = NO;
|
||||
_hasMoreReplies = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setReplies:(NSArray<KBAIReplyModel *> *)replies {
|
||||
_replies = replies;
|
||||
_totalReplyCount = replies.count;
|
||||
_hasMoreReplies = replies.count > 0;
|
||||
}
|
||||
|
||||
- (NSString *)formattedTime {
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.createTime];
|
||||
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date];
|
||||
|
||||
if (interval < 60) {
|
||||
return @"刚刚";
|
||||
} else if (interval < 3600) {
|
||||
return [NSString stringWithFormat:@"%.0f分钟前", interval / 60];
|
||||
} else if (interval < 86400) {
|
||||
return [NSString stringWithFormat:@"%.0f小时前", interval / 3600];
|
||||
} else if (interval < 86400 * 30) {
|
||||
return [NSString stringWithFormat:@"%.0f天前", interval / 86400];
|
||||
} else {
|
||||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||||
formatter.dateFormat = @"MM-dd";
|
||||
return [formatter stringFromDate:date];
|
||||
}
|
||||
}
|
||||
|
||||
- (KBAIReplyFooterState)footerState {
|
||||
// 无二级评论
|
||||
if (self.totalReplyCount == 0) {
|
||||
return KBAIReplyFooterStateHidden;
|
||||
}
|
||||
|
||||
// 未展开(初始状态)
|
||||
if (!self.isRepliesExpanded) {
|
||||
return KBAIReplyFooterStateExpand;
|
||||
}
|
||||
|
||||
// 已展开但还有更多
|
||||
if (self.displayedReplies.count < self.totalReplyCount) {
|
||||
return KBAIReplyFooterStateLoadMore;
|
||||
}
|
||||
|
||||
// 全部展开,显示收起
|
||||
return KBAIReplyFooterStateCollapse;
|
||||
}
|
||||
|
||||
- (void)loadMoreReplies:(NSInteger)count {
|
||||
self.isRepliesExpanded = YES;
|
||||
|
||||
NSInteger currentCount = self.displayedReplies.count;
|
||||
NSInteger endIndex = MIN(currentCount + count, self.replies.count);
|
||||
|
||||
for (NSInteger i = currentCount; i < endIndex; i++) {
|
||||
[self.displayedReplies addObject:self.replies[i]];
|
||||
}
|
||||
|
||||
self.hasMoreReplies = (self.displayedReplies.count < self.totalReplyCount);
|
||||
}
|
||||
|
||||
- (void)collapseReplies {
|
||||
self.isRepliesExpanded = NO;
|
||||
[self.displayedReplies removeAllObjects];
|
||||
self.hasMoreReplies = self.totalReplyCount > 0;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user