mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 01:45:36 +03:00
Merge pull request #8798 from element-hq/feature/bma/reportUserStateEvent
When reporting a user, use the membership state eventId for the eventId.
This commit is contained in:
commit
9b4394bbe6
2 changed files with 26 additions and 6 deletions
|
@ -766,7 +766,7 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRoom(roomId: String): RoomSummary? =
|
fun getRoom(roomId: String): RoomSummary? =
|
||||||
session.roomService().getRoomSummary(roomId)
|
session.roomService().getRoomSummary(roomId)
|
||||||
|
|
||||||
private fun handleComposerFocusChange(action: RoomDetailAction.ComposerFocusChange) {
|
private fun handleComposerFocusChange(action: RoomDetailAction.ComposerFocusChange) {
|
||||||
if (room == null) return
|
if (room == null) return
|
||||||
|
@ -1147,7 +1147,22 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
if (room == null) return
|
if (room == null) return
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val event = try {
|
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)
|
RoomDetailViewEvents.ActionSuccess(action)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
RoomDetailViewEvents.ActionFailure(action, failure)
|
RoomDetailViewEvents.ActionFailure(action, failure)
|
||||||
|
|
|
@ -174,15 +174,20 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReportAction() {
|
private fun handleReportAction() {
|
||||||
|
room ?: return
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val event = try {
|
val event = try {
|
||||||
// The API need an Event, use the latest Event.
|
// The API needs an Event, use user state event if available (it should always be available)
|
||||||
val latestEventId = room?.roomSummary()?.latestPreviewableEvent?.eventId ?: return@launch
|
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()
|
room.reportingService()
|
||||||
.reportContent(
|
.reportContent(
|
||||||
eventId = latestEventId,
|
eventId = eventId,
|
||||||
score = -100,
|
score = -100,
|
||||||
reason = "Reporting user ${initialState.userId} (eventId is not relevant)"
|
reason = "Reporting user ${initialState.userId}"
|
||||||
)
|
)
|
||||||
RoomMemberProfileViewEvents.OnReportActionSuccess
|
RoomMemberProfileViewEvents.OnReportActionSuccess
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
|
|
Loading…
Reference in a new issue