fix crash when quickly unfollowing hashtags (#4404)

Steps to reproduce: Quickly unfollow a bunch of hashtags, try clicking
unfollow buttons multiple times. If you are faster than the network, the
app crashes.

```
java.lang.ArrayIndexOutOfBoundsException: length=20; index=-1
       at java.util.ArrayList.remove(ArrayList.java:506)
       at com.keylesspalace.tusky.components.followedtags.FollowedTagsActivity$unfollow$1.invokeSuspend(FollowedTagsActivity.kt:152)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7872)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
```
This commit is contained in:
Konrad Pozniak 2024-05-01 18:43:45 +02:00 committed by GitHub
parent b2547c5eef
commit 88fbf33832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -149,7 +149,7 @@ class FollowedTagsActivity :
lifecycleScope.launch { lifecycleScope.launch {
api.unfollowTag(tagName).fold( api.unfollowTag(tagName).fold(
{ {
viewModel.tags.removeAt(position) viewModel.tags.removeIf { tag -> tag.name == tagName }
Snackbar.make( Snackbar.make(
this@FollowedTagsActivity, this@FollowedTagsActivity,
binding.followedTagsView, binding.followedTagsView,