Skip to content

Commit

Permalink
Merge pull request #5767 from vector-im/feature/bma/unignore_user
Browse files Browse the repository at this point in the history
Unignore user must perform an initial sync
  • Loading branch information
bmarty authored Apr 14, 2022
2 parents a171a29 + b1cff1a commit 97f2206
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 150 deletions.
1 change: 1 addition & 0 deletions changelog.d/5767.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unignoring a user will perform an initial sync
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ interface UserService {

/**
* Ignore users
* Note: once done, for the change to take effect, you have to request an initial sync.
* This may be improved in the future
*/
suspend fun ignoreUserIds(userIds: List<String>)

/**
* Un-ignore some users
* Note: once done, for the change to take effect, you have to request an initial sync.
*/
suspend fun unIgnoreUserIds(userIds: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ import im.vector.app.core.utils.startInstallFromSourceIntent
import im.vector.app.core.utils.toast
import im.vector.app.databinding.DialogReportContentBinding
import im.vector.app.databinding.FragmentTimelineBinding
import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
import im.vector.app.features.analytics.extensions.toAnalyticsInteraction
import im.vector.app.features.analytics.plan.Interaction
import im.vector.app.features.analytics.plan.MobileScreen
Expand All @@ -136,6 +138,7 @@ import im.vector.app.features.call.conference.ConferenceEventObserver
import im.vector.app.features.call.conference.JitsiCallViewModel
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.command.Command
import im.vector.app.features.command.ParsedCommand
import im.vector.app.features.crypto.keysbackup.restore.KeysBackupRestoreActivity
import im.vector.app.features.crypto.verification.VerificationBottomSheet
import im.vector.app.features.home.AvatarRenderer
Expand Down Expand Up @@ -438,6 +441,7 @@ class TimelineFragment @Inject constructor(
messageComposerViewModel.observeViewEvents {
when (it) {
is MessageComposerViewEvents.JoinRoomCommandSuccess -> handleJoinedToAnotherRoom(it)
is MessageComposerViewEvents.SlashCommandConfirmationRequest -> handleSlashCommandConfirmationRequest(it)
is MessageComposerViewEvents.SendMessageResult -> renderSendMessageResult(it)
is MessageComposerViewEvents.ShowMessage -> showSnackWithMessage(it.message)
is MessageComposerViewEvents.ShowRoomUpgradeDialog -> handleShowRoomUpgradeDialog(it)
Expand Down Expand Up @@ -496,6 +500,25 @@ class TimelineFragment @Inject constructor(
}
}

private fun handleSlashCommandConfirmationRequest(action: MessageComposerViewEvents.SlashCommandConfirmationRequest) {
when (action.parsedCommand) {
is ParsedCommand.UnignoreUser -> promptUnignoreUser(action.parsedCommand)
else -> TODO("Add case for ${action.parsedCommand.javaClass.simpleName}")
}
lockSendButton = false
}

private fun promptUnignoreUser(command: ParsedCommand.UnignoreUser) {
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.room_participants_action_unignore_title)
.setMessage(getString(R.string.settings_unignore_user, command.userId))
.setPositiveButton(R.string.unignore) { _, _ ->
messageComposerViewModel.handle(MessageComposerAction.SlashCommandConfirmed(command))
}
.setNegativeButton(R.string.action_cancel, null)
.show()
}

private fun renderVoiceMessageMode(content: String) {
ContentAttachmentData.fromJsonString(content)?.let { audioAttachmentData ->
views.voiceMessageRecorderView.isVisible = true
Expand Down Expand Up @@ -1686,9 +1709,7 @@ class TimelineFragment @Inject constructor(
displayCommandError(getString(R.string.unrecognized_command, sendMessageResult.command))
}
is MessageComposerViewEvents.SlashCommandResultOk -> {
dismissLoadingDialog()
views.composerLayout.setTextIfDifferent("")
sendMessageResult.messageRes?.let { showSnackWithMessage(getString(it)) }
handleSlashCommandResultOk(sendMessageResult.parsedCommand)
}
is MessageComposerViewEvents.SlashCommandResultError -> {
dismissLoadingDialog()
Expand All @@ -1705,6 +1726,21 @@ class TimelineFragment @Inject constructor(
lockSendButton = false
}

private fun handleSlashCommandResultOk(parsedCommand: ParsedCommand) {
dismissLoadingDialog()
views.composerLayout.setTextIfDifferent("")
when (parsedCommand) {
is ParsedCommand.SetMarkdown -> {
showSnackWithMessage(getString(if (parsedCommand.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled))
}
is ParsedCommand.UnignoreUser -> {
// A user has been un-ignored, perform a initial sync
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
}
else -> Unit
}
}

private fun displayCommandError(message: String) {
MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.command_error)
Expand Down Expand Up @@ -2418,23 +2454,23 @@ class TimelineFragment @Inject constructor(
}

private fun displayThreadsBetaOptInDialog() {
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.threads_beta_enable_notice_title)
.setMessage(threadsManager.getBetaEnableThreadsMessage())
.setCancelable(true)
.setNegativeButton(R.string.action_not_now) { _, _ -> }
.setPositiveButton(R.string.action_try_it_out) { _, _ ->
threadsManager.enableThreadsAndRestart(it)
}
.show()
?.findViewById<TextView>(android.R.id.message)
?.apply {
linksClickable = true
movementMethod = LinkMovementMethod.getInstance()
}
}
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.threads_beta_enable_notice_title)
.setMessage(threadsManager.getBetaEnableThreadsMessage())
.setCancelable(true)
.setNegativeButton(R.string.action_not_now) { _, _ -> }
.setPositiveButton(R.string.action_try_it_out) { _, _ ->
threadsManager.enableThreadsAndRestart(it)
}
.show()
?.findViewById<TextView>(android.R.id.message)
?.apply {
linksClickable = true
movementMethod = LinkMovementMethod.getInstance()
}
}
}

/**
* Navigate to Threads list for the current room
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package im.vector.app.features.home.room.detail.composer

import im.vector.app.core.platform.VectorViewModelAction
import im.vector.app.features.command.ParsedCommand
import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
Expand All @@ -30,6 +31,7 @@ sealed class MessageComposerAction : VectorViewModelAction {
data class UserIsTyping(val isTyping: Boolean) : MessageComposerAction()
data class OnTextChanged(val text: CharSequence) : MessageComposerAction()
data class OnEntersBackground(val composerText: String) : MessageComposerAction()
data class SlashCommandConfirmed(val parsedCommand: ParsedCommand) : MessageComposerAction()

// Voice Message
data class InitializeVoiceRecorder(val attachmentData: ContentAttachmentData) : MessageComposerAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package im.vector.app.features.home.room.detail.composer

import androidx.annotation.StringRes
import im.vector.app.core.platform.VectorViewEvents
import im.vector.app.features.command.Command
import im.vector.app.features.command.ParsedCommand

sealed class MessageComposerViewEvents : VectorViewEvents {

Expand All @@ -30,13 +30,14 @@ sealed class MessageComposerViewEvents : VectorViewEvents {

object MessageSent : SendMessageResult()
data class JoinRoomCommandSuccess(val roomId: String) : SendMessageResult()
class SlashCommandError(val command: Command) : SendMessageResult()
class SlashCommandUnknown(val command: String) : SendMessageResult()
class SlashCommandNotSupportedInThreads(val command: Command) : SendMessageResult()
data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult()
data class SlashCommandError(val command: Command) : SendMessageResult()
data class SlashCommandUnknown(val command: String) : SendMessageResult()
data class SlashCommandNotSupportedInThreads(val command: Command) : SendMessageResult()
object SlashCommandLoading : SendMessageResult()
data class SlashCommandResultOk(@StringRes val messageRes: Int? = null) : SendMessageResult()
class SlashCommandResultError(val throwable: Throwable) : SendMessageResult()
data class SlashCommandResultOk(val parsedCommand: ParsedCommand) : SendMessageResult()
data class SlashCommandResultError(val throwable: Throwable) : SendMessageResult()

data class SlashCommandConfirmationRequest(val parsedCommand: ParsedCommand) : MessageComposerViewEvents()

data class OpenRoomMemberProfile(val userId: String) : MessageComposerViewEvents()

Expand Down
Loading

0 comments on commit 97f2206

Please sign in to comment.