Skip to content

Commit

Permalink
fix: Don't crash when toggling an account's "Show boosts" option (#1149)
Browse files Browse the repository at this point in the history
Previous code would crash because toggling show boosts would treat this
as a new follow, and try and insert a follower relationship in to the
database where one already existed.

Fix this by providing explicit actions for show/hiding reblogs that
don't disturb the follower relationship.
  • Loading branch information
nikclayton authored Dec 2, 2024
1 parent cf46190 commit 4c03e40
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ class AccountViewModel @AssistedInject constructor(

fun changeShowReblogsState() {
if (relationshipData.value?.data?.showingReblogs == true) {
changeRelationship(RelationShipAction.FOLLOW, false)
changeRelationship(RelationShipAction.HIDE_REBLOGS)
} else {
changeRelationship(RelationShipAction.FOLLOW, true)
changeRelationship(RelationShipAction.SHOW_REBLOGS)
}
}

Expand Down Expand Up @@ -230,14 +230,17 @@ class AccountViewModel @AssistedInject constructor(
relation.copy(subscribing = false)
}
}

RelationShipAction.SHOW_REBLOGS -> relation.copy(showingReblogs = true)
RelationShipAction.HIDE_REBLOGS -> relation.copy(showingReblogs = false)
}
relationshipData.postValue(Loading(newRelation))
}

val relationshipCall = when (relationshipAction) {
RelationShipAction.FOLLOW -> mastodonApi.followAccount(
accountId,
showReblogs = parameter ?: true,
showReblogs = true,
)
RelationShipAction.UNFOLLOW -> mastodonApi.unfollowAccount(accountId)
RelationShipAction.BLOCK -> mastodonApi.blockAccount(accountId)
Expand All @@ -262,6 +265,8 @@ class AccountViewModel @AssistedInject constructor(
mastodonApi.unsubscribeAccount(accountId)
}
}
RelationShipAction.SHOW_REBLOGS -> mastodonApi.followAccount(accountId, showReblogs = true)
RelationShipAction.HIDE_REBLOGS -> mastodonApi.followAccount(accountId, showReblogs = false)
}

relationshipCall
Expand Down Expand Up @@ -333,6 +338,8 @@ class AccountViewModel @AssistedInject constructor(
UNMUTE,
SUBSCRIBE,
UNSUBSCRIBE,
SHOW_REBLOGS,
HIDE_REBLOGS,
}

@AssistedFactory
Expand Down

0 comments on commit 4c03e40

Please sign in to comment.