From 8cc96e27bcd80a1da1b22249c5f600a779a4194b Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Wed, 19 Jan 2022 12:28:00 +0200 Subject: [PATCH] - Add threads to lab settings - Disable thread awareness due to the new fallback mechanism --- .../java/org/matrix/android/sdk/api/Matrix.kt | 5 +++ .../database/helper/ThreadEventsHelper.kt | 1 - .../session/room/timeline/TimelineChunk.kt | 5 ++- .../room/timeline/TimelineEventDecryptor.kt | 17 ++++---- .../room/timeline/TokenChunkEventPersistor.kt | 21 ++++++---- .../session/sync/SyncResponseHandler.kt | 7 ++-- .../sync/handler/room/RoomSyncHandler.kt | 42 +++++++++++-------- .../app/core/platform/VectorBaseActivity.kt | 2 + .../core/resources/UserPreferencesProvider.kt | 4 ++ .../command/AutocompleteCommandPresenter.kt | 2 +- .../app/features/command/CommandParser.kt | 2 +- .../home/room/detail/TimelineFragment.kt | 2 +- .../home/room/detail/TimelineViewModel.kt | 2 +- .../detail/search/SearchResultController.kt | 5 ++- .../room/detail/search/SearchResultItem.kt | 3 +- .../action/MessageActionsViewModel.kt | 4 +- .../helper/MessageItemAttributesFactory.kt | 5 ++- .../helper/TimelineEventVisibilityHelper.kt | 5 +-- .../detail/timeline/item/AbsMessageItem.kt | 5 ++- .../features/settings/VectorPreferences.kt | 5 +++ .../settings/VectorSettingsLabsFragment.kt | 13 ++++++ vector/src/main/res/values/strings.xml | 2 + .../src/main/res/xml/vector_settings_labs.xml | 15 ++++--- 23 files changed, 116 insertions(+), 58 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt index 901ba75d16..f903898398 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt @@ -96,6 +96,11 @@ class Matrix private constructor(context: Context, matrixConfiguration: MatrixCo companion object { + /** + * Determines whether or not thread messages are enabled + */ + var areThreadMessagesEnabled: Boolean = false + private lateinit var instance: Matrix private val isInit = AtomicBoolean(false) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ThreadEventsHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ThreadEventsHelper.kt index 57e65941e7..71be1f3a4a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ThreadEventsHelper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/helper/ThreadEventsHelper.kt @@ -40,7 +40,6 @@ internal fun Map.updateThreadSummaryIfNeeded( roomId: String, realm: Realm, currentUserId: String, shouldUpdateNotifications: Boolean = true) { - if (!BuildConfig.THREADING_ENABLED) return for ((rootThreadEventId, eventEntity) in this) { eventEntity.findAllThreadsForRootEventId(eventEntity.realm, rootThreadEventId).let { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineChunk.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineChunk.kt index 33f8d88d73..9db9fe7c93 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineChunk.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineChunk.kt @@ -295,7 +295,8 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity, .orEmpty() if (timelineEvents.isEmpty()) return LoadedFromStorage() - fetchRootThreadEventsIfNeeded(timelineEvents) +// Disabled due to the new fallback +// fetchRootThreadEventsIfNeeded(timelineEvents) if (direction == Timeline.Direction.FORWARDS) { builtEventsIndexes.entries.forEach { it.setValue(it.value + timelineEvents.size) } } @@ -332,7 +333,7 @@ internal class TimelineChunk(private val chunkEntity: ChunkEntity, * in order to be able to display the event to the user appropriately */ private suspend fun fetchRootThreadEventsIfNeeded(offsetResults: List) { - if (BuildConfig.THREADING_ENABLED) return +// if (BuildConfig.THREADING_ENABLED) return val eventEntityList = offsetResults .mapNotNull { it.root diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineEventDecryptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineEventDecryptor.kt index a4d48903ad..5913aa6e7f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineEventDecryptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineEventDecryptor.kt @@ -116,15 +116,16 @@ internal class TimelineEventDecryptor @Inject constructor( eventEntity?.apply { val decryptedPayload = - if (!BuildConfig.THREADING_ENABLED) { - threadsAwarenessHandler.handleIfNeededDuringDecryption( - it, - roomId = event.roomId, - event, - result) - } else { +// Disabled due to the new fallback +// if (!BuildConfig.THREADING_ENABLED) { +// threadsAwarenessHandler.handleIfNeededDuringDecryption( +// it, +// roomId = event.roomId, +// event, +// result) +// } else { null - } +// } setDecryptionResult(result, decryptedPayload) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt index 5115c852ca..bf7ebbec54 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -19,6 +19,8 @@ package org.matrix.android.sdk.internal.session.room.timeline import com.zhuinden.monarchy.Monarchy import dagger.Lazy import io.realm.Realm +import org.matrix.android.sdk.api.Matrix +import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.RoomMemberContent @@ -50,6 +52,7 @@ import javax.inject.Inject internal class TokenChunkEventPersistor @Inject constructor( @SessionDatabase private val monarchy: Monarchy, @UserId private val userId: String, + private val matrixConfiguration: MatrixConfiguration, private val liveEventManager: Lazy) { enum class Result { @@ -182,18 +185,22 @@ internal class TokenChunkEventPersistor @Inject constructor( } liveEventManager.get().dispatchPaginatedEventReceived(event, roomId) currentChunk.addTimelineEvent(roomId, eventEntity, direction, roomMemberContentsByUser) - eventEntity.rootThreadEventId?.let { - // This is a thread event - optimizedThreadSummaryMap[it] = eventEntity - } ?: run { - // This is a normal event or a root thread one - optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity + if(Matrix.areThreadMessagesEnabled) { + eventEntity.rootThreadEventId?.let { + // This is a thread event + optimizedThreadSummaryMap[it] = eventEntity + } ?: run { + // This is a normal event or a root thread one + optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity + } } } } if (currentChunk.isValid) { RoomEntity.where(realm, roomId).findFirst()?.addIfNecessary(currentChunk) } - optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(roomId = roomId, realm = realm, currentUserId = userId) + if(Matrix.areThreadMessagesEnabled) { + optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(roomId = roomId, realm = realm, currentUserId = userId) + } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt index a3cfddd472..cfe021f08c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt @@ -102,9 +102,10 @@ internal class SyncResponseHandler @Inject constructor( val aggregator = SyncResponsePostTreatmentAggregator() // Prerequisite for thread events handling in RoomSyncHandler - if (!BuildConfig.THREADING_ENABLED) { - threadsAwarenessHandler.fetchRootThreadEventsIfNeeded(syncResponse) - } +// Disabled due to the new fallback +// if (!BuildConfig.THREADING_ENABLED) { +// threadsAwarenessHandler.fetchRootThreadEventsIfNeeded(syncResponse) +// } // Start one big transaction monarchy.awaitTransaction { realm -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt index 5b6e2a9428..cf0cdc1015 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt @@ -19,7 +19,8 @@ package org.matrix.android.sdk.internal.session.sync.handler.room import dagger.Lazy import io.realm.Realm import io.realm.kotlin.createObject -import org.matrix.android.sdk.BuildConfig +import org.matrix.android.sdk.api.Matrix +import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.EventType @@ -82,6 +83,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle private val roomMemberEventHandler: RoomMemberEventHandler, private val roomTypingUsersHandler: RoomTypingUsersHandler, private val threadsAwarenessHandler: ThreadsAwarenessHandler, + private val matrixConfiguration: MatrixConfiguration, private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource, @UserId private val userId: String, private val timelineInput: TimelineInput, @@ -379,13 +381,13 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle if (event.isEncrypted() && !isInitialSync) { decryptIfNeeded(event, roomId) } - - if (!BuildConfig.THREADING_ENABLED) { - threadsAwarenessHandler.handleIfNeeded( - realm = realm, - roomId = roomId, - event = event) - } +// Disabled due to the new fallback +// if (!BuildConfig.THREADING_ENABLED) { +// threadsAwarenessHandler.handleIfNeeded( +// realm = realm, +// roomId = roomId, +// event = event) +// } val ageLocalTs = event.unsignedData?.age?.let { syncLocalTimestampMillis - it } val eventEntity = event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, insertType) @@ -408,12 +410,14 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle } chunkEntity.addTimelineEvent(roomId, eventEntity, PaginationDirection.FORWARDS, roomMemberContentsByUser) - eventEntity.rootThreadEventId?.let { - // This is a thread event - optimizedThreadSummaryMap[it] = eventEntity - } ?: run { - // This is a normal event or a root thread one - optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity + if(Matrix.areThreadMessagesEnabled) { + eventEntity.rootThreadEventId?.let { + // This is a thread event + optimizedThreadSummaryMap[it] = eventEntity + } ?: run { + // This is a normal event or a root thread one + optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity + } } // Give info to crypto module @@ -442,10 +446,12 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle } // Handle deletion of [stuck] local echos if needed deleteLocalEchosIfNeeded(insertType, roomEntity, eventList) - optimizedThreadSummaryMap.updateThreadSummaryIfNeeded( - roomId = roomId, - realm = realm, - currentUserId = userId) + if(Matrix.areThreadMessagesEnabled) { + optimizedThreadSummaryMap.updateThreadSummaryIfNeeded( + roomId = roomId, + realm = realm, + currentUserId = userId) + } // posting new events to timeline if any is registered timelineInput.onNewTimelineEvents(roomId = roomId, eventIds = eventIds) diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 21419d55cf..67463a2ead 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -83,6 +83,7 @@ import im.vector.app.features.themes.ThemeUtils import im.vector.app.receivers.DebugReceiver import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import org.matrix.android.sdk.api.Matrix import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.failure.GlobalError import reactivecircus.flowbinding.android.view.clicks @@ -193,6 +194,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver navigator = singletonEntryPoint.navigator() activeSessionHolder = singletonEntryPoint.activeSessionHolder() vectorPreferences = singletonEntryPoint.vectorPreferences() + Matrix.areThreadMessagesEnabled = vectorPreferences.areThreadMessagesEnabled() configurationViewModel.activityRestarter.observe(this) { if (!it.hasBeenHandled) { // Recreate the Activity because configuration has changed diff --git a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt index e7cabd1540..77e773c781 100644 --- a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt @@ -52,4 +52,8 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences: fun shouldShowPolls(): Boolean { return vectorPreferences.labsEnablePolls() } + + fun areThreadMessagesEnabled(): Boolean { + return vectorPreferences.areThreadMessagesEnabled() + } } diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt index 4e4f1fef8a..85f0a8ba2d 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt @@ -57,7 +57,7 @@ class AutocompleteCommandPresenter @AssistedInject constructor( !it.isDevCommand || vectorPreferences.developerMode() } .filter { - if (BuildConfig.THREADING_ENABLED && isInThreadTimeline) { + if (vectorPreferences.areThreadMessagesEnabled() && isInThreadTimeline) { it.isThreadCommand } else { true diff --git a/vector/src/main/java/im/vector/app/features/command/CommandParser.kt b/vector/src/main/java/im/vector/app/features/command/CommandParser.kt index e76428fb1e..983a094fa3 100644 --- a/vector/src/main/java/im/vector/app/features/command/CommandParser.kt +++ b/vector/src/main/java/im/vector/app/features/command/CommandParser.kt @@ -65,7 +65,7 @@ object CommandParser { val slashCommand = messageParts.first() val message = textMessage.substring(slashCommand.length).trim() - if (BuildConfig.THREADING_ENABLED && isInThreadTimeline) { + if (isInThreadTimeline) { val notSupportedCommandsInThreads = Command.values().filter { !it.isThreadCommand }.map { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index f9e2535205..1f0f796cf7 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -1958,7 +1958,7 @@ class TimelineFragment @Inject constructor( } override fun onThreadSummaryClicked(eventId: String, isRootThreadEvent: Boolean) { - if (BuildConfig.THREADING_ENABLED && isRootThreadEvent && !isThreadTimeLine()) { + if (vectorPreferences.areThreadMessagesEnabled() && isRootThreadEvent && !isThreadTimeLine()) { navigateToThreadTimeline(eventId) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index 69d17e448a..d051860f32 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -695,7 +695,7 @@ class TimelineViewModel @AssistedInject constructor( // Show Join conference button only if there is an active conf id not joined. Otherwise fallback to default video disabled. ^ R.id.join_conference -> !state.isWebRTCCallOptionAvailable() && state.jitsiState.confId != null && !state.jitsiState.hasJoined R.id.search -> true - R.id.menu_timeline_thread_list -> BuildConfig.THREADING_ENABLED + R.id.menu_timeline_thread_list -> vectorPreferences.areThreadMessagesEnabled() R.id.dev_tools -> vectorPreferences.developerMode() else -> false } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt index 5c0f47a452..f966cd251e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt @@ -30,6 +30,7 @@ import im.vector.app.core.epoxy.charsequence.toEpoxyCharSequence import im.vector.app.core.epoxy.loadingItem import im.vector.app.core.epoxy.noResultItem import im.vector.app.core.resources.StringProvider +import im.vector.app.core.resources.UserPreferencesProvider import im.vector.app.core.ui.list.GenericHeaderItem_ import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.session.Session @@ -43,7 +44,8 @@ class SearchResultController @Inject constructor( private val session: Session, private val avatarRenderer: AvatarRenderer, private val stringProvider: StringProvider, - private val dateFormatter: VectorDateFormatter + private val dateFormatter: VectorDateFormatter, + private val userPreferencesProvider: UserPreferencesProvider ) : TypedEpoxyController() { var listener: Listener? = null @@ -123,6 +125,7 @@ class SearchResultController @Inject constructor( .sender(eventAndSender.sender ?: eventAndSender.event.senderId?.let { session.getRoomMember(it, data.roomId) }?.toMatrixItem()) .threadDetails(event.threadDetails) + .areThreadMessagesEnabled(userPreferencesProvider.areThreadMessagesEnabled()) .listener { listener?.onItemClicked(eventAndSender.event) } .let { result.add(it) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultItem.kt index fcddc2286b..8e10ea94a6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultItem.kt @@ -43,6 +43,7 @@ abstract class SearchResultItem : VectorEpoxyModel() { @EpoxyAttribute lateinit var spannable: EpoxyCharSequence @EpoxyAttribute var sender: MatrixItem? = null @EpoxyAttribute var threadDetails: ThreadDetails? = null + @EpoxyAttribute var areThreadMessagesEnabled: Boolean = false @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null @@ -55,7 +56,7 @@ abstract class SearchResultItem : VectorEpoxyModel() { holder.timeView.text = formattedDate holder.contentView.text = spannable.charSequence - if (BuildConfig.THREADING_ENABLED) { + if (areThreadMessagesEnabled) { threadDetails?.let { if (it.isRootThread) { showThreadSummary(holder) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index e979704d6a..4a7f1a5e03 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -447,7 +447,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted private fun canReplyInThread(event: TimelineEvent, messageContent: MessageContent?, actionPermissions: ActionPermissions): Boolean { - if (!BuildConfig.THREADING_ENABLED) return false + if (!vectorPreferences.areThreadMessagesEnabled()) return false if (initialState.isFromThreadTimeline) return false if (event.root.getClearType() != EventType.MESSAGE && !event.isSticker() && !event.isPoll()) return false @@ -472,7 +472,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted private fun canViewInRoom(event: TimelineEvent, messageContent: MessageContent?, actionPermissions: ActionPermissions): Boolean { - if (!BuildConfig.THREADING_ENABLED) return false + if (!vectorPreferences.areThreadMessagesEnabled()) return false if (!initialState.isFromThreadTimeline) return false if (event.root.getClearType() != EventType.MESSAGE && !event.isSticker() && !event.isPoll()) return false diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt index a2cdbec7c6..845b765101 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt @@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail.timeline.helper import im.vector.app.EmojiCompatFontProvider import im.vector.app.R import im.vector.app.core.resources.StringProvider +import im.vector.app.core.resources.UserPreferencesProvider import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController @@ -31,6 +32,7 @@ class MessageItemAttributesFactory @Inject constructor( private val messageColorProvider: MessageColorProvider, private val avatarSizeProvider: AvatarSizeProvider, private val stringProvider: StringProvider, + private val preferencesProvider: UserPreferencesProvider, private val emojiCompatFontProvider: EmojiCompatFontProvider) { fun create(messageContent: Any?, @@ -57,7 +59,8 @@ class MessageItemAttributesFactory @Inject constructor( readReceiptsCallback = callback, emojiTypeFace = emojiCompatFontProvider.typeface, decryptionErrorMessage = stringProvider.getString(R.string.encrypted_message), - threadDetails = threadDetails + threadDetails = threadDetails, + areThreadMessagesEnabled = preferencesProvider.areThreadMessagesEnabled() ) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt index 6d23d22ff0..29ecdd361e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt @@ -152,12 +152,11 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen return true } - if (BuildConfig.THREADING_ENABLED && !isFromThreadTimeline && root.isThread()) { + if (userPreferencesProvider.areThreadMessagesEnabled() && !isFromThreadTimeline && root.isThread()) { return true } - if (BuildConfig.THREADING_ENABLED && isFromThreadTimeline) { - // // + if (userPreferencesProvider.areThreadMessagesEnabled() && isFromThreadTimeline) { return if (root.getRootThreadEventId() == rootThreadEventId) { false } else root.eventId != rootThreadEventId diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index 33eae89e31..484309571f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -113,7 +113,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem holder.eventSendingIndicator.isVisible = attributes.informationData.sendStateDecoration == SendStateDecoration.SENDING_MEDIA // Threads - if (BuildConfig.THREADING_ENABLED) { + if (attributes.areThreadMessagesEnabled) { holder.threadSummaryConstraintLayout.onClick(_threadClickListener) attributes.threadDetails?.let { threadDetails -> holder.threadSummaryConstraintLayout.isVisible = threadDetails.isRootThread @@ -186,7 +186,8 @@ abstract class AbsMessageItem : AbsBaseMessageItem override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null, val emojiTypeFace: Typeface? = null, val decryptionErrorMessage: String? = null, - val threadDetails: ThreadDetails? = null + val threadDetails: ThreadDetails? = null, + val areThreadMessagesEnabled: Boolean = false ) : AbsBaseMessageItem.Attributes { // Have to override as it's used to diff epoxy items diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index f46ab86c7c..148b7e3841 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -197,6 +197,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { private const val TAKE_PHOTO_VIDEO_MODE = "TAKE_PHOTO_VIDEO_MODE" private const val SETTINGS_LABS_ENABLE_POLLS = "SETTINGS_LABS_ENABLE_POLLS" + const val SETTINGS_LABS_ENABLE_THREAD_MESSAGES = "SETTINGS_LABS_ENABLE_THREAD_MESSAGES" // Possible values for TAKE_PHOTO_VIDEO_MODE const val TAKE_PHOTO_VIDEO_MODE_ALWAYS_ASK = 0 @@ -995,4 +996,8 @@ class VectorPreferences @Inject constructor(private val context: Context) { fun labsEnablePolls(): Boolean { return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_POLLS, false) } + + fun areThreadMessagesEnabled(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_THREAD_MESSAGES, false) + } } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt index a83b4c33f4..3dd59e666d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt @@ -16,8 +16,11 @@ package im.vector.app.features.settings +import androidx.preference.Preference import im.vector.app.R import im.vector.app.core.preference.VectorSwitchPreference +import im.vector.app.features.MainActivity +import im.vector.app.features.MainActivityArgs import javax.inject.Inject class VectorSettingsLabsFragment @Inject constructor( @@ -32,5 +35,15 @@ class VectorSettingsLabsFragment @Inject constructor( // ensure correct default pref.isChecked = vectorPreferences.labsAutoReportUISI() } + + // clear cache + findPreference(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let { + it.onPreferenceClickListener = Preference.OnPreferenceClickListener { + displayLoadingView() + MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true)) + false + } + } + } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index bad94dd158..c35e501d7c 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -3600,6 +3600,8 @@ Auto Report Decryption Errors. Your system will automatically send logs when an unable to decrypt error occurs + Enable Thread Messages + Note: app will be restarted %s invites you diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index d2e9df4985..07601d8b8d 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -56,11 +56,16 @@ android:key="SETTINGS_LABS_ENABLE_POLLS" android:title="@string/labs_enable_polls" /> + - + \ No newline at end of file