Skip to content

Commit c8fc274

Browse files
committed
Change ActivityData.update to avoid overwriting feed capabilities
1 parent bad22a9 commit c8fc274

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

stream-feeds-android-client/src/main/kotlin/io/getstream/feeds/android/client/internal/model/ActivityOperations.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ internal fun ActivityResponse.Visibility.toModel(): ActivityDataVisibility =
7979
}
8080

8181
/**
82-
* Extension function to update the activity while preserving own bookmarks, reactions, and poll
83-
* votes because "own" data from WS events is not reliable. Optionally, different instances can be
84-
* provided to be used instead of the current ones.
82+
* Extension function to update the activity while preserving own bookmarks, reactions, poll votes,
83+
* and feed capabilities because "own" data from WS events is not reliable. Optionally, different
84+
* instances can be provided to be used instead of the current ones.
8585
*/
8686
internal fun ActivityData.update(
8787
updated: ActivityData,
@@ -92,6 +92,7 @@ internal fun ActivityData.update(
9292
ownBookmarks = ownBookmarks,
9393
ownReactions = ownReactions,
9494
poll = updated.poll?.let { poll?.update(it) ?: it },
95+
currentFeed = updated.currentFeed?.let { currentFeed?.update(it) ?: it },
9596
)
9697

9798
/**

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state/ActivityStateImplTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import io.getstream.feeds.android.client.api.state.ActivityCommentListState
2222
import io.getstream.feeds.android.client.internal.test.TestData.activityData
2323
import io.getstream.feeds.android.client.internal.test.TestData.bookmarkData
2424
import io.getstream.feeds.android.client.internal.test.TestData.commentData
25+
import io.getstream.feeds.android.client.internal.test.TestData.feedData
2526
import io.getstream.feeds.android.client.internal.test.TestData.feedsReactionData
2627
import io.getstream.feeds.android.client.internal.test.TestData.pollData
2728
import io.getstream.feeds.android.client.internal.test.TestData.pollVoteData
29+
import io.getstream.feeds.android.network.models.FeedOwnCapability
2830
import io.mockk.mockk
2931
import kotlinx.coroutines.test.runTest
3032
import org.junit.Assert.assertEquals
@@ -130,33 +132,41 @@ internal class ActivityStateImplTest {
130132
val initialReaction = feedsReactionData("activity-1", "like", currentUserId)
131133
val ownVote = pollVoteData("vote-1", "poll-1", "option-1", currentUserId)
132134
val initialPoll = pollData("poll-1", "Test Poll", ownVotes = listOf(ownVote))
135+
val initialCapabilities = setOf(FeedOwnCapability.ReadFeed, FeedOwnCapability.AddActivity)
136+
val initialFeed =
137+
feedData(id = "1", groupId = "user", ownCapabilities = initialCapabilities)
133138
val initialActivity =
134139
activityData(
135140
"activity-1",
136141
text = "Original",
137142
poll = initialPoll,
138143
ownBookmarks = listOf(initialBookmark),
139144
ownReactions = listOf(initialReaction),
145+
currentFeed = initialFeed,
140146
)
141147
// Backend sends update with empty "own" properties
142148
val updatedPoll = pollData("poll-1", "Updated Poll", ownVotes = emptyList())
149+
val updatedFeed = feedData(id = "1", groupId = "user", ownCapabilities = emptySet())
143150
val updatedActivity =
144151
activityData(
145152
"activity-1",
146153
text = "Updated",
147154
poll = updatedPoll,
148155
ownBookmarks = emptyList(),
149156
ownReactions = emptyList(),
157+
currentFeed = updatedFeed,
150158
)
151159
setupAndUpdateActivity(initialActivity, updatedActivity)
152160

153161
// Verify all "own" properties are preserved
154162
val expectedPoll = updatedPoll.copy(ownVotes = listOf(ownVote))
163+
val expectedFeed = updatedFeed.copy(ownCapabilities = initialCapabilities)
155164
val expectedActivity =
156165
updatedActivity.copy(
157166
poll = expectedPoll,
158167
ownBookmarks = listOf(initialBookmark),
159168
ownReactions = listOf(initialReaction),
169+
currentFeed = expectedFeed,
160170
)
161171
expectActivityAndPoll(expectedActivity, expectedPoll)
162172
}

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state/FeedStateImplTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,35 +180,43 @@ internal class FeedStateImplTest {
180180
val initialReaction = feedsReactionData("activity-1", "like", currentUserId)
181181
val ownVote = pollVoteData("vote-1", "poll-1", "option-1", currentUserId)
182182
val initialPoll = pollData("poll-1", "Test Poll", ownVotes = listOf(ownVote))
183+
val initialCapabilities = setOf(FeedOwnCapability.ReadFeed, FeedOwnCapability.AddActivity)
184+
val initialFeed =
185+
feedData(id = "1", groupId = "user", ownCapabilities = initialCapabilities)
183186
val initialActivity =
184187
activityData(
185188
"activity-1",
186189
text = "Original",
187190
poll = initialPoll,
188191
ownBookmarks = listOf(initialBookmark),
189192
ownReactions = listOf(initialReaction),
193+
currentFeed = initialFeed,
190194
)
191195
setupInitialState(listOf(initialActivity))
192196

193197
// Backend sends update with empty "own" properties
194198
val updatedPoll = pollData("poll-1", "Updated Poll", ownVotes = emptyList())
199+
val updatedFeed = feedData(id = "1", groupId = "user", ownCapabilities = emptySet())
195200
val updatedActivity =
196201
activityData(
197202
"activity-1",
198203
text = "Updated",
199204
poll = updatedPoll,
200205
ownBookmarks = emptyList(),
201206
ownReactions = emptyList(),
207+
currentFeed = updatedFeed,
202208
)
203209
feedState.onActivityUpdated(updatedActivity)
204210

205211
// Verify all "own" properties are preserved
206212
val expectedPoll = updatedPoll.copy(ownVotes = listOf(ownVote))
213+
val expectedFeed = updatedFeed.copy(ownCapabilities = initialCapabilities)
207214
val expectedActivity =
208215
updatedActivity.copy(
209216
poll = expectedPoll,
210217
ownBookmarks = listOf(initialBookmark),
211218
ownReactions = listOf(initialReaction),
219+
currentFeed = expectedFeed,
212220
)
213221
assertEquals(listOf(expectedActivity), feedState.activities.value)
214222
}

0 commit comments

Comments
 (0)