Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Poll] Improve rendering of poll end message when poll start event isn't available (PSG-1157) #8136

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8129.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Poll] Improve rendering of poll end message when poll start event isn't available
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ data class MessageEndPollContent(
override val msgType: String = MessageType.MSGTYPE_POLL_END,
@Json(name = "body") override val body: String = "",
@Json(name = "m.new_content") override val newContent: Content? = null,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null
) : MessageContent
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "org.matrix.msc1767.text") val unstableText: String? = null,
@Json(name = "m.text") val text: String? = null,
) : MessageContent {
fun getBestText() = text ?: unstableText
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ internal class LocalEchoEventFactory @Inject constructor(
relatesTo = RelationDefaultContent(
type = RelationType.REFERENCE,
eventId = eventId
)
),
unstableText = "Ended poll",
)
val localId = LocalEcho.createLocalEchoId()
return Event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ import org.matrix.android.sdk.api.session.room.model.relation.ReplyToContent
import org.matrix.android.sdk.api.session.room.timeline.getRelationContent
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
import org.matrix.android.sdk.api.util.MimeTypes
import timber.log.Timber
import javax.inject.Inject

class MessageItemFactory @Inject constructor(
Expand Down Expand Up @@ -160,8 +159,8 @@ class MessageItemFactory @Inject constructor(
textRendererFactory.create(roomId)
}

private val useRichTextEditorStyle: Boolean get() =
vectorPreferences.isRichTextEditorEnabled()
private val useRichTextEditorStyle: Boolean
get() = vectorPreferences.isRichTextEditorEnabled()

fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? {
val event = params.event
Expand Down Expand Up @@ -264,7 +263,7 @@ class MessageItemFactory @Inject constructor(
return PollItem_()
.attributes(attributes)
.eventId(informationData.eventId)
.pollQuestion(createPollQuestion(informationData, pollViewState.question, callback))
.pollTitle(createPollQuestion(informationData, pollViewState.question, callback))
.canVote(pollViewState.canVote)
.votesStatus(pollViewState.votesStatus)
.optionViewStates(pollViewState.optionViewStates.orEmpty())
Expand All @@ -281,21 +280,37 @@ class MessageItemFactory @Inject constructor(
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes,
): PollItem? {
pollStartEventId ?: return null.also {
Timber.e("### buildEndedPollItem. Cannot render poll end event because poll start event id is null")
): PollItem {
val pollStartEvent = if (pollStartEventId?.isNotEmpty() == true) {
session.roomService().getRoom(roomId)?.getTimelineEvent(pollStartEventId)
} else {
null
}
val pollContent = pollStartEvent?.root?.getClearContent()?.toModel<MessagePollContent>()

return if (pollContent == null) {
val title = stringProvider.getString(R.string.message_reply_to_ended_poll_preview).toEpoxyCharSequence()
PollItem_()
.attributes(attributes)
.eventId(informationData.eventId)
.pollTitle(title)
.optionViewStates(emptyList())
.edited(informationData.hasBeenEdited)
.ended(true)
.hasContent(false)
.highlighted(highlight)
.leftGuideline(avatarSizeProvider.leftGuideline)
.callback(callback)
} else {
buildPollItem(
pollContent,
informationData,
highlight,
callback,
attributes,
isEnded = true,
)
}
val pollStartEvent = session.roomService().getRoom(roomId)?.getTimelineEvent(pollStartEventId)
val pollContent = pollStartEvent?.root?.getClearContent()?.toModel<MessagePollContent>() ?: return null

return buildPollItem(
pollContent,
informationData,
highlight,
callback,
attributes,
isEnded = true
)
}

private fun createPollQuestion(
Expand Down Expand Up @@ -487,7 +502,6 @@ class MessageItemFactory @Inject constructor(
highlight,
callback,
attributes,
useRichTextEditorStyle = vectorPreferences.isRichTextEditorEnabled(),
)
}

Expand Down Expand Up @@ -594,7 +608,7 @@ class MessageItemFactory @Inject constructor(
val replyToContent = messageContent.relatesTo?.inReplyTo
buildFormattedTextItem(matrixFormattedBody, informationData, highlight, callback, attributes, replyToContent)
} else {
buildMessageTextItem(messageContent.body, false, informationData, highlight, callback, attributes, useRichTextEditorStyle)
buildMessageTextItem(messageContent.body, false, informationData, highlight, callback, attributes)
}
}

Expand All @@ -618,7 +632,6 @@ class MessageItemFactory @Inject constructor(
highlight,
callback,
attributes,
useRichTextEditorStyle,
)
}

Expand All @@ -629,7 +642,6 @@ class MessageItemFactory @Inject constructor(
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes,
useRichTextEditorStyle: Boolean,
): MessageTextItem? {
val renderedBody = textRenderer.render(body)
val bindingOptions = spanUtils.getBindingOptions(renderedBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package im.vector.app.features.home.room.detail.timeline.item

import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.children
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.home.room.detail.RoomDetailAction
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
Expand All @@ -31,7 +33,7 @@ import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
abstract class PollItem : AbsMessageItem<PollItem.Holder>() {

@EpoxyAttribute
var pollQuestion: EpoxyCharSequence? = null
var pollTitle: EpoxyCharSequence? = null

@EpoxyAttribute
var callback: TimelineEventController.Callback? = null
Expand All @@ -54,15 +56,18 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
@EpoxyAttribute
var ended: Boolean = false

@EpoxyAttribute
var hasContent: Boolean = true

override fun getViewStubId() = STUB_ID

override fun bind(holder: Holder) {
super.bind(holder)

renderSendState(holder.view, holder.questionTextView)

holder.questionTextView.text = pollQuestion?.charSequence
holder.votesStatusTextView.text = votesStatus
holder.questionTextView.text = pollTitle?.charSequence
holder.votesStatusTextView.setTextOrHide(votesStatus)

while (holder.optionsContainer.childCount < optionViewStates.size) {
holder.optionsContainer.addView(PollOptionView(holder.view.context))
Expand All @@ -80,7 +85,8 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
}
}

holder.endedPollTextView.isVisible = ended
holder.endedPollTextView.isVisible = ended && hasContent
holder.pollIcon.isVisible = ended && hasContent.not()
}

private fun onPollItemClick(optionViewState: PollOptionViewState) {
Expand All @@ -96,6 +102,7 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
val votesStatusTextView by bind<TextView>(R.id.optionsVotesStatusTextView)
val endedPollTextView by bind<TextView>(R.id.endedPollTextView)
val pollIcon by bind<ImageView>(R.id.timelinePollIcon)
}

companion object {
Expand Down
19 changes: 17 additions & 2 deletions vector/src/main/res/layout/item_timeline_event_poll.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,31 @@
<TextView
android:id="@+id/questionTextView"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="?vctr_content_primary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/timelinePollIcon"
app:layout_constraintTop_toBottomOf="@id/endedPollTextView"
tools:text="@sample/poll.json/question" />

<ImageView
android:id="@+id/timelinePollIcon"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="no"
android:src="@drawable/ic_attachment_poll"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@id/questionTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/questionTextView"
app:tint="?vctr_content_secondary"
tools:ignore="ContentDescription" />

<LinearLayout
android:id="@+id/optionsContainer"
android:layout_width="0dp"
Expand Down