Skip to content

Add action to report room. #9000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8998.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add action to report room.
2 changes: 2 additions & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,8 @@
</plurals>
<string name="room_profile_section_more_polls">Poll history</string>
<string name="room_profile_section_more_uploads">Uploads</string>
<string name="room_profile_section_more_report">Report Room</string>
<string name="room_profile_section_more_report_success_content">The room has been successfully reported.</string>
<string name="room_profile_section_more_leave">Leave Room</string>
<string name="direct_room_profile_section_more_leave">Leave</string>
<string name="room_profile_leaving_room">"Leaving the room…"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ sealed class RoomProfileAction : VectorViewModelAction {
object CreateShortcut : RoomProfileAction()
object RestoreEncryptionState : RoomProfileAction()
data class SetEncryptToVerifiedDeviceOnly(val enabled: Boolean) : RoomProfileAction()
data class ReportRoom(val reason: String) : RoomProfileAction()
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RoomProfileController @Inject constructor(
fun onUploadsClicked()
fun createShortcut()
fun onSettingsClicked()
fun onReportRoomClicked()
fun onLeaveRoomClicked()
fun onRoomAliasesClicked()
fun onRoomPermissionsClicked()
Expand Down Expand Up @@ -279,6 +280,13 @@ class RoomProfileController @Inject constructor(
action = { callback?.createShortcut() }
)
}
buildProfileAction(
id = "Report",
title = stringProvider.getString(CommonStrings.room_profile_section_more_report),
icon = R.drawable.ic_report_spam,
editable = false,
action = { callback?.onReportRoomClicked() }
)
buildProfileAction(
id = "leave",
title = stringProvider.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.utils.copyToClipboard
import im.vector.app.core.utils.startSharePlainTextIntent
import im.vector.app.databinding.DialogReportContentBinding
import im.vector.app.databinding.FragmentMatrixProfileBinding
import im.vector.app.databinding.ViewStubRoomProfileHeaderBinding
import im.vector.app.features.analytics.plan.Interaction
Expand Down Expand Up @@ -123,6 +124,7 @@ class RoomProfileFragment :
is RoomProfileViewEvents.ShareRoomProfile -> onShareRoomProfile(it.permalink)
is RoomProfileViewEvents.OnShortcutReady -> addShortcut(it)
RoomProfileViewEvents.DismissLoading -> dismissLoadingDialog()
is RoomProfileViewEvents.Success -> dismissSuccessDialog(it.message)
}
}
roomListQuickActionsSharedActionViewModel
Expand All @@ -133,6 +135,17 @@ class RoomProfileFragment :
setupLongClicks()
}

private fun dismissSuccessDialog(message: CharSequence) {
MaterialAlertDialogBuilder(
requireActivity(),
im.vector.lib.ui.styles.R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive
)
.setTitle(CommonStrings.room_profile_section_more_report)
.setMessage(message)
.setPositiveButton(CommonStrings.ok, null)
.show()
}

private fun setupWaitingView() {
views.waitingView.waitingStatusText.setText(CommonStrings.please_wait)
views.waitingView.waitingStatusText.isVisible = true
Expand Down Expand Up @@ -286,6 +299,26 @@ class RoomProfileFragment :
ShortcutManagerCompat.requestPinShortcut(requireContext(), onShortcutReady.shortcutInfo, null)
}

override fun onReportRoomClicked() {
promptReasonToReportRoom()
}

private fun promptReasonToReportRoom() {
val inflater = requireActivity().layoutInflater
val layout = inflater.inflate(R.layout.dialog_report_content, null)
val views = DialogReportContentBinding.bind(layout)

MaterialAlertDialogBuilder(requireActivity())
.setTitle(CommonStrings.room_profile_section_more_report)
.setView(layout)
.setPositiveButton(CommonStrings.report_content_custom_submit) { _, _ ->
val reason = views.dialogReportContentInput.text.toString()
roomProfileViewModel.handle(RoomProfileAction.ReportRoom(reason))
}
.setNegativeButton(CommonStrings.action_cancel, null)
.show()
}

override fun onLeaveRoomClicked() {
val isPublicRoom = roomProfileViewModel.isPublicRoom()
val message = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sealed class RoomProfileViewEvents : VectorViewEvents {
data class Loading(val message: CharSequence? = null) : RoomProfileViewEvents()
object DismissLoading : RoomProfileViewEvents()
data class Failure(val throwable: Throwable) : RoomProfileViewEvents()
data class Success(val message: CharSequence) : RoomProfileViewEvents()

data class ShareRoomProfile(val permalink: String) : RoomProfileViewEvents()
data class OnShortcutReady(val shortcutInfo: ShortcutInfoCompat) : RoomProfileViewEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ class RoomProfileViewModel @AssistedInject constructor(
RoomProfileAction.CreateShortcut -> handleCreateShortcut()
RoomProfileAction.RestoreEncryptionState -> restoreEncryptionState()
is RoomProfileAction.SetEncryptToVerifiedDeviceOnly -> setEncryptToVerifiedDeviceOnly(action.enabled)
is RoomProfileAction.ReportRoom -> handleReportRoom(action.reason)
}
}

private fun handleReportRoom(reason: String) {
_viewEvents.post(RoomProfileViewEvents.Loading())
session.coroutineScope.launch {
try {
// When reporting a user, use the user state event if available (it should always be available)
val createStateEventId = room.stateService()
.getStateEvent(EventType.STATE_ROOM_CREATE, QueryStringValue.IsEmpty)
?.eventId
?: throw IllegalStateException("Failure: m.room.create event not found.")
room.reportingService()
.reportContent(
eventId = createStateEventId,
score = -100,
reason = reason,
)
_viewEvents.post(
RoomProfileViewEvents.Success(
stringProvider.getString(CommonStrings.room_profile_section_more_report_success_content)
)
)
} catch (failure: Throwable) {
Timber.e(failure, "Failed to report room ${room.roomId}")
_viewEvents.post(RoomProfileViewEvents.Failure(failure))
} finally {
_viewEvents.post(RoomProfileViewEvents.DismissLoading)
}
}
}

Expand Down
Loading