Skip to content

Commit

Permalink
fix: Don't crash if a conversation has no participants (#978)
Browse files Browse the repository at this point in the history
It's possible for some servers to return a conversation that has an
empty (or possibly missing) `accounts` property. In the previous code
this would crash trying to access an item in an empty list.

Fix this by handling the "no participants" case.

Fixes #971
  • Loading branch information
nikclayton authored Oct 4, 2024
1 parent cdbd0ef commit ec27aa2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ConversationViewHolder internal constructor(

private fun setConversationName(accounts: List<ConversationAccountEntity>) {
conversationNameTextView.text = when (accounts.size) {
0 -> context.getString(R.string.conversation_0_recipients)
1 -> context.getString(
R.string.conversation_1_recipients,
accounts[0].username,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
</plurals>
<string name="title_reblogged_by">Boosted by</string>
<string name="title_favourited_by">Favorited by</string>
<string name="conversation_0_recipients">No other participants</string>
<string name="conversation_1_recipients">%1$s</string>
<string name="conversation_2_recipients">%1$s and %2$s</string>
<string name="conversation_more_recipients">%1$s, %2$s and %3$d more</string>
Expand Down

0 comments on commit ec27aa2

Please sign in to comment.