Skip to content

Commit b14cb81

Browse files
committed
Add action to report a user form the user profile view. EventId is not relevant, but requested by the API.
1 parent 99ec61e commit b14cb81

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import im.vector.app.core.platform.VectorViewModelAction
2222
sealed class RoomMemberProfileAction : VectorViewModelAction {
2323
object RetryFetchingInfo : RoomMemberProfileAction()
2424
object IgnoreUser : RoomMemberProfileAction()
25+
object ReportUser : RoomMemberProfileAction()
2526
data class BanOrUnbanUser(val reason: String?) : RoomMemberProfileAction()
2627
data class KickUser(val reason: String?) : RoomMemberProfileAction()
2728
object InviteUser : RoomMemberProfileAction()

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class RoomMemberProfileController @Inject constructor(
3939

4040
interface Callback {
4141
fun onIgnoreClicked()
42+
fun onReportClicked()
4243
fun onTapVerify()
4344
fun onShowDeviceList()
4445
fun onShowDeviceListNoCrossSigning()
@@ -225,7 +226,7 @@ class RoomMemberProfileController @Inject constructor(
225226
title = stringProvider.getString(R.string.room_participants_action_invite),
226227
destructive = false,
227228
editable = false,
228-
divider = ignoreActionTitle != null,
229+
divider = true,
229230
action = { callback?.onInviteClicked() }
230231
)
231232
}
@@ -235,10 +236,18 @@ class RoomMemberProfileController @Inject constructor(
235236
title = ignoreActionTitle,
236237
destructive = true,
237238
editable = false,
238-
divider = false,
239+
divider = true,
239240
action = { callback?.onIgnoreClicked() }
240241
)
241242
}
243+
buildProfileAction(
244+
id = "report",
245+
title = stringProvider.getString(R.string.message_report_user),
246+
destructive = true,
247+
editable = false,
248+
divider = false,
249+
action = { callback?.onReportClicked() }
250+
)
242251
}
243252
}
244253

@@ -314,9 +323,9 @@ class RoomMemberProfileController @Inject constructor(
314323
private fun RoomMemberProfileViewState.buildIgnoreActionTitle(): String? {
315324
val isIgnored = isIgnored() ?: return null
316325
return if (isIgnored) {
317-
stringProvider.getString(R.string.unignore)
326+
stringProvider.getString(R.string.room_participants_action_unignore_title)
318327
} else {
319-
stringProvider.getString(R.string.action_ignore)
328+
stringProvider.getString(R.string.room_participants_action_ignore_title)
320329
}
321330
}
322331
}

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,20 @@ class RoomMemberProfileFragment :
140140
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
141141
is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit
142142
RoomMemberProfileViewEvents.GoBack -> handleGoBack()
143+
RoomMemberProfileViewEvents.OnReportActionSuccess -> handleReportSuccess()
143144
}
144145
}
145146
setupLongClicks()
146147
}
147148

149+
private fun handleReportSuccess() {
150+
MaterialAlertDialogBuilder(requireContext())
151+
.setTitle(R.string.user_reported_as_inappropriate_title)
152+
.setMessage(R.string.user_reported_as_inappropriate_content)
153+
.setPositiveButton(R.string.ok, null)
154+
.show()
155+
}
156+
148157
private fun setupLongClicks() {
149158
headerViews.memberProfileNameView.copyOnLongClick()
150159
headerViews.memberProfileIdView.copyOnLongClick()
@@ -301,6 +310,10 @@ class RoomMemberProfileFragment :
301310
}
302311
}
303312

313+
override fun onReportClicked() {
314+
viewModel.handle(RoomMemberProfileAction.ReportUser)
315+
}
316+
304317
override fun onTapVerify() {
305318
viewModel.handle(RoomMemberProfileAction.VerifyUser)
306319
}

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewEvents.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
2626
data class Failure(val throwable: Throwable) : RoomMemberProfileViewEvents()
2727

2828
object OnIgnoreActionSuccess : RoomMemberProfileViewEvents()
29+
object OnReportActionSuccess : RoomMemberProfileViewEvents()
2930
object OnSetPowerLevelSuccess : RoomMemberProfileViewEvents()
3031
object OnInviteActionSuccess : RoomMemberProfileViewEvents()
3132
object OnKickActionSuccess : RoomMemberProfileViewEvents()

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
161161
when (action) {
162162
is RoomMemberProfileAction.RetryFetchingInfo -> handleRetryFetchProfileInfo()
163163
is RoomMemberProfileAction.IgnoreUser -> handleIgnoreAction()
164+
is RoomMemberProfileAction.ReportUser -> handleReportAction()
164165
is RoomMemberProfileAction.VerifyUser -> prepareVerification()
165166
is RoomMemberProfileAction.ShareRoomMemberProfile -> handleShareRoomMemberProfile()
166167
is RoomMemberProfileAction.SetPowerLevel -> handleSetPowerLevel(action)
@@ -172,6 +173,25 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
172173
}
173174
}
174175

176+
private fun handleReportAction() {
177+
viewModelScope.launch {
178+
val event = try {
179+
// The API need an Event, use the latest Event.
180+
val latestEventId = room?.roomSummary()?.latestPreviewableEvent?.eventId ?: return@launch
181+
room.reportingService()
182+
.reportContent(
183+
eventId = latestEventId,
184+
score = -100,
185+
reason = "Reporting user ${initialState.userId} (eventId is not relevant)"
186+
)
187+
RoomMemberProfileViewEvents.OnReportActionSuccess
188+
} catch (failure: Throwable) {
189+
RoomMemberProfileViewEvents.Failure(failure)
190+
}
191+
_viewEvents.post(event)
192+
}
193+
}
194+
175195
private fun handleOpenOrCreateDm(action: RoomMemberProfileAction.OpenOrCreateDm) {
176196
viewModelScope.launch {
177197
_viewEvents.post(RoomMemberProfileViewEvents.Loading())

0 commit comments

Comments
 (0)