Files
Hacki/lib/models/comment.dart
Jiaqi Feng 9cefffa518 v0.2.20 (#56)
* bumped version.

* fixed web analyzer.

* improved comments loading mechanism.

* fixed delete all button.

* improved reply box logic.

* improved web analyzer.

* allow users to sort comments.

* fixed styles.

* fixed bugs.

* bumped version.

* fixed comments cubit.

* fixed dead comments.
2022-06-21 02:38:24 -07:00

102 lines
2.3 KiB
Dart

import 'dart:convert';
import 'package:hacki/extensions/extensions.dart';
import 'package:hacki/models/item.dart';
class Comment extends Item {
Comment({
required super.id,
required super.time,
required super.parent,
required super.score,
required super.by,
required super.text,
required super.kids,
required super.dead,
required super.deleted,
required this.level,
}) : super(
descendants: 0,
parts: <int>[],
title: '',
url: '',
type: '',
);
Comment.fromJson(Map<String, dynamic> json, {this.level = 0})
: super(
id: json['id'] as int? ?? 0,
time: json['time'] as int? ?? 0,
by: json['by'] as String? ?? '',
text: json['text'] as String? ?? '',
kids: (json['kids'] as List<dynamic>?)?.cast<int>() ?? <int>[],
parent: json['parent'] as int? ?? 0,
deleted: json['deleted'] as bool? ?? false,
score: json['score'] as int? ?? 0,
descendants: 0,
dead: json['dead'] as bool? ?? false,
parts: <int>[],
title: '',
url: '',
type: '',
);
final int level;
String get postedDate =>
DateTime.fromMillisecondsSinceEpoch(time * 1000).toReadableString();
Comment copyWith({int? level}) {
return Comment(
id: id,
time: time,
parent: parent,
score: score,
by: by,
text: text,
kids: kids,
dead: dead,
deleted: deleted,
level: level ?? this.level,
);
}
Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
'time': time,
'by': by,
'text': text,
'kids': kids,
'parent': parent,
'deleted': deleted,
'dead': dead,
'score': score,
'level': level,
};
@override
String toString() {
final String prettyString =
const JsonEncoder.withIndent(' ').convert(this);
return 'Comment $prettyString';
}
@override
List<Object?> get props => <Object?>[
id,
score,
descendants,
time,
by,
title,
url,
kids,
dead,
parts,
deleted,
parent,
text,
type,
];
}