diff --git a/lib/src/api/users.dart b/lib/src/api/users.dart index edaea714..88bc9795 100644 --- a/lib/src/api/users.dart +++ b/lib/src/api/users.dart @@ -1,5 +1,3 @@ -import 'package:http/http.dart' as http; -import 'package:http_parser/http_parser.dart'; import 'package:image_picker/image_picker.dart'; import 'package:interstellar/src/api/client.dart'; import 'package:interstellar/src/api/community.dart'; @@ -8,8 +6,6 @@ import 'package:interstellar/src/models/user.dart'; import 'package:interstellar/src/screens/explore/explore_screen.dart'; import 'package:interstellar/src/utils/models.dart'; import 'package:interstellar/src/utils/utils.dart'; -import 'package:mime/mime.dart'; -import 'package:path/path.dart'; class APIUsers { APIUsers(this.client); @@ -187,10 +183,10 @@ class APIUsers { } } - Future follow(int userId, bool state) async { + Future follow(DetailedUserModel user, bool state) async { switch (client.software) { case ServerSoftware.mbin: - final path = '/users/$userId/${state ? 'follow' : 'unfollow'}'; + final path = '/users/${user.id}/${state ? 'follow' : 'unfollow'}'; final response = await client.put(path); @@ -200,7 +196,14 @@ class APIUsers { throw Exception('User follow not allowed on lemmy'); case ServerSoftware.piefed: - throw Exception('User follow not allowed on piefed'); + final path = '/user/${state ? 'follow' : 'unfollow'}'; + + final response = await client.post( + path, + body: {'user_id': user.id.toString()}, + ); + + return user; } } diff --git a/lib/src/screens/explore/explore_screen_item.dart b/lib/src/screens/explore/explore_screen_item.dart index 2580644c..37b00ad9 100644 --- a/lib/src/screens/explore/explore_screen_item.dart +++ b/lib/src/screens/explore/explore_screen_item.dart @@ -93,7 +93,7 @@ class ExploreScreenItem extends StatelessWidget { }, final DetailedUserModel i => (bool selected) async { final newValue = await context.read().api.users.follow( - i.id, + i, selected, ); diff --git a/lib/src/screens/explore/user_screen.dart b/lib/src/screens/explore/user_screen.dart index 31c245c4..eff145d9 100644 --- a/lib/src/screens/explore/user_screen.dart +++ b/lib/src/screens/explore/user_screen.dart @@ -231,14 +231,14 @@ class _UserScreenState extends State { child: Text(l(context).account_edit), ), if (!isMyUser && - ac.serverSoftware == ServerSoftware.mbin) + ac.serverSoftware != ServerSoftware.lemmy) SubscriptionButton( isSubscribed: user.isFollowedByUser, subscriptionCount: user.followersCount ?? 0, onSubscribe: (selected) async { final newValue = await ac.api.users - .follow(user.id, selected); + .follow(user, selected); setState(() { _data = newValue; }); diff --git a/lib/src/screens/settings/account_migration.dart b/lib/src/screens/settings/account_migration.dart index c076a58a..8ea9ab92 100644 --- a/lib/src/screens/settings/account_migration.dart +++ b/lib/src/screens/settings/account_migration.dart @@ -169,7 +169,7 @@ class _AccountMigrationScreenState extends State { denormalizeName(item, destAccountHost), ); if (res.isFollowedByUser == false) { - await destAPI.users.follow(res.id, true); + await destAPI.users.follow(res, true); } _migrateUserFollows.complete.add(item); } catch (e) { diff --git a/lib/src/screens/settings/account_reset.dart b/lib/src/screens/settings/account_reset.dart index f24bb378..0dedea83 100644 --- a/lib/src/screens/settings/account_reset.dart +++ b/lib/src/screens/settings/account_reset.dart @@ -2,6 +2,7 @@ import 'package:auto_route/annotations.dart'; import 'package:flutter/material.dart'; import 'package:interstellar/src/controller/controller.dart'; import 'package:interstellar/src/controller/server.dart'; +import 'package:interstellar/src/models/user.dart'; import 'package:interstellar/src/screens/explore/explore_screen.dart'; import 'package:interstellar/src/screens/settings/account_migration.dart'; import 'package:interstellar/src/screens/settings/account_selection.dart'; @@ -25,7 +26,7 @@ class _AccountResetScreenState extends State { final _resetCommunitySubscriptions = MigrationOrResetType(); final _resetCommunityBlocks = MigrationOrResetType(); - final _resetUserFollows = MigrationOrResetType(); + final _resetUserFollows = MigrationOrResetType(); final _resetUserBlocks = MigrationOrResetType(); @override @@ -93,7 +94,7 @@ class _AccountResetScreenState extends State { filter: ExploreFilter.subscribed, ); - _resetUserFollows.found.addAll(res.items.map((e) => e.id)); + _resetUserFollows.found.addAll(res.items.map((e) => e)); nextPage = res.nextPage; if (progressAndCheckCancel()) return; diff --git a/lib/src/widgets/menus/user_menu.dart b/lib/src/widgets/menus/user_menu.dart index 93c02d27..b611c7b8 100644 --- a/lib/src/widgets/menus/user_menu.dart +++ b/lib/src/widgets/menus/user_menu.dart @@ -34,13 +34,13 @@ Future showUserMenu( return ContextMenu( actions: [ - if (!isMe && ac.serverSoftware == ServerSoftware.mbin) + if (!isMe && ac.serverSoftware != ServerSoftware.lemmy) ContextMenuAction( child: SubscriptionButton( isSubscribed: user.isFollowedByUser, subscriptionCount: user.followersCount, onSubscribe: (selected) async { - final newValue = await ac.api.users.follow(user.id, selected); + final newValue = await ac.api.users.follow(user, selected); if (update != null) { update(newValue); }