diff --git a/lib/client/models/comment.dart b/lib/client/models/comment.dart new file mode 100644 index 0000000..ab322c6 --- /dev/null +++ b/lib/client/models/comment.dart @@ -0,0 +1,94 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'comment.g.dart'; + +/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/comment_view.rs#L91 +@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false) +class CommentView { + final int id; + final int creatorId; + final int postId; + final String postName; + /// can be null + final int parentId; + final String content; + final bool removed; + final bool read; + final DateTime published; + /// can be null + @JsonKey(fromJson: DateTime.tryParse) + final DateTime updated; + final bool deleted; + final String apId; + final bool local; + final int communityId; + final String communityActorId; + final bool communityLocal; + final String communityName; + /// can be null + final String communityIcon; + final bool banned; + final bool bannedFromCommunity; + final String creatorActorId; + final bool creatorLocal; + final String creatorName; + /// can be null + final String creatorPreferredUsername; + final DateTime creatorPublished; + /// can be null + final String creatorAvatar; + final int score; + final int upvotes; + final int downvotes; + final int hotRank; + final int hotRankActive; + /// can be null + final int userId; + /// can be null + final int myVote; + /// can be null + final bool subscribed; + /// can be null + final bool saved; + + const CommentView({ + this.id, + this.creatorId, + this.postId, + this.postName, + this.parentId, + this.content, + this.removed, + this.read, + this.published, + this.updated, + this.deleted, + this.apId, + this.local, + this.communityId, + this.communityActorId, + this.communityLocal, + this.communityName, + this.communityIcon, + this.banned, + this.bannedFromCommunity, + this.creatorActorId, + this.creatorLocal, + this.creatorName, + this.creatorPreferredUsername, + this.creatorPublished, + this.creatorAvatar, + this.score, + this.upvotes, + this.downvotes, + this.hotRank, + this.hotRankActive, + this.userId, + this.myVote, + this.subscribed, + this.saved, + }); + + factory CommentView.fromJson(Map json) => + _$CommentViewFromJson(json); +} diff --git a/lib/client/models/comment.g.dart b/lib/client/models/comment.g.dart new file mode 100644 index 0000000..93d366e --- /dev/null +++ b/lib/client/models/comment.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'comment.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CommentView _$CommentViewFromJson(Map json) { + return CommentView( + id: json['id'] as int, + creatorId: json['creator_id'] as int, + postId: json['post_id'] as int, + postName: json['post_name'] as String, + parentId: json['parent_id'] as int, + content: json['content'] as String, + removed: json['removed'] as bool, + read: json['read'] as bool, + published: json['published'] == null + ? null + : DateTime.parse(json['published'] as String), + updated: DateTime.tryParse(json['updated'] as String), + deleted: json['deleted'] as bool, + apId: json['ap_id'] as String, + local: json['local'] as bool, + communityId: json['community_id'] as int, + communityActorId: json['community_actor_id'] as String, + communityLocal: json['community_local'] as bool, + communityName: json['community_name'] as String, + communityIcon: json['community_icon'] as String, + banned: json['banned'] as bool, + bannedFromCommunity: json['banned_from_community'] as bool, + creatorActorId: json['creator_actor_id'] as String, + creatorLocal: json['creator_local'] as bool, + creatorName: json['creator_name'] as String, + creatorPreferredUsername: json['creator_preferred_username'] as String, + creatorPublished: json['creator_published'] == null + ? null + : DateTime.parse(json['creator_published'] as String), + creatorAvatar: json['creator_avatar'] as String, + score: json['score'] as int, + upvotes: json['upvotes'] as int, + downvotes: json['downvotes'] as int, + hotRank: json['hot_rank'] as int, + hotRankActive: json['hot_rank_active'] as int, + userId: json['user_id'] as int, + myVote: json['my_vote'] as int, + subscribed: json['subscribed'] as bool, + saved: json['saved'] as bool, + ); +} diff --git a/lib/client/models/post.dart b/lib/client/models/post.dart new file mode 100644 index 0000000..12b860a --- /dev/null +++ b/lib/client/models/post.dart @@ -0,0 +1,122 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'post.g.dart'; + +/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/post_view.rs#L113 +@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false) +class PostView { + final int id; + final String name; + /// can be null + final String url; + /// can be null + final String body; + final int creatorId; + final int communityId; + final bool removed; + final bool locked; + final DateTime published; + /// can be null + @JsonKey(fromJson: DateTime.tryParse) + final DateTime updated; + final bool deleted; + final bool nsfw; + final bool stickied; + /// can be null + final String embedTitle; + /// can be null + final String embedDescription; + /// can be null + final String embedHtml; + /// can be null + final String thumbnailUrl; + final String apId; + final bool local; + final String creatorActorId; + final bool creatorLocal; + final String creatorName; + /// can be null + final String creatorPreferredUsername; + final DateTime creatorPublished; + /// can be null + final String creatorAvatar; + final bool banned; + final bool bannedFromCommunity; + final String communityActorId; + final bool communityLocal; + final String communityName; + /// can be null + final String communityIcon; + final bool communityRemoved; + final bool communityDeleted; + final bool communityNsfw; + final int numberOfComments; + final int score; + final int upvotes; + final int downvotes; + final int hotRank; + final int hotRankActive; + final DateTime newestActivityTime; + /// can be null + final int userId; + /// can be null + final int myVote; + /// can be null + final bool subscribed; + /// can be null + final bool read; + /// can be null + final bool saved; + + const PostView({ + this.id, + this.name, + this.url, + this.body, + this.creatorId, + this.communityId, + this.removed, + this.locked, + this.published, + this.updated, + this.deleted, + this.nsfw, + this.stickied, + this.embedTitle, + this.embedDescription, + this.embedHtml, + this.thumbnailUrl, + this.apId, + this.local, + this.creatorActorId, + this.creatorLocal, + this.creatorName, + this.creatorPreferredUsername, + this.creatorPublished, + this.creatorAvatar, + this.banned, + this.bannedFromCommunity, + this.communityActorId, + this.communityLocal, + this.communityName, + this.communityIcon, + this.communityRemoved, + this.communityDeleted, + this.communityNsfw, + this.numberOfComments, + this.score, + this.upvotes, + this.downvotes, + this.hotRank, + this.hotRankActive, + this.newestActivityTime, + this.userId, + this.myVote, + this.subscribed, + this.read, + this.saved, + }); + + factory PostView.fromJson(Map json) => + _$PostViewFromJson(json); +} diff --git a/lib/client/models/post.g.dart b/lib/client/models/post.g.dart new file mode 100644 index 0000000..6e12e5a --- /dev/null +++ b/lib/client/models/post.g.dart @@ -0,0 +1,64 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'post.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PostView _$PostViewFromJson(Map json) { + return PostView( + id: json['id'] as int, + name: json['name'] as String, + url: json['url'] as String, + body: json['body'] as String, + creatorId: json['creator_id'] as int, + communityId: json['community_id'] as int, + removed: json['removed'] as bool, + locked: json['locked'] as bool, + published: json['published'] == null + ? null + : DateTime.parse(json['published'] as String), + updated: DateTime.tryParse(json['updated'] as String), + deleted: json['deleted'] as bool, + nsfw: json['nsfw'] as bool, + stickied: json['stickied'] as bool, + embedTitle: json['embed_title'] as String, + embedDescription: json['embed_description'] as String, + embedHtml: json['embed_html'] as String, + thumbnailUrl: json['thumbnail_url'] as String, + apId: json['ap_id'] as String, + local: json['local'] as bool, + creatorActorId: json['creator_actor_id'] as String, + creatorLocal: json['creator_local'] as bool, + creatorName: json['creator_name'] as String, + creatorPreferredUsername: json['creator_preferred_username'] as String, + creatorPublished: json['creator_published'] == null + ? null + : DateTime.parse(json['creator_published'] as String), + creatorAvatar: json['creator_avatar'] as String, + banned: json['banned'] as bool, + bannedFromCommunity: json['banned_from_community'] as bool, + communityActorId: json['community_actor_id'] as String, + communityLocal: json['community_local'] as bool, + communityName: json['community_name'] as String, + communityIcon: json['community_icon'] as String, + communityRemoved: json['community_removed'] as bool, + communityDeleted: json['community_deleted'] as bool, + communityNsfw: json['community_nsfw'] as bool, + numberOfComments: json['number_of_comments'] as int, + score: json['score'] as int, + upvotes: json['upvotes'] as int, + downvotes: json['downvotes'] as int, + hotRank: json['hot_rank'] as int, + hotRankActive: json['hot_rank_active'] as int, + newestActivityTime: json['newest_activity_time'] == null + ? null + : DateTime.parse(json['newest_activity_time'] as String), + userId: json['user_id'] as int, + myVote: json['my_vote'] as int, + subscribed: json['subscribed'] as bool, + read: json['read'] as bool, + saved: json['saved'] as bool, + ); +} diff --git a/pubspec.lock b/pubspec.lock index dacbe7b..6dad3fa 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "0.39.14" archive: dependency: transitive description: @@ -29,6 +43,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.2" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.10" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.1" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.0" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.2" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "7.1.0" charcode: dependency: transitive description: @@ -36,6 +106,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.3" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "3.4.0" collection: dependency: transitive description: @@ -57,6 +148,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.4" + csslib: + dependency: transitive + description: + name: csslib + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.2" cupertino_icons: dependency: "direct main" description: @@ -64,6 +162,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.6" effective_dart: dependency: "direct dev" description: @@ -71,6 +176,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.4" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.11" flutter: dependency: "direct main" description: flutter @@ -81,6 +193,41 @@ packages: description: flutter source: sdk version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + html: + dependency: transitive + description: + name: html + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0+3" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" image: dependency: transitive description: @@ -88,6 +235,41 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.12" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.0" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "0.11.4" matcher: dependency: transitive description: @@ -102,6 +284,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.8" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.6+3" + node_interop: + dependency: transitive + description: + name: node_interop + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + node_io: + dependency: transitive + description: + name: node_io + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" path: dependency: transitive description: @@ -109,6 +319,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.4" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" petitparser: dependency: transitive description: @@ -116,6 +333,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" quiver: dependency: transitive description: @@ -123,11 +361,32 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.3" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.7" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.3" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.6" source_span: dependency: transitive description: @@ -149,6 +408,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" string_scanner: dependency: transitive description: @@ -170,6 +436,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.15" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1+2" typed_data: dependency: transitive description: @@ -184,6 +457,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+15" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" xml: dependency: transitive description: @@ -191,5 +478,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.6.1" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" sdks: dart: ">=2.7.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 2b7d01f..dc1e7f1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,6 +21,7 @@ environment: sdk: ">=2.7.0 <3.0.0" dependencies: + json_annotation: ^3.0.1 flutter: sdk: flutter @@ -33,6 +34,8 @@ dev_dependencies: flutter_test: sdk: flutter effective_dart: ^1.0.0 + json_serializable: ^3.3.0 + build_runner: ^1.10.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec