Skip to content

Commit 6cd9e6e

Browse files
committed
When reporting a user, use the membership state eventId for the eventId.
1 parent c2b46a1 commit 6cd9e6e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class TimelineViewModel @AssistedInject constructor(
766766
}
767767

768768
fun getRoom(roomId: String): RoomSummary? =
769-
session.roomService().getRoomSummary(roomId)
769+
session.roomService().getRoomSummary(roomId)
770770

771771
private fun handleComposerFocusChange(action: RoomDetailAction.ComposerFocusChange) {
772772
if (room == null) return
@@ -1147,7 +1147,22 @@ class TimelineViewModel @AssistedInject constructor(
11471147
if (room == null) return
11481148
viewModelScope.launch {
11491149
val event = try {
1150-
room.reportingService().reportContent(action.eventId, -100, action.reason)
1150+
if (action.user && action.senderId != null) {
1151+
// When reporting a user, use the user state event if available (it should always be available)
1152+
val userStateEventId = room.stateService()
1153+
.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(action.senderId))
1154+
?.eventId
1155+
// If not found fallback to the provided event
1156+
val eventId = userStateEventId ?: action.eventId
1157+
room.reportingService()
1158+
.reportContent(
1159+
eventId = eventId,
1160+
score = -100,
1161+
reason = action.reason
1162+
)
1163+
} else {
1164+
room.reportingService().reportContent(action.eventId, -100, action.reason)
1165+
}
11511166
RoomDetailViewEvents.ActionSuccess(action)
11521167
} catch (failure: Throwable) {
11531168
RoomDetailViewEvents.ActionFailure(action, failure)

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,20 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
174174
}
175175

176176
private fun handleReportAction() {
177+
room ?: return
177178
viewModelScope.launch {
178179
val event = try {
179-
// The API need an Event, use the latest Event.
180-
val latestEventId = room?.roomSummary()?.latestPreviewableEvent?.eventId ?: return@launch
180+
// The API needs an Event, use user state event if available (it should always be available)
181+
val userStateEventId = room.stateService()
182+
.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(initialState.userId))
183+
?.eventId
184+
// If not found fallback to the latest event
185+
val eventId = (userStateEventId ?: room.roomSummary()?.latestPreviewableEvent?.eventId) ?: return@launch
181186
room.reportingService()
182187
.reportContent(
183-
eventId = latestEventId,
188+
eventId = eventId,
184189
score = -100,
185-
reason = "Reporting user ${initialState.userId} (eventId is not relevant)"
190+
reason = "Reporting user ${initialState.userId}"
186191
)
187192
RoomMemberProfileViewEvents.OnReportActionSuccess
188193
} catch (failure: Throwable) {

0 commit comments

Comments
 (0)