Skip to content
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

When reporting a user, use the membership state eventId for the eventId. #8798

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ class TimelineViewModel @AssistedInject constructor(
}

fun getRoom(roomId: String): RoomSummary? =
session.roomService().getRoomSummary(roomId)
session.roomService().getRoomSummary(roomId)

private fun handleComposerFocusChange(action: RoomDetailAction.ComposerFocusChange) {
if (room == null) return
Expand Down Expand Up @@ -1147,7 +1147,22 @@ class TimelineViewModel @AssistedInject constructor(
if (room == null) return
viewModelScope.launch {
val event = try {
room.reportingService().reportContent(action.eventId, -100, action.reason)
if (action.user && action.senderId != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just create a reportUser method to avoid repeating?

// When reporting a user, use the user state event if available (it should always be available)
val userStateEventId = room.stateService()
.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(action.senderId))
?.eventId
// If not found fallback to the provided event
val eventId = userStateEventId ?: action.eventId
room.reportingService()
.reportContent(
eventId = eventId,
score = -100,
reason = action.reason
)
} else {
room.reportingService().reportContent(action.eventId, -100, action.reason)
}
RoomDetailViewEvents.ActionSuccess(action)
} catch (failure: Throwable) {
RoomDetailViewEvents.ActionFailure(action, failure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,20 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
}

private fun handleReportAction() {
room ?: return
viewModelScope.launch {
val event = try {
// The API need an Event, use the latest Event.
val latestEventId = room?.roomSummary()?.latestPreviewableEvent?.eventId ?: return@launch
// The API needs an Event, use user state event if available (it should always be available)
val userStateEventId = room.stateService()
.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(initialState.userId))
?.eventId
// If not found fallback to the latest event
val eventId = (userStateEventId ?: room.roomSummary()?.latestPreviewableEvent?.eventId) ?: return@launch
room.reportingService()
.reportContent(
eventId = latestEventId,
eventId = eventId,
score = -100,
reason = "Reporting user ${initialState.userId} (eventId is not relevant)"
reason = "Reporting user ${initialState.userId}"
)
RoomMemberProfileViewEvents.OnReportActionSuccess
} catch (failure: Throwable) {
Expand Down
Loading