Skip to content

Commit 9f43f26

Browse files
authored
Remove fid-based filtering of poll events (#137)
* Remove fid-based filtering of poll events * Add comment explaining why we're not filtering by fid anymore
1 parent 784ff3c commit 9f43f26

File tree

4 files changed

+35
-114
lines changed

4 files changed

+35
-114
lines changed

stream-feeds-android-client/src/main/kotlin/io/getstream/feeds/android/client/internal/state/event/handler/ActivityEventHandler.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,18 @@ internal class ActivityEventHandler(
104104
state.onCommentReactionUpserted(event.comment, event.reaction, event.enforceUnique)
105105
}
106106

107-
is StateUpdateEvent.PollDeleted -> {
108-
if (event.fid != fid.rawValue) return
109-
state.onPollDeleted(event.pollId)
110-
}
107+
// The fid in poll events doesn't necessarily match all the feeds that contain the poll
108+
// so we can't early return here based on that.
109+
is StateUpdateEvent.PollDeleted -> state.onPollDeleted(event.pollId)
111110

112-
is StateUpdateEvent.PollUpdated -> {
113-
if (event.fid != fid.rawValue) return
114-
state.onPollUpdated(event.poll)
115-
}
111+
is StateUpdateEvent.PollUpdated -> state.onPollUpdated(event.poll)
116112

117-
is StateUpdateEvent.PollVoteCasted -> {
118-
if (event.fid != fid.rawValue) return
119-
state.onPollVoteUpserted(event.vote, event.pollId)
120-
}
113+
is StateUpdateEvent.PollVoteCasted -> state.onPollVoteUpserted(event.vote, event.pollId)
121114

122-
is StateUpdateEvent.PollVoteChanged -> {
123-
if (event.fid != fid.rawValue) return
115+
is StateUpdateEvent.PollVoteChanged ->
124116
state.onPollVoteUpserted(event.vote, event.pollId)
125-
}
126117

127-
is StateUpdateEvent.PollVoteRemoved -> {
128-
if (event.fid != fid.rawValue) return
129-
state.onPollVoteRemoved(event.vote, event.pollId)
130-
}
118+
is StateUpdateEvent.PollVoteRemoved -> state.onPollVoteRemoved(event.vote, event.pollId)
131119

132120
else -> {}
133121
}

stream-feeds-android-client/src/main/kotlin/io/getstream/feeds/android/client/internal/state/event/handler/FeedEventHandler.kt

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,35 +195,18 @@ internal class FeedEventHandler(
195195
}
196196
}
197197

198-
is StateUpdateEvent.PollDeleted -> {
199-
if (event.fid == fid.rawValue) {
200-
state.onPollDeleted(event.pollId)
201-
}
202-
}
198+
// The fid in poll events doesn't necessarily match all the feeds that contain the poll
199+
// so we can't early return here based on that.
200+
is StateUpdateEvent.PollDeleted -> state.onPollDeleted(event.pollId)
203201

204-
is StateUpdateEvent.PollUpdated -> {
205-
if (event.fid == fid.rawValue) {
206-
state.onPollUpdated(event.poll)
207-
}
208-
}
202+
is StateUpdateEvent.PollUpdated -> state.onPollUpdated(event.poll)
209203

210-
is StateUpdateEvent.PollVoteCasted -> {
211-
if (event.fid == fid.rawValue) {
212-
state.onPollVoteUpserted(event.vote, event.pollId)
213-
}
214-
}
204+
is StateUpdateEvent.PollVoteCasted -> state.onPollVoteUpserted(event.vote, event.pollId)
215205

216-
is StateUpdateEvent.PollVoteChanged -> {
217-
if (event.fid == fid.rawValue) {
218-
state.onPollVoteUpserted(event.vote, event.pollId)
219-
}
220-
}
206+
is StateUpdateEvent.PollVoteChanged ->
207+
state.onPollVoteUpserted(event.vote, event.pollId)
221208

222-
is StateUpdateEvent.PollVoteRemoved -> {
223-
if (event.fid == fid.rawValue) {
224-
state.onPollVoteRemoved(event.vote, event.pollId)
225-
}
226-
}
209+
is StateUpdateEvent.PollVoteRemoved -> state.onPollVoteRemoved(event.vote, event.pollId)
227210

228211
else -> {
229212
// Handle other events if necessary

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state/event/handler/ActivityEventHandlerTest.kt

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -209,55 +209,30 @@ internal class ActivityEventHandlerTest(
209209
verifyBlock = { it wasNot called },
210210
),
211211
testParams<ActivityStateUpdates>(
212-
name = "PollDeleted matching feed",
213-
event = PollDeleted(fid.rawValue, "poll-1"),
212+
name = "PollDeleted handled regardless of feed ID",
213+
event = PollDeleted("any:feed", "poll-1"),
214214
verifyBlock = { it.onPollDeleted("poll-1") },
215215
),
216216
testParams<ActivityStateUpdates>(
217-
name = "PollDeleted non-matching feed",
218-
event = PollDeleted(otherFid, "poll-1"),
219-
verifyBlock = { it wasNot called },
220-
),
221-
testParams<ActivityStateUpdates>(
222-
name = "PollUpdated matching feed",
223-
event = PollUpdated(fid.rawValue, pollData()),
217+
name = "PollUpdated handled regardless of feed ID",
218+
event = PollUpdated("any:feed", pollData()),
224219
verifyBlock = { it.onPollUpdated(pollData()) },
225220
),
226221
testParams<ActivityStateUpdates>(
227-
name = "PollUpdated non-matching feed",
228-
event = PollUpdated(otherFid, pollData()),
229-
verifyBlock = { it wasNot called },
230-
),
231-
testParams<ActivityStateUpdates>(
232-
name = "PollVoteCasted matching feed",
233-
event = PollVoteCasted(fid.rawValue, "poll-1", pollVoteData()),
222+
name = "PollVoteCasted handled regardless of feed ID",
223+
event = PollVoteCasted("any:feed", "poll-1", pollVoteData()),
234224
verifyBlock = { it.onPollVoteUpserted(pollVoteData(), "poll-1") },
235225
),
236226
testParams<ActivityStateUpdates>(
237-
name = "PollVoteCasted non-matching feed",
238-
event = PollVoteCasted(otherFid, "poll-1", pollVoteData()),
239-
verifyBlock = { it wasNot called },
240-
),
241-
testParams<ActivityStateUpdates>(
242-
name = "PollVoteChanged matching feed",
243-
event = PollVoteChanged(fid.rawValue, "poll-1", pollVoteData()),
227+
name = "PollVoteChanged handled regardless of feed ID",
228+
event = PollVoteChanged("any:feed", "poll-1", pollVoteData()),
244229
verifyBlock = { it.onPollVoteUpserted(pollVoteData(), "poll-1") },
245230
),
246231
testParams<ActivityStateUpdates>(
247-
name = "PollVoteChanged non-matching feed",
248-
event = PollVoteChanged(otherFid, "poll-1", pollVoteData()),
249-
verifyBlock = { it wasNot called },
250-
),
251-
testParams<ActivityStateUpdates>(
252-
name = "PollVoteRemoved matching feed",
253-
event = PollVoteRemoved(fid.rawValue, "poll-1", pollVoteData()),
232+
name = "PollVoteRemoved handled regardless of feed ID",
233+
event = PollVoteRemoved("any:feed", "poll-1", pollVoteData()),
254234
verifyBlock = { it.onPollVoteRemoved(pollVoteData(), "poll-1") },
255235
),
256-
testParams<ActivityStateUpdates>(
257-
name = "PollVoteRemoved non-matching feed",
258-
event = PollVoteRemoved(otherFid, "poll-1", pollVoteData()),
259-
verifyBlock = { it wasNot called },
260-
),
261236
testParams<ActivityStateUpdates>(
262237
name = "CommentAdded matching feed and activity",
263238
event = CommentAdded(fid.rawValue, matchingComment),

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/internal/state/event/handler/FeedEventHandlerTest.kt

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -376,55 +376,30 @@ internal class FeedEventHandlerTest(
376376
verifyBlock = { state -> state wasNot called },
377377
),
378378
testParams<FeedStateUpdates>(
379-
name = "PollDeleted matching feed",
380-
event = PollDeleted(fid.rawValue, pollId),
379+
name = "PollDeleted handled regardless of feed ID",
380+
event = PollDeleted("any:feed", pollId),
381381
verifyBlock = { state -> state.onPollDeleted(pollId) },
382382
),
383383
testParams<FeedStateUpdates>(
384-
name = "PollDeleted non-matching feed",
385-
event = PollDeleted("group:different", pollId),
386-
verifyBlock = { state -> state wasNot called },
387-
),
388-
testParams<FeedStateUpdates>(
389-
name = "PollUpdated matching feed",
390-
event = PollUpdated(fid.rawValue, poll),
384+
name = "PollUpdated handled regardless of feed ID",
385+
event = PollUpdated("any:feed", poll),
391386
verifyBlock = { state -> state.onPollUpdated(poll) },
392387
),
393388
testParams<FeedStateUpdates>(
394-
name = "PollUpdated non-matching feed",
395-
event = PollUpdated("group:different", poll),
396-
verifyBlock = { state -> state wasNot called },
397-
),
398-
testParams<FeedStateUpdates>(
399-
name = "PollVoteCasted matching feed",
400-
event = PollVoteCasted(fid.rawValue, pollId, pollVote),
389+
name = "PollVoteCasted handled regardless of feed ID",
390+
event = PollVoteCasted("any:feed", pollId, pollVote),
401391
verifyBlock = { state -> state.onPollVoteUpserted(pollVote, pollId) },
402392
),
403393
testParams<FeedStateUpdates>(
404-
name = "PollVoteCasted non-matching feed",
405-
event = PollVoteCasted("group:different", pollId, pollVote),
406-
verifyBlock = { state -> state wasNot called },
407-
),
408-
testParams<FeedStateUpdates>(
409-
name = "PollVoteChanged matching feed",
410-
event = PollVoteChanged(fid.rawValue, pollId, pollVote),
394+
name = "PollVoteChanged handled regardless of feed ID",
395+
event = PollVoteChanged("any:feed", pollId, pollVote),
411396
verifyBlock = { state -> state.onPollVoteUpserted(pollVote, pollId) },
412397
),
413398
testParams<FeedStateUpdates>(
414-
name = "PollVoteChanged non-matching feed",
415-
event = PollVoteChanged("group:different", pollId, pollVote),
416-
verifyBlock = { state -> state wasNot called },
417-
),
418-
testParams<FeedStateUpdates>(
419-
name = "PollVoteRemoved matching feed",
420-
event = PollVoteRemoved(fid.rawValue, pollId, pollVote),
399+
name = "PollVoteRemoved handled regardless of feed ID",
400+
event = PollVoteRemoved("any:feed", pollId, pollVote),
421401
verifyBlock = { state -> state.onPollVoteRemoved(pollVote, pollId) },
422402
),
423-
testParams<FeedStateUpdates>(
424-
name = "PollVoteRemoved non-matching feed",
425-
event = PollVoteRemoved("group:different", pollId, pollVote),
426-
verifyBlock = { state -> state wasNot called },
427-
),
428403
)
429404
}
430405
}

0 commit comments

Comments
 (0)