From 6cd9e6eedd16554e62dbc0e8c84f733f65170c6f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 2 Apr 2024 20:45:46 +0200 Subject: [PATCH] When reporting a user, use the membership state eventId for the eventId. --- .../home/room/detail/TimelineViewModel.kt | 19 +++++++++++++++++-- .../RoomMemberProfileViewModel.kt | 13 +++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index 9e3802101e..0f396a4a8b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -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 @@ -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) { + // 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) diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt index f688793f4b..614cb159d9 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -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) {