diff --git a/stream-chat-android-client/api/stream-chat-android-client.api b/stream-chat-android-client/api/stream-chat-android-client.api index b4a4d05f0d5..802db9c13cc 100644 --- a/stream-chat-android-client/api/stream-chat-android-client.api +++ b/stream-chat-android-client/api/stream-chat-android-client.api @@ -1242,6 +1242,10 @@ public abstract interface class io/getstream/chat/android/client/events/HasOwnUs public abstract fun getMe ()Lio/getstream/chat/android/models/User; } +public abstract interface class io/getstream/chat/android/client/events/HasPoll { + public abstract fun getPoll ()Lio/getstream/chat/android/models/Poll; +} + public abstract interface class io/getstream/chat/android/client/events/HasReaction { public abstract fun getReaction ()Lio/getstream/chat/android/models/Reaction; } @@ -1796,75 +1800,69 @@ public final class io/getstream/chat/android/client/events/NotificationRemovedFr public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/PollClosedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)V +public final class io/getstream/chat/android/client/events/PollClosedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollClosedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollClosedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollClosedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollClosedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollClosedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollClosedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public fun getType ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/PollDeletedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)V +public final class io/getstream/chat/android/client/events/PollDeletedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollDeletedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollDeletedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollDeletedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollDeletedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollDeletedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollDeletedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public fun getType ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/PollUpdatedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)V +public final class io/getstream/chat/android/client/events/PollUpdatedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollUpdatedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollUpdatedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollUpdatedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;)Lio/getstream/chat/android/client/events/PollUpdatedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/PollUpdatedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/PollUpdatedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public fun getType ()Ljava/lang/String; public fun hashCode ()I @@ -2128,80 +2126,74 @@ public final class io/getstream/chat/android/client/events/UserUpdatedEvent : io public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/VoteCastedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V +public final class io/getstream/chat/android/client/events/VoteCastedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun component9 ()Lio/getstream/chat/android/models/Vote; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteCastedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteCastedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteCastedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun component8 ()Lio/getstream/chat/android/models/Vote; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteCastedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteCastedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteCastedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; public final fun getNewVote ()Lio/getstream/chat/android/models/Vote; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public fun getType ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/VoteChangedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V +public final class io/getstream/chat/android/client/events/VoteChangedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun component9 ()Lio/getstream/chat/android/models/Vote; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteChangedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteChangedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteChangedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun component8 ()Lio/getstream/chat/android/models/Vote; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteChangedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteChangedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteChangedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; public final fun getNewVote ()Lio/getstream/chat/android/models/Vote; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public fun getType ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class io/getstream/chat/android/client/events/VoteRemovedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasMessage { - public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V +public final class io/getstream/chat/android/client/events/VoteRemovedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll { + public fun (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Ljava/util/Date; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; public final fun component6 ()Ljava/lang/String; - public final fun component7 ()Lio/getstream/chat/android/models/Message; - public final fun component8 ()Lio/getstream/chat/android/models/Poll; - public final fun component9 ()Lio/getstream/chat/android/models/Vote; - public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteRemovedEvent; - public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteRemovedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteRemovedEvent; + public final fun component7 ()Lio/getstream/chat/android/models/Poll; + public final fun component8 ()Lio/getstream/chat/android/models/Vote; + public final fun copy (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;)Lio/getstream/chat/android/client/events/VoteRemovedEvent; + public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/VoteRemovedEvent;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Poll;Lio/getstream/chat/android/models/Vote;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/VoteRemovedEvent; public fun equals (Ljava/lang/Object;)Z public fun getChannelId ()Ljava/lang/String; public fun getChannelType ()Ljava/lang/String; public fun getCid ()Ljava/lang/String; public fun getCreatedAt ()Ljava/util/Date; - public fun getMessage ()Lio/getstream/chat/android/models/Message; - public final fun getPoll ()Lio/getstream/chat/android/models/Poll; + public fun getPoll ()Lio/getstream/chat/android/models/Poll; public fun getRawCreatedAt ()Ljava/lang/String; public final fun getRemovedVote ()Lio/getstream/chat/android/models/Vote; public fun getType ()Ljava/lang/String; diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt index 27bd6fc2565..4d1f3a27079 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt @@ -127,8 +127,7 @@ import io.getstream.chat.android.client.events.UserUpdatedEvent import io.getstream.chat.android.client.events.VoteCastedEvent import io.getstream.chat.android.client.events.VoteChangedEvent import io.getstream.chat.android.client.events.VoteRemovedEvent -import io.getstream.chat.android.models.Message -import io.getstream.chat.android.models.Poll +import io.getstream.chat.android.client.extensions.cidToTypeAndId import io.getstream.chat.android.models.UserId internal fun ConnectedEvent.toDto(): UpstreamConnectedEventDto { @@ -727,48 +726,49 @@ private fun UserUpdatedEventDto.toDomain(currentUserId: UserId?): UserUpdatedEve private fun PollClosedEventDto.toDomain(currentUserId: UserId?): PollClosedEvent { val newPoll = poll.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() return PollClosedEvent( type = type, createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, ) } private fun PollDeletedEventDto.toDomain(currentUserId: UserId?): PollDeletedEvent { val newPoll = poll.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() return PollDeletedEvent( type = type, createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, ) } private fun PollUpdatedEventDto.toDomain(currentUserId: UserId?): PollUpdatedEvent { val newPoll = poll.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() return PollUpdatedEvent( type = type, createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, ) } private fun VoteCastedEventDto.toDomain(currentUserId: UserId?): VoteCastedEvent { val pollVote = poll_vote.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() val newPoll = poll.toDomain(currentUserId) .let { poll -> pollVote.takeIf { it.user?.id == currentUserId } @@ -784,9 +784,8 @@ private fun VoteCastedEventDto.toDomain(currentUserId: UserId?): VoteCastedEvent createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, newVote = pollVote, ) @@ -794,6 +793,7 @@ private fun VoteCastedEventDto.toDomain(currentUserId: UserId?): VoteCastedEvent private fun VoteChangedEventDto.toDomain(currentUserId: UserId?): VoteChangedEvent { val pollVote = poll_vote.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() val newPoll = poll.toDomain(currentUserId) .let { poll -> pollVote.takeIf { it.user?.id == currentUserId } @@ -809,24 +809,23 @@ private fun VoteChangedEventDto.toDomain(currentUserId: UserId?): VoteChangedEve createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, newVote = pollVote, ) } private fun VoteRemovedEventDto.toDomain(currentUserId: UserId?): VoteRemovedEvent { val removedVote = poll_vote.toDomain(currentUserId) + val (channelType, channelId) = cid.cidToTypeAndId() val newPoll = poll.toDomain(currentUserId) return VoteRemovedEvent( type = type, createdAt = created_at.date, rawCreatedAt = created_at.rawDate, cid = cid, - channelType = channel_type, - channelId = channel_id, - message = message.toDomain(currentUserId).enrichWithPoll(newPoll), + channelType = channelType, + channelId = channelId, poll = newPoll, removedVote = removedVote, ) @@ -886,13 +885,3 @@ private fun UnknownEventDto.toDomain(currentUserId: UserId?): UnknownEvent { rawData = rawData, ) } - -private fun Message.enrichWithPoll(newPoll: Poll): Message = - newPoll.takeUnless { it.updatedAt < poll?.updatedAt } - ?.let { - copy( - poll = it, - updatedAt = listOfNotNull(updatedAt, it.updatedAt).maxBy { it.time }, - ) - } - ?: this diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt index b210e6c60ab..47a860c1e24 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt @@ -466,9 +466,6 @@ internal data class UserUpdatedEventDto( internal data class PollUpdatedEventDto( val type: String, val cid: String, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, val created_at: ExactDate, ) : ChatEventDto() @@ -478,9 +475,6 @@ internal data class PollDeletedEventDto( val type: String, val cid: String, val created_at: ExactDate, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, ) : ChatEventDto() @@ -489,9 +483,6 @@ internal data class PollClosedEventDto( val type: String, val cid: String, val created_at: ExactDate, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, ) : ChatEventDto() @@ -500,9 +491,6 @@ internal data class VoteCastedEventDto( val type: String, val cid: String, val created_at: ExactDate, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, val poll_vote: DownstreamVoteDto, ) : ChatEventDto() @@ -511,9 +499,6 @@ internal data class VoteCastedEventDto( internal data class VoteChangedEventDto( val type: String, val cid: String, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, val created_at: ExactDate, val poll_vote: DownstreamVoteDto, @@ -523,9 +508,6 @@ internal data class VoteChangedEventDto( internal data class VoteRemovedEventDto( val type: String, val cid: String, - val channel_type: String, - val channel_id: String, - val message: DownstreamMessageDto, val poll: DownstreamPollDto, val created_at: ExactDate, val poll_vote: DownstreamVoteDto, diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/events/ChatEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/events/ChatEvent.kt index a4d6befe6e8..c633d514fd6 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/events/ChatEvent.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/events/ChatEvent.kt @@ -69,6 +69,10 @@ public sealed interface HasOwnUser { public val me: User } +public sealed interface HasPoll { + public val poll: Poll +} + /** * Interface that marks a [ChatEvent] as having the information about watcher count. * @@ -668,9 +672,8 @@ public data class PollUpdatedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, -) : CidEvent(), HasMessage + override val poll: Poll, +) : CidEvent(), HasPoll /** * Triggered when a poll is deleted. @@ -682,9 +685,8 @@ public data class PollDeletedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, -) : CidEvent(), HasMessage + override val poll: Poll, +) : CidEvent(), HasPoll /** * Triggered when a poll is closed. @@ -696,9 +698,8 @@ public data class PollClosedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, -) : CidEvent(), HasMessage + override val poll: Poll, +) : CidEvent(), HasPoll /** * Triggered when a vote is casted. @@ -710,10 +711,9 @@ public data class VoteCastedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, + override val poll: Poll, val newVote: Vote, -) : CidEvent(), HasMessage +) : CidEvent(), HasPoll /** * Triggered when a vote is changed. @@ -725,10 +725,9 @@ public data class VoteChangedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, + override val poll: Poll, val newVote: Vote, -) : CidEvent(), HasMessage +) : CidEvent(), HasPoll /** * Triggered when a vote is removed. @@ -740,10 +739,9 @@ public data class VoteRemovedEvent( override val cid: String, override val channelType: String, override val channelId: String, - override val message: Message, - val poll: Poll, + override val poll: Poll, val removedVote: Vote, -) : CidEvent(), HasMessage +) : CidEvent(), HasPoll /** * Triggered when a user gets connected to the WS diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/extensions/ChatEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/extensions/ChatEvent.kt index 1e9f5ae724c..163a1718df8 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/extensions/ChatEvent.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/extensions/ChatEvent.kt @@ -24,15 +24,9 @@ import io.getstream.chat.android.client.events.MessageDeletedEvent import io.getstream.chat.android.client.events.MessageUpdatedEvent import io.getstream.chat.android.client.events.NewMessageEvent import io.getstream.chat.android.client.events.NotificationMessageNewEvent -import io.getstream.chat.android.client.events.PollClosedEvent -import io.getstream.chat.android.client.events.PollDeletedEvent -import io.getstream.chat.android.client.events.PollUpdatedEvent import io.getstream.chat.android.client.events.ReactionDeletedEvent import io.getstream.chat.android.client.events.ReactionNewEvent import io.getstream.chat.android.client.events.ReactionUpdateEvent -import io.getstream.chat.android.client.events.VoteCastedEvent -import io.getstream.chat.android.client.events.VoteChangedEvent -import io.getstream.chat.android.client.events.VoteRemovedEvent import io.getstream.chat.android.client.extensions.enrichWithCid public fun ChatEvent.enrichIfNeeded(): ChatEvent = when (this) { @@ -46,11 +40,5 @@ public fun ChatEvent.enrichIfNeeded(): ChatEvent = when (this) { is ChannelTruncatedEvent -> copy(message = message?.enrichWithCid(cid)) is ChannelUpdatedByUserEvent -> copy(message = message?.enrichWithCid(cid)) is NotificationMessageNewEvent -> copy(message = message.enrichWithCid(cid)) - is PollUpdatedEvent -> copy(message = message.enrichWithCid(cid)) - is PollDeletedEvent -> copy(message = message.enrichWithCid(cid)) - is PollClosedEvent -> copy(message = message.enrichWithCid(cid)) - is VoteCastedEvent -> copy(message = message.enrichWithCid(cid)) - is VoteChangedEvent -> copy(message = message.enrichWithCid(cid)) - is VoteRemovedEvent -> copy(message = message.enrichWithCid(cid)) else -> this } diff --git a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/event/handler/internal/EventHandlerSequential.kt b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/event/handler/internal/EventHandlerSequential.kt index 1be66422e0b..e3bea59bb30 100644 --- a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/event/handler/internal/EventHandlerSequential.kt +++ b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/event/handler/internal/EventHandlerSequential.kt @@ -54,9 +54,6 @@ import io.getstream.chat.android.client.events.NotificationMarkUnreadEvent import io.getstream.chat.android.client.events.NotificationMessageNewEvent import io.getstream.chat.android.client.events.NotificationMutesUpdatedEvent import io.getstream.chat.android.client.events.NotificationRemovedFromChannelEvent -import io.getstream.chat.android.client.events.PollClosedEvent -import io.getstream.chat.android.client.events.PollDeletedEvent -import io.getstream.chat.android.client.events.PollUpdatedEvent import io.getstream.chat.android.client.events.ReactionDeletedEvent import io.getstream.chat.android.client.events.ReactionNewEvent import io.getstream.chat.android.client.events.ReactionUpdateEvent @@ -65,9 +62,6 @@ import io.getstream.chat.android.client.events.UserPresenceChangedEvent import io.getstream.chat.android.client.events.UserStartWatchingEvent import io.getstream.chat.android.client.events.UserStopWatchingEvent import io.getstream.chat.android.client.events.UserUpdatedEvent -import io.getstream.chat.android.client.events.VoteCastedEvent -import io.getstream.chat.android.client.events.VoteChangedEvent -import io.getstream.chat.android.client.events.VoteRemovedEvent import io.getstream.chat.android.client.extensions.cidToTypeAndId import io.getstream.chat.android.client.extensions.internal.addMember import io.getstream.chat.android.client.extensions.internal.addMembership @@ -672,24 +666,6 @@ internal class EventHandlerSequential( is UserUpdatedEvent -> if (event.user.id == currentUserId) { repos.insertCurrentUser(event.user) } - is PollClosedEvent -> { - batch.addMessage(event.message) - } - is PollDeletedEvent -> { - batch.addMessage(event.message) - } - is PollUpdatedEvent -> { - batch.addMessage(event.message) - } - is VoteCastedEvent -> { - batch.addMessage(event.message) - } - is VoteChangedEvent -> { - batch.addMessage(event.message) - } - is VoteRemovedEvent -> { - batch.addMessage(event.message) - } else -> Unit } } diff --git a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelLogic.kt b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelLogic.kt index 3b720b614d4..18f04f897d2 100644 --- a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelLogic.kt +++ b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelLogic.kt @@ -673,55 +673,40 @@ internal class ChannelLogic( is UnknownEvent, is UserDeletedEvent, -> Unit // Ignore these events - is PollClosedEvent -> { - upsertEventMessage(event.message) - } - is PollDeletedEvent -> { - upsertEventMessage(event.message) - } - is PollUpdatedEvent -> { - upsertEventMessage(event.message) - } + is PollClosedEvent -> channelStateLogic.upsertPoll(event.poll) + is PollDeletedEvent -> channelStateLogic.upsertPoll(event.poll) + is PollUpdatedEvent -> channelStateLogic.upsertPoll(event.poll) is VoteCastedEvent -> { val ownVotes = ( - mutableState.getMessageById(event.message.id)?.poll?.ownVotes?.associateBy { it.id } + channelStateLogic.getPoll(event.poll.id)?.ownVotes?.associateBy { it.id } ?: emptyMap() ) + listOfNotNull(event.newVote.takeIf { it.user?.id == currentUserId }).associateBy { it.id } - - upsertEventMessage( - event.message.copy( - poll = event.poll.copy( - ownVotes = ownVotes.values.toList(), - ), + channelStateLogic.upsertPoll( + event.poll.copy( + ownVotes = ownVotes.values.toList(), ), ) } is VoteChangedEvent -> { - val ownVotes = event.newVote.takeIf { it.user?.id == currentUserId }?.let { listOf(it) } ?: getMessage( - event.message.id, - )?.poll?.ownVotes - - upsertEventMessage( - event.message.copy( - poll = event.poll.copy( - ownVotes = ownVotes ?: emptyList(), - ), + val ownVotes = event.newVote.takeIf { it.user?.id == currentUserId }?.let { listOf(it) } + ?: channelStateLogic.getPoll(event.poll.id)?.ownVotes + channelStateLogic.upsertPoll( + event.poll.copy( + ownVotes = ownVotes ?: emptyList(), ), ) } is VoteRemovedEvent -> { val ownVotes = ( - mutableState.getMessageById(event.message.id)?.poll?.ownVotes?.associateBy { it.id } + channelStateLogic.getPoll(event.poll.id)?.ownVotes?.associateBy { it.id } ?: emptyMap() ) - event.removedVote.id - upsertEventMessage( - event.message.copy( - poll = event.poll.copy( - ownVotes = ownVotes.values.toList(), - ), + channelStateLogic.upsertPoll( + event.poll.copy( + ownVotes = ownVotes.values.toList(), ), ) } diff --git a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt index b269b713a3d..4c7ad0de2b7 100644 --- a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt +++ b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/logic/channel/internal/ChannelStateLogic.kt @@ -36,6 +36,7 @@ import io.getstream.chat.android.models.ChannelData import io.getstream.chat.android.models.ChannelUserRead import io.getstream.chat.android.models.Member import io.getstream.chat.android.models.Message +import io.getstream.chat.android.models.Poll import io.getstream.chat.android.models.SyncStatus import io.getstream.chat.android.models.TypingEvent import io.getstream.chat.android.models.User @@ -70,6 +71,9 @@ internal class ChannelStateLogic( coroutineScope: CoroutineScope, ) : ChannelMessagesUpdateLogic { + private val polls = mutableMapOf() + private val messageIdsWithPoll = mutableMapOf>() + private val logger by taggedLogger(TAG) private val processedMessageIds = LruCache(CACHE_SIZE) @@ -275,6 +279,7 @@ internal class ChannelStateLogic( mutableState.upsertMessages(newMessages + normalizedReplies) } } + messages.forEach { it.storePoll() } } /** @@ -305,6 +310,7 @@ internal class ChannelStateLogic( mutableState.upsertPinnedMessages(newMessages + normalizedReplies) } } + messages.forEach { it.storePoll() } } /** @@ -762,6 +768,24 @@ internal class ChannelStateLogic( processedMessageIds.put(message.id, true) } + private fun Message.storePoll() { + poll?.let { + upsertPoll(it) + messageIdsWithPoll[it.id] = messageIdsWithPoll[it.id].orEmpty() + id + } + } + + fun upsertPoll(poll: Poll) { + polls[poll.id] = poll + messageIdsWithPoll[poll.id]?.forEach { + mutableState.getMessageById(it)?.let { message -> + mutableState.upsertMessage(message.copy(poll = poll)) + } + } + } + + fun getPoll(pollId: String): Poll? = polls[pollId] + private companion object { private const val TAG = "Chat:ChannelStateLogic" private const val TEXT_LIMIT = 10 diff --git a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/state/channel/internal/ChannelMutableState.kt b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/state/channel/internal/ChannelMutableState.kt index 45102618c9b..298d5961e7d 100644 --- a/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/state/channel/internal/ChannelMutableState.kt +++ b/stream-chat-android-state/src/main/java/io/getstream/chat/android/state/plugin/state/channel/internal/ChannelMutableState.kt @@ -483,7 +483,7 @@ internal class ChannelMutableState( * @param message message to be upserted. */ fun upsertMessage(message: Message) { - _messages?.apply { value = value + (message.id to message) } + upsertMessages(listOf(message)) } fun upsertUserPresence(user: User) { @@ -536,6 +536,13 @@ internal class ChannelMutableState( fun upsertMessages(updatedMessages: Collection) { _messages?.apply { value += updatedMessages.associateBy(Message::id) } + _pinnedMessages?.value + ?.let { pinnedMessages -> + val pinnedMessageIds = pinnedMessages.keys + updatedMessages + .filter { pinnedMessageIds.contains(it.id) } + .let { upsertPinnedMessages(it) } + } } fun setMessages(messages: List) {