Disable utd merge by default, issue with back paginate

This commit is contained in:
Valere 2020-06-26 14:07:22 +02:00 committed by Benoit Marty
parent 668967546c
commit a1ce245e3a
8 changed files with 68 additions and 56 deletions

View file

@ -15,7 +15,6 @@
*/
package im.vector.riotx.features.home.room.detail.timeline.action
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext

View file

@ -56,7 +56,22 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
EventType.ENCRYPTED == event.root.getClearType() -> {
val cryptoError = event.root.mCryptoError
val spannableStr = if (vectorPreferences.hideE2ETechnicalErrors()) {
val spannableStr = if (vectorPreferences.developerMode()) {
val errorDescription =
if (cryptoError == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
stringProvider.getString(R.string.notice_crypto_error_unkwown_inbound_session_id)
} else {
// TODO i18n
cryptoError?.name
}
val message = stringProvider.getString(R.string.encrypted_message).takeIf { cryptoError == null }
?: stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
span(message) {
textStyle = "italic"
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
}
} else {
val colorFromAttribute = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
if (cryptoError == null) {
span(stringProvider.getString(R.string.encrypted_message)) {
@ -93,21 +108,6 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
}
}
}
} else {
val errorDescription =
if (cryptoError == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
stringProvider.getString(R.string.notice_crypto_error_unkwown_inbound_session_id)
} else {
// TODO i18n
cryptoError?.name
}
val message = stringProvider.getString(R.string.encrypted_message).takeIf { cryptoError == null }
?: stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
span(message) {
textStyle = "italic"
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
}
}
val informationData = messageInformationDataFactory.create(event, nextEvent)

View file

@ -16,7 +16,6 @@
package im.vector.riotx.features.home.room.detail.timeline.factory
import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.create.RoomCreateContent
@ -40,6 +39,7 @@ import im.vector.riotx.features.home.room.detail.timeline.item.MergedRoomCreatio
import im.vector.riotx.features.home.room.detail.timeline.item.MergedUTDItem
import im.vector.riotx.features.home.room.detail.timeline.item.MergedUTDItem_
import im.vector.riotx.features.settings.VectorPreferences
import timber.log.Timber
import javax.inject.Inject
class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
@ -64,7 +64,8 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
requestModelBuild: () -> Unit)
: BasedMergedItem<*>? {
return if (shouldMergedAsCannotDecryptGroup(event, nextEvent)) {
buildUTDMergedSummary(currentPosition, items, event, eventIdToHighlight, requestModelBuild, callback)
Timber.v("## MERGE: Candidate for merge, top event ${event.eventId}")
buildUTDMergedSummary(currentPosition, items, event, eventIdToHighlight, /*requestModelBuild,*/ callback)
} else if (nextEvent?.root?.getClearType() == EventType.STATE_ROOM_CREATE
&& event.isRoomConfiguration(nextEvent.root.getClearContent()?.toModel<RoomCreateContent>()?.creator)) {
// It's the first item before room.create
@ -139,33 +140,37 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
// Event should be UTD
// Next event should not
private fun shouldMergedAsCannotDecryptGroup(event: TimelineEvent, nextEvent: TimelineEvent?) : Boolean {
if (!vectorPreferences.hideE2ETechnicalErrors()) return false
private fun shouldMergedAsCannotDecryptGroup(event: TimelineEvent, nextEvent: TimelineEvent?): Boolean {
if (!vectorPreferences.mergeUTDinTimeline()) return false
// if event is not UTD return false
if (event.root.getClearType() != EventType.ENCRYPTED || event.root.mCryptoError != MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) return false
if (!isEventUTD(event)) return false
// At this point event cannot be decrypted
// Let's check if older event is not UTD
return nextEvent == null || nextEvent.root.getClearType() != EventType.ENCRYPTED
return nextEvent == null || !isEventUTD(event)
}
private fun isEventUTD(event: TimelineEvent): Boolean {
return event.root.getClearType() == EventType.ENCRYPTED && !event.root.isRedacted()
}
private fun buildUTDMergedSummary(currentPosition: Int,
items: List<TimelineEvent>,
event: TimelineEvent,
eventIdToHighlight: String?,
requestModelBuild: () -> Unit,
callback: TimelineEventController.Callback?): MergedUTDItem_? {
var prevEvent = if (currentPosition > 0) items[currentPosition - 1] else null
items: List<TimelineEvent>,
event: TimelineEvent,
eventIdToHighlight: String?,
// requestModelBuild: () -> Unit,
callback: TimelineEventController.Callback?): MergedUTDItem_? {
Timber.v("## MERGE: buildUTDMergedSummary from position $currentPosition")
var prevEvent = items.prevOrNull(currentPosition)
var tmpPos = currentPosition - 1
val mergedEvents = ArrayList<TimelineEvent>().also { it.add(event) }
while (prevEvent != null
&& prevEvent.root.getClearType() == EventType.ENCRYPTED
&& prevEvent.root.mCryptoError == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
while (prevEvent != null && isEventUTD(prevEvent)) {
mergedEvents.add(prevEvent)
tmpPos--
prevEvent = if (tmpPos >= 0) items[tmpPos] else null
}
Timber.v("## MERGE: buildUTDMergedSummary merge group size ${mergedEvents.size}")
if (mergedEvents.size < 3) return null
var highlighted = false
@ -187,37 +192,28 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde
mergedData.add(data)
}
val mergedEventIds = mergedEvents.map { it.localId }
// We try to find if one of the item id were used as mergeItemCollapseStates key
// => handle case where paginating from mergeable events and we get more
val previousCollapseStateKey = mergedEventIds.intersect(mergeItemCollapseStates.keys).firstOrNull()
val initialCollapseState = mergeItemCollapseStates.remove(previousCollapseStateKey)
?: true
val isCollapsed = mergeItemCollapseStates.getOrPut(event.localId) { initialCollapseState }
if (isCollapsed) {
collapsedEventIds.addAll(mergedEventIds)
} else {
collapsedEventIds.removeAll(mergedEventIds)
}
collapsedEventIds.addAll(mergedEventIds)
val mergeId = mergedEventIds.joinToString(separator = "_") { it.toString() }
val attributes = MergedUTDItem.Attributes(
isCollapsed = isCollapsed,
isCollapsed = true,
mergeData = mergedData,
avatarRenderer = avatarRenderer,
onCollapsedStateChanged = {
mergeItemCollapseStates[event.localId] = it
requestModelBuild()
}
onCollapsedStateChanged = {}
)
return MergedUTDItem_()
.id(mergeId)
.big(mergedEventIds.size > 5)
.leftGuideline(avatarSizeProvider.leftGuideline)
.highlighted(isCollapsed && highlighted)
.highlighted(highlighted)
.attributes(attributes)
.also {
it.setOnVisibilityStateChanged(MergedTimelineEventVisibilityStateChangedListener(callback, mergedEvents))
}
}
private fun buildRoomCreationMergedSummary(currentPosition: Int,
items: List<TimelineEvent>,
event: TimelineEvent,

View file

@ -16,7 +16,9 @@
package im.vector.riotx.features.home.room.detail.timeline.item
import android.util.TypedValue
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
@ -32,6 +34,9 @@ abstract class MergedUTDItem : BasedMergedItem<MergedUTDItem.Holder>() {
@EpoxyAttribute
override lateinit var attributes: Attributes
@EpoxyAttribute
var big: Boolean? = false
override fun getViewType() = STUB_ID
override fun bind(holder: Holder) {
@ -39,7 +44,17 @@ abstract class MergedUTDItem : BasedMergedItem<MergedUTDItem.Holder>() {
holder.mergedTile.updateLayoutParams<RelativeLayout.LayoutParams> {
this.marginEnd = leftGuideline
if (big == true) {
this.height = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
800f,
holder.view.context.resources.displayMetrics
).toInt()
} else {
this.height = LinearLayout.LayoutParams.WRAP_CONTENT
}
}
// if (attributes.isCollapsed) {
// // Take the oldest data
// val data = distinctMergeData.lastOrNull()

View file

@ -144,7 +144,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY"
private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY"
private const val SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY"
private const val SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS = "SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS"
// SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS
private const val SETTINGS_LABS_MERGE_E2E_ERRORS = "SETTINGS_LABS_MERGE_E2E_ERRORS"
// analytics
const val SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY"
@ -266,8 +267,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY, true)
}
fun hideE2ETechnicalErrors(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS, true)
fun mergeUTDinTimeline(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_MERGE_E2E_ERRORS, false)
}
fun labAllowedExtendedLogging(): Boolean {

View file

@ -11,6 +11,7 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:layout_marginEnd="52dp"

View file

@ -1734,7 +1734,7 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="room_directory_search_hint">Name or ID (#example:matrix.org)</string>
<string name="labs_swipe_to_reply_in_timeline">Enable swipe to reply in timeline</string>
<string name="labs_hide_technical_e2e_in_timeline">Hide failed to decrypt technical details in timeline</string>
<string name="labs_merge_e2e_in_timeline">Merge failed to decrypt message in timeline</string>
<string name="link_copied_to_clipboard">Link copied to clipboard</string>

View file

@ -41,9 +41,9 @@
<im.vector.riotx.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:key="SETTINGS_LABS_HIDE_TECHNICAL_E2E_ERRORS"
android:title="@string/labs_hide_technical_e2e_in_timeline" />
android:defaultValue="false"
android:key="SETTINGS_LABS_MERGE_E2E_ERRORS"
android:title="@string/labs_merge_e2e_in_timeline" />
<!--</im.vector.riotx.core.preference.VectorPreferenceCategory>-->
</androidx.preference.PreferenceScreen>