diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 191c2ebd8e..23857c78e8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.util.Pair; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; @@ -709,26 +710,17 @@ public void onRevealSpoilerClick(SpoilerStatusDisplayItem.Holder holder){ } public void updateStatusWithQuote(DisplayItemsParent parent) { - int startIndex=-1; - int endIndex=-1; - for(int i=0; i items=findAllItemsOfParent(parent); + if (items==null) return; // Only StatusListFragments/NotificationsListFragments can display status with quotes assert (this instanceof StatusListFragment) || (this instanceof NotificationsListFragment); - List oldItems = displayItems.subList(startIndex, endIndex+1); + List oldItems = displayItems.subList(items.first, items.second+1); List newItems=this.buildDisplayItems((T) parent); int prevSize=oldItems.size(); oldItems.clear(); - displayItems.addAll(startIndex, newItems); + displayItems.addAll(items.first, newItems); // Update the cache final CacheController cache=AccountSessionManager.get(accountID).getCacheController(); @@ -738,8 +730,19 @@ public void updateStatusWithQuote(DisplayItemsParent parent) { cache.updateNotification((Notification) parent); } - adapter.notifyItemRangeRemoved(startIndex, prevSize); - adapter.notifyItemRangeInserted(startIndex, newItems.size()); + adapter.notifyItemRangeRemoved(items.first, prevSize); + adapter.notifyItemRangeInserted(items.first, newItems.size()); + } + + public void removeStatus(DisplayItemsParent parent) { + Pair items=findAllItemsOfParent(parent); + if (items==null) + return; + + List statusDisplayItems = displayItems.subList(items.first, items.second+1); + int prevSize=statusDisplayItems.size(); + statusDisplayItems.clear(); + adapter.notifyItemRangeRemoved(items.first, prevSize); } public void onVisibilityIconClick(HeaderStatusDisplayItem.Holder holder) { @@ -943,6 +946,23 @@ protected > H return null; } + @Nullable + protected Pair findAllItemsOfParent(DisplayItemsParent parent){ + int startIndex=-1; + int endIndex=-1; + for(int i=0; i> List findAllHoldersOfType(String id, Class type){ ArrayList holders=new ArrayList<>(); for(int i=0;i(){ - @Override - public void onSuccess(SearchResults results){ - AccountSessionManager.get(accountID).filterStatuses(results.statuses, filterContext); - if (!results.statuses.isEmpty()){ - status.quote=results.statuses.get(0); - fragment.updateStatusWithQuote(status); - } - } + if (!UiUtils.looksLikeFediverseUrl(quoteURL)) + return; - @Override - public void onError(ErrorResponse error){ - Log.w("StatusDisplayItem", "onError: failed to find quote status with URL: " + quoteURL + " " + error); - } - }).exec(accountID); - } + new GetSearchResults(quoteURL, GetSearchResults.Type.STATUSES, true, null, 0, 0).setCallback(new Callback<>(){ + @Override + public void onSuccess(SearchResults results){ + AccountSessionManager.get(accountID).filterStatuses(results.statuses, filterContext); + if (results.statuses.isEmpty()) + return; + + Status quote=results.statuses.get(0); + new GetAccountRelationships(Collections.singletonList(quote.account.id)) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(List relationships){ + if(relationships.isEmpty()) + return; + + Relationship relationship=relationships.get(0); + if(relationship.domainBlocking || relationship.muting || relationship.blocking) { + // do not show posts that are quoting a muted/blocked user + fragment.removeStatus(status); + return; + } + + status.quote=results.statuses.get(0); + fragment.updateStatusWithQuote(status); + } + + @Override + public void onError(ErrorResponse error){} + }) + .exec(accountID); + } + + @Override + public void onError(ErrorResponse error){ + Log.w("StatusDisplayItem", "onError: failed to find quote status with URL: " + quoteURL + " " + error); + } + }).exec(accountID); } public enum Type{