diff --git a/README.md b/README.md index c284708..d2a3ad5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/src/api/api.dart b/lib/src/api/api.dart index c2a694e..7a9174c 100644 --- a/lib/src/api/api.dart +++ b/lib/src/api/api.dart @@ -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); } diff --git a/lib/src/api/comments.dart b/lib/src/api/comments.dart index 3c1d728..56e8ba5 100644 --- a/lib/src/api/comments.dart +++ b/lib/src/api/comments.dart @@ -50,11 +50,11 @@ const SelectionMenu 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); 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); case ServerSoftware.lemmy: @@ -163,15 +161,14 @@ class APIComments { Future 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); 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); + case ServerSoftware.lemmy: const path = '/api/v3/comment/like'; @@ -233,15 +230,14 @@ class APIComments { Future 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); 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); 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); case ServerSoftware.lemmy: @@ -334,9 +328,8 @@ class APIComments { Future 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 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), diff --git a/lib/src/api/domains.dart b/lib/src/api/domains.dart index 01483b8..09b9c7a 100644 --- a/lib/src/api/domains.dart +++ b/lib/src/api/domains.dart @@ -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 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); } @@ -46,7 +46,7 @@ class KbinAPIDomains { httpErrorHandler(response, message: 'Failed to load domain'); - return DomainModel.fromKbin( + return DomainModel.fromMbin( jsonDecode(response.body) as Map); } @@ -57,7 +57,7 @@ class KbinAPIDomains { httpErrorHandler(response, message: 'Failed to send subscribe'); - return DomainModel.fromKbin( + return DomainModel.fromMbin( jsonDecode(response.body) as Map); } @@ -68,7 +68,7 @@ class KbinAPIDomains { httpErrorHandler(response, message: 'Failed to send block'); - return DomainModel.fromKbin( + return DomainModel.fromMbin( jsonDecode(response.body) as Map); } } diff --git a/lib/src/api/magazines.dart b/lib/src/api/magazines.dart index f7a4092..427a718 100644 --- a/lib/src/api/magazines.dart +++ b/lib/src/api/magazines.dart @@ -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); case ServerSoftware.lemmy: @@ -169,7 +166,6 @@ class APIMagazines { Future 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); case ServerSoftware.lemmy: @@ -198,7 +194,6 @@ class APIMagazines { Future 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); case ServerSoftware.lemmy: @@ -227,7 +222,6 @@ class APIMagazines { Future 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); case ServerSoftware.lemmy: @@ -261,7 +255,6 @@ class APIMagazines { Future 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); case ServerSoftware.lemmy: diff --git a/lib/src/api/messages.dart b/lib/src/api/messages.dart index 9f4e134..64c310f 100644 --- a/lib/src/api/messages.dart +++ b/lib/src/api/messages.dart @@ -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); } @@ -43,7 +43,7 @@ class KbinAPIMessages { httpErrorHandler(response, message: 'Failed to send message'); - return MessageThreadModel.fromKbin( + return MessageThreadModel.fromMbin( jsonDecode(response.body) as Map); } @@ -60,7 +60,7 @@ class KbinAPIMessages { httpErrorHandler(response, message: 'Failed to send message'); - return MessageThreadModel.fromKbin( + return MessageThreadModel.fromMbin( jsonDecode(response.body) as Map); } } diff --git a/lib/src/api/microblogs.dart b/lib/src/api/microblogs.dart index f9017d1..f4b3391 100644 --- a/lib/src/api/microblogs.dart +++ b/lib/src/api/microblogs.dart @@ -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); } @@ -62,7 +62,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: 'Failed to load posts'); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } @@ -73,7 +73,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: 'Failed to send vote'); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } @@ -84,7 +84,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: 'Failed to send vote'); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } @@ -103,7 +103,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: "Failed to edit post"); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } @@ -130,7 +130,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: "Failed to create post"); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } @@ -162,7 +162,7 @@ class KbinAPIMicroblogs { httpErrorHandler(response, message: "Failed to create post"); - return PostModel.fromKbinPost( + return PostModel.fromMbinPost( jsonDecode(response.body) as Map); } diff --git a/lib/src/api/notifications.dart b/lib/src/api/notifications.dart index 0cdc657..c024148 100644 --- a/lib/src/api/notifications.dart +++ b/lib/src/api/notifications.dart @@ -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); } Future 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); } } diff --git a/lib/src/api/search.dart b/lib/src/api/search.dart index 864bfe2..88fd9ec 100644 --- a/lib/src/api/search.dart +++ b/lib/src/api/search.dart @@ -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); 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? nextPage = null; - if ((json['comments'] as List).isNotEmpty - || (json['posts'] as List).isNotEmpty - || (json['communities'] as List).isNotEmpty - || (json['users'] as List).isNotEmpty) { + final json = jsonDecode(response.body) as Map; + String? nextPage; + if ((json['comments'] as List).isNotEmpty || + (json['posts'] as List).isNotEmpty || + (json['communities'] as List).isNotEmpty || + (json['users'] as List).isNotEmpty) { nextPage = (int.parse(page ?? '1') + 1).toString(); } diff --git a/lib/src/api/threads.dart b/lib/src/api/threads.dart index b7a6b6d..9275af0 100644 --- a/lib/src/api/threads.dart +++ b/lib/src/api/threads.dart @@ -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); case ServerSoftware.lemmy: @@ -126,7 +125,6 @@ class APIThreads { Future 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); case ServerSoftware.lemmy: @@ -154,7 +152,6 @@ class APIThreads { Future 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); case ServerSoftware.lemmy: @@ -188,7 +185,6 @@ class APIThreads { Future 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); 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); 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 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 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); case ServerSoftware.lemmy: @@ -341,7 +332,6 @@ class APIThreads { required List 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); case ServerSoftware.lemmy: @@ -396,7 +386,6 @@ class APIThreads { required List 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); + case ServerSoftware.lemmy: const pictrsPath = '/pictrs/image'; @@ -468,7 +458,6 @@ class APIThreads { Future report(int postId, String reason) async { switch (software) { - case ServerSoftware.kbin: case ServerSoftware.mbin: final path = '/api/entry/$postId/report'; diff --git a/lib/src/api/users.dart b/lib/src/api/users.dart index 76f5572..4c7c127 100644 --- a/lib/src/api/users.dart +++ b/lib/src/api/users.dart @@ -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); case ServerSoftware.lemmy: @@ -50,7 +49,6 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -78,7 +76,6 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -107,7 +104,6 @@ class APIUsers { Future 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); 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); case ServerSoftware.lemmy: @@ -153,7 +148,6 @@ class APIUsers { Future 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); 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); case ServerSoftware.lemmy: @@ -215,7 +208,6 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -275,14 +267,13 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -292,7 +283,6 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -350,14 +340,13 @@ class APIUsers { Future 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); 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); 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); case ServerSoftware.lemmy: @@ -415,14 +402,13 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: @@ -439,7 +425,6 @@ class APIUsers { Future 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); case ServerSoftware.lemmy: diff --git a/lib/src/models/comment.dart b/lib/src/models/comment.dart index 67bc5a3..39700a2 100644 --- a/lib/src/models/comment.dart +++ b/lib/src/models/comment.dart @@ -14,12 +14,12 @@ class CommentListModel with _$CommentListModel { required String? nextPage, }) = _CommentListModel; - factory CommentListModel.fromKbin(Map json) => + factory CommentListModel.fromMbin(Map json) => CommentListModel( items: (json['items'] as List) - .map((post) => CommentModel.fromKbin(post as Map)) + .map((post) => CommentModel.fromMbin(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); @@ -62,17 +62,17 @@ class CommentModel with _$CommentModel { required String visibility, }) = _CommentModel; - factory CommentModel.fromKbin(Map json) => CommentModel( + factory CommentModel.fromMbin(Map json) => CommentModel( id: json['commentId'] as int, - user: UserModel.fromKbin(json['user'] as Map), + user: UserModel.fromMbin(json['user'] as Map), magazine: - MagazineModel.fromKbin(json['magazine'] as Map), + MagazineModel.fromMbin(json['magazine'] as Map), 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?), + image: mbinGetImage(json['image'] as Map?), 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) - .map((c) => CommentModel.fromKbin(c as Map)) + .map((c) => CommentModel.fromMbin(c as Map)) .toList(), childCount: json['childCount'] as int, visibility: json['visibility'] as String, diff --git a/lib/src/models/domain.dart b/lib/src/models/domain.dart index 3e5573c..12c386a 100644 --- a/lib/src/models/domain.dart +++ b/lib/src/models/domain.dart @@ -10,12 +10,12 @@ class DomainListModel with _$DomainListModel { required String? nextPage, }) = _DomainListModel; - factory DomainListModel.fromKbin(Map json) => + factory DomainListModel.fromMbin(Map json) => DomainListModel( items: (json['items'] as List) - .map((post) => DomainModel.fromKbin(post as Map)) + .map((post) => DomainModel.fromMbin(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); } @@ -31,7 +31,7 @@ class DomainModel with _$DomainModel { required bool? isBlockedByUser, }) = _DomainModel; - factory DomainModel.fromKbin(Map json) => DomainModel( + factory DomainModel.fromMbin(Map json) => DomainModel( id: json['domainId'] as int, name: json['name'] as String, entryCount: json['entryCount'] as int, diff --git a/lib/src/models/image.dart b/lib/src/models/image.dart index b8bc9b5..024f303 100644 --- a/lib/src/models/image.dart +++ b/lib/src/models/image.dart @@ -12,7 +12,7 @@ class ImageModel with _$ImageModel { required int? blurHashHeight, }) = _ImageModel; - factory ImageModel.fromKbin(Map json) => ImageModel( + factory ImageModel.fromMbin(Map json) => ImageModel( src: (json['storageUrl'] ?? json['sourceUrl']) as String, altText: json['altText'] as String?, blurHash: json['blurHash'] as String?, diff --git a/lib/src/models/magazine.dart b/lib/src/models/magazine.dart index 5bec8eb..a45a662 100644 --- a/lib/src/models/magazine.dart +++ b/lib/src/models/magazine.dart @@ -13,13 +13,13 @@ class DetailedMagazineListModel with _$DetailedMagazineListModel { required String? nextPage, }) = _DetailedMagazineListModel; - factory DetailedMagazineListModel.fromKbin(Map json) => + factory DetailedMagazineListModel.fromMbin(Map json) => DetailedMagazineListModel( items: (json['items'] as List) .map((item) => - DetailedMagazineModel.fromKbin(item as Map)) + DetailedMagazineModel.fromMbin(item as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); @@ -53,16 +53,16 @@ class DetailedMagazineModel with _$DetailedMagazineModel { required bool? isBlockedByUser, }) = _DetailedMagazineModel; - factory DetailedMagazineModel.fromKbin(Map json) { + factory DetailedMagazineModel.fromMbin(Map 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?), + icon: mbinGetImage(json['icon'] as Map?), description: json['description'] as String?, rules: json['rules'] as String?, moderators: ((json['moderators'] ?? []) as List) - .map((user) => UserModel.fromKbin(user as Map)) + .map((user) => UserModel.fromMbin(user as Map)) .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 json) => MagazineModel( + factory MagazineModel.fromMbin(Map json) => MagazineModel( id: json['magazineId'] as int, name: json['name'] as String, - icon: kbinGetImage(json['icon'] as Map?), + icon: mbinGetImage(json['icon'] as Map?), ); factory MagazineModel.fromLemmy(Map json) => MagazineModel( diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 0cdb7b5..e50f90a 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -11,13 +11,13 @@ class MessageListModel with _$MessageListModel { required String? nextPage, }) = _MessageListModel; - factory MessageListModel.fromKbin(Map json) => + factory MessageListModel.fromMbin(Map json) => MessageListModel( items: (json['items'] as List) .map((post) => - MessageThreadModel.fromKbin(post as Map)) + MessageThreadModel.fromMbin(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); } @@ -31,16 +31,16 @@ class MessageThreadModel with _$MessageThreadModel { required int threadId, }) = _MessageThreadModel; - factory MessageThreadModel.fromKbin(Map json) => + factory MessageThreadModel.fromMbin(Map json) => MessageThreadModel( participants: (json['participants'] as List) .map((participant) => - DetailedUserModel.fromKbin(participant as Map)) + DetailedUserModel.fromMbin(participant as Map)) .toList(), messageCount: json['messageCount'] as int, messages: (json['messages'] as List) .map((message) => - MessageItemModel.fromKbin(message as Map)) + MessageItemModel.fromMbin(message as Map)) .toList(), threadId: json['threadId'] as int, ); @@ -57,9 +57,9 @@ class MessageItemModel with _$MessageItemModel { required int messageId, }) = _MessageItemModel; - factory MessageItemModel.fromKbin(Map json) => + factory MessageItemModel.fromMbin(Map json) => MessageItemModel( - sender: UserModel.fromKbin(json['sender'] as Map), + sender: UserModel.fromMbin(json['sender'] as Map), body: json['body'] as String, status: json['status'] as String, threadId: json['threadId'] as int, diff --git a/lib/src/models/notification.dart b/lib/src/models/notification.dart index 91c263f..42a3500 100644 --- a/lib/src/models/notification.dart +++ b/lib/src/models/notification.dart @@ -10,13 +10,13 @@ class NotificationListModel with _$NotificationListModel { required String? nextPage, }) = _NotificationListModel; - factory NotificationListModel.fromKbin(Map json) => + factory NotificationListModel.fromMbin(Map json) => NotificationListModel( items: (json['items'] as List) .map((post) => - NotificationModel.fromKbin(post as Map)) + NotificationModel.fromMbin(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); } @@ -30,7 +30,7 @@ class NotificationModel with _$NotificationModel { required Map subject, }) = _NotificationModel; - factory NotificationModel.fromKbin(Map json) => + factory NotificationModel.fromMbin(Map json) => NotificationModel( id: json['notificationId'] as int, type: notificationTypeEnumMap.entries diff --git a/lib/src/models/post.dart b/lib/src/models/post.dart index cb4bf3a..d2e6335 100644 --- a/lib/src/models/post.dart +++ b/lib/src/models/post.dart @@ -16,22 +16,22 @@ class PostListModel with _$PostListModel { required String? nextPage, }) = _PostListModel; - factory PostListModel.fromKbinEntries(Map json) => + factory PostListModel.fromMbinEntries(Map json) => PostListModel( items: (json['items'] as List) .map( - (post) => PostModel.fromKbinEntry(post as Map)) + (post) => PostModel.fromMbinEntry(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); - factory PostListModel.fromKbinPosts(Map json) => + factory PostListModel.fromMbinPosts(Map json) => PostListModel( items: (json['items'] as List) - .map((post) => PostModel.fromKbinPost(post as Map)) + .map((post) => PostModel.fromMbinPost(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); @@ -71,16 +71,16 @@ class PostModel with _$PostModel { required String visibility, }) = _PostModel; - factory PostModel.fromKbinEntry(Map json) => PostModel( + factory PostModel.fromMbinEntry(Map json) => PostModel( type: PostType.thread, id: json['entryId'] as int, - user: UserModel.fromKbin(json['user'] as Map), + user: UserModel.fromMbin(json['user'] as Map), magazine: - MagazineModel.fromKbin(json['magazine'] as Map), - domain: DomainModel.fromKbin(json['domain'] as Map), + MagazineModel.fromMbin(json['magazine'] as Map), + domain: DomainModel.fromMbin(json['domain'] as Map), title: json['title'] as String, url: json['url'] as String?, - image: kbinGetImage(json['image'] as Map?), + image: mbinGetImage(json['image'] as Map?), 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 json) => PostModel( + factory PostModel.fromMbinPost(Map json) => PostModel( type: PostType.microblog, id: json['postId'] as int, - user: UserModel.fromKbin(json['user'] as Map), + user: UserModel.fromMbin(json['user'] as Map), magazine: - MagazineModel.fromKbin(json['magazine'] as Map), + MagazineModel.fromMbin(json['magazine'] as Map), domain: null, title: null, url: null, - image: kbinGetImage(json['image'] as Map?), + image: mbinGetImage(json['image'] as Map?), body: json['body'] as String, lang: json['lang'] as String, numComments: json['comments'] as int, diff --git a/lib/src/models/search.dart b/lib/src/models/search.dart index ffe9a9a..5a8e043 100644 --- a/lib/src/models/search.dart +++ b/lib/src/models/search.dart @@ -14,33 +14,33 @@ class SearchListModel with _$SearchListModel { required String? nextPage, }) = _SearchListModel; - factory SearchListModel.fromKbin(Map json) { + factory SearchListModel.fromMbin(Map json) { List 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)); } else if (type == 'magazine') { - items.add(DetailedMagazineModel.fromKbin( + items.add(DetailedMagazineModel.fromMbin( actor['object'] as Map)); } } for (var item in json['items']) { var itemType = item['itemType']; if (itemType == 'entry') { - items.add(PostModel.fromKbinEntry(item as Map)); + items.add(PostModel.fromMbinEntry(item as Map)); } else if (itemType == 'post') { - items.add(PostModel.fromKbinPost(item as Map)); + items.add(PostModel.fromMbinPost(item as Map)); } else if (itemType == 'entry_comment' || itemType == 'post_comment') { - items.add(CommentModel.fromKbin(item as Map)); + items.add(CommentModel.fromMbin(item as Map)); } } return SearchListModel( items: items, - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); } @@ -53,7 +53,8 @@ class SearchListModel with _$SearchListModel { } for (var community in json['communities']) { - items.add(DetailedMagazineModel.fromLemmy(community as Map)); + items.add( + DetailedMagazineModel.fromLemmy(community as Map)); } 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?); } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 23bd402..a8c0e95 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -12,13 +12,13 @@ class DetailedUserListModel with _$DetailedUserListModel { required String? nextPage, }) = _DetailedUserListModel; - factory DetailedUserListModel.fromKbin(Map json) => + factory DetailedUserListModel.fromMbin(Map json) => DetailedUserListModel( items: (json['items'] as List) .map((post) => - DetailedUserModel.fromKbin(post as Map)) + DetailedUserModel.fromMbin(post as Map)) .toList(), - nextPage: kbinCalcNextPaginationPage( + nextPage: mbinCalcNextPaginationPage( json['pagination'] as Map), ); } @@ -40,13 +40,13 @@ class DetailedUserModel with _$DetailedUserModel { required bool? isBlockedByUser, }) = _DetailedUserModel; - factory DetailedUserModel.fromKbin(Map json) { + factory DetailedUserModel.fromMbin(Map 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?), - cover: kbinGetImage(json['cover'] as Map?), + avatar: mbinGetImage(json['avatar'] as Map?), + cover: mbinGetImage(json['cover'] as Map?), 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 json) => UserModel( + factory UserModel.fromMbin(Map json) => UserModel( id: json['userId'] as int, - name: kbinNormalizeUsername(json['username'] as String), - avatar: kbinGetImage(json['avatar'] as Map?), + name: mbinNormalizeUsername(json['username'] as String), + avatar: mbinGetImage(json['avatar'] as Map?), ); factory UserModel.fromLemmy(Map json) => UserModel( @@ -122,7 +122,7 @@ class UserSettings with _$UserSettings { required bool? notifyOnNewPostCommentReply, }) = _UserSettings; - factory UserSettings.fromKbin(Map json) => UserSettings( + factory UserSettings.fromMbin(Map json) => UserSettings( showNSFW: !(json['hideAdult'] as bool), blurNSFW: null, showReadPosts: null, diff --git a/lib/src/screens/explore/domains_screen.dart b/lib/src/screens/explore/domains_screen.dart index 034509c..40a2e51 100644 --- a/lib/src/screens/explore/domains_screen.dart +++ b/lib/src/screens/explore/domains_screen.dart @@ -21,7 +21,7 @@ class DomainsScreen extends StatefulWidget { } class _DomainsScreenState extends State { - KbinAPIDomainsFilter filter = KbinAPIDomainsFilter.all; + MbinAPIDomainsFilter filter = MbinAPIDomainsFilter.all; String search = ""; final PagingController _pagingController = @@ -32,7 +32,7 @@ class _DomainsScreenState extends State { super.initState(); if (widget.onlySubbed) { - filter = KbinAPIDomainsFilter.subscribed; + filter = MbinAPIDomainsFilter.subscribed; } _pagingController.addPageRequestListener(_fetchPage); @@ -77,7 +77,7 @@ class _DomainsScreenState extends State { ...whenLoggedIn(context, [ Padding( padding: const EdgeInsets.only(right: 12), - child: DropdownButton( + child: DropdownButton( value: filter, onChanged: (newFilter) { if (newFilter != null) { @@ -89,15 +89,15 @@ class _DomainsScreenState extends State { }, 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 { ) ]) ?? [], - if (filter == KbinAPIDomainsFilter.all) + if (filter == MbinAPIDomainsFilter.all) SizedBox( width: 128, child: TextFormField( diff --git a/lib/src/screens/feed/nav_drawer.dart b/lib/src/screens/feed/nav_drawer.dart index d288426..eca26dd 100644 --- a/lib/src/screens/feed/nav_drawer.dart +++ b/lib/src/screens/feed/nav_drawer.dart @@ -60,7 +60,7 @@ class _NavDrawerState extends State { .read() .api .domains - .list(filter: KbinAPIDomainsFilter.subscribed) + .list(filter: MbinAPIDomainsFilter.subscribed) .then((value) => setState(() { if (value.items.isNotEmpty) { subbedDomains = value.items; diff --git a/lib/src/screens/profile/notification/notification_item.dart b/lib/src/screens/profile/notification/notification_item.dart index b43c1b4..c29b120 100644 --- a/lib/src/screens/profile/notification/notification_item.dart +++ b/lib/src/screens/profile/notification/notification_item.dart @@ -53,11 +53,11 @@ class _NotificationItemState extends State { Map rawUser = (widget.item.subject['user'] ?? widget.item.subject['sender'] ?? widget.item.subject['bannedBy']) as Map; - 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) : null; diff --git a/lib/src/screens/settings/login_confirm.dart b/lib/src/screens/settings/login_confirm.dart index e724aa5..adef21a 100644 --- a/lib/src/screens/settings/login_confirm.dart +++ b/lib/src/screens/settings/login_confirm.dart @@ -133,7 +133,7 @@ class _LoginConfirmScreenState extends State { String identifier = await context .read() - .getKbinOAuthIdentifier( + .getMbinOAuthIdentifier( widget.software, widget.server); final grant = oauth2.AuthorizationCodeGrant( diff --git a/lib/src/screens/settings/settings_controller.dart b/lib/src/screens/settings/settings_controller.dart index 02e655a..3eb6f25 100644 --- a/lib/src/screens/settings/settings_controller.dart +++ b/lib/src/screens/settings/settings_controller.dart @@ -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 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 getKbinOAuthIdentifier( + Future 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) { diff --git a/lib/src/utils/models.dart b/lib/src/utils/models.dart index 2014bd9..6364649 100644 --- a/lib/src/utils/models.dart +++ b/lib/src/utils/models.dart @@ -3,21 +3,21 @@ import 'package:interstellar/src/models/image.dart'; DateTime? optionalDateTime(String? value) => value == null ? null : DateTime.parse(value); -String? kbinCalcNextPaginationPage(Map pagination) { +String? mbinCalcNextPaginationPage(Map pagination) { return (pagination['currentPage'] as int) != (pagination['maxPage'] as int) ? ((pagination['currentPage'] as int) + 1).toString() : null; } -ImageModel? kbinGetImage(Map? json) { - return json == null ? null : ImageModel.fromKbin(json); +ImageModel? mbinGetImage(Map? 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; }