mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Merge pull request #7939 from vector-im/feature/ons/fix_edit_poll
Fix rendering of edited polls (PSG-963)
This commit is contained in:
commit
1787031cc6
5 changed files with 22 additions and 7 deletions
1
changelog.d/7938.bugfix
Normal file
1
changelog.d/7938.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix rendering of edited polls
|
|
@ -148,8 +148,8 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? {
|
|||
// Polls/Beacon are not message contents like others as there is no msgtype subtype to discriminate moshi parsing
|
||||
// so toModel<MessageContent> won't parse them correctly
|
||||
// It's discriminated on event type instead. Maybe it shouldn't be MessageContent at all to avoid confusion?
|
||||
in EventType.POLL_START.values -> (getLastEditNewContent() ?: root.getClearContent()).toModel<MessagePollContent>()
|
||||
in EventType.POLL_END.values -> (getLastEditNewContent() ?: root.getClearContent()).toModel<MessageEndPollContent>()
|
||||
in EventType.POLL_START.values -> (getLastPollEditNewContent() ?: root.getClearContent()).toModel<MessagePollContent>()
|
||||
in EventType.POLL_END.values -> (getLastPollEditNewContent() ?: root.getClearContent()).toModel<MessageEndPollContent>()
|
||||
in EventType.STATE_ROOM_BEACON_INFO.values -> (getLastEditNewContent() ?: root.getClearContent()).toModel<MessageBeaconInfoContent>()
|
||||
in EventType.BEACON_LOCATION_DATA.values -> (getLastEditNewContent() ?: root.getClearContent()).toModel<MessageBeaconLocationDataContent>()
|
||||
else -> (getLastEditNewContent() ?: root.getClearContent()).toModel()
|
||||
|
@ -160,6 +160,10 @@ fun TimelineEvent.getLastEditNewContent(): Content? {
|
|||
return annotations?.editSummary?.latestEdit?.getClearContent()?.toModel<MessageContent>()?.newContent
|
||||
}
|
||||
|
||||
private fun TimelineEvent.getLastPollEditNewContent(): Content? {
|
||||
return annotations?.editSummary?.latestEdit?.getClearContent()?.toModel<MessagePollContent>()?.newContent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it's a reply.
|
||||
*/
|
||||
|
|
|
@ -16,13 +16,16 @@
|
|||
|
||||
package org.matrix.android.sdk.internal.session.room
|
||||
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
||||
import org.matrix.android.sdk.api.session.events.model.RelationType
|
||||
import org.matrix.android.sdk.api.session.events.model.getRelationContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.events.model.toValidDecryptedEvent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
|
||||
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
@ -101,7 +104,7 @@ internal class EventEditValidator @Inject constructor(val cryptoStore: IMXCrypto
|
|||
if (originalDecrypted.type != replaceDecrypted.type) {
|
||||
return EditValidity.Invalid("replacement and original events must have the same type")
|
||||
}
|
||||
if (replaceDecrypted.clearContent.toModel<MessageContent>()?.newContent == null) {
|
||||
if (!hasNewContent(replaceDecrypted.type, replaceDecrypted.clearContent)) {
|
||||
return EditValidity.Invalid("replacement event must have an m.new_content property")
|
||||
}
|
||||
} else {
|
||||
|
@ -116,11 +119,18 @@ internal class EventEditValidator @Inject constructor(val cryptoStore: IMXCrypto
|
|||
if (originalEvent.type != replaceEvent.type) {
|
||||
return EditValidity.Invalid("replacement and original events must have the same type")
|
||||
}
|
||||
if (replaceEvent.content.toModel<MessageContent>()?.newContent == null) {
|
||||
if (!hasNewContent(replaceEvent.type, replaceEvent.content)) {
|
||||
return EditValidity.Invalid("replacement event must have an m.new_content property")
|
||||
}
|
||||
}
|
||||
|
||||
return EditValidity.Valid
|
||||
}
|
||||
|
||||
private fun hasNewContent(eventType: String?, content: Content?): Boolean {
|
||||
return when (eventType) {
|
||||
in EventType.POLL_START.values -> content.toModel<MessagePollContent>()?.newContent != null
|
||||
else -> content.toModel<MessageContent>()?.newContent != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,8 +216,8 @@ class MessageActionsViewModel @AssistedInject constructor(
|
|||
noticeEventFormatter.format(timelineEvent, room?.roomSummary()?.isDirect.orFalse())
|
||||
}
|
||||
in EventType.POLL_START.values -> {
|
||||
timelineEvent.root.getClearContent().toModel<MessagePollContent>(catchError = true)
|
||||
?.getBestPollCreationInfo()?.question?.getBestQuestion() ?: ""
|
||||
(timelineEvent.getVectorLastMessageContent() as? MessagePollContent)?.getBestPollCreationInfo()?.question?.getBestQuestion()
|
||||
?: stringProvider.getString(R.string.message_reply_to_poll_preview)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class DisplayableEventFormatter @Inject constructor(
|
|||
span { }
|
||||
}
|
||||
in EventType.POLL_START.values -> {
|
||||
timelineEvent.root.getClearContent().toModel<MessagePollContent>(catchError = true)?.getBestPollCreationInfo()?.question?.getBestQuestion()
|
||||
(timelineEvent.getVectorLastMessageContent() as? MessagePollContent)?.getBestPollCreationInfo()?.question?.getBestQuestion()
|
||||
?: stringProvider.getString(R.string.sent_a_poll)
|
||||
}
|
||||
in EventType.POLL_RESPONSE.values -> {
|
||||
|
|
Loading…
Reference in a new issue