Skip to content

Commit 20e2ec8

Browse files
Fixed an issue where a poll would not update if its a thread root (#5968)
* Fix poll not updating when it is a thread root. * Update CHANGELOG.md. * Ensure poll events are processed in a batch. --------- Co-authored-by: André Mion <[email protected]>
1 parent 5bcc371 commit 20e2ec8

File tree

12 files changed

+622
-36
lines changed

12 files changed

+622
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
## stream-chat-android-state
3838
### 🐞 Fixed
3939
- Fix poll state getting overridden by `message.new` events. [#5963](https://github.com/GetStream/stream-chat-android/pull/5963)
40+
- Fix polls not updated live when they are a thread parent message. [#5968](https://github.com/GetStream/stream-chat-android/pull/5968)
4041

4142
### ⬆️ Improved
4243

stream-chat-android-client-test/src/main/java/io/getstream/chat/android/client/test/Mother.kt

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.getstream.chat.android.client.test
1818

19+
import io.getstream.chat.android.client.events.AnswerCastedEvent
1920
import io.getstream.chat.android.client.events.ChannelDeletedEvent
2021
import io.getstream.chat.android.client.events.ChannelHiddenEvent
2122
import io.getstream.chat.android.client.events.ChannelUpdatedByUserEvent
@@ -39,7 +40,9 @@ import io.getstream.chat.android.client.events.NotificationMessageNewEvent
3940
import io.getstream.chat.android.client.events.NotificationMutesUpdatedEvent
4041
import io.getstream.chat.android.client.events.NotificationReminderDueEvent
4142
import io.getstream.chat.android.client.events.NotificationRemovedFromChannelEvent
43+
import io.getstream.chat.android.client.events.PollClosedEvent
4244
import io.getstream.chat.android.client.events.PollDeletedEvent
45+
import io.getstream.chat.android.client.events.PollUpdatedEvent
4346
import io.getstream.chat.android.client.events.ReactionNewEvent
4447
import io.getstream.chat.android.client.events.ReminderCreatedEvent
4548
import io.getstream.chat.android.client.events.ReminderDeletedEvent
@@ -48,9 +51,13 @@ import io.getstream.chat.android.client.events.TypingStartEvent
4851
import io.getstream.chat.android.client.events.TypingStopEvent
4952
import io.getstream.chat.android.client.events.UserMessagesDeletedEvent
5053
import io.getstream.chat.android.client.events.UserStartWatchingEvent
54+
import io.getstream.chat.android.client.events.VoteCastedEvent
55+
import io.getstream.chat.android.client.events.VoteChangedEvent
56+
import io.getstream.chat.android.client.events.VoteRemovedEvent
5157
import io.getstream.chat.android.client.extensions.cidToTypeAndId
5258
import io.getstream.chat.android.client.parser2.adapters.internal.StreamDateFormatter
5359
import io.getstream.chat.android.client.query.QueryChannelsSpec
60+
import io.getstream.chat.android.models.Answer
5461
import io.getstream.chat.android.models.Channel
5562
import io.getstream.chat.android.models.EventType
5663
import io.getstream.chat.android.models.FilterObject
@@ -61,6 +68,7 @@ import io.getstream.chat.android.models.NeutralFilterObject
6168
import io.getstream.chat.android.models.Poll
6269
import io.getstream.chat.android.models.Reaction
6370
import io.getstream.chat.android.models.User
71+
import io.getstream.chat.android.models.Vote
6472
import io.getstream.chat.android.models.querysort.QuerySortByField
6573
import io.getstream.chat.android.models.querysort.QuerySorter
6674
import io.getstream.chat.android.positiveRandomInt
@@ -73,6 +81,8 @@ import io.getstream.chat.android.randomMember
7381
import io.getstream.chat.android.randomMessage
7482
import io.getstream.chat.android.randomMessageReminder
7583
import io.getstream.chat.android.randomPoll
84+
import io.getstream.chat.android.randomPollAnswer
85+
import io.getstream.chat.android.randomPollVote
7686
import io.getstream.chat.android.randomReaction
7787
import io.getstream.chat.android.randomString
7888
import io.getstream.chat.android.randomUser
@@ -707,6 +717,7 @@ public fun randomUserMessagesDeletedEvent(
707717
public fun randomPollDeletedEvent(
708718
createdAt: Date = randomDate(),
709719
cid: String = randomCID(),
720+
messageId: String = randomString(),
710721
poll: Poll = randomPoll(),
711722
): PollDeletedEvent {
712723
val (type, id) = cid.cidToTypeAndId()
@@ -717,6 +728,129 @@ public fun randomPollDeletedEvent(
717728
cid = cid,
718729
channelType = type,
719730
channelId = id,
731+
messageId = messageId,
732+
poll = poll,
733+
)
734+
}
735+
736+
public fun randomPollUpdatedEvent(
737+
createdAt: Date = randomDate(),
738+
cid: String = randomCID(),
739+
messageId: String = randomString(),
740+
poll: Poll = randomPoll(),
741+
): PollUpdatedEvent {
742+
val (type, id) = cid.cidToTypeAndId()
743+
return PollUpdatedEvent(
744+
type = EventType.POLL_UPDATED,
745+
createdAt = createdAt,
746+
rawCreatedAt = streamFormatter.format(createdAt),
747+
cid = cid,
748+
channelType = type,
749+
channelId = id,
750+
messageId = messageId,
751+
poll = poll,
752+
)
753+
}
754+
755+
public fun randomPollClosedEvent(
756+
createdAt: Date = randomDate(),
757+
cid: String = randomCID(),
758+
messageId: String = randomString(),
759+
poll: Poll = randomPoll(),
760+
): PollClosedEvent {
761+
val (type, id) = cid.cidToTypeAndId()
762+
return PollClosedEvent(
763+
type = EventType.POLL_CLOSED,
764+
createdAt = createdAt,
765+
rawCreatedAt = streamFormatter.format(createdAt),
766+
cid = cid,
767+
channelType = type,
768+
channelId = id,
769+
messageId = messageId,
770+
poll = poll,
771+
)
772+
}
773+
774+
public fun randomVoteCastedEvent(
775+
createdAt: Date = randomDate(),
776+
cid: String = randomCID(),
777+
messageId: String = randomString(),
778+
poll: Poll = randomPoll(),
779+
newVote: Vote = randomPollVote(),
780+
): VoteCastedEvent {
781+
val (type, id) = cid.cidToTypeAndId()
782+
return VoteCastedEvent(
783+
type = EventType.POLL_VOTE_CASTED,
784+
createdAt = createdAt,
785+
rawCreatedAt = streamFormatter.format(createdAt),
786+
cid = cid,
787+
channelType = type,
788+
channelId = id,
789+
messageId = messageId,
790+
poll = poll,
791+
newVote = newVote,
792+
)
793+
}
794+
795+
public fun randomAnswerCastedEvent(
796+
createdAt: Date = randomDate(),
797+
cid: String = randomCID(),
798+
messageId: String = randomString(),
799+
poll: Poll = randomPoll(),
800+
newAnswer: Answer = randomPollAnswer(),
801+
): AnswerCastedEvent {
802+
val (type, id) = cid.cidToTypeAndId()
803+
return AnswerCastedEvent(
804+
type = EventType.POLL_VOTE_CASTED,
805+
createdAt = createdAt,
806+
rawCreatedAt = streamFormatter.format(createdAt),
807+
cid = cid,
808+
channelType = type,
809+
channelId = id,
810+
messageId = messageId,
811+
poll = poll,
812+
newAnswer = newAnswer,
813+
)
814+
}
815+
816+
public fun randomVoteChangedEvent(
817+
createdAt: Date = randomDate(),
818+
cid: String = randomCID(),
819+
messageId: String = randomString(),
820+
poll: Poll = randomPoll(),
821+
newVote: Vote = randomPollVote(),
822+
): VoteChangedEvent {
823+
val (type, id) = cid.cidToTypeAndId()
824+
return VoteChangedEvent(
825+
type = EventType.POLL_VOTE_CHANGED,
826+
createdAt = createdAt,
827+
rawCreatedAt = streamFormatter.format(createdAt),
828+
cid = cid,
829+
channelType = type,
830+
channelId = id,
831+
messageId = messageId,
832+
poll = poll,
833+
newVote = newVote,
834+
)
835+
}
836+
837+
public fun randomVoteRemovedEvent(
838+
createdAt: Date = randomDate(),
839+
cid: String = randomCID(),
840+
messageId: String = randomString(),
841+
poll: Poll = randomPoll(),
842+
removedVote: Vote = randomPollVote(),
843+
): VoteRemovedEvent {
844+
val (type, id) = cid.cidToTypeAndId()
845+
return VoteRemovedEvent(
846+
type = EventType.POLL_VOTE_REMOVED,
847+
createdAt = createdAt,
848+
rawCreatedAt = streamFormatter.format(createdAt),
849+
cid = cid,
850+
channelType = type,
851+
channelId = id,
852+
messageId = messageId,
720853
poll = poll,
854+
removedVote = removedVote,
721855
)
722856
}

0 commit comments

Comments
 (0)