// // JXCommentContent.m // AICity // // Created by TogetherWatch on 2025-10-20. // Feature: 010-ui-ios - iOS平台完整功能实现(对标Android) // #import "JXCommentContent.h" @implementation JXCommentContent #pragma mark - 初始化方法 - (instancetype)init { self = [super init]; if (self) { _commentId = 0; _userId = 0; _userName = @""; _userAvatar = @""; _content = @""; _likeCount = 0; _replyCount = 0; _isLiked = NO; _createdAt = 0; _isVerified = NO; } return self; } - (instancetype)initWithDictionary:(NSDictionary *)dict { self = [super init]; if (self) { _commentId = [dict[@"id"] longLongValue]; _userId = [dict[@"userId"] longLongValue]; _userName = dict[@"userName"] ?: @""; _userAvatar = dict[@"userAvatar"] ?: @""; _content = dict[@"content"] ?: @""; _likeCount = [dict[@"likeCount"] longLongValue]; _replyCount = [dict[@"replyCount"] longLongValue]; _reply_count = [dict[@"reply_count"] longLongValue]; _isLiked = [dict[@"isLiked"] boolValue]; _createdAt = [dict[@"createdAt"] longLongValue]; _isVerified = [dict[@"isVerified"] boolValue]; } return self; } + (instancetype)commentWithDictionary:(NSDictionary *)dict { return [[self alloc] initWithDictionary:dict]; } - (NSDictionary *)toDictionary { return @{ @"id": @(self.commentId), @"userId": @(self.userId), @"userName": self.userName, @"userAvatar": self.userAvatar, @"content": self.content, @"likeCount": @(self.likeCount), @"replyCount": @(self.replyCount), @"reply_count": @(self.reply_count), @"isLiked": @(self.isLiked), @"createdAt": @(self.createdAt), @"isVerified": @(self.isVerified) }; } #pragma mark - UI格式化方法 - (NSString *)formattedTime { // 将毫秒时间戳转换为秒 NSTimeInterval timestamp = self.createdAt / 1000.0; NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp]; // 获取当前日期和评论日期的年份 NSCalendar *calendar = [NSCalendar currentCalendar]; NSInteger currentYear = [calendar component:NSCalendarUnitYear fromDate:[NSDate date]]; NSInteger commentYear = [calendar component:NSCalendarUnitYear fromDate:date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; if (currentYear == commentYear) { // 今年内:显示 "月-日" [formatter setDateFormat:@"MM-dd"]; } else { // 非今年:显示 "年-月-日" [formatter setDateFormat:@"yyyy-MM-dd"]; } return [formatter stringFromDate:date]; } - (NSString *)formattedLikeCount { return [self formatCount:self.likeCount]; } - (NSString *)formatCount:(long long)count { if (count >= 10000) { return [NSString stringWithFormat:@"%.1fw", count / 10000.0]; } else if (count >= 1000) { return [NSString stringWithFormat:@"%.1fk", count / 1000.0]; } else { return [NSString stringWithFormat:@"%lld", count]; } } #pragma mark - NSObject - (NSString *)description { return [NSString stringWithFormat:@"", self.commentId, self.userName, self.content, [self formattedTime]]; } @end