Skip to content

Commit

Permalink
Added compatibility with new Lemmy API changes 0.19.0-alpha.18 (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu authored Nov 17, 2023
1 parent 0bc0623 commit c2ef56e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
17 changes: 11 additions & 6 deletions lib/shared/input_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ Widget buildCommunitySuggestionWidget(payload, {void Function(CommunityView)? on
}

/// Shows a dialog which allows typing/search for an instance
void showInstanceInputDialog(BuildContext context, {required String title, required void Function(Instance) onInstanceSelected, Iterable<Instance>? emptySuggestions}) async {
void showInstanceInputDialog(
BuildContext context, {
required String title,
required void Function(InstanceWithFederationState) onInstanceSelected,
Iterable<InstanceWithFederationState>? emptySuggestions,
}) async {
Account? account = await fetchActiveProfileAccount();

GetFederatedInstancesResponse getFederatedInstancesResponse = await LemmyClient.instance.lemmyApiV3.run(
Expand All @@ -187,12 +192,12 @@ void showInstanceInputDialog(BuildContext context, {required String title, requi
),
);

Future<String?> onSubmitted({Instance? payload, String? value}) async {
Future<String?> onSubmitted({InstanceWithFederationState? payload, String? value}) async {
if (payload != null) {
onInstanceSelected(payload);
Navigator.of(context).pop();
} else if (value != null) {
final Instance? instance = getFederatedInstancesResponse.federatedInstances?.linked.firstWhereOrNull((Instance instance) => instance.domain == value);
final InstanceWithFederationState? instance = getFederatedInstancesResponse.federatedInstances?.linked.firstWhereOrNull((InstanceWithFederationState instance) => instance.domain == value);

if (instance != null) {
onInstanceSelected(instance);
Expand All @@ -206,7 +211,7 @@ void showInstanceInputDialog(BuildContext context, {required String title, requi
}

if (context.mounted) {
showInputDialog<Instance>(
showInputDialog<InstanceWithFederationState>(
context: context,
title: title,
inputLabel: AppLocalizations.of(context)!.instance,
Expand All @@ -217,12 +222,12 @@ void showInstanceInputDialog(BuildContext context, {required String title, requi
}
}

Future<Iterable<Instance>> getInstanceSuggestions(String query, Iterable<Instance>? emptySuggestions) async {
Future<Iterable<InstanceWithFederationState>> getInstanceSuggestions(String query, Iterable<InstanceWithFederationState>? emptySuggestions) async {
if (query.isEmpty) {
return const Iterable.empty();
}

Iterable<Instance> filteredInstances = emptySuggestions?.where((Instance instance) => instance.domain.contains(query)) ?? const Iterable.empty();
Iterable<InstanceWithFederationState> filteredInstances = emptySuggestions?.where((InstanceWithFederationState instance) => instance.domain.contains(query)) ?? const Iterable.empty();
return filteredInstances;
}

Expand Down
42 changes: 33 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,28 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7e108028e3d258667d079986da8c0bc32da4cb57431c2af03b1dc1038621a9dc"
url: "https://pub.dev"
source: hosted
version: "9.0.13"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: b06739349ec2477e943055aea30172c5c7000225f79dad4702e2ec0eda79a6ff
url: "https://pub.dev"
source: hosted
version: "1.0.5"
lemmy_api_client:
dependency: "direct main"
description:
path: "."
ref: "67c33a2ddc08f8d99aabfce81bab1fde107bd0a7"
resolved-ref: "67c33a2ddc08f8d99aabfce81bab1fde107bd0a7"
ref: "11893cac21d13e424f188420cbbdbf9164c28498"
resolved-ref: "11893cac21d13e424f188420cbbdbf9164c28498"
url: "https://github.com/thunder-app/lemmy_api_client.git"
source: git
version: "0.21.0"
Expand Down Expand Up @@ -933,18 +949,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1576,6 +1592,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.2"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
watcher:
dependency: transitive
description:
Expand All @@ -1588,10 +1612,10 @@ packages:
dependency: transitive
description:
name: web
sha256: "14f1f70c51119012600c5f1f60ca68efda5a9b6077748163c6af2893ec5df8fc"
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.2.1-beta"
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -1673,5 +1697,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-157.0.dev <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.13.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
lemmy_api_client:
git:
url: https://github.com/thunder-app/lemmy_api_client.git
ref: 67c33a2ddc08f8d99aabfce81bab1fde107bd0a7
ref: 11893cac21d13e424f188420cbbdbf9164c28498
link_preview_generator:
git:
url: https://github.com/thunder-app/link_preview_generator.git
Expand Down

0 comments on commit c2ef56e

Please sign in to comment.