From cf59f9f2ae59627d2d134202d6e7d636deed9737 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 10 Aug 2020 12:39:22 +0000 Subject: [PATCH] added UserMention and Site views --- lib/client/models/site.dart | 62 +++++++++++++++++++++++ lib/client/models/user.dart | 98 +++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 lib/client/models/site.dart diff --git a/lib/client/models/site.dart b/lib/client/models/site.dart new file mode 100644 index 0000000..edb6721 --- /dev/null +++ b/lib/client/models/site.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; + +part 'site.g.dart'; + +/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/site_view.rs#L31 +@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false) +class SiteView { + final int id; + final String name; + + /// can be null + final String description; + final int creatorId; + final DateTime published; + + /// can be null + final DateTime updated; + final bool enableDownvotes; + final bool openRegistration; + final bool enableNsfw; + + /// can be null + final String icon; + + /// can be null + final String banner; + final String creatorName; + + /// can be null + final String creatorPreferredUsername; + + /// can be null + final String creatorAvatar; + final int numberOfUsers; + final int numberOfPosts; + final int numberOfComments; + final int numberOfCommunities; + + const SiteView({ + this.id, + this.name, + this.description, + this.creatorId, + this.published, + this.updated, + this.enableDownvotes, + this.openRegistration, + this.enableNsfw, + this.icon, + this.banner, + this.creatorName, + this.creatorPreferredUsername, + this.creatorAvatar, + this.numberOfUsers, + this.numberOfPosts, + this.numberOfComments, + this.numberOfCommunities, + }); + + factory SiteView.fromJson(Map json) => + _$SiteViewFromJson(json); +} diff --git a/lib/client/models/user.dart b/lib/client/models/user.dart index 279150c..cb6e954 100644 --- a/lib/client/models/user.dart +++ b/lib/client/models/user.dart @@ -58,6 +58,104 @@ class UserView { this.numberOfComments, this.commentScore, }); + factory UserView.fromJson(Map json) => _$UserViewFromJson(json); } + +/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/user_mention_view.rs#L90 +@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false) +class UserMentionView { + final int id; + final int userMentionId; + final int creatorId; + final String creatorActorId; + final bool creatorLocal; + 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 + final DateTime updated; + final bool deleted; + 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 creatorName; + + /// can be null + final String creatorPreferredUsername; + + /// 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 saved; + final int recipientId; + final String recipientActorId; + final bool recipientLocal; + + const UserMentionView({ + this.id, + this.userMentionId, + this.creatorId, + this.creatorActorId, + this.creatorLocal, + this.postId, + this.postName, + this.parentId, + this.content, + this.removed, + this.read, + this.published, + this.updated, + this.deleted, + this.communityId, + this.communityActorId, + this.communityLocal, + this.communityName, + this.communityIcon, + this.banned, + this.bannedFromCommunity, + this.creatorName, + this.creatorPreferredUsername, + this.creatorAvatar, + this.score, + this.upvotes, + this.downvotes, + this.hotRank, + this.hotRankActive, + this.userId, + this.myVote, + this.saved, + this.recipientId, + this.recipientActorId, + this.recipientLocal, + }); + + factory UserMentionView.fromJson(Map json) => + _$UserMentionViewFromJson(json); +}