Skip to content

Commit

Permalink
also auto-reveal ancestors
Browse files Browse the repository at this point in the history
closes #603
  • Loading branch information
sk22 committed Jun 22, 2023
1 parent b9afb87 commit 6da85a2
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.joinmastodon.android.events.StatusCreatedEvent;
import org.joinmastodon.android.events.StatusUpdatedEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.StatusContext;
Expand Down Expand Up @@ -153,6 +152,26 @@ public void onError(ErrorResponse error) {}
}).exec(accountID);
}

private void restoreStatusStates(List<Status> newData, Map<String, Status> oldData) {
for (Status s : newData) {
if (s == mainStatus) continue;
Status oldStatus = oldData == null ? null : oldData.get(s.id);
// restore previous spoiler/filter revealed states when refreshing
if (oldStatus != null) {
s.spoilerRevealed = oldStatus.spoilerRevealed;
s.sensitiveRevealed = oldStatus.sensitiveRevealed;
s.filterRevealed = oldStatus.filterRevealed;
}
if (GlobalUserPreferences.autoRevealEqualSpoilers != AutoRevealMode.NEVER &&
s.spoilerText != null &&
s.spoilerText.equals(mainStatus.spoilerText)) {
if (GlobalUserPreferences.autoRevealEqualSpoilers == AutoRevealMode.DISCUSSIONS || Objects.equals(mainStatus.account.id, s.account.id)) {
s.spoilerRevealed = mainStatus.spoilerRevealed;
}
}
}

}
protected void maybeApplyContext() {
if (!transitionFinished || result == null || getContext() == null) return;
Map<String, Status> oldData = null;
Expand All @@ -171,6 +190,8 @@ protected void maybeApplyContext() {

result.descendants=filterStatuses(result.descendants);
result.ancestors=filterStatuses(result.ancestors);
restoreStatusStates(result.descendants, oldData);
restoreStatusStates(result.ancestors, oldData);

for (NeighborAncestryInfo i : mapNeighborhoodAncestry(mainStatus, result)) {
ancestryMap.put(i.status.id, i);
Expand All @@ -180,26 +201,9 @@ protected void maybeApplyContext() {
footerProgress.setVisibility(View.GONE);
data.addAll(result.descendants);

for (Status s : data) {
if (s == mainStatus) continue;
Status oldStatus = oldData == null ? null : oldData.get(s.id);
// restore previous spoiler/filter revealed states when refreshing
if (oldStatus != null) {
s.spoilerRevealed = oldStatus.spoilerRevealed;
s.sensitiveRevealed = oldStatus.sensitiveRevealed;
s.filterRevealed = oldStatus.filterRevealed;
}
if (GlobalUserPreferences.autoRevealEqualSpoilers != AutoRevealMode.NEVER &&
s.spoilerText != null &&
s.spoilerText.equals(mainStatus.spoilerText)) {
if (GlobalUserPreferences.autoRevealEqualSpoilers == AutoRevealMode.DISCUSSIONS || Objects.equals(mainStatus.account.id, s.account.id)) {
s.spoilerRevealed = mainStatus.spoilerRevealed;
}
}
}

int prevCount=displayItems.size();
onAppendItems(result.descendants);

int count=displayItems.size();
if(!refreshing)
adapter.notifyItemRangeInserted(prevCount, count-prevCount);
Expand All @@ -226,7 +230,6 @@ protected void maybeApplyContext() {

result = null;
}

protected Object maybeApplyMainStatus() {
if (updatedStatus == null || !contextInitiallyRendered) return null;

Expand Down

0 comments on commit 6da85a2

Please sign in to comment.