feat(follower): show own domain accounts as username

This commit is contained in:
FineFindus
2023-04-16 21:32:26 +02:00
parent 4da6016e06
commit c3c76126a3

View File

@@ -4,12 +4,16 @@ import android.net.Uri;
import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.api.requests.HeaderPaginationRequest; import org.joinmastodon.android.api.requests.HeaderPaginationRequest;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.api.SimpleCallback;
public abstract class PaginatedAccountListFragment extends BaseAccountListFragment{ public abstract class PaginatedAccountListFragment extends BaseAccountListFragment{
@@ -23,10 +27,10 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme
@Override @Override
protected void doLoadData(int offset, int count){ protected void doLoadData(int offset, int count){
if(GlobalUserPreferences.loadRemoteAccountFollowers){ if(GlobalUserPreferences.loadRemoteAccountFollowers && targetAccount.getDomain() != null){
if ((this instanceof FollowingListFragment || this instanceof FollowerListFragment) && targetAccount != null){ if ((this instanceof FollowingListFragment || this instanceof FollowerListFragment) && targetAccount != null){
UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> { UiUtils.lookupRemoteAccount(getContext(), targetAccount, accountID, null, account -> {
if(account != null && account.getDomain() != null){ if(account != null){
loadRemoteFollower(offset, count, account); loadRemoteFollower(offset, count, account);
} else { } else {
loadFollower(offset, count); loadFollower(offset, count);
@@ -54,8 +58,9 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme
} }
private void loadRemoteFollower(int offset, int count, Account account) { private void loadRemoteFollower(int offset, int count, Account account) {
String ownDomain = AccountSessionManager.getInstance().getLastActiveAccount().domain;
currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count) currentRequest=onCreateRemoteRequest(account.id, offset==0 ? null : nextMaxID, count)
.setCallback(new SimpleCallback<>(this){ .setCallback(new Callback<>(){
@Override @Override
public void onSuccess(HeaderPaginationList<Account> result){ public void onSuccess(HeaderPaginationList<Account> result){
if(result.nextPageUri!=null) if(result.nextPageUri!=null)
@@ -66,10 +71,18 @@ public abstract class PaginatedAccountListFragment extends BaseAccountListFragme
remoteAccount.reloadWhenClicked = true; remoteAccount.reloadWhenClicked = true;
if (remoteAccount.getDomain() == null) { if (remoteAccount.getDomain() == null) {
remoteAccount.acct += "@" + Uri.parse(remoteAccount.url).getHost(); remoteAccount.acct += "@" + Uri.parse(remoteAccount.url).getHost();
} else if (remoteAccount.getDomain().equals(ownDomain)) {
remoteAccount.acct = remoteAccount.username;
} }
}); });
onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false); onDataLoaded(result.stream().map(AccountItem::new).collect(Collectors.toList()), false);
} }
@Override
public void onError(ErrorResponse error) {
error.showToast(getContext());
loadFollower(offset, count);
}
}) })
.execNoAuth(targetAccount.getDomain()); .execNoAuth(targetAccount.getDomain());
} }