Remove all references to kbin

This commit is contained in:
John Wesley 2024-05-31 11:25:42 -04:00
parent e3a1be2f0d
commit 3275bd7429
26 changed files with 202 additions and 247 deletions

View File

@ -1,6 +1,6 @@
# Interstellar
An app for Kbin, Mbin, and Lemmy; connecting you to the fediverse.
An app for Mbin and Lemmy; connecting you to the fediverse.
## Downloads
@ -12,6 +12,7 @@ See the [latest release](https://github.com/jwr1/interstellar/releases/latest) f
## Discussion
You can ask questions, report bugs, make suggestions, etc., to any of the following:
- [GitHub](https://github.com/jwr1/interstellar/issues)
- [Mbin](https://kbin.earth/m/interstellar)
- [Matrix](https://matrix.to/#/#interstellar-space:matrix.org)

View File

@ -19,12 +19,12 @@ class API {
final String server;
final APIComments comments;
final KbinAPIDomains domains;
final MbinAPIDomains domains;
final APIThreads threads;
final APIMagazines magazines;
final KbinAPIMessages messages;
final KbinAPINotifications notifications;
final KbinAPIMicroblogs microblogs;
final MbinAPIMessages messages;
final MbinAPINotifications notifications;
final MbinAPIMicroblogs microblogs;
final APISearch search;
final APIUsers users;
@ -33,12 +33,12 @@ class API {
this.httpClient,
this.server,
) : comments = APIComments(software, httpClient, server),
domains = KbinAPIDomains(software, httpClient, server),
domains = MbinAPIDomains(software, httpClient, server),
threads = APIThreads(software, httpClient, server),
magazines = APIMagazines(software, httpClient, server),
messages = KbinAPIMessages(software, httpClient, server),
notifications = KbinAPINotifications(software, httpClient, server),
microblogs = KbinAPIMicroblogs(software, httpClient, server),
messages = MbinAPIMessages(software, httpClient, server),
notifications = MbinAPINotifications(software, httpClient, server),
microblogs = MbinAPIMicroblogs(software, httpClient, server),
search = APISearch(software, httpClient, server),
users = APIUsers(software, httpClient, server);
}

View File

@ -50,11 +50,11 @@ const SelectionMenu<CommentSort> commentSortSelect = SelectionMenu(
],
);
const _postTypeKbin = {
const _postTypeMbin = {
PostType.thread: 'entry',
PostType.microblog: 'posts',
};
const _postTypeKbinComment = {
const _postTypeMbinComment = {
PostType.thread: 'comments',
PostType.microblog: 'post-comments',
};
@ -79,9 +79,8 @@ class APIComments {
bool? usePreferredLangs,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbin[postType]}/$postId/comments';
final path = '/api/${_postTypeMbin[postType]}/$postId/comments';
final query = queryParams({
'p': page,
'sortBy': sort?.name,
@ -93,7 +92,7 @@ class APIComments {
httpErrorHandler(response, message: 'Failed to load comments');
return CommentListModel.fromKbin(
return CommentListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -123,9 +122,8 @@ class APIComments {
bool? usePreferredLangs,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId/${_postTypeKbinComment[postType]}';
final path = '/api/users/$userId/${_postTypeMbinComment[postType]}';
final query = queryParams({
'p': page,
'sort': sort?.name,
@ -137,7 +135,7 @@ class APIComments {
httpErrorHandler(response, message: 'Failed to load comments');
return CommentListModel.fromKbin(
return CommentListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -163,15 +161,14 @@ class APIComments {
Future<CommentModel> get(PostType postType, int commentId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbinComment[postType]}/$commentId';
final path = '/api/${_postTypeMbinComment[postType]}/$commentId';
final response = await httpClient.get(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to load comment');
return CommentModel.fromKbin(
return CommentModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -200,18 +197,18 @@ class APIComments {
int newScore,
) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = choice == 1
? '/api/${_postTypeKbinComment[postType]}/$commentId/favourite'
: '/api/${_postTypeKbinComment[postType]}/$commentId/vote/$choice';
? '/api/${_postTypeMbinComment[postType]}/$commentId/favourite'
: '/api/${_postTypeMbinComment[postType]}/$commentId/vote/$choice';
final response = await httpClient.put(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to send vote');
return CommentModel.fromKbin(
return CommentModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
const path = '/api/v3/comment/like';
@ -233,15 +230,14 @@ class APIComments {
Future<CommentModel> boost(PostType postType, int commentId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbinComment[postType]}/$commentId/vote/1';
final path = '/api/${_postTypeMbinComment[postType]}/$commentId/vote/1';
final response = await httpClient.put(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to send boost');
return CommentModel.fromKbin(
return CommentModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -256,10 +252,9 @@ class APIComments {
int? parentCommentId,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path =
'/api/${_postTypeKbin[postType]}/$postId/comments${parentCommentId != null ? '/$parentCommentId/reply' : ''}';
'/api/${_postTypeMbin[postType]}/$postId/comments${parentCommentId != null ? '/$parentCommentId/reply' : ''}';
final response = await httpClient.post(
Uri.https(server, path),
@ -268,7 +263,7 @@ class APIComments {
httpErrorHandler(response, message: 'Failed to create comment');
return CommentModel.fromKbin(
return CommentModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -297,9 +292,8 @@ class APIComments {
String body,
) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbinComment[postType]}/$commentId';
final path = '/api/${_postTypeMbinComment[postType]}/$commentId';
final response = await httpClient.put(
Uri.https(server, path),
@ -310,7 +304,7 @@ class APIComments {
httpErrorHandler(response, message: "Failed to edit comment");
return CommentModel.fromKbin(
return CommentModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -334,9 +328,8 @@ class APIComments {
Future<void> delete(PostType postType, int commentId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbinComment[postType]}/$commentId';
final path = '/api/${_postTypeMbinComment[postType]}/$commentId';
final response = await httpClient.delete(Uri.https(server, path));
@ -360,9 +353,8 @@ class APIComments {
Future<void> report(PostType postType, int commentId, String reason) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/${_postTypeKbinComment[postType]}/$commentId/report';
final path = '/api/${_postTypeMbinComment[postType]}/$commentId/report';
final response = await httpClient.post(
Uri.https(server, path),

View File

@ -5,14 +5,14 @@ import 'package:interstellar/src/models/domain.dart';
import 'package:interstellar/src/screens/settings/settings_controller.dart';
import 'package:interstellar/src/utils/utils.dart';
enum KbinAPIDomainsFilter { all, subscribed, blocked }
enum MbinAPIDomainsFilter { all, subscribed, blocked }
class KbinAPIDomains {
class MbinAPIDomains {
final ServerSoftware software;
final http.Client httpClient;
final String server;
KbinAPIDomains(
MbinAPIDomains(
this.software,
this.httpClient,
this.server,
@ -20,14 +20,14 @@ class KbinAPIDomains {
Future<DomainListModel> list({
String? page,
KbinAPIDomainsFilter? filter,
MbinAPIDomainsFilter? filter,
String? search,
}) async {
final path = (filter == null || filter == KbinAPIDomainsFilter.all)
final path = (filter == null || filter == MbinAPIDomainsFilter.all)
? '/api/domains'
: '/api/domains/${filter.name}';
final query = queryParams(
(filter == null || filter == KbinAPIDomainsFilter.all)
(filter == null || filter == MbinAPIDomainsFilter.all)
? {'p': page, 'q': search}
: {'p': page});
@ -35,7 +35,7 @@ class KbinAPIDomains {
httpErrorHandler(response, message: 'Failed to load domains');
return DomainListModel.fromKbin(
return DomainListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -46,7 +46,7 @@ class KbinAPIDomains {
httpErrorHandler(response, message: 'Failed to load domain');
return DomainModel.fromKbin(
return DomainModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -57,7 +57,7 @@ class KbinAPIDomains {
httpErrorHandler(response, message: 'Failed to send subscribe');
return DomainModel.fromKbin(
return DomainModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -68,7 +68,7 @@ class KbinAPIDomains {
httpErrorHandler(response, message: 'Failed to send block');
return DomainModel.fromKbin(
return DomainModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
}

View File

@ -32,8 +32,6 @@ enum APIMagazinesSort {
scaled,
}
class APIMagazines {
final ServerSoftware software;
final http.Client httpClient;
@ -52,7 +50,6 @@ class APIMagazines {
String? search,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = (filter == null ||
filter == APIMagazinesFilter.all ||
@ -77,7 +74,7 @@ class APIMagazines {
httpErrorHandler(response, message: 'Failed to load magazines');
return DetailedMagazineListModel.fromKbin(
return DetailedMagazineListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -169,7 +166,6 @@ class APIMagazines {
Future<DetailedMagazineModel> get(int magazineId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/$magazineId';
@ -177,7 +173,7 @@ class APIMagazines {
httpErrorHandler(response, message: 'Failed to load magazine');
return DetailedMagazineModel.fromKbin(
return DetailedMagazineModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -198,7 +194,6 @@ class APIMagazines {
Future<DetailedMagazineModel> getByName(String magazineName) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/name/$magazineName';
@ -206,7 +201,7 @@ class APIMagazines {
httpErrorHandler(response, message: 'Failed to load magazine');
return DetailedMagazineModel.fromKbin(
return DetailedMagazineModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -227,7 +222,6 @@ class APIMagazines {
Future<DetailedMagazineModel> subscribe(int magazineId, bool state) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path =
'/api/magazine/$magazineId/${state ? 'subscribe' : 'unsubscribe'}';
@ -236,7 +230,7 @@ class APIMagazines {
httpErrorHandler(response, message: 'Failed to send subscribe');
return DetailedMagazineModel.fromKbin(
return DetailedMagazineModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -261,7 +255,6 @@ class APIMagazines {
Future<DetailedMagazineModel> block(int magazineId, bool state) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/$magazineId/${state ? 'block' : 'unblock'}';
@ -269,7 +262,7 @@ class APIMagazines {
httpErrorHandler(response, message: 'Failed to send block');
return DetailedMagazineModel.fromKbin(
return DetailedMagazineModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:

View File

@ -5,12 +5,12 @@ import 'package:interstellar/src/models/message.dart';
import 'package:interstellar/src/screens/settings/settings_controller.dart';
import 'package:interstellar/src/utils/utils.dart';
class KbinAPIMessages {
class MbinAPIMessages {
final ServerSoftware software;
final http.Client httpClient;
final String server;
KbinAPIMessages(
MbinAPIMessages(
this.software,
this.httpClient,
this.server,
@ -26,7 +26,7 @@ class KbinAPIMessages {
httpErrorHandler(response, message: 'Failed to load messages');
return MessageListModel.fromKbin(
return MessageListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -43,7 +43,7 @@ class KbinAPIMessages {
httpErrorHandler(response, message: 'Failed to send message');
return MessageThreadModel.fromKbin(
return MessageThreadModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -60,7 +60,7 @@ class KbinAPIMessages {
httpErrorHandler(response, message: 'Failed to send message');
return MessageThreadModel.fromKbin(
return MessageThreadModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
}

View File

@ -10,12 +10,12 @@ import 'package:interstellar/src/utils/utils.dart';
import 'package:mime/mime.dart';
import 'package:path/path.dart';
class KbinAPIMicroblogs {
class MbinAPIMicroblogs {
final ServerSoftware software;
final http.Client httpClient;
final String server;
KbinAPIMicroblogs(
MbinAPIMicroblogs(
this.software,
this.httpClient,
this.server,
@ -51,7 +51,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: 'Failed to load posts');
return PostListModel.fromKbinPosts(
return PostListModel.fromMbinPosts(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -62,7 +62,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: 'Failed to load posts');
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -73,7 +73,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: 'Failed to send vote');
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -84,7 +84,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: 'Failed to send vote');
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -103,7 +103,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: "Failed to edit post");
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -130,7 +130,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: "Failed to create post");
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}
@ -162,7 +162,7 @@ class KbinAPIMicroblogs {
httpErrorHandler(response, message: "Failed to create post");
return PostModel.fromKbinPost(
return PostModel.fromMbinPost(
jsonDecode(response.body) as Map<String, Object?>);
}

View File

@ -8,12 +8,12 @@ import 'package:interstellar/src/utils/utils.dart';
// new_ is used because new is a reserved keyword
enum NotificationsFilter { all, new_, read }
class KbinAPINotifications {
class MbinAPINotifications {
final ServerSoftware software;
final http.Client httpClient;
final String server;
KbinAPINotifications(
MbinAPINotifications(
this.software,
this.httpClient,
this.server,
@ -31,13 +31,12 @@ class KbinAPINotifications {
httpErrorHandler(response, message: 'Failed to load notifications');
return NotificationListModel.fromKbin(
return NotificationListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
Future<int> getCount() async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/notifications/count';
@ -81,7 +80,7 @@ class KbinAPINotifications {
httpErrorHandler(response, message: 'Failed to mark notification');
return NotificationModel.fromKbin(
return NotificationModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
}
}

View File

@ -21,7 +21,6 @@ class APISearch {
String? search,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/search';
@ -33,7 +32,7 @@ class APISearch {
httpErrorHandler(response, message: 'Failed to load search');
return SearchListModel.fromKbin(
return SearchListModel.fromMbin(
jsonDecode(response.body) as Map<String, dynamic>);
case ServerSoftware.lemmy:
@ -45,21 +44,16 @@ class APISearch {
'listing_type': 'All'
});
final response = await httpClient.get(Uri.https(
server,
path,
query
));
final response = await httpClient.get(Uri.https(server, path, query));
httpErrorHandler(response, message: 'Failed to load search');
final json = jsonDecode(response.body) as Map<String, Object?>;
String? nextPage = null;
if ((json['comments'] as List<dynamic>).isNotEmpty
|| (json['posts'] as List<dynamic>).isNotEmpty
|| (json['communities'] as List<dynamic>).isNotEmpty
|| (json['users'] as List<dynamic>).isNotEmpty) {
final json = jsonDecode(response.body) as Map<String, Object?>;
String? nextPage;
if ((json['comments'] as List<dynamic>).isNotEmpty ||
(json['posts'] as List<dynamic>).isNotEmpty ||
(json['communities'] as List<dynamic>).isNotEmpty ||
(json['users'] as List<dynamic>).isNotEmpty) {
nextPage = (int.parse(page ?? '1') + 1).toString();
}

View File

@ -53,7 +53,6 @@ class APIThreads {
bool? usePreferredLangs,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = switch (source) {
FeedSource.all => '/api/entries',
@ -75,7 +74,7 @@ class APIThreads {
httpErrorHandler(response, message: 'Failed to load entries');
return PostListModel.fromKbinEntries(
return PostListModel.fromMbinEntries(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -126,7 +125,6 @@ class APIThreads {
Future<PostModel> get(int postId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/entry/$postId';
@ -134,7 +132,7 @@ class APIThreads {
httpErrorHandler(response, message: 'Failed to load post');
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -154,7 +152,6 @@ class APIThreads {
Future<PostModel> vote(int postId, int choice, int newScore) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = choice == 1
? '/api/entry/$postId/favourite'
@ -164,7 +161,7 @@ class APIThreads {
httpErrorHandler(response, message: 'Failed to send vote');
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -188,7 +185,6 @@ class APIThreads {
Future<PostModel> boost(int postId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/entry/$postId/vote/1';
@ -196,7 +192,7 @@ class APIThreads {
httpErrorHandler(response, message: 'Failed to send boost');
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -213,7 +209,6 @@ class APIThreads {
bool? isAdult,
) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/entry/$entryID';
@ -231,21 +226,21 @@ class APIThreads {
httpErrorHandler(response, message: "Failed to edit entry");
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
const path = '/api/v3/post';
final response = await httpClient.put(
Uri.https(server, path),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'post_id': entryID,
'name': title,
'body': body,
'nsfw': isAdult
})
Uri.https(server, path),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'post_id': entryID,
'name': title,
'body': body,
'nsfw': isAdult
}),
);
httpErrorHandler(response, message: 'Failed to edit entry');
@ -257,22 +252,19 @@ class APIThreads {
Future<void> delete(int postID) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final response =
await httpClient.delete(Uri.https(server, '/api/entry/$postID'));
await httpClient.delete(Uri.https(server, '/api/entry/$postID'));
httpErrorHandler(response, message: "Failed to delete entry");
break;
case ServerSoftware.lemmy:
final response =
await httpClient.post(Uri.https(server, '/api/v3/post/delete'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'post_id': postID,
'deleted': true
}));
final response = await httpClient.post(
Uri.https(server, '/api/v3/post/delete'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'post_id': postID, 'deleted': true}),
);
httpErrorHandler(response, message: "Failed to delete entry");
break;
@ -289,7 +281,6 @@ class APIThreads {
required List<String> tags,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/$magazineID/article';
@ -307,7 +298,7 @@ class APIThreads {
httpErrorHandler(response, message: "Failed to create entry");
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -341,7 +332,6 @@ class APIThreads {
required List<String> tags,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/$magazineID/link';
@ -360,7 +350,7 @@ class APIThreads {
httpErrorHandler(response, message: "Failed to create entry");
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -396,7 +386,6 @@ class APIThreads {
required List<String> tags,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/magazine/$magazineID/image';
@ -422,8 +411,9 @@ class APIThreads {
httpErrorHandler(response, message: "Failed to create entry");
return PostModel.fromKbinEntry(
return PostModel.fromMbinEntry(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
const pictrsPath = '/pictrs/image';
@ -468,7 +458,6 @@ class APIThreads {
Future<void> report(int postId, String reason) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/entry/$postId/report';

View File

@ -27,7 +27,6 @@ class APIUsers {
UsersFilter? filter,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = (filter == null || filter == UsersFilter.all)
? '/api/users'
@ -40,7 +39,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load users');
return DetailedUserListModel.fromKbin(
return DetailedUserListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -50,7 +49,6 @@ class APIUsers {
Future<DetailedUserModel> get(int userId) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId';
@ -58,7 +56,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load user');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -78,7 +76,6 @@ class APIUsers {
Future<DetailedUserModel> getByName(String username) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path =
'/api/users/name/${username.contains('@') ? '@$username' : username}';
@ -87,7 +84,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load user');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -107,7 +104,6 @@ class APIUsers {
Future<UserModel> getMe() async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/me';
@ -115,7 +111,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load user');
return UserModel.fromKbin(
return UserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -135,7 +131,6 @@ class APIUsers {
bool state,
) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId/${state ? 'follow' : 'unfollow'}';
@ -143,7 +138,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to send follow');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -153,7 +148,6 @@ class APIUsers {
Future<DetailedUserModel?> updateProfile(String about) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/profile';
@ -162,7 +156,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to update profile');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -183,7 +177,6 @@ class APIUsers {
bool state,
) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId/${state ? 'block' : 'unblock'}';
@ -191,7 +184,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to send block');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -215,7 +208,6 @@ class APIUsers {
Future<DetailedUserModel?> updateAvatar(XFile image) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/avatar';
@ -232,7 +224,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to update avatar');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -275,14 +267,13 @@ class APIUsers {
Future<DetailedUserModel> deleteAvatar() async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/avatar';
var response = await httpClient.delete(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to delete avatar');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -292,7 +283,6 @@ class APIUsers {
Future<DetailedUserModel?> updateCover(XFile image) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/cover';
@ -309,7 +299,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to update cover');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -350,14 +340,13 @@ class APIUsers {
Future<DetailedUserModel> deleteCover() async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/cover';
var response = await httpClient.delete(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to delete cover');
return DetailedUserModel.fromKbin(
return DetailedUserModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -370,7 +359,6 @@ class APIUsers {
String? page,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId/followers';
final query = queryParams({
@ -381,7 +369,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load followers');
return DetailedUserListModel.fromKbin(
return DetailedUserListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -394,7 +382,6 @@ class APIUsers {
String? page,
}) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
final path = '/api/users/$userId/followed';
final query = queryParams({
@ -405,7 +392,7 @@ class APIUsers {
httpErrorHandler(response, message: 'Failed to load following');
return DetailedUserListModel.fromKbin(
return DetailedUserListModel.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -415,14 +402,13 @@ class APIUsers {
Future<UserSettings> getUserSettings() async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/settings';
final response = await httpClient.get(Uri.https(server, path));
httpErrorHandler(response, message: 'Failed to get user settings');
return UserSettings.fromKbin(
return UserSettings.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:
@ -439,7 +425,6 @@ class APIUsers {
Future<UserSettings> saveUserSettings(UserSettings settings) async {
switch (software) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
const path = '/api/users/settings';
final response = await httpClient.put(Uri.https(server, path),
@ -452,15 +437,17 @@ class APIUsers {
'showProfileFollowings': settings.showProfileFollowings,
'notifyOnNewEntry': settings.notifyOnNewEntry,
'notifyOnNewEntryReply': settings.notifyOnNewEntryReply,
'notifyOnNewEntryCommentReply': settings.notifyOnNewEntryCommentReply,
'notifyOnNewEntryCommentReply':
settings.notifyOnNewEntryCommentReply,
'notifyOnNewPost': settings.notifyOnNewPost,
'notifyOnNewPostReply': settings.notifyOnNewPostReply,
'notifyOnNewPostCommentReply': settings.notifyOnNewPostCommentReply,
'notifyOnNewPostCommentReply':
settings.notifyOnNewPostCommentReply,
}));
httpErrorHandler(response, message: 'Failed to save user settings');
return UserSettings.fromKbin(
return UserSettings.fromMbin(
jsonDecode(response.body) as Map<String, Object?>);
case ServerSoftware.lemmy:

View File

@ -14,12 +14,12 @@ class CommentListModel with _$CommentListModel {
required String? nextPage,
}) = _CommentListModel;
factory CommentListModel.fromKbin(Map<String, Object?> json) =>
factory CommentListModel.fromMbin(Map<String, Object?> json) =>
CommentListModel(
items: (json['items'] as List<dynamic>)
.map((post) => CommentModel.fromKbin(post as Map<String, Object?>))
.map((post) => CommentModel.fromMbin(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
@ -62,17 +62,17 @@ class CommentModel with _$CommentModel {
required String visibility,
}) = _CommentModel;
factory CommentModel.fromKbin(Map<String, Object?> json) => CommentModel(
factory CommentModel.fromMbin(Map<String, Object?> json) => CommentModel(
id: json['commentId'] as int,
user: UserModel.fromKbin(json['user'] as Map<String, Object?>),
user: UserModel.fromMbin(json['user'] as Map<String, Object?>),
magazine:
MagazineModel.fromKbin(json['magazine'] as Map<String, Object?>),
MagazineModel.fromMbin(json['magazine'] as Map<String, Object?>),
postType:
(json['postId'] != null ? PostType.microblog : PostType.thread),
postId: (json['entryId'] ?? json['postId']) as int,
rootId: json['rootId'] as int?,
parentId: json['parentId'] as int?,
image: kbinGetImage(json['image'] as Map<String, Object?>?),
image: mbinGetImage(json['image'] as Map<String, Object?>?),
body: json['body'] as String?,
lang: json['lang'] as String,
upvotes: json['favourites'] as int?,
@ -85,7 +85,7 @@ class CommentModel with _$CommentModel {
createdAt: DateTime.parse(json['createdAt'] as String),
editedAt: optionalDateTime(json['editedAt'] as String?),
children: (json['children'] as List<dynamic>)
.map((c) => CommentModel.fromKbin(c as Map<String, Object?>))
.map((c) => CommentModel.fromMbin(c as Map<String, Object?>))
.toList(),
childCount: json['childCount'] as int,
visibility: json['visibility'] as String,

View File

@ -10,12 +10,12 @@ class DomainListModel with _$DomainListModel {
required String? nextPage,
}) = _DomainListModel;
factory DomainListModel.fromKbin(Map<String, Object?> json) =>
factory DomainListModel.fromMbin(Map<String, Object?> json) =>
DomainListModel(
items: (json['items'] as List<dynamic>)
.map((post) => DomainModel.fromKbin(post as Map<String, Object?>))
.map((post) => DomainModel.fromMbin(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
}
@ -31,7 +31,7 @@ class DomainModel with _$DomainModel {
required bool? isBlockedByUser,
}) = _DomainModel;
factory DomainModel.fromKbin(Map<String, Object?> json) => DomainModel(
factory DomainModel.fromMbin(Map<String, Object?> json) => DomainModel(
id: json['domainId'] as int,
name: json['name'] as String,
entryCount: json['entryCount'] as int,

View File

@ -12,7 +12,7 @@ class ImageModel with _$ImageModel {
required int? blurHashHeight,
}) = _ImageModel;
factory ImageModel.fromKbin(Map<String, Object?> json) => ImageModel(
factory ImageModel.fromMbin(Map<String, Object?> json) => ImageModel(
src: (json['storageUrl'] ?? json['sourceUrl']) as String,
altText: json['altText'] as String?,
blurHash: json['blurHash'] as String?,

View File

@ -13,13 +13,13 @@ class DetailedMagazineListModel with _$DetailedMagazineListModel {
required String? nextPage,
}) = _DetailedMagazineListModel;
factory DetailedMagazineListModel.fromKbin(Map<String, Object?> json) =>
factory DetailedMagazineListModel.fromMbin(Map<String, Object?> json) =>
DetailedMagazineListModel(
items: (json['items'] as List<dynamic>)
.map((item) =>
DetailedMagazineModel.fromKbin(item as Map<String, Object?>))
DetailedMagazineModel.fromMbin(item as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
@ -53,16 +53,16 @@ class DetailedMagazineModel with _$DetailedMagazineModel {
required bool? isBlockedByUser,
}) = _DetailedMagazineModel;
factory DetailedMagazineModel.fromKbin(Map<String, Object?> json) {
factory DetailedMagazineModel.fromMbin(Map<String, Object?> json) {
final magazine = DetailedMagazineModel(
id: json['magazineId'] as int,
name: json['name'] as String,
title: json['title'] as String,
icon: kbinGetImage(json['icon'] as Map<String, Object?>?),
icon: mbinGetImage(json['icon'] as Map<String, Object?>?),
description: json['description'] as String?,
rules: json['rules'] as String?,
moderators: ((json['moderators'] ?? []) as List<dynamic>)
.map((user) => UserModel.fromKbin(user as Map<String, Object?>))
.map((user) => UserModel.fromMbin(user as Map<String, Object?>))
.toList(),
subscriptionsCount: json['subscriptionsCount'] as int,
threadCount: json['entryCount'] as int,
@ -115,10 +115,10 @@ class MagazineModel with _$MagazineModel {
required ImageModel? icon,
}) = _MagazineModel;
factory MagazineModel.fromKbin(Map<String, Object?> json) => MagazineModel(
factory MagazineModel.fromMbin(Map<String, Object?> json) => MagazineModel(
id: json['magazineId'] as int,
name: json['name'] as String,
icon: kbinGetImage(json['icon'] as Map<String, Object?>?),
icon: mbinGetImage(json['icon'] as Map<String, Object?>?),
);
factory MagazineModel.fromLemmy(Map<String, Object?> json) => MagazineModel(

View File

@ -11,13 +11,13 @@ class MessageListModel with _$MessageListModel {
required String? nextPage,
}) = _MessageListModel;
factory MessageListModel.fromKbin(Map<String, Object?> json) =>
factory MessageListModel.fromMbin(Map<String, Object?> json) =>
MessageListModel(
items: (json['items'] as List<dynamic>)
.map((post) =>
MessageThreadModel.fromKbin(post as Map<String, Object?>))
MessageThreadModel.fromMbin(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
}
@ -31,16 +31,16 @@ class MessageThreadModel with _$MessageThreadModel {
required int threadId,
}) = _MessageThreadModel;
factory MessageThreadModel.fromKbin(Map<String, Object?> json) =>
factory MessageThreadModel.fromMbin(Map<String, Object?> json) =>
MessageThreadModel(
participants: (json['participants'] as List<dynamic>)
.map((participant) =>
DetailedUserModel.fromKbin(participant as Map<String, Object?>))
DetailedUserModel.fromMbin(participant as Map<String, Object?>))
.toList(),
messageCount: json['messageCount'] as int,
messages: (json['messages'] as List<dynamic>)
.map((message) =>
MessageItemModel.fromKbin(message as Map<String, Object?>))
MessageItemModel.fromMbin(message as Map<String, Object?>))
.toList(),
threadId: json['threadId'] as int,
);
@ -57,9 +57,9 @@ class MessageItemModel with _$MessageItemModel {
required int messageId,
}) = _MessageItemModel;
factory MessageItemModel.fromKbin(Map<String, Object?> json) =>
factory MessageItemModel.fromMbin(Map<String, Object?> json) =>
MessageItemModel(
sender: UserModel.fromKbin(json['sender'] as Map<String, Object?>),
sender: UserModel.fromMbin(json['sender'] as Map<String, Object?>),
body: json['body'] as String,
status: json['status'] as String,
threadId: json['threadId'] as int,

View File

@ -10,13 +10,13 @@ class NotificationListModel with _$NotificationListModel {
required String? nextPage,
}) = _NotificationListModel;
factory NotificationListModel.fromKbin(Map<String, Object?> json) =>
factory NotificationListModel.fromMbin(Map<String, Object?> json) =>
NotificationListModel(
items: (json['items'] as List<dynamic>)
.map((post) =>
NotificationModel.fromKbin(post as Map<String, Object?>))
NotificationModel.fromMbin(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
}
@ -30,7 +30,7 @@ class NotificationModel with _$NotificationModel {
required Map<String, Object?> subject,
}) = _NotificationModel;
factory NotificationModel.fromKbin(Map<String, Object?> json) =>
factory NotificationModel.fromMbin(Map<String, Object?> json) =>
NotificationModel(
id: json['notificationId'] as int,
type: notificationTypeEnumMap.entries

View File

@ -16,22 +16,22 @@ class PostListModel with _$PostListModel {
required String? nextPage,
}) = _PostListModel;
factory PostListModel.fromKbinEntries(Map<String, Object?> json) =>
factory PostListModel.fromMbinEntries(Map<String, Object?> json) =>
PostListModel(
items: (json['items'] as List<dynamic>)
.map(
(post) => PostModel.fromKbinEntry(post as Map<String, Object?>))
(post) => PostModel.fromMbinEntry(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
factory PostListModel.fromKbinPosts(Map<String, Object?> json) =>
factory PostListModel.fromMbinPosts(Map<String, Object?> json) =>
PostListModel(
items: (json['items'] as List<dynamic>)
.map((post) => PostModel.fromKbinPost(post as Map<String, Object?>))
.map((post) => PostModel.fromMbinPost(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
@ -71,16 +71,16 @@ class PostModel with _$PostModel {
required String visibility,
}) = _PostModel;
factory PostModel.fromKbinEntry(Map<String, Object?> json) => PostModel(
factory PostModel.fromMbinEntry(Map<String, Object?> json) => PostModel(
type: PostType.thread,
id: json['entryId'] as int,
user: UserModel.fromKbin(json['user'] as Map<String, Object?>),
user: UserModel.fromMbin(json['user'] as Map<String, Object?>),
magazine:
MagazineModel.fromKbin(json['magazine'] as Map<String, Object?>),
domain: DomainModel.fromKbin(json['domain'] as Map<String, Object?>),
MagazineModel.fromMbin(json['magazine'] as Map<String, Object?>),
domain: DomainModel.fromMbin(json['domain'] as Map<String, Object?>),
title: json['title'] as String,
url: json['url'] as String?,
image: kbinGetImage(json['image'] as Map<String, Object?>?),
image: mbinGetImage(json['image'] as Map<String, Object?>?),
body: json['body'] as String?,
lang: json['lang'] as String,
numComments: json['numComments'] as int,
@ -100,16 +100,16 @@ class PostModel with _$PostModel {
visibility: json['visibility'] as String,
);
factory PostModel.fromKbinPost(Map<String, Object?> json) => PostModel(
factory PostModel.fromMbinPost(Map<String, Object?> json) => PostModel(
type: PostType.microblog,
id: json['postId'] as int,
user: UserModel.fromKbin(json['user'] as Map<String, Object?>),
user: UserModel.fromMbin(json['user'] as Map<String, Object?>),
magazine:
MagazineModel.fromKbin(json['magazine'] as Map<String, Object?>),
MagazineModel.fromMbin(json['magazine'] as Map<String, Object?>),
domain: null,
title: null,
url: null,
image: kbinGetImage(json['image'] as Map<String, Object?>?),
image: mbinGetImage(json['image'] as Map<String, Object?>?),
body: json['body'] as String,
lang: json['lang'] as String,
numComments: json['comments'] as int,

View File

@ -14,33 +14,33 @@ class SearchListModel with _$SearchListModel {
required String? nextPage,
}) = _SearchListModel;
factory SearchListModel.fromKbin(Map<String, dynamic> json) {
factory SearchListModel.fromMbin(Map<String, dynamic> json) {
List<Object> items = [];
for (var actor in json['apActors']) {
var type = actor['type'];
if (type == 'user') {
items.add(DetailedUserModel.fromKbin(
items.add(DetailedUserModel.fromMbin(
actor['object'] as Map<String, Object?>));
} else if (type == 'magazine') {
items.add(DetailedMagazineModel.fromKbin(
items.add(DetailedMagazineModel.fromMbin(
actor['object'] as Map<String, Object?>));
}
}
for (var item in json['items']) {
var itemType = item['itemType'];
if (itemType == 'entry') {
items.add(PostModel.fromKbinEntry(item as Map<String, Object?>));
items.add(PostModel.fromMbinEntry(item as Map<String, Object?>));
} else if (itemType == 'post') {
items.add(PostModel.fromKbinPost(item as Map<String, Object?>));
items.add(PostModel.fromMbinPost(item as Map<String, Object?>));
} else if (itemType == 'entry_comment' || itemType == 'post_comment') {
items.add(CommentModel.fromKbin(item as Map<String, Object?>));
items.add(CommentModel.fromMbin(item as Map<String, Object?>));
}
}
return SearchListModel(
items: items,
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
}
@ -53,7 +53,8 @@ class SearchListModel with _$SearchListModel {
}
for (var community in json['communities']) {
items.add(DetailedMagazineModel.fromLemmy(community as Map<String, Object?>));
items.add(
DetailedMagazineModel.fromLemmy(community as Map<String, Object?>));
}
for (var post in json['posts']) {
@ -65,8 +66,6 @@ class SearchListModel with _$SearchListModel {
}
return SearchListModel(
items: items,
nextPage: json['next_page'] as String?
);
items: items, nextPage: json['next_page'] as String?);
}
}

View File

@ -12,13 +12,13 @@ class DetailedUserListModel with _$DetailedUserListModel {
required String? nextPage,
}) = _DetailedUserListModel;
factory DetailedUserListModel.fromKbin(Map<String, Object?> json) =>
factory DetailedUserListModel.fromMbin(Map<String, Object?> json) =>
DetailedUserListModel(
items: (json['items'] as List<dynamic>)
.map((post) =>
DetailedUserModel.fromKbin(post as Map<String, Object?>))
DetailedUserModel.fromMbin(post as Map<String, Object?>))
.toList(),
nextPage: kbinCalcNextPaginationPage(
nextPage: mbinCalcNextPaginationPage(
json['pagination'] as Map<String, Object?>),
);
}
@ -40,13 +40,13 @@ class DetailedUserModel with _$DetailedUserModel {
required bool? isBlockedByUser,
}) = _DetailedUserModel;
factory DetailedUserModel.fromKbin(Map<String, Object?> json) {
factory DetailedUserModel.fromMbin(Map<String, Object?> json) {
final user = DetailedUserModel(
id: json['userId'] as int,
name: kbinNormalizeUsername(json['username'] as String),
name: mbinNormalizeUsername(json['username'] as String),
displayName: null,
avatar: kbinGetImage(json['avatar'] as Map<String, Object?>?),
cover: kbinGetImage(json['cover'] as Map<String, Object?>?),
avatar: mbinGetImage(json['avatar'] as Map<String, Object?>?),
cover: mbinGetImage(json['cover'] as Map<String, Object?>?),
createdAt: DateTime.parse(json['createdAt'] as String),
isBot: json['isBot'] as bool,
about: json['about'] as String?,
@ -90,10 +90,10 @@ class UserModel with _$UserModel {
required ImageModel? avatar,
}) = _UserModel;
factory UserModel.fromKbin(Map<String, Object?> json) => UserModel(
factory UserModel.fromMbin(Map<String, Object?> json) => UserModel(
id: json['userId'] as int,
name: kbinNormalizeUsername(json['username'] as String),
avatar: kbinGetImage(json['avatar'] as Map<String, Object?>?),
name: mbinNormalizeUsername(json['username'] as String),
avatar: mbinGetImage(json['avatar'] as Map<String, Object?>?),
);
factory UserModel.fromLemmy(Map<String, Object?> json) => UserModel(
@ -122,7 +122,7 @@ class UserSettings with _$UserSettings {
required bool? notifyOnNewPostCommentReply,
}) = _UserSettings;
factory UserSettings.fromKbin(Map<String, Object?> json) => UserSettings(
factory UserSettings.fromMbin(Map<String, Object?> json) => UserSettings(
showNSFW: !(json['hideAdult'] as bool),
blurNSFW: null,
showReadPosts: null,

View File

@ -21,7 +21,7 @@ class DomainsScreen extends StatefulWidget {
}
class _DomainsScreenState extends State<DomainsScreen> {
KbinAPIDomainsFilter filter = KbinAPIDomainsFilter.all;
MbinAPIDomainsFilter filter = MbinAPIDomainsFilter.all;
String search = "";
final PagingController<String, DomainModel> _pagingController =
@ -32,7 +32,7 @@ class _DomainsScreenState extends State<DomainsScreen> {
super.initState();
if (widget.onlySubbed) {
filter = KbinAPIDomainsFilter.subscribed;
filter = MbinAPIDomainsFilter.subscribed;
}
_pagingController.addPageRequestListener(_fetchPage);
@ -77,7 +77,7 @@ class _DomainsScreenState extends State<DomainsScreen> {
...whenLoggedIn(context, [
Padding(
padding: const EdgeInsets.only(right: 12),
child: DropdownButton<KbinAPIDomainsFilter>(
child: DropdownButton<MbinAPIDomainsFilter>(
value: filter,
onChanged: (newFilter) {
if (newFilter != null) {
@ -89,15 +89,15 @@ class _DomainsScreenState extends State<DomainsScreen> {
},
items: const [
DropdownMenuItem(
value: KbinAPIDomainsFilter.all,
value: MbinAPIDomainsFilter.all,
child: Text('All'),
),
DropdownMenuItem(
value: KbinAPIDomainsFilter.subscribed,
value: MbinAPIDomainsFilter.subscribed,
child: Text('Subscribed'),
),
DropdownMenuItem(
value: KbinAPIDomainsFilter.blocked,
value: MbinAPIDomainsFilter.blocked,
child: Text('Blocked'),
),
],
@ -105,7 +105,7 @@ class _DomainsScreenState extends State<DomainsScreen> {
)
]) ??
[],
if (filter == KbinAPIDomainsFilter.all)
if (filter == MbinAPIDomainsFilter.all)
SizedBox(
width: 128,
child: TextFormField(

View File

@ -60,7 +60,7 @@ class _NavDrawerState extends State<NavDrawer> {
.read<SettingsController>()
.api
.domains
.list(filter: KbinAPIDomainsFilter.subscribed)
.list(filter: MbinAPIDomainsFilter.subscribed)
.then((value) => setState(() {
if (value.items.isNotEmpty) {
subbedDomains = value.items;

View File

@ -53,11 +53,11 @@ class _NotificationItemState extends State<NotificationItem> {
Map<String, Object?> rawUser = (widget.item.subject['user'] ??
widget.item.subject['sender'] ??
widget.item.subject['bannedBy']) as Map<String, Object?>;
UserModel user = UserModel.fromKbin(rawUser);
UserModel user = UserModel.fromMbin(rawUser);
MagazineModel? bannedMagazine =
widget.item.type == NotificationType.banNotification &&
widget.item.subject['magazine'] != null
? MagazineModel.fromKbin(
? MagazineModel.fromMbin(
widget.item.subject['magazine'] as Map<String, Object?>)
: null;

View File

@ -133,7 +133,7 @@ class _LoginConfirmScreenState extends State<LoginConfirmScreen> {
String identifier = await context
.read<SettingsController>()
.getKbinOAuthIdentifier(
.getMbinOAuthIdentifier(
widget.software, widget.server);
final grant = oauth2.AuthorizationCodeGrant(

View File

@ -15,7 +15,7 @@ import 'package:interstellar/src/widgets/markdown/markdown_mention.dart';
import 'package:oauth2/oauth2.dart' as oauth2;
import 'package:shared_preferences/shared_preferences.dart';
enum ServerSoftware { kbin, mbin, lemmy }
enum ServerSoftware { mbin, lemmy }
enum PostImagePosition { auto, top, right }
@ -26,7 +26,9 @@ class Server {
Server(this.software, {this.oauthIdentifier});
factory Server.fromJson(Map<String, Object?> json) => Server(
ServerSoftware.values.byName(json['software'] as String),
ServerSoftware.values.byName(json['software'] as String == 'kbin'
? 'mbin'
: json['software'] as String),
oauthIdentifier: json['oauthIdentifier'] as String?,
);
@ -496,7 +498,7 @@ class SettingsController with ChangeNotifier {
await prefs.setString('servers', jsonEncode(_servers));
}
Future<String> getKbinOAuthIdentifier(
Future<String> getMbinOAuthIdentifier(
ServerSoftware software, String server) async {
if (_servers.containsKey(server) &&
_servers[server]!.oauthIdentifier != null) {
@ -573,7 +575,6 @@ class SettingsController with ChangeNotifier {
http.Client httpClient = http.Client();
switch (serverSoftware) {
case ServerSoftware.kbin:
case ServerSoftware.mbin:
oauth2.Credentials? credentials = _accounts[_selectedAccount]!.oauth;
if (credentials != null) {

View File

@ -3,21 +3,21 @@ import 'package:interstellar/src/models/image.dart';
DateTime? optionalDateTime(String? value) =>
value == null ? null : DateTime.parse(value);
String? kbinCalcNextPaginationPage(Map<String, Object?> pagination) {
String? mbinCalcNextPaginationPage(Map<String, Object?> pagination) {
return (pagination['currentPage'] as int) != (pagination['maxPage'] as int)
? ((pagination['currentPage'] as int) + 1).toString()
: null;
}
ImageModel? kbinGetImage(Map<String, Object?>? json) {
return json == null ? null : ImageModel.fromKbin(json);
ImageModel? mbinGetImage(Map<String, Object?>? json) {
return json == null ? null : ImageModel.fromMbin(json);
}
ImageModel? lemmyGetImage(String? json) {
return json == null ? null : ImageModel.fromLemmy(json);
}
String kbinNormalizeUsername(String username) {
String mbinNormalizeUsername(String username) {
return username.startsWith('@') ? username.substring(1) : username;
}