Merge pull request #5775 from vector-im/feature/aris/threads_after_release_experience

Enhance user experience when home servers do not support threads.
This commit is contained in:
Aris Kotsomitopoulos 2022-04-19 10:59:41 +03:00 committed by GitHub
commit abe07c73a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 11 deletions

1
changelog.d/5761.feature Normal file
View File

@ -0,0 +1 @@
Improve user experience when home servers do not yet support threads

View File

@ -54,7 +54,7 @@ data class HomeServerCapabilities(
/**
* True if the home server support threading
*/
var canUseThreading: Boolean = false
val canUseThreading: Boolean = false
) {
enum class RoomCapabilitySupport {

View File

@ -452,6 +452,10 @@ class MessageActionsViewModel @AssistedInject constructor(
actionPermissions: ActionPermissions): Boolean {
// We let reply in thread visible even if threads are not enabled, with an enhanced flow to attract users
// if (!vectorPreferences.areThreadMessagesEnabled()) return false
// Disable beta prompt if the homeserver do not support threads
if (!vectorPreferences.areThreadMessagesEnabled() &&
!session.getHomeServerCapabilities().canUseThreading) return false
if (initialState.isFromThreadTimeline) return false
if (event.root.isThread()) return false
if (event.root.getClearType() != EventType.MESSAGE &&

View File

@ -18,6 +18,7 @@ package im.vector.app.features.home.room.threads
import android.app.Activity
import android.text.Spanned
import androidx.annotation.StringRes
import androidx.core.text.HtmlCompat
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
@ -49,11 +50,17 @@ class ThreadsManager @Inject constructor(
/**
* Generates and return an Html spanned string to be rendered especially in dialogs
*/
fun getBetaEnableThreadsMessage(): Spanned {
private fun generateLearnMoreHtmlString(@StringRes messageId: Int): Spanned {
val learnMore = stringProvider.getString(R.string.action_learn_more)
val learnMoreUrl = stringProvider.getString(R.string.threads_learn_more_url)
val href = "<a href='$learnMoreUrl'>$learnMore</a>.<br><br>"
val message = stringProvider.getString(R.string.threads_beta_enable_notice_message, href)
val message = stringProvider.getString(messageId, href)
return HtmlCompat.fromHtml(message, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
fun getBetaEnableThreadsMessage(): Spanned =
generateLearnMoreHtmlString(R.string.threads_beta_enable_notice_message)
fun getLabsEnableThreadsMessage(): Spanned =
generateLearnMoreHtmlString(R.string.threads_labs_enable_notice_message)
}

View File

@ -17,18 +17,23 @@
package im.vector.app.features.settings
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.widget.TextView
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
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 im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.home.room.threads.ThreadsManager
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
import javax.inject.Inject
class VectorSettingsLabsFragment @Inject constructor(
private val vectorPreferences: VectorPreferences,
private val lightweightSettingsStorage: LightweightSettingsStorage
private val lightweightSettingsStorage: LightweightSettingsStorage,
private val threadsManager: ThreadsManager
) : VectorSettingsBaseFragment() {
override var titleRes = R.string.room_settings_labs_pref_title
@ -46,15 +51,51 @@ class VectorSettingsLabsFragment @Inject constructor(
}
// clear cache
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
// We should migrate threads only if threads are disabled
vectorPreferences.setShouldMigrateThreads(!vectorPreferences.areThreadMessagesEnabled())
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
displayLoadingView()
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let { vectorPref ->
vectorPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
onThreadsPreferenceClickedInterceptor(vectorPref)
false
}
}
}
/**
* Intercept the click to display a user friendly dialog when their homeserver do not support threads
*/
private fun onThreadsPreferenceClickedInterceptor(vectorSwitchPreference: VectorSwitchPreference) {
val userEnabledThreads = vectorPreferences.areThreadMessagesEnabled()
if (!session.getHomeServerCapabilities().canUseThreading && userEnabledThreads) {
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.threads_labs_enable_notice_title)
.setMessage(threadsManager.getLabsEnableThreadsMessage())
.setCancelable(true)
.setNegativeButton(R.string.action_not_now) { _, _ ->
vectorSwitchPreference.isChecked = false
}
.setPositiveButton(R.string.action_try_it_out) { _, _ ->
onThreadsPreferenceClicked()
}
.show()
?.findViewById<TextView>(android.R.id.message)
?.apply {
linksClickable = true
movementMethod = LinkMovementMethod.getInstance()
}
}
} else {
onThreadsPreferenceClicked()
}
}
/**
* Action when threads preference switch is actually clicked
*/
private fun onThreadsPreferenceClicked() {
// We should migrate threads only if threads are disabled
vectorPreferences.setShouldMigrateThreads(!vectorPreferences.areThreadMessagesEnabled())
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
displayLoadingView()
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
}
}

View File

@ -739,6 +739,9 @@
<string name="threads_beta_enable_notice_title">Threads Beta</string>
<!-- %s will be replaced with action_learn_more string resource that will be clickable(url redirection) -->
<string name="threads_beta_enable_notice_message">Threads help keep your conversations on-topic and easy to track. %sEnabling threads will refresh the app. This may take longer for some accounts.</string>
<string name="threads_labs_enable_notice_title">Threads Beta</string>
<string name="threads_labs_enable_notice_message">Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. %sDo you want to enable threads anyway?</string>
<!-- Search -->
<string name="search_hint">Search</string>