Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into feature/threads_v2
Browse files Browse the repository at this point in the history
# Conflicts:
#	stream-chat-android-compose/src/main/res/values/strings.xml
  • Loading branch information
PetarVelikov committed Oct 23, 2024
2 parents ecbb061 + 918ccd1 commit 266550d
Show file tree
Hide file tree
Showing 37 changed files with 864 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
- Add `AttachmentsPickerSystemTabFactory(filesAllowed, mediaAllowed, captureImageAllowed, captureVideoAllowed, pollAllowed)` to to customize which attachment pickers are allowed. [#5430](https://github.com/GetStream/stream-chat-android/pull/5430)
- Added `ChatTheme.imageAssetTransformer` to transform image assets before rendering them on the UI. [#5438](https://github.com/GetStream/stream-chat-android/pull/5438)
- Added option to suggest new options on a poll. [#5424](https://github.com/GetStream/stream-chat-android/pull/5424)
- Added UI for Answers. [#5432](https://github.com/GetStream/stream-chat-android/pull/5432)

### ⚠️ Changed
- Exposed `DefaultMessageComposerRecordingContent` and `DefaultAudioRecordButton` components. [#5433](https://github.com/GetStream/stream-chat-android/pull/5433)
Expand Down
26 changes: 26 additions & 0 deletions stream-chat-android-client/api/stream-chat-android-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class io/getstream/chat/android/client/ChatClient {
public final fun appSettings ()Lio/getstream/result/call/Call;
public final fun banUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)Lio/getstream/result/call/Call;
public final fun blockUser (Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun castPollAnswer (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun castPollVote (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Option;)Lio/getstream/result/call/Call;
public final fun channel (Ljava/lang/String;)Lio/getstream/chat/android/client/channel/ChannelClient;
public final fun channel (Ljava/lang/String;Ljava/lang/String;)Lio/getstream/chat/android/client/channel/ChannelClient;
Expand Down Expand Up @@ -918,6 +919,31 @@ public abstract class io/getstream/chat/android/client/errors/cause/StreamSdkExc
public synthetic fun <init> (Ljava/lang/Throwable;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}

public final class io/getstream/chat/android/client/events/AnswerCastedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasPoll {
public fun <init> (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/Answer;)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/Poll;
public final fun component8 ()Lio/getstream/chat/android/models/Answer;
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/Answer;)Lio/getstream/chat/android/client/events/AnswerCastedEvent;
public static synthetic fun copy$default (Lio/getstream/chat/android/client/events/AnswerCastedEvent;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/Answer;ILjava/lang/Object;)Lio/getstream/chat/android/client/events/AnswerCastedEvent;
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 final fun getNewAnswer ()Lio/getstream/chat/android/models/Answer;
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/ChannelDeletedEvent : io/getstream/chat/android/client/events/CidEvent, io/getstream/chat/android/client/events/HasChannel {
public fun <init> (Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Channel;Lio/getstream/chat/android/models/User;)V
public final fun component1 ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,15 @@ internal constructor(
return api.castPollVote(messageId, pollId, option.id)
}

@CheckResult
public fun castPollAnswer(
messageId: String,
pollId: String,
answer: String,
): Call<Vote> {
return api.castPollAnswer(messageId, pollId, answer)
}

/**
* Remove a vote for a poll in a message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ internal interface ChatApi {
@CheckResult
fun castPollVote(messageId: String, pollId: String, optionId: String): Call<Vote>

@CheckResult
fun castPollAnswer(messageId: String, pollId: String, answer: String): Call<Vote>

@CheckResult
fun removePollVote(messageId: String, pollId: String, voteId: String): Call<Vote>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,31 @@ constructor(
messageId: String,
pollId: String,
optionId: String,
): Call<Vote> = castVote(
messageId = messageId,
pollId = pollId,
vote = UpstreamVoteDto(option_id = optionId),
)

override fun castPollAnswer(
messageId: String,
pollId: String,
answer: String,
): Call<Vote> = castVote(
messageId = messageId,
pollId = pollId,
vote = UpstreamVoteDto(answer_text = answer),
)

private fun castVote(
messageId: String,
pollId: String,
vote: UpstreamVoteDto,
): Call<Vote> {
return pollsApi.castPollVote(
messageId,
pollId,
PollVoteRequest(UpstreamVoteDto(optionId)),
PollVoteRequest(vote),
).map { it.vote.toDomain(currentUserIdProvider()) }
}

Expand Down Expand Up @@ -1226,6 +1246,7 @@ constructor(
enforce_unique_vote = pollConfig.enforceUniqueVote,
max_votes_allowed = pollConfig.maxVotesAllowed,
allow_user_suggested_options = pollConfig.allowUserSuggestedOptions,
allow_answers = pollConfig.allowAnswers,
),
).map { it.poll.toDomain(currentUserIdProvider()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.getstream.chat.android.client.api2.mapping

import io.getstream.chat.android.client.api2.model.dto.AnswerCastedEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelDeletedEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelHiddenEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelTruncatedEventDto
Expand Down Expand Up @@ -74,6 +75,7 @@ import io.getstream.chat.android.client.api2.model.dto.UserUpdatedEventDto
import io.getstream.chat.android.client.api2.model.dto.VoteCastedEventDto
import io.getstream.chat.android.client.api2.model.dto.VoteChangedEventDto
import io.getstream.chat.android.client.api2.model.dto.VoteRemovedEventDto
import io.getstream.chat.android.client.events.AnswerCastedEvent
import io.getstream.chat.android.client.events.ChannelDeletedEvent
import io.getstream.chat.android.client.events.ChannelHiddenEvent
import io.getstream.chat.android.client.events.ChannelTruncatedEvent
Expand Down Expand Up @@ -197,6 +199,7 @@ internal fun ChatEventDto.toDomain(currentUserId: UserId?): ChatEvent {
is PollUpdatedEventDto -> toDomain(currentUserId)
is VoteCastedEventDto -> toDomain(currentUserId)
is VoteChangedEventDto -> toDomain(currentUserId)
is AnswerCastedEventDto -> toDomain(currentUserId)
is VoteRemovedEventDto -> toDomain(currentUserId)
}
}
Expand Down Expand Up @@ -809,6 +812,21 @@ private fun VoteCastedEventDto.toDomain(currentUserId: UserId?): VoteCastedEvent
)
}

private fun AnswerCastedEventDto.toDomain(currentUserId: UserId?): AnswerCastedEvent {
val newAnswer = poll_vote.toAnswerDomain(currentUserId)
val (channelType, channelId) = cid.cidToTypeAndId()
return AnswerCastedEvent(
type = type,
createdAt = created_at.date,
rawCreatedAt = created_at.rawDate,
cid = cid,
channelType = channelType,
channelId = channelId,
poll = poll.toDomain(currentUserId),
newAnswer = newAnswer,
)
}

private fun VoteChangedEventDto.toDomain(currentUserId: UserId?): VoteChangedEvent {
val pollVote = poll_vote.toDomain(currentUserId)
val (channelType, channelId) = cid.cidToTypeAndId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.chat.android.client.api2.mapping
import io.getstream.chat.android.client.api2.model.dto.DownstreamOptionDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamPollDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamVoteDto
import io.getstream.chat.android.models.Answer
import io.getstream.chat.android.models.Option
import io.getstream.chat.android.models.Poll
import io.getstream.chat.android.models.UserId
Expand All @@ -32,12 +33,23 @@ import io.getstream.chat.android.models.VotingVisibility
*/
internal fun DownstreamPollDto.toDomain(currentUserId: UserId?): Poll {
val ownUserId = currentUserId ?: own_votes.firstOrNull()?.user?.id
val votes = latest_votes_by_option?.values?.flatten()?.map { it.toDomain(currentUserId) } ?: emptyList()
val ownVotes = (own_votes.map { it.toDomain(currentUserId) } + votes.filter { it.user?.id == ownUserId })
val votes = latest_votes_by_option
?.values
?.flatten()
?.filter { it.is_answer != true }
?.map { it.toDomain(currentUserId) } ?: emptyList()
val ownVotes = (
own_votes
.filter { it.is_answer != true }
.map { it.toDomain(currentUserId) } +
votes.filter { it.user?.id == ownUserId }
)
.associateBy { it.id }
.values
.toList()

val answer = latest_answers?.map { it.toAnswerDomain(currentUserId) } ?: emptyList()

return Poll(
id = id,
name = name,
Expand All @@ -54,6 +66,7 @@ internal fun DownstreamPollDto.toDomain(currentUserId: UserId?): Poll {
createdAt = created_at,
updatedAt = updated_at,
closed = is_closed,
answers = answer,
)
}

Expand Down Expand Up @@ -81,6 +94,20 @@ internal fun DownstreamVoteDto.toDomain(currentUserId: UserId?): Vote = Vote(
user = user?.toDomain(currentUserId),
)

/**
* Transforms DownstreamVoteDto to Answer
*
* @return Answer
*/
internal fun DownstreamVoteDto.toAnswerDomain(currentUserId: UserId?): Answer = Answer(
id = id,
pollId = poll_id,
text = answer_text ?: "",
createdAt = created_at,
updatedAt = updated_at,
user = user?.toDomain(currentUserId),
)

/**
* Transforms String to VotingVisibility
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ internal data class VoteCastedEventDto(
val poll_vote: DownstreamVoteDto,
) : ChatEventDto()

@JsonClass(generateAdapter = true)
internal data class AnswerCastedEventDto(
val type: String,
val cid: String,
val created_at: ExactDate,
val poll: DownstreamPollDto,
val poll_vote: DownstreamVoteDto,
) : ChatEventDto()

@JsonClass(generateAdapter = true)
internal data class VoteChangedEventDto(
val type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ internal data class DownstreamVoteDto(
val updated_at: Date,
val user: DownstreamUserDto?,
val user_id: String?,
val is_answer: Boolean?,
val answer_text: String?,
)

/**
Expand Down Expand Up @@ -88,6 +90,7 @@ internal data class DownstreamPollDto(
val options: List<DownstreamOptionDto>,
val vote_counts_by_option: Map<String, Int>?,
val latest_votes_by_option: Map<String, List<DownstreamVoteDto>>?,
val latest_answers: List<DownstreamVoteDto>?,
val created_at: Date,
val created_by: DownstreamUserDto,
val created_by_id: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal data class PollRequest(
val enforce_unique_vote: Boolean,
val max_votes_allowed: Int,
val allow_user_suggested_options: Boolean,
val allow_answers: Boolean,
) {

companion object {
Expand Down Expand Up @@ -95,5 +96,6 @@ internal data class PollUpdateRequest(
*/
@JsonClass(generateAdapter = true)
internal data class UpstreamVoteDto(
val option_id: String,
val option_id: String? = null,
val answer_text: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.getstream.chat.android.client.api.models.PinnedMessagesPagination
import io.getstream.chat.android.client.api.models.QueryChannelRequest
import io.getstream.chat.android.client.api.models.SendActionRequest
import io.getstream.chat.android.client.api.models.WatchChannelRequest
import io.getstream.chat.android.client.events.AnswerCastedEvent
import io.getstream.chat.android.client.events.ChannelDeletedEvent
import io.getstream.chat.android.client.events.ChannelHiddenEvent
import io.getstream.chat.android.client.events.ChannelTruncatedEvent
Expand Down Expand Up @@ -259,6 +260,7 @@ public class ChannelClient internal constructor(
is VoteCastedEvent -> event.cid == cid
is VoteChangedEvent -> event.cid == cid
is VoteRemovedEvent -> event.cid == cid
is AnswerCastedEvent -> event.cid == cid
is UnknownEvent -> event.rawData["cid"] == cid
is HealthEvent,
is NotificationChannelMutesUpdatedEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.getstream.chat.android.client.events

import io.getstream.chat.android.client.clientstate.DisconnectCause
import io.getstream.chat.android.client.errors.ChatError
import io.getstream.chat.android.models.Answer
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.Member
import io.getstream.chat.android.models.Message
Expand Down Expand Up @@ -742,6 +743,20 @@ public data class VoteCastedEvent(
val newVote: Vote,
) : CidEvent(), HasPoll

/**
* Triggered when a vote is casted.
*/
public data class AnswerCastedEvent(
override val type: String,
override val createdAt: Date,
override val rawCreatedAt: String?,
override val cid: String,
override val channelType: String,
override val channelId: String,
override val poll: Poll,
val newAnswer: Answer,
) : CidEvent(), HasPoll

/**
* Triggered when a vote is changed.
*/
Expand Down
Loading

0 comments on commit 266550d

Please sign in to comment.