Merge branch 'http-client' of https://github.com/krawieck/lemmur into http-client
This commit is contained in:
commit
76b5067487
|
@ -1,15 +0,0 @@
|
|||
import 'v1/main.dart';
|
||||
|
||||
export 'v1/main.dart';
|
||||
|
||||
class LemmyAPI {
|
||||
/// host uri of this lemmy instance
|
||||
String host;
|
||||
|
||||
V1 v1;
|
||||
|
||||
/// initialize lemmy api instance
|
||||
LemmyAPI(this.host)
|
||||
: assert(host != null),
|
||||
v1 = V1(host);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
extension OkResponse on http.Response {
|
||||
bool get ok => statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
|
||||
mixin HttpHelper {
|
||||
String host;
|
||||
String extraPath;
|
||||
|
||||
Future<Map<String, dynamic>> get(String path,
|
||||
[Map<String, String> query]) async {
|
||||
var res = await http.get(Uri.https(host, '$extraPath$path', query));
|
||||
|
||||
if (!res.ok) {
|
||||
// failed request, handle here
|
||||
}
|
||||
|
||||
return jsonDecode(res.body);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> post(
|
||||
String path, Map<String, dynamic> body) async {
|
||||
var res = await http.post(
|
||||
Uri.https(host, '$extraPath$path'),
|
||||
body: jsonEncode(body),
|
||||
headers: {HttpHeaders.contentTypeHeader: ContentType.json.mimeType},
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
// failed request, handle here
|
||||
}
|
||||
|
||||
return jsonDecode(res.body);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'captcha.g.dart';
|
||||
|
||||
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-captcha
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class Captcha {
|
||||
final String png;
|
||||
|
||||
/// can be null
|
||||
final String wav;
|
||||
final String uuid;
|
||||
|
||||
const Captcha({
|
||||
/// A Base64 encoded png
|
||||
this.png,
|
||||
|
||||
/// A Base64 encoded wav audio file
|
||||
this.wav,
|
||||
this.uuid,
|
||||
});
|
||||
|
||||
factory Captcha.fromJson(Map<String, dynamic> json) =>
|
||||
_$CaptchaFromJson(json);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'captcha.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Captcha _$CaptchaFromJson(Map<String, dynamic> json) {
|
||||
return Captcha(
|
||||
png: json['png'] as String,
|
||||
wav: json['wav'] as String,
|
||||
uuid: json['uuid'] as String,
|
||||
);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'category.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/category.rs#L10
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class Category {
|
||||
final int id;
|
||||
final String name;
|
||||
|
||||
const Category({
|
||||
this.id,
|
||||
this.name,
|
||||
});
|
||||
|
||||
factory Category.fromJson(Map<String, dynamic> json) =>
|
||||
_$CategoryFromJson(json);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'category.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Category _$CategoryFromJson(Map<String, dynamic> json) {
|
||||
return Category(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
);
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
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
|
||||
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<String, dynamic> json) =>
|
||||
_$CommentViewFromJson(json);
|
||||
}
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/comment_view.rs#L356
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class ReplyView {
|
||||
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
|
||||
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;
|
||||
|
||||
/// can be null
|
||||
final String creatorAvatar;
|
||||
final DateTime creatorPublished;
|
||||
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;
|
||||
final int recipientId;
|
||||
|
||||
const ReplyView({
|
||||
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.creatorAvatar,
|
||||
this.creatorPublished,
|
||||
this.score,
|
||||
this.upvotes,
|
||||
this.downvotes,
|
||||
this.hotRank,
|
||||
this.hotRankActive,
|
||||
this.userId,
|
||||
this.myVote,
|
||||
this.subscribed,
|
||||
this.saved,
|
||||
this.recipientId,
|
||||
});
|
||||
|
||||
factory ReplyView.fromJson(Map<String, dynamic> json) =>
|
||||
_$ReplyViewFromJson(json);
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'comment.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CommentView _$CommentViewFromJson(Map<String, dynamic> 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: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(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,
|
||||
);
|
||||
}
|
||||
|
||||
ReplyView _$ReplyViewFromJson(Map<String, dynamic> json) {
|
||||
return ReplyView(
|
||||
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: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(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,
|
||||
creatorAvatar: json['creator_avatar'] as String,
|
||||
creatorPublished: json['creator_published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['creator_published'] 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,
|
||||
recipientId: json['recipient_id'] as int,
|
||||
);
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'community.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/community_view.rs#L130
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class CommunityView {
|
||||
final int id;
|
||||
final String name;
|
||||
final String title;
|
||||
|
||||
/// can be null
|
||||
final String icon;
|
||||
|
||||
/// can be null
|
||||
final String banner;
|
||||
|
||||
/// can be null
|
||||
final String description;
|
||||
final int categoryId;
|
||||
final int creatorId;
|
||||
final bool removed;
|
||||
final DateTime published;
|
||||
|
||||
/// can be null
|
||||
final DateTime updated;
|
||||
final bool deleted;
|
||||
final bool nsfw;
|
||||
final String actorId;
|
||||
final bool local;
|
||||
final DateTime lastRefreshedAt;
|
||||
final String creatorActorId;
|
||||
final bool creatorLocal;
|
||||
final String creatorName;
|
||||
|
||||
/// can be null
|
||||
final String creatorPreferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String creatorAvatar;
|
||||
final String categoryName;
|
||||
final int numberOfSubscribers;
|
||||
final int numberOfPosts;
|
||||
final int numberOfComments;
|
||||
final int hotRank;
|
||||
|
||||
/// can be null
|
||||
final int userId;
|
||||
|
||||
/// can be null
|
||||
final bool subscribed;
|
||||
|
||||
const CommunityView({
|
||||
this.id,
|
||||
this.name,
|
||||
this.title,
|
||||
this.icon,
|
||||
this.banner,
|
||||
this.description,
|
||||
this.categoryId,
|
||||
this.creatorId,
|
||||
this.removed,
|
||||
this.published,
|
||||
this.updated,
|
||||
this.deleted,
|
||||
this.nsfw,
|
||||
this.actorId,
|
||||
this.local,
|
||||
this.lastRefreshedAt,
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.creatorName,
|
||||
this.creatorPreferredUsername,
|
||||
this.creatorAvatar,
|
||||
this.categoryName,
|
||||
this.numberOfSubscribers,
|
||||
this.numberOfPosts,
|
||||
this.numberOfComments,
|
||||
this.hotRank,
|
||||
this.userId,
|
||||
this.subscribed,
|
||||
});
|
||||
|
||||
factory CommunityView.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommunityViewFromJson(json);
|
||||
}
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/community_view.rs#L336
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class CommunityFollowerView {
|
||||
final int id;
|
||||
final int communityId;
|
||||
final int userId;
|
||||
final DateTime published;
|
||||
final String userActorId;
|
||||
final bool userLocal;
|
||||
final String userName;
|
||||
|
||||
/// can be null
|
||||
final String userPreferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String avatar;
|
||||
final String communityActorId;
|
||||
final bool communityLocal;
|
||||
final String communityName;
|
||||
|
||||
/// can be null
|
||||
final String communityIcon;
|
||||
|
||||
const CommunityFollowerView({
|
||||
this.id,
|
||||
this.communityId,
|
||||
this.userId,
|
||||
this.published,
|
||||
this.userActorId,
|
||||
this.userLocal,
|
||||
this.userName,
|
||||
this.userPreferredUsername,
|
||||
this.avatar,
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName,
|
||||
this.communityIcon,
|
||||
});
|
||||
|
||||
factory CommunityFollowerView.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommunityFollowerViewFromJson(json);
|
||||
}
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/community_view.rs#L298
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class CommunityModeratorView {
|
||||
final int id;
|
||||
final int communityId;
|
||||
final int userId;
|
||||
final DateTime published;
|
||||
final String userActorId;
|
||||
final bool userLocal;
|
||||
final String userName;
|
||||
|
||||
/// can be null
|
||||
final String userPreferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String avatar;
|
||||
final String communityActorId;
|
||||
final bool communityLocal;
|
||||
final String communityName;
|
||||
|
||||
/// can be null
|
||||
final String communityIcon;
|
||||
|
||||
const CommunityModeratorView({
|
||||
this.id,
|
||||
this.communityId,
|
||||
this.userId,
|
||||
this.published,
|
||||
this.userActorId,
|
||||
this.userLocal,
|
||||
this.userName,
|
||||
this.userPreferredUsername,
|
||||
this.avatar,
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName,
|
||||
this.communityIcon,
|
||||
});
|
||||
|
||||
factory CommunityModeratorView.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommunityModeratorViewFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class FullCommunityView {
|
||||
final CommunityView community;
|
||||
final List<CommunityModeratorView> moderators;
|
||||
|
||||
FullCommunityView({this.community, this.moderators});
|
||||
|
||||
factory FullCommunityView.fromJson(Map<String, dynamic> json) =>
|
||||
_$FullCommunityViewFromJson(json);
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'community.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CommunityView _$CommunityViewFromJson(Map<String, dynamic> json) {
|
||||
return CommunityView(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
title: json['title'] as String,
|
||||
icon: json['icon'] as String,
|
||||
banner: json['banner'] as String,
|
||||
description: json['description'] as String,
|
||||
categoryId: json['category_id'] as int,
|
||||
creatorId: json['creator_id'] as int,
|
||||
removed: json['removed'] as bool,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
updated: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
deleted: json['deleted'] as bool,
|
||||
nsfw: json['nsfw'] as bool,
|
||||
actorId: json['actor_id'] as String,
|
||||
local: json['local'] as bool,
|
||||
lastRefreshedAt: json['last_refreshed_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['last_refreshed_at'] as String),
|
||||
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,
|
||||
creatorAvatar: json['creator_avatar'] as String,
|
||||
categoryName: json['category_name'] as String,
|
||||
numberOfSubscribers: json['number_of_subscribers'] as int,
|
||||
numberOfPosts: json['number_of_posts'] as int,
|
||||
numberOfComments: json['number_of_comments'] as int,
|
||||
hotRank: json['hot_rank'] as int,
|
||||
userId: json['user_id'] as int,
|
||||
subscribed: json['subscribed'] as bool,
|
||||
);
|
||||
}
|
||||
|
||||
CommunityFollowerView _$CommunityFollowerViewFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return CommunityFollowerView(
|
||||
id: json['id'] as int,
|
||||
communityId: json['community_id'] as int,
|
||||
userId: json['user_id'] as int,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
userActorId: json['user_actor_id'] as String,
|
||||
userLocal: json['user_local'] as bool,
|
||||
userName: json['user_name'] as String,
|
||||
userPreferredUsername: json['user_preferred_username'] as String,
|
||||
avatar: json['avatar'] as String,
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
CommunityModeratorView _$CommunityModeratorViewFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return CommunityModeratorView(
|
||||
id: json['id'] as int,
|
||||
communityId: json['community_id'] as int,
|
||||
userId: json['user_id'] as int,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
userActorId: json['user_actor_id'] as String,
|
||||
userLocal: json['user_local'] as bool,
|
||||
userName: json['user_name'] as String,
|
||||
userPreferredUsername: json['user_preferred_username'] as String,
|
||||
avatar: json['avatar'] as String,
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
FullCommunityView _$FullCommunityViewFromJson(Map<String, dynamic> json) {
|
||||
return FullCommunityView(
|
||||
community: json['community'] == null
|
||||
? null
|
||||
: CommunityView.fromJson(json['community'] as Map<String, dynamic>),
|
||||
moderators: (json['moderators'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: CommunityModeratorView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
);
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import './comment.dart';
|
||||
import './community.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
|
||||
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<String, dynamic> json) =>
|
||||
_$PostViewFromJson(json);
|
||||
}
|
||||
|
||||
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-post
|
||||
@JsonSerializable(createToJson: false)
|
||||
class FullPost {
|
||||
final PostView post;
|
||||
final List<CommentView> comments;
|
||||
final CommunityView community;
|
||||
final List<CommunityModeratorView> moderators;
|
||||
|
||||
const FullPost({
|
||||
this.post,
|
||||
this.comments,
|
||||
this.community,
|
||||
this.moderators,
|
||||
});
|
||||
|
||||
factory FullPost.fromJson(Map<String, dynamic> json) =>
|
||||
_$FullPostFromJson(json);
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'post.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
PostView _$PostViewFromJson(Map<String, dynamic> 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: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(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,
|
||||
);
|
||||
}
|
||||
|
||||
FullPost _$FullPostFromJson(Map<String, dynamic> json) {
|
||||
return FullPost(
|
||||
post: json['post'] == null
|
||||
? null
|
||||
: PostView.fromJson(json['post'] as Map<String, dynamic>),
|
||||
comments: (json['comments'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : CommentView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
community: json['community'] == null
|
||||
? null
|
||||
: CommunityView.fromJson(json['community'] as Map<String, dynamic>),
|
||||
moderators: (json['moderators'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: CommunityModeratorView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'private_message.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/private_message_view.rs#L35
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class PrivateMessageView {
|
||||
final int id;
|
||||
final int creatorId;
|
||||
final int recipientId;
|
||||
final String content;
|
||||
final bool deleted;
|
||||
final bool read;
|
||||
final DateTime published;
|
||||
|
||||
/// can be null
|
||||
final DateTime updated;
|
||||
final String apId;
|
||||
final bool local;
|
||||
final String creatorName;
|
||||
|
||||
/// can be null
|
||||
final String creatorPreferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String creatorAvatar;
|
||||
final String creatorActorId;
|
||||
final bool creatorLocal;
|
||||
final String recipientName;
|
||||
|
||||
/// can be null
|
||||
final String recipientPreferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String recipientAvatar;
|
||||
final String recipientActorId;
|
||||
final bool recipientLocal;
|
||||
|
||||
const PrivateMessageView({
|
||||
this.id,
|
||||
this.creatorId,
|
||||
this.recipientId,
|
||||
this.content,
|
||||
this.deleted,
|
||||
this.read,
|
||||
this.published,
|
||||
this.updated,
|
||||
this.apId,
|
||||
this.local,
|
||||
this.creatorName,
|
||||
this.creatorPreferredUsername,
|
||||
this.creatorAvatar,
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.recipientName,
|
||||
this.recipientPreferredUsername,
|
||||
this.recipientAvatar,
|
||||
this.recipientActorId,
|
||||
this.recipientLocal,
|
||||
});
|
||||
|
||||
factory PrivateMessageView.fromJson(Map<String, dynamic> json) =>
|
||||
_$PrivateMessageViewFromJson(json);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'private_message.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
PrivateMessageView _$PrivateMessageViewFromJson(Map<String, dynamic> json) {
|
||||
return PrivateMessageView(
|
||||
id: json['id'] as int,
|
||||
creatorId: json['creator_id'] as int,
|
||||
recipientId: json['recipient_id'] as int,
|
||||
content: json['content'] as String,
|
||||
deleted: json['deleted'] as bool,
|
||||
read: json['read'] as bool,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
updated: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
apId: json['ap_id'] as String,
|
||||
local: json['local'] as bool,
|
||||
creatorName: json['creator_name'] as String,
|
||||
creatorPreferredUsername: json['creator_preferred_username'] as String,
|
||||
creatorAvatar: json['creator_avatar'] as String,
|
||||
creatorActorId: json['creator_actor_id'] as String,
|
||||
creatorLocal: json['creator_local'] as bool,
|
||||
recipientName: json['recipient_name'] as String,
|
||||
recipientPreferredUsername: json['recipient_preferred_username'] as String,
|
||||
recipientAvatar: json['recipient_avatar'] as String,
|
||||
recipientActorId: json['recipient_actor_id'] as String,
|
||||
recipientLocal: json['recipient_local'] as bool,
|
||||
);
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import './comment.dart';
|
||||
import './community.dart';
|
||||
import './post.dart';
|
||||
import './user.dart';
|
||||
|
||||
part 'search.g.dart';
|
||||
|
||||
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#search
|
||||
@JsonSerializable(createToJson: false)
|
||||
class Search {
|
||||
@JsonKey(name: 'type_')
|
||||
final String type;
|
||||
final List<CommentView> comments;
|
||||
final List<PostView> posts;
|
||||
final List<CommunityView> communities;
|
||||
final List<UserView> users;
|
||||
|
||||
const Search({
|
||||
this.type,
|
||||
this.comments,
|
||||
this.posts,
|
||||
this.communities,
|
||||
this.users,
|
||||
});
|
||||
|
||||
factory Search.fromJson(Map<String, dynamic> json) => _$SearchFromJson(json);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'search.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Search _$SearchFromJson(Map<String, dynamic> json) {
|
||||
return Search(
|
||||
type: json['type_'] as String,
|
||||
comments: (json['comments'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : CommentView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
posts: (json['posts'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : PostView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
communities: (json['communities'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: CommunityView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
users: (json['users'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : UserView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../models/user.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<String, dynamic> json) =>
|
||||
_$SiteViewFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class FullSiteView {
|
||||
/// can be null
|
||||
final SiteView site;
|
||||
final List<UserView> admins;
|
||||
final List<UserView> banned;
|
||||
final int online;
|
||||
final String version;
|
||||
final UserView myUser;
|
||||
|
||||
FullSiteView({
|
||||
this.site,
|
||||
this.admins,
|
||||
this.banned,
|
||||
this.online,
|
||||
this.version,
|
||||
this.myUser,
|
||||
});
|
||||
|
||||
factory FullSiteView.fromJson(Map<String, dynamic> json) =>
|
||||
_$FullSiteViewFromJson(json);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'site.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
SiteView _$SiteViewFromJson(Map<String, dynamic> json) {
|
||||
return SiteView(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
creatorId: json['creator_id'] as int,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
updated: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
enableDownvotes: json['enable_downvotes'] as bool,
|
||||
openRegistration: json['open_registration'] as bool,
|
||||
enableNsfw: json['enable_nsfw'] as bool,
|
||||
icon: json['icon'] as String,
|
||||
banner: json['banner'] as String,
|
||||
creatorName: json['creator_name'] as String,
|
||||
creatorPreferredUsername: json['creator_preferred_username'] as String,
|
||||
creatorAvatar: json['creator_avatar'] as String,
|
||||
numberOfUsers: json['number_of_users'] as int,
|
||||
numberOfPosts: json['number_of_posts'] as int,
|
||||
numberOfComments: json['number_of_comments'] as int,
|
||||
numberOfCommunities: json['number_of_communities'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
FullSiteView _$FullSiteViewFromJson(Map<String, dynamic> json) {
|
||||
return FullSiteView(
|
||||
site: json['site'] == null
|
||||
? null
|
||||
: SiteView.fromJson(json['site'] as Map<String, dynamic>),
|
||||
admins: (json['admins'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : UserView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
banned: (json['banned'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : UserView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
online: json['online'] as int,
|
||||
version: json['version'] as String,
|
||||
myUser: json['my_user'] == null
|
||||
? null
|
||||
: UserView.fromJson(json['my_user'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import './comment.dart';
|
||||
import './community.dart';
|
||||
import './post.dart';
|
||||
|
||||
part 'user.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/user_view.rs#L58
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class UserView {
|
||||
final int id;
|
||||
final String actorId;
|
||||
final String name;
|
||||
|
||||
/// can be null
|
||||
final String preferredUsername;
|
||||
|
||||
/// can be null
|
||||
final String avatar;
|
||||
|
||||
/// can be null
|
||||
final String banner;
|
||||
|
||||
/// can be null
|
||||
final String email;
|
||||
|
||||
/// can be null
|
||||
final String matrixUserId;
|
||||
|
||||
/// can be null
|
||||
final String bio;
|
||||
final bool local;
|
||||
final bool admin;
|
||||
final bool banned;
|
||||
final bool showAvatars;
|
||||
final bool sendNotificationsToEmail;
|
||||
final DateTime published;
|
||||
final int numberOfPosts;
|
||||
final int postScore;
|
||||
final int numberOfComments;
|
||||
final int commentScore;
|
||||
|
||||
const UserView({
|
||||
this.id,
|
||||
this.actorId,
|
||||
this.name,
|
||||
this.preferredUsername,
|
||||
this.avatar,
|
||||
this.banner,
|
||||
this.email,
|
||||
this.matrixUserId,
|
||||
this.bio,
|
||||
this.local,
|
||||
this.admin,
|
||||
this.banned,
|
||||
this.showAvatars,
|
||||
this.sendNotificationsToEmail,
|
||||
this.published,
|
||||
this.numberOfPosts,
|
||||
this.postScore,
|
||||
this.numberOfComments,
|
||||
this.commentScore,
|
||||
});
|
||||
|
||||
factory UserView.fromJson(Map<String, dynamic> 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<String, dynamic> json) =>
|
||||
_$UserMentionViewFromJson(json);
|
||||
}
|
||||
|
||||
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-details
|
||||
@JsonSerializable(createToJson: false)
|
||||
class UserDetails {
|
||||
final UserView user;
|
||||
final List<CommunityFollowerView> follows;
|
||||
final List<CommunityModeratorView> moderates;
|
||||
final List<CommentView> comments;
|
||||
final List<PostView> posts;
|
||||
|
||||
const UserDetails({
|
||||
this.user,
|
||||
this.follows,
|
||||
this.moderates,
|
||||
this.comments,
|
||||
this.posts,
|
||||
});
|
||||
|
||||
factory UserDetails.fromJson(Map<String, dynamic> json) =>
|
||||
_$UserDetailsFromJson(json);
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'user.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UserView _$UserViewFromJson(Map<String, dynamic> json) {
|
||||
return UserView(
|
||||
id: json['id'] as int,
|
||||
actorId: json['actor_id'] as String,
|
||||
name: json['name'] as String,
|
||||
preferredUsername: json['preferred_username'] as String,
|
||||
avatar: json['avatar'] as String,
|
||||
banner: json['banner'] as String,
|
||||
email: json['email'] as String,
|
||||
matrixUserId: json['matrix_user_id'] as String,
|
||||
bio: json['bio'] as String,
|
||||
local: json['local'] as bool,
|
||||
admin: json['admin'] as bool,
|
||||
banned: json['banned'] as bool,
|
||||
showAvatars: json['show_avatars'] as bool,
|
||||
sendNotificationsToEmail: json['send_notifications_to_email'] as bool,
|
||||
published: json['published'] == null
|
||||
? null
|
||||
: DateTime.parse(json['published'] as String),
|
||||
numberOfPosts: json['number_of_posts'] as int,
|
||||
postScore: json['post_score'] as int,
|
||||
numberOfComments: json['number_of_comments'] as int,
|
||||
commentScore: json['comment_score'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
UserMentionView _$UserMentionViewFromJson(Map<String, dynamic> json) {
|
||||
return UserMentionView(
|
||||
id: json['id'] as int,
|
||||
userMentionId: json['user_mention_id'] as int,
|
||||
creatorId: json['creator_id'] as int,
|
||||
creatorActorId: json['creator_actor_id'] as String,
|
||||
creatorLocal: json['creator_local'] as bool,
|
||||
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: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
deleted: json['deleted'] 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,
|
||||
creatorName: json['creator_name'] as String,
|
||||
creatorPreferredUsername: json['creator_preferred_username'] 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,
|
||||
saved: json['saved'] as bool,
|
||||
recipientId: json['recipient_id'] as int,
|
||||
recipientActorId: json['recipient_actor_id'] as String,
|
||||
recipientLocal: json['recipient_local'] as bool,
|
||||
);
|
||||
}
|
||||
|
||||
UserDetails _$UserDetailsFromJson(Map<String, dynamic> json) {
|
||||
return UserDetails(
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: UserView.fromJson(json['user'] as Map<String, dynamic>),
|
||||
follows: (json['follows'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: CommunityFollowerView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
moderates: (json['moderates'] as List)
|
||||
?.map((e) => e == null
|
||||
? null
|
||||
: CommunityModeratorView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
comments: (json['comments'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : CommentView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
posts: (json['posts'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : PostView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
);
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
|
||||
import '../models/comment.dart';
|
||||
import 'main.dart';
|
||||
|
||||
extension CommentEndpoint on V1 {
|
||||
/// POST /comment
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-comment
|
||||
Future<CommentView> createComment({
|
||||
@required String content,
|
||||
int parentId,
|
||||
@required int postId,
|
||||
int formId,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(content != null);
|
||||
assert(postId != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// PUT /comment
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-comment
|
||||
Future<CommentView> editComment({
|
||||
@required String content,
|
||||
@required int editId,
|
||||
String formId,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(content != null);
|
||||
assert(editId != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /comment/delete
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-comment
|
||||
/// Only the creator can delete the comment
|
||||
Future<CommentView> deleteComment({
|
||||
@required int editId,
|
||||
@required bool deleted,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(deleted != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /comment/remove
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#remove-comment
|
||||
/// Only a mod or admin can remove the comment
|
||||
Future<CommentView> removeComment({
|
||||
@required int editId,
|
||||
@required bool removed,
|
||||
String reason,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(removed != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /comment/mark_as_read
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-comment-as-read
|
||||
Future<CommentView> markCommentAsRead({
|
||||
@required int editId,
|
||||
@required bool read,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(read != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /comment/save
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-comment
|
||||
Future<CommentView> saveComment({
|
||||
@required int commentId,
|
||||
@required bool save,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(commentId != null);
|
||||
assert(save != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /comment/like
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-comment-like
|
||||
Future<CommentView> createCommentLike({
|
||||
@required int commentId,
|
||||
@required Vote score,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(commentId != null);
|
||||
assert(score != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
|
||||
import '../models/community.dart';
|
||||
import 'main.dart';
|
||||
|
||||
extension CommunityEndpoint on V1 {
|
||||
/// GET /community
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-community
|
||||
Future<FullCommunityView> getCommunity({
|
||||
int id,
|
||||
String name,
|
||||
String auth,
|
||||
}) async {
|
||||
assert(id != null || name != null);
|
||||
|
||||
var res = await get('/community', {
|
||||
if (id != null) 'id': id.toString(),
|
||||
if (name != null) 'name': name,
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return FullCommunityView.fromJson(res);
|
||||
}
|
||||
|
||||
/// GET /community/list
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#list-communities
|
||||
Future<List<CommunityView>> listCommunities({
|
||||
@required SortType sort,
|
||||
int page,
|
||||
int limit,
|
||||
String auth,
|
||||
}) async {
|
||||
assert(sort != null);
|
||||
|
||||
var res = await get('/community/list', {
|
||||
'sort': sort.value,
|
||||
if (page != null) 'page': page.toString(),
|
||||
if (limit != null) 'limit': limit.toString(),
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
List<dynamic> communities = res['communities'];
|
||||
return communities.map((e) => CommunityView.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
/// POST /community/follow
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#follow-community
|
||||
Future<CommunityView> followCommunity({
|
||||
@required int communityId,
|
||||
@required bool follow,
|
||||
@required String auth,
|
||||
}) async {
|
||||
var res = await post('/community/follow', {
|
||||
if (communityId != null) 'community_id': communityId,
|
||||
if (follow != null) 'follow': follow,
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return CommunityView.fromJson(res['community']);
|
||||
}
|
||||
|
||||
/// GET /user/followed_communities
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-followed-communities
|
||||
Future<List<CommunityFollowerView>> getFollowedCommunities({
|
||||
@required String auth,
|
||||
}) async {
|
||||
final res = await get('/user/followed_communities', {
|
||||
'auth': auth,
|
||||
});
|
||||
final List<dynamic> communities = res['communities'];
|
||||
|
||||
return communities.map((e) => CommunityFollowerView.fromJson(e)).toList();
|
||||
}
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
|
||||
import '../http_helper.dart';
|
||||
import '../models/category.dart';
|
||||
import '../models/search.dart';
|
||||
|
||||
export 'comment_endpoint.dart';
|
||||
export 'community_endpoint.dart';
|
||||
export 'post_endpoint.dart';
|
||||
export 'site_endpoint.dart';
|
||||
export 'user_endpoint.dart';
|
||||
|
||||
class V1 with HttpHelper {
|
||||
@override
|
||||
final String host;
|
||||
@override
|
||||
final String extraPath = '/api/v1';
|
||||
|
||||
V1(this.host);
|
||||
|
||||
/// GET /categories
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#list-categories
|
||||
Future<List<Category>> listCategories() async {
|
||||
var res = await get('/categories');
|
||||
List<dynamic> categories = res['categories'];
|
||||
|
||||
return categories.map((e) => Category.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
/// ~~POST~~ GET /search
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#search
|
||||
Future<Search> search({
|
||||
@required String q,
|
||||
@required SearchType type,
|
||||
String communityId,
|
||||
@required SortType sort,
|
||||
int page,
|
||||
int limit,
|
||||
String auth,
|
||||
}) async {
|
||||
assert(q != null);
|
||||
assert(type != null);
|
||||
assert(sort != null);
|
||||
|
||||
var res = await get('/search', {
|
||||
'q': q,
|
||||
'type_': type.value,
|
||||
if (communityId != null) 'community_id': communityId,
|
||||
'sort': sort.value,
|
||||
if (page != null) 'page': page.toString(),
|
||||
if (limit != null) 'limit': limit.toString(),
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return Search.fromJson(res);
|
||||
}
|
||||
}
|
||||
|
||||
enum Vote {
|
||||
up,
|
||||
none,
|
||||
down,
|
||||
}
|
||||
|
||||
extension VoteValue on Vote {
|
||||
int get value {
|
||||
switch (this) {
|
||||
case Vote.up:
|
||||
return 1;
|
||||
case Vote.none:
|
||||
return 0;
|
||||
case Vote.down:
|
||||
return -1;
|
||||
}
|
||||
throw Exception('unreachable');
|
||||
}
|
||||
}
|
||||
|
||||
enum PostListingType {
|
||||
all,
|
||||
subscribed,
|
||||
community,
|
||||
}
|
||||
|
||||
extension PostTypeValue on PostListingType {
|
||||
String get value {
|
||||
switch (this) {
|
||||
case PostListingType.all:
|
||||
return 'All';
|
||||
case PostListingType.subscribed:
|
||||
return 'Subscribed';
|
||||
case PostListingType.community:
|
||||
return 'Community';
|
||||
}
|
||||
throw Exception('unreachable');
|
||||
}
|
||||
}
|
||||
|
||||
enum SortType {
|
||||
active,
|
||||
hot,
|
||||
// ignore: constant_identifier_names
|
||||
new_,
|
||||
topDay,
|
||||
topWeek,
|
||||
topMonth,
|
||||
topYear,
|
||||
topAll,
|
||||
}
|
||||
|
||||
extension SortTypeValue on SortType {
|
||||
String get value {
|
||||
switch (this) {
|
||||
case SortType.active:
|
||||
return 'Active';
|
||||
case SortType.hot:
|
||||
return 'Hot';
|
||||
case SortType.new_:
|
||||
return 'New';
|
||||
case SortType.topDay:
|
||||
return 'TopDay';
|
||||
case SortType.topWeek:
|
||||
return 'TopWeek';
|
||||
case SortType.topMonth:
|
||||
return 'TopMonth';
|
||||
case SortType.topYear:
|
||||
return 'TopYear';
|
||||
case SortType.topAll:
|
||||
return 'TopAll';
|
||||
}
|
||||
throw Exception('unreachable');
|
||||
}
|
||||
}
|
||||
|
||||
enum SearchType {
|
||||
all,
|
||||
comments,
|
||||
posts,
|
||||
communities,
|
||||
users,
|
||||
url,
|
||||
}
|
||||
|
||||
extension SearchTypeValue on SearchType {
|
||||
String get value {
|
||||
switch (this) {
|
||||
case SearchType.all:
|
||||
return 'All';
|
||||
case SearchType.comments:
|
||||
return 'Comments';
|
||||
case SearchType.posts:
|
||||
return 'Posts';
|
||||
case SearchType.communities:
|
||||
return 'Communities';
|
||||
case SearchType.users:
|
||||
return 'Users';
|
||||
case SearchType.url:
|
||||
return 'Url';
|
||||
}
|
||||
throw Exception('unreachable');
|
||||
}
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
|
||||
import '../models/post.dart';
|
||||
import 'main.dart';
|
||||
|
||||
extension PostEndpoint on V1 {
|
||||
/// POST /post
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#post
|
||||
Future<PostView> createPost({
|
||||
@required String name,
|
||||
String url,
|
||||
String body,
|
||||
@required bool nsfw,
|
||||
@required int communityId,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(name != null);
|
||||
assert(nsfw != null);
|
||||
assert(communityId != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// GET /post
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-post
|
||||
Future<FullPost> getPost({
|
||||
@required int id,
|
||||
String auth,
|
||||
}) async {
|
||||
assert(id != null);
|
||||
|
||||
var res = await get('/post', {
|
||||
'id': id.toString(),
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return FullPost.fromJson(res);
|
||||
}
|
||||
|
||||
/// GET /post/list
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-posts
|
||||
Future<List<PostView>> getPosts({
|
||||
@required PostListingType type,
|
||||
@required SortType sort,
|
||||
int page,
|
||||
int limit,
|
||||
int communityId,
|
||||
String communityName,
|
||||
}) async {
|
||||
assert(type != null);
|
||||
assert(sort != null);
|
||||
|
||||
var json = await get('/post/list', {
|
||||
'type_': type.value,
|
||||
'sort': sort.value,
|
||||
if (page != null) 'page': page.toString(),
|
||||
if (limit != null) 'limit': limit.toString(),
|
||||
if (communityId != null) 'community_id': communityId.toString(),
|
||||
if (communityName != null) 'community_name': communityName,
|
||||
});
|
||||
|
||||
List<dynamic> posts = json['posts'];
|
||||
return posts.map((e) => PostView.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
/// POST /post/like
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-post-like
|
||||
Future<PostView> createPostLike({
|
||||
@required int postId,
|
||||
@required Vote score,
|
||||
@required String auth,
|
||||
}) async {
|
||||
assert(postId != null);
|
||||
assert(score != null);
|
||||
assert(auth != null);
|
||||
|
||||
var res = await post('/post/like', {
|
||||
'post_id': postId,
|
||||
'score': score.value,
|
||||
'auth': auth,
|
||||
});
|
||||
|
||||
return PostView.fromJson(res);
|
||||
}
|
||||
|
||||
/// PUT /post
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-post
|
||||
Future<PostView> editPost({
|
||||
@required int editId,
|
||||
@required String name,
|
||||
String url,
|
||||
String body,
|
||||
@required bool nsfw,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(name != null);
|
||||
assert(nsfw != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /post/delete
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-post
|
||||
/// delete a post in a user deleting their own kind of way
|
||||
Future<PostView> deletePost({
|
||||
@required int editId,
|
||||
@required bool deleted,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(deleted != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /post/remove
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#remove-post
|
||||
/// remove post in an admin kind of way
|
||||
Future<PostView> removePost({
|
||||
@required int editId,
|
||||
@required bool removed,
|
||||
String reason,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(removed != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /post/save
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-post
|
||||
Future<PostView> savePost({
|
||||
@required int postId,
|
||||
@required bool save,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(postId != null);
|
||||
assert(save != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
import '../models/site.dart';
|
||||
import '../v1/main.dart';
|
||||
|
||||
extension SiteEndpoint on V1 {
|
||||
/// GET /site
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-site
|
||||
Future<FullSiteView> getSite({String auth}) async {
|
||||
var res = await get('/site', {
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return FullSiteView.fromJson(res);
|
||||
}
|
||||
|
||||
/// GET /site/config
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-site-config
|
||||
/// admin stuff
|
||||
Future<String> getSiteConfig() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
|
@ -1,251 +0,0 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
|
||||
import '../models/captcha.dart';
|
||||
import '../models/comment.dart';
|
||||
import '../models/private_message.dart';
|
||||
import '../models/user.dart';
|
||||
import 'main.dart';
|
||||
|
||||
extension UserEndpoint on V1 {
|
||||
/// POST /user/login
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#login
|
||||
/// returns jwt
|
||||
Future<String> login({
|
||||
@required String usernameOrEmail,
|
||||
@required String password,
|
||||
}) async {
|
||||
assert(usernameOrEmail != null, password != null);
|
||||
|
||||
final res = await post('/user/login', {
|
||||
'username_or_email': usernameOrEmail,
|
||||
'password': password,
|
||||
});
|
||||
|
||||
return res['jwt'];
|
||||
}
|
||||
|
||||
/// POST /user/register
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#register
|
||||
/// returns jwt
|
||||
Future<String> register({
|
||||
@required String username,
|
||||
String email,
|
||||
@required String password,
|
||||
@required String passwordVerify,
|
||||
@required bool admin,
|
||||
String captchaUuid,
|
||||
String captchaAnswer,
|
||||
}) {
|
||||
assert(username != null);
|
||||
assert(password != null);
|
||||
assert(passwordVerify != null);
|
||||
assert(admin != null);
|
||||
assert(((captchaUuid != null) ^ (captchaAnswer != null)));
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// GET /user/get_captcha
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-captcha
|
||||
Future<Captcha> getCaptcha() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// GET /user
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-details
|
||||
Future<UserDetails> getUserDetails({
|
||||
int userId,
|
||||
String username,
|
||||
@required SortType sort,
|
||||
int page,
|
||||
int limit,
|
||||
int communityId,
|
||||
@required bool savedOnly,
|
||||
String auth,
|
||||
}) async {
|
||||
assert(sort != null);
|
||||
assert(savedOnly != null);
|
||||
assert((userId != null) ^ (username != null));
|
||||
assert(limit == null || limit >= 0);
|
||||
assert(page == null || page > 0);
|
||||
|
||||
var res = await get('/user', {
|
||||
if (userId != null) 'user_id': userId.toString(),
|
||||
if (username != null) 'username': username,
|
||||
'sort': sort.value,
|
||||
if (page != null) 'page': page.toString(),
|
||||
if (limit != null) 'limit': limit.toString(),
|
||||
if (communityId != null) 'community_id': communityId.toString(),
|
||||
if (savedOnly != null) 'saved_only': savedOnly.toString(),
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return UserDetails.fromJson(res);
|
||||
}
|
||||
|
||||
/// PUT /save_user_settings
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-user-settings
|
||||
/// returns jwt
|
||||
Future<String> saveUserSettings({
|
||||
@required bool showNsfw,
|
||||
@required String theme,
|
||||
@required SortType defaultSortType,
|
||||
@required PostListingType defaultListingType,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(showNsfw != null);
|
||||
assert(theme != null);
|
||||
assert(defaultSortType != null);
|
||||
assert(defaultListingType != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// GET /user/replies
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-replies--inbox
|
||||
Future<List<ReplyView>> getReplies({
|
||||
@required SortType sort,
|
||||
int page,
|
||||
int limit,
|
||||
@required bool unreadOnly,
|
||||
@required String auth,
|
||||
}) async {
|
||||
assert(sort != null);
|
||||
assert(unreadOnly != null);
|
||||
assert(auth != null);
|
||||
|
||||
var res = await get('/user/replies', {
|
||||
'sort': sort.value,
|
||||
if (page != null) 'page': page.toString(),
|
||||
if (limit != null) 'limit': limit.toString(),
|
||||
'unread_only': unreadOnly.toString(),
|
||||
'auth': auth,
|
||||
});
|
||||
List<dynamic> replies = res['replies'];
|
||||
return replies.map((e) => ReplyView.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
/// GET /user/mentions
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-mentions
|
||||
Future<List<UserMentionView>> getUserMentions({
|
||||
@required String sort,
|
||||
int page,
|
||||
int limit,
|
||||
@required bool unreadOnly,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(sort != null);
|
||||
assert(unreadOnly != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /user/mention/mark_as_read
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-user-mention-as-read
|
||||
Future<UserMentionView> markUserMentionAsRead({
|
||||
@required int userMentionId,
|
||||
@required bool read,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(userMentionId != null);
|
||||
assert(read != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// GET /private_message/list
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-private-messages
|
||||
Future<List<PrivateMessageView>> getPrivateMessages({
|
||||
@required bool unreadOnly,
|
||||
int page,
|
||||
int limit,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(unreadOnly != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /private_message
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-private-message
|
||||
Future<PrivateMessageView> createPrivateMessage({
|
||||
@required String content,
|
||||
@required int recipientId,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(content != null);
|
||||
assert(recipientId != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// PUT /private_message
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-private-message
|
||||
Future<PrivateMessageView> editPrivateMessage({
|
||||
@required int editId,
|
||||
@required String content,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(content != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /private_message/delete
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-private-message
|
||||
Future<PrivateMessageView> deletePrivateMessage({
|
||||
@required int editId,
|
||||
@required bool deleted,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(deleted != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /private_message/mark_as_read
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-private-message-as-read
|
||||
Future<PrivateMessageView> markPrivateMessageAsRead({
|
||||
@required int editId,
|
||||
@required bool read,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(editId != null);
|
||||
assert(read != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /user/mark_all_as_read
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-all-as-read
|
||||
Future<List<ReplyView>> markAllAsRead({
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
/// POST /user/delete_account
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-account
|
||||
/// returns jwt
|
||||
Future<String> deleteAccount({
|
||||
@required String password,
|
||||
@required String auth,
|
||||
}) {
|
||||
assert(password != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ description: A new Flutter project.
|
|||
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
|
@ -18,11 +18,9 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: '>=2.7.0 <3.0.0'
|
||||
sdk: ">=2.7.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
json_annotation: ^3.0.1
|
||||
http: ^0.12.2
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
|
@ -34,7 +32,6 @@ 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
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lemmur/client/models/comment.dart';
|
||||
|
||||
void main() {
|
||||
test('CommentView test', () {
|
||||
Map<String, dynamic> commentFromApi = jsonDecode("""
|
||||
{
|
||||
"id": 14296,
|
||||
"creator_id": 8218,
|
||||
"post_id": 38501,
|
||||
"post_name": "Niklaus Wirth was right and that is a problem",
|
||||
"parent_id": 14286,
|
||||
"content": "I think that the same functionality current crop of apps has could be implemented much more cleanly and efficiently if there wasn't a rush to get products to market. If developers could spend the time to think things through and try different approaches to see what works best we'd have much higher quality software today. Instead, everything is rushed to market as fast as possible, and developers are constantly overwhelmed with unreasonable amounts of work with no time to do things properly or clean things up along the way.",
|
||||
"removed": false,
|
||||
"read": true,
|
||||
"published": "2020-08-02T20:31:19.303284",
|
||||
"updated": null,
|
||||
"deleted": false,
|
||||
"ap_id": "https://dev.lemmy.ml/comment/14296",
|
||||
"local": true,
|
||||
"community_id": 14680,
|
||||
"community_actor_id": "https://dev.lemmy.ml/c/programming",
|
||||
"community_local": true,
|
||||
"community_name": "programming",
|
||||
"community_icon": null,
|
||||
"banned": false,
|
||||
"banned_from_community": false,
|
||||
"creator_actor_id": "https://dev.lemmy.ml/u/yogthos",
|
||||
"creator_local": true,
|
||||
"creator_name": "yogthos",
|
||||
"creator_preferred_username": null,
|
||||
"creator_published": "2020-01-18T04:02:39.254957",
|
||||
"creator_avatar": "https://dev.lemmy.ml/pictrs/image/bwk1q2.png",
|
||||
"score": 1,
|
||||
"upvotes": 1,
|
||||
"downvotes": 0,
|
||||
"hot_rank": 0,
|
||||
"hot_rank_active": 0,
|
||||
"user_id": 13709,
|
||||
"my_vote": 0,
|
||||
"subscribed": false,
|
||||
"saved": false
|
||||
}""");
|
||||
|
||||
var comment = CommentView.fromJson(commentFromApi);
|
||||
|
||||
expect(comment.id, 14296);
|
||||
expect(comment.creatorId, 8218);
|
||||
expect(comment.postId, 38501);
|
||||
expect(comment.postName, 'Niklaus Wirth was right and that is a problem');
|
||||
expect(comment.parentId, 14286);
|
||||
expect(comment.content,
|
||||
'''I think that the same functionality current crop of apps has could be implemented much more cleanly and efficiently if there wasn't a rush to get products to market. If developers could spend the time to think things through and try different approaches to see what works best we'd have much higher quality software today. Instead, everything is rushed to market as fast as possible, and developers are constantly overwhelmed with unreasonable amounts of work with no time to do things properly or clean things up along the way.''');
|
||||
expect(comment.removed, false);
|
||||
expect(comment.read, true);
|
||||
expect(comment.published, DateTime.parse('2020-08-02T20:31:19.303284'));
|
||||
expect(comment.updated, null);
|
||||
expect(comment.deleted, false);
|
||||
expect(comment.apId, 'https://dev.lemmy.ml/comment/14296');
|
||||
expect(comment.local, true);
|
||||
expect(comment.communityId, 14680);
|
||||
expect(comment.communityActorId, 'https://dev.lemmy.ml/c/programming');
|
||||
expect(comment.communityLocal, true);
|
||||
expect(comment.communityName, 'programming');
|
||||
expect(comment.communityIcon, null);
|
||||
expect(comment.banned, false);
|
||||
expect(comment.bannedFromCommunity, false);
|
||||
expect(comment.creatorActorId, 'https://dev.lemmy.ml/u/yogthos');
|
||||
expect(comment.creatorLocal, true);
|
||||
expect(comment.creatorName, 'yogthos');
|
||||
expect(comment.creatorPreferredUsername, null);
|
||||
expect(
|
||||
comment.creatorPublished, DateTime.parse('2020-01-18T04:02:39.254957'));
|
||||
expect(
|
||||
comment.creatorAvatar, 'https://dev.lemmy.ml/pictrs/image/bwk1q2.png');
|
||||
expect(comment.score, 1);
|
||||
expect(comment.upvotes, 1);
|
||||
expect(comment.downvotes, 0);
|
||||
expect(comment.hotRank, 0);
|
||||
expect(comment.hotRankActive, 0);
|
||||
expect(comment.userId, 13709);
|
||||
expect(comment.myVote, 0);
|
||||
expect(comment.subscribed, false);
|
||||
expect(comment.saved, false);
|
||||
});
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lemmur/client/models/community.dart';
|
||||
|
||||
void main() {
|
||||
test('PostView test', () {
|
||||
Map<String, dynamic> communityJson = jsonDecode('''
|
||||
{
|
||||
"id": 3,
|
||||
"name": "haskell",
|
||||
"title": "The Haskell Lemmy Forum",
|
||||
"icon": null,
|
||||
"banner": null,
|
||||
"description": null,
|
||||
"category_id": 21,
|
||||
"creator_id": 77,
|
||||
"removed": false,
|
||||
"published": "2019-04-22T17:52:37.759443",
|
||||
"updated": null,
|
||||
"deleted": false,
|
||||
"nsfw": false,
|
||||
"actor_id": "https://dev.lemmy.ml/c/haskell",
|
||||
"local": true,
|
||||
"last_refreshed_at": "2020-06-30T00:49:22.589810",
|
||||
"creator_actor_id": "https://dev.lemmy.ml/u/topos",
|
||||
"creator_local": true,
|
||||
"creator_name": "topos",
|
||||
"creator_preferred_username": null,
|
||||
"creator_avatar": null,
|
||||
"category_name": "Programming/Software",
|
||||
"number_of_subscribers": 85,
|
||||
"number_of_posts": 0,
|
||||
"number_of_comments": 0,
|
||||
"hot_rank": 0,
|
||||
"user_id": null,
|
||||
"subscribed": null
|
||||
}''');
|
||||
|
||||
var community = CommunityView.fromJson(communityJson);
|
||||
|
||||
expect(community.id, 3);
|
||||
expect(community.name, 'haskell');
|
||||
expect(community.title, 'The Haskell Lemmy Forum');
|
||||
expect(community.icon, null);
|
||||
expect(community.banner, null);
|
||||
expect(community.description, null);
|
||||
expect(community.categoryId, 21);
|
||||
expect(community.creatorId, 77);
|
||||
expect(community.removed, false);
|
||||
expect(community.published, DateTime.parse('2019-04-22T17:52:37.759443'));
|
||||
expect(community.updated, null);
|
||||
expect(community.deleted, false);
|
||||
expect(community.nsfw, false);
|
||||
expect(community.actorId, 'https://dev.lemmy.ml/c/haskell');
|
||||
expect(community.local, true);
|
||||
expect(community.lastRefreshedAt,
|
||||
DateTime.parse('2020-06-30T00:49:22.589810'));
|
||||
expect(community.creatorActorId, 'https://dev.lemmy.ml/u/topos');
|
||||
expect(community.creatorLocal, true);
|
||||
expect(community.creatorName, 'topos');
|
||||
expect(community.creatorPreferredUsername, null);
|
||||
expect(community.creatorAvatar, null);
|
||||
expect(community.categoryName, 'Programming/Software');
|
||||
expect(community.numberOfSubscribers, 85);
|
||||
expect(community.numberOfPosts, 0);
|
||||
expect(community.numberOfComments, 0);
|
||||
expect(community.hotRank, 0);
|
||||
expect(community.userId, null);
|
||||
expect(community.subscribed, null);
|
||||
});
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lemmur/client/models/post.dart';
|
||||
|
||||
void main() {
|
||||
test('PostView test', () {
|
||||
Map<String, dynamic> postJson = jsonDecode('''
|
||||
{
|
||||
"id": 38501,
|
||||
"name": "Niklaus Wirth was right and that is a problem",
|
||||
"url": "https://bowero.nl/blog/2020/07/31/niklaus-wirth-was-right-and-that-is-a-problem/",
|
||||
"body": null,
|
||||
"creator_id": 8218,
|
||||
"community_id": 14680,
|
||||
"removed": false,
|
||||
"locked": false,
|
||||
"published": "2020-08-02T01:56:28.072727",
|
||||
"updated": null,
|
||||
"deleted": false,
|
||||
"nsfw": false,
|
||||
"stickied": false,
|
||||
"embed_title": "Niklaus Wirth was right and that is a problem",
|
||||
"embed_description": null,
|
||||
"embed_html": null,
|
||||
"thumbnail_url": null,
|
||||
"ap_id": "https://dev.lemmy.ml/post/38501",
|
||||
"local": true,
|
||||
"creator_actor_id": "https://dev.lemmy.ml/u/yogthos",
|
||||
"creator_local": true,
|
||||
"creator_name": "yogthos",
|
||||
"creator_preferred_username": null,
|
||||
"creator_published": "2020-01-18T04:02:39.254957",
|
||||
"creator_avatar": "https://dev.lemmy.ml/pictrs/image/bwk1q2.png",
|
||||
"banned": false,
|
||||
"banned_from_community": false,
|
||||
"community_actor_id": "https://dev.lemmy.ml/c/programming",
|
||||
"community_local": true,
|
||||
"community_name": "programming",
|
||||
"community_icon": null,
|
||||
"community_removed": false,
|
||||
"community_deleted": false,
|
||||
"community_nsfw": false,
|
||||
"number_of_comments": 4,
|
||||
"score": 8,
|
||||
"upvotes": 8,
|
||||
"downvotes": 0,
|
||||
"hot_rank": 1,
|
||||
"hot_rank_active": 1,
|
||||
"newest_activity_time": "2020-08-02T20:31:19.303284",
|
||||
"user_id": 13709,
|
||||
"my_vote": 0,
|
||||
"subscribed": false,
|
||||
"read": false,
|
||||
"saved": false
|
||||
}''');
|
||||
|
||||
var post = PostView.fromJson(postJson);
|
||||
|
||||
expect(post.id, 38501);
|
||||
expect(post.name, 'Niklaus Wirth was right and that is a problem');
|
||||
expect(post.url,
|
||||
'https://bowero.nl/blog/2020/07/31/niklaus-wirth-was-right-and-that-is-a-problem/');
|
||||
expect(post.body, null);
|
||||
expect(post.creatorId, 8218);
|
||||
expect(post.communityId, 14680);
|
||||
expect(post.removed, false);
|
||||
expect(post.locked, false);
|
||||
expect(post.published, DateTime.parse('2020-08-02T01:56:28.072727'));
|
||||
expect(post.updated, null);
|
||||
expect(post.deleted, false);
|
||||
expect(post.nsfw, false);
|
||||
expect(post.stickied, false);
|
||||
expect(post.embedTitle, 'Niklaus Wirth was right and that is a problem');
|
||||
expect(post.embedDescription, null);
|
||||
expect(post.embedHtml, null);
|
||||
expect(post.thumbnailUrl, null);
|
||||
expect(post.apId, 'https://dev.lemmy.ml/post/38501');
|
||||
expect(post.local, true);
|
||||
expect(post.creatorActorId, 'https://dev.lemmy.ml/u/yogthos');
|
||||
expect(post.creatorLocal, true);
|
||||
expect(post.creatorName, 'yogthos');
|
||||
expect(post.creatorPreferredUsername, null);
|
||||
expect(post.creatorPublished, DateTime.parse('2020-01-18T04:02:39.254957'));
|
||||
expect(post.creatorAvatar, 'https://dev.lemmy.ml/pictrs/image/bwk1q2.png');
|
||||
expect(post.banned, false);
|
||||
expect(post.bannedFromCommunity, false);
|
||||
expect(post.communityActorId, 'https://dev.lemmy.ml/c/programming');
|
||||
expect(post.communityLocal, true);
|
||||
expect(post.communityName, 'programming');
|
||||
expect(post.communityIcon, null);
|
||||
expect(post.communityRemoved, false);
|
||||
expect(post.communityDeleted, false);
|
||||
expect(post.communityNsfw, false);
|
||||
expect(post.numberOfComments, 4);
|
||||
expect(post.score, 8);
|
||||
expect(post.upvotes, 8);
|
||||
expect(post.downvotes, 0);
|
||||
expect(post.hotRank, 1);
|
||||
expect(post.hotRankActive, 1);
|
||||
expect(
|
||||
post.newestActivityTime, DateTime.parse('2020-08-02T20:31:19.303284'));
|
||||
expect(post.userId, 13709);
|
||||
expect(post.myVote, 0);
|
||||
expect(post.subscribed, false);
|
||||
expect(post.read, false);
|
||||
expect(post.saved, false);
|
||||
});
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lemmur/client/models/user.dart';
|
||||
|
||||
void main() {
|
||||
test('UserView test', () {
|
||||
Map<String, dynamic> userJson = jsonDecode('''
|
||||
{
|
||||
"id": 13709,
|
||||
"actor_id": "https://dev.lemmy.ml/u/krawieck",
|
||||
"name": "krawieck",
|
||||
"preferred_username": null,
|
||||
"avatar": null,
|
||||
"banner": null,
|
||||
"email": null,
|
||||
"matrix_user_id": null,
|
||||
"bio": null,
|
||||
"local": true,
|
||||
"admin": false,
|
||||
"banned": false,
|
||||
"show_avatars": true,
|
||||
"send_notifications_to_email": false,
|
||||
"published": "2020-08-03T12:22:12.389085",
|
||||
"number_of_posts": 0,
|
||||
"post_score": 0,
|
||||
"number_of_comments": 0,
|
||||
"comment_score": 0
|
||||
}''');
|
||||
|
||||
var user = UserView.fromJson(userJson);
|
||||
|
||||
expect(user.id, 13709);
|
||||
expect(user.actorId, 'https://dev.lemmy.ml/u/krawieck');
|
||||
expect(user.name, 'krawieck');
|
||||
expect(user.preferredUsername, null);
|
||||
expect(user.avatar, null);
|
||||
expect(user.banner, null);
|
||||
expect(user.email, null);
|
||||
expect(user.matrixUserId, null);
|
||||
expect(user.bio, null);
|
||||
expect(user.local, true);
|
||||
expect(user.admin, false);
|
||||
expect(user.banned, false);
|
||||
expect(user.showAvatars, true);
|
||||
expect(user.sendNotificationsToEmail, false);
|
||||
expect(user.published, DateTime.parse('2020-08-03T12:22:12.389085'));
|
||||
expect(user.numberOfPosts, 0);
|
||||
expect(user.postScore, 0);
|
||||
expect(user.numberOfComments, 0);
|
||||
expect(user.commentScore, 0);
|
||||
});
|
||||
}
|
|
@ -1,495 +0,0 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lemmur/client/client.dart';
|
||||
|
||||
// these are mock exceptions
|
||||
// should be removed as soon as the real one is implemented
|
||||
class NotLoggedInException implements Exception {
|
||||
final String _message;
|
||||
|
||||
NotLoggedInException(this._message);
|
||||
|
||||
@override
|
||||
String toString() => _message;
|
||||
}
|
||||
|
||||
class UsernameTakenException implements Exception {
|
||||
final String _message;
|
||||
|
||||
UsernameTakenException(this._message);
|
||||
|
||||
@override
|
||||
String toString() => _message;
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('lemmy API v1', () {
|
||||
final lemmy = LemmyAPI('dev.lemmy.ml').v1;
|
||||
|
||||
group('listCategories', () {
|
||||
test('correctly fetches', () async {
|
||||
await lemmy.listCategories();
|
||||
});
|
||||
});
|
||||
|
||||
group('search', () {
|
||||
test('correctly fetches', () async {
|
||||
final res = await lemmy.search(
|
||||
type: SearchType.all, q: 'asd', sort: SortType.active);
|
||||
|
||||
expect(res.type, SortType.active.value);
|
||||
});
|
||||
|
||||
test('forbids illegal numbers', () async {
|
||||
expect(() async {
|
||||
await lemmy.search(
|
||||
type: SearchType.all, q: 'asd', sort: SortType.active, page: 0);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
expect(() async {
|
||||
await lemmy.search(
|
||||
type: SearchType.all, q: 'asd', sort: SortType.active, limit: -1);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.search(
|
||||
type: SearchType.all,
|
||||
q: 'asd',
|
||||
sort: SortType.active,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('createComment', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.createComment(
|
||||
content: '123',
|
||||
postId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('editComment', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.editComment(
|
||||
content: '123',
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('deleteComment', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.deleteComment(
|
||||
deleted: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('removeComment', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.removeComment(
|
||||
removed: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('markCommentAsRead', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.markCommentAsRead(
|
||||
read: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('saveComment', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.saveComment(
|
||||
save: true,
|
||||
commentId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('createCommentLike', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.createCommentLike(
|
||||
score: Vote.up,
|
||||
commentId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('createPost', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.createPost(
|
||||
name: 'asd',
|
||||
nsfw: false,
|
||||
communityId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('getPost', () {
|
||||
test('correctly fetches', () async {
|
||||
await lemmy.getPost(id: 38936);
|
||||
});
|
||||
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.getPost(
|
||||
id: 1,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('getPosts', () {
|
||||
test('correctly fetches', () async {
|
||||
final res = await lemmy.getPosts(
|
||||
type: PostListingType.all, sort: SortType.active);
|
||||
expect(res.length, 10);
|
||||
});
|
||||
|
||||
test('forbids illegal numbers', () async {
|
||||
expect(() async {
|
||||
await lemmy.getPosts(
|
||||
type: PostListingType.all, sort: SortType.active, page: 0);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
expect(() async {
|
||||
await lemmy.getPosts(
|
||||
type: PostListingType.all, sort: SortType.active, limit: -1);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('createPostLike', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.createPostLike(
|
||||
postId: 1,
|
||||
score: Vote.up,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('editPost', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.editPost(
|
||||
name: 'asd',
|
||||
nsfw: false,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('deletePost', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.deletePost(
|
||||
deleted: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('removePost', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.removePost(
|
||||
removed: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('login', () {
|
||||
test('handles invalid credentials', () async {
|
||||
expect(() async {
|
||||
await lemmy.login(
|
||||
usernameOrEmail: '123',
|
||||
password: '123',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('register', () {
|
||||
// TODO(krawieck): the signature seems to be wrong, waiting for correction
|
||||
// test('handles already existing account', () async {
|
||||
// expect(() async {
|
||||
// await lemmy.register(
|
||||
// usernameOrEmail: '123',
|
||||
// password: '123',
|
||||
// );
|
||||
// }, throwsA(isInstanceOf<UsernameTakenException>()));
|
||||
// });
|
||||
});
|
||||
|
||||
group('getCaptcha', () {
|
||||
test('correctly fetches', () async {
|
||||
await lemmy.getCaptcha();
|
||||
});
|
||||
});
|
||||
|
||||
group('getUserDetails', () {
|
||||
test('correctly fetches', () async {
|
||||
await lemmy.getUserDetails(sort: SortType.active, username: 'krawieck');
|
||||
});
|
||||
|
||||
test('forbids illegal numbers', () async {
|
||||
expect(() async {
|
||||
await lemmy.getUserDetails(sort: SortType.active, page: 0);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
expect(() async {
|
||||
await lemmy.getUserDetails(sort: SortType.active, limit: -1);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
|
||||
test('forbids both username and userId being passed at once', () async {
|
||||
expect(() async {
|
||||
await lemmy.getUserDetails(
|
||||
sort: SortType.active,
|
||||
username: 'asd',
|
||||
userId: 123,
|
||||
);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.getUserDetails(
|
||||
sort: SortType.active,
|
||||
auth: '123',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('saveUserSettings', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.saveUserSettings(
|
||||
showNsfw: true,
|
||||
theme: 'asd',
|
||||
defaultSortType: SortType.active,
|
||||
defaultListingType: PostListingType.all,
|
||||
auth: '123',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('getReplies', () {
|
||||
test('forbids illegal numbers', () async {
|
||||
expect(() async {
|
||||
await lemmy.getReplies(
|
||||
sort: SortType.active,
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
page: 0,
|
||||
);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
expect(() async {
|
||||
await lemmy.getReplies(
|
||||
sort: SortType.active,
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
limit: -1,
|
||||
);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.getReplies(
|
||||
sort: SortType.active,
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('getUserMentions', () {
|
||||
// TODO(krawieck): the signature seems to be wrong, waiting for correction
|
||||
// test('forbids illegal numbers', () async {
|
||||
// expect(() async {
|
||||
// await lemmy.getUserMentions(
|
||||
// sort: SortType.active,
|
||||
// unreadOnly: false,
|
||||
// auth: 'asd',
|
||||
// page: 0,
|
||||
// );
|
||||
// }, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
// expect(() async {
|
||||
// await lemmy.getUserMentions(
|
||||
// sort: SortType.active,
|
||||
// unreadOnly: false,
|
||||
// auth: 'asd',
|
||||
// limit: -1,
|
||||
// );
|
||||
// }, throwsA(isInstanceOf<AssertionError>()));
|
||||
// });
|
||||
|
||||
// test('handles invalid tokens', () async {
|
||||
// expect(() async {
|
||||
// await lemmy.getUserMentions(
|
||||
// sort: SortType.active,
|
||||
// unreadOnly: false,
|
||||
// auth: 'asd',
|
||||
// );
|
||||
// }, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
// });
|
||||
});
|
||||
|
||||
group('markUserMentionAsRead', () {
|
||||
test('handles invalid credentials', () async {
|
||||
expect(() async {
|
||||
await lemmy.markUserMentionAsRead(
|
||||
userMentionId: 123,
|
||||
read: true,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('getPrivateMessages', () {
|
||||
test('forbids illegal numbers', () async {
|
||||
expect(() async {
|
||||
await lemmy.getPrivateMessages(
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
page: 0,
|
||||
);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
|
||||
expect(() async {
|
||||
await lemmy.getPrivateMessages(
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
limit: -1,
|
||||
);
|
||||
}, throwsA(isInstanceOf<AssertionError>()));
|
||||
});
|
||||
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.getPrivateMessages(
|
||||
unreadOnly: false,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('createPrivateMessage', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.createPrivateMessage(
|
||||
content: 'asd',
|
||||
recipientId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('editPrivateMessage', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.editPrivateMessage(
|
||||
content: 'asd',
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('deletePrivateMessage', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.deletePrivateMessage(
|
||||
deleted: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('markPrivateMessageAsRead', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.markPrivateMessageAsRead(
|
||||
read: true,
|
||||
editId: 123,
|
||||
auth: 'asd',
|
||||
);
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('markAllAsRead', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.markAllAsRead(auth: 'asd');
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('deleteAccount', () {
|
||||
test('handles invalid tokens', () async {
|
||||
expect(() async {
|
||||
await lemmy.deleteAccount(password: 'asd', auth: 'asd');
|
||||
}, throwsA(isInstanceOf<NotLoggedInException>()));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue