From 8111ea04b93b5639f480b9b65c945b09b9feb68a Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Wed, 22 Feb 2023 17:21:33 -0300 Subject: [PATCH] fix: Profile lookups on custom local timelines now work --- .../requests/accounts/GetAccountByHandle.java | 11 +++++++++ .../CustomLocalTimelineFragment.java | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountByHandle.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountByHandle.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountByHandle.java new file mode 100644 index 000000000..584f7819d --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountByHandle.java @@ -0,0 +1,11 @@ +package org.joinmastodon.android.api.requests.accounts; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Account; + +public class GetAccountByHandle extends MastodonAPIRequest{ + public GetAccountByHandle(String acct){ + super(HttpMethod.GET, "/accounts/lookup", Account.class); + addQueryParameter("acct", acct); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java index 5f4d3020a..9849580f4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/CustomLocalTimelineFragment.java @@ -5,8 +5,14 @@ import android.view.Menu; import android.view.MenuInflater; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.accounts.GetAccountByHandle; +import org.joinmastodon.android.api.requests.accounts.GetAccountByID; +import org.joinmastodon.android.api.requests.search.GetSearchResults; +import org.joinmastodon.android.api.requests.statuses.GetStatusByID; import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; +import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Filter; +import org.joinmastodon.android.model.SearchResults; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.TimelineDefinition; import org.joinmastodon.android.utils.StatusFilterPredicate; @@ -14,6 +20,8 @@ import org.joinmastodon.android.utils.StatusFilterPredicate; import java.util.List; import java.util.stream.Collectors; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; public class CustomLocalTimelineFragment extends PinnableStatusListFragment { @@ -55,6 +63,22 @@ public class CustomLocalTimelineFragment extends PinnableStatusListFragment { maxID=result.get(result.size()-1).id; if (getActivity() == null) return; result=result.stream().filter(new StatusFilterPredicate(accountID, Filter.FilterContext.PUBLIC)).collect(Collectors.toList()); + result.stream().forEach(status -> { + status.account.acct += "@"+domain; + new GetAccountByHandle(status.account.acct) + .setCallback(new Callback() { + @Override + public void onSuccess(Account result) { + status.account.id = result.id; + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + } + }).exec(accountID); + }); + onDataLoaded(result, !result.isEmpty()); } })