You've already forked element-android
mirror of
https://github.com/vector-im/element-android.git
synced 2025-08-06 03:42:41 +03:00
Add action to report room: use the report Room API.
This commit is contained in:
@@ -26,4 +26,9 @@ interface ReportingService {
|
|||||||
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
|
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
|
||||||
*/
|
*/
|
||||||
suspend fun reportContent(eventId: String, score: Int, reason: String)
|
suspend fun reportContent(eventId: String, score: Int, reason: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a room.
|
||||||
|
*/
|
||||||
|
suspend fun reportRoom(reason: String)
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ import org.matrix.android.sdk.internal.session.room.read.ReadBody
|
|||||||
import org.matrix.android.sdk.internal.session.room.relation.RelationsResponse
|
import org.matrix.android.sdk.internal.session.room.relation.RelationsResponse
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.ThreadSummariesResponse
|
import org.matrix.android.sdk.internal.session.room.relation.threads.ThreadSummariesResponse
|
||||||
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentBody
|
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentBody
|
||||||
|
import org.matrix.android.sdk.internal.session.room.reporting.ReportRoomBody
|
||||||
import org.matrix.android.sdk.internal.session.room.send.SendResponse
|
import org.matrix.android.sdk.internal.session.room.send.SendResponse
|
||||||
import org.matrix.android.sdk.internal.session.room.send.model.EventRedactBody
|
import org.matrix.android.sdk.internal.session.room.send.model.EventRedactBody
|
||||||
import org.matrix.android.sdk.internal.session.room.tags.TagBody
|
import org.matrix.android.sdk.internal.session.room.tags.TagBody
|
||||||
@@ -375,6 +376,18 @@ internal interface RoomAPI {
|
|||||||
@Body body: ReportContentBody,
|
@Body body: ReportContentBody,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports a room as inappropriate to the server, which may then notify the appropriate people.
|
||||||
|
*
|
||||||
|
* @param roomId the room id
|
||||||
|
* @param body body containing the reason
|
||||||
|
*/
|
||||||
|
@POST(NetworkConstants.URI_API_PREFIX_PATH_V3 + "rooms/{roomId}/report")
|
||||||
|
suspend fun reportRoom(
|
||||||
|
@Path("roomId") roomId: String,
|
||||||
|
@Body body: ReportRoomBody,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of aliases maintained by the local server for the given room.
|
* Get a list of aliases maintained by the local server for the given room.
|
||||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-aliases
|
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-aliases
|
||||||
|
@@ -114,7 +114,9 @@ import org.matrix.android.sdk.internal.session.room.relation.threads.DefaultFetc
|
|||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadSummariesTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadSummariesTask
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.reporting.DefaultReportContentTask
|
import org.matrix.android.sdk.internal.session.room.reporting.DefaultReportContentTask
|
||||||
|
import org.matrix.android.sdk.internal.session.room.reporting.DefaultReportRoomTask
|
||||||
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentTask
|
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentTask
|
||||||
|
import org.matrix.android.sdk.internal.session.room.reporting.ReportRoomTask
|
||||||
import org.matrix.android.sdk.internal.session.room.state.DefaultSendStateTask
|
import org.matrix.android.sdk.internal.session.room.state.DefaultSendStateTask
|
||||||
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
import org.matrix.android.sdk.internal.session.room.state.SendStateTask
|
||||||
import org.matrix.android.sdk.internal.session.room.tags.AddTagToRoomTask
|
import org.matrix.android.sdk.internal.session.room.tags.AddTagToRoomTask
|
||||||
@@ -281,6 +283,9 @@ internal abstract class RoomModule {
|
|||||||
@Binds
|
@Binds
|
||||||
abstract fun bindReportContentTask(task: DefaultReportContentTask): ReportContentTask
|
abstract fun bindReportContentTask(task: DefaultReportContentTask): ReportContentTask
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindReportRoomTask(task: DefaultReportRoomTask): ReportRoomTask
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindGetContextOfEventTask(task: DefaultGetContextOfEventTask): GetContextOfEventTask
|
abstract fun bindGetContextOfEventTask(task: DefaultGetContextOfEventTask): GetContextOfEventTask
|
||||||
|
|
||||||
|
@@ -23,7 +23,8 @@ import org.matrix.android.sdk.api.session.room.reporting.ReportingService
|
|||||||
|
|
||||||
internal class DefaultReportingService @AssistedInject constructor(
|
internal class DefaultReportingService @AssistedInject constructor(
|
||||||
@Assisted private val roomId: String,
|
@Assisted private val roomId: String,
|
||||||
private val reportContentTask: ReportContentTask
|
private val reportContentTask: ReportContentTask,
|
||||||
|
private val reportRoomTask: ReportRoomTask,
|
||||||
) : ReportingService {
|
) : ReportingService {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
@@ -35,4 +36,9 @@ internal class DefaultReportingService @AssistedInject constructor(
|
|||||||
val params = ReportContentTask.Params(roomId, eventId, score, reason)
|
val params = ReportContentTask.Params(roomId, eventId, score, reason)
|
||||||
reportContentTask.execute(params)
|
reportContentTask.execute(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun reportRoom(reason: String) {
|
||||||
|
val params = ReportRoomTask.Params(roomId, reason)
|
||||||
|
reportRoomTask.execute(params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.session.room.reporting
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
internal data class ReportRoomBody(
|
||||||
|
/**
|
||||||
|
* Required. The reason the content is being reported. May be blank.
|
||||||
|
*/
|
||||||
|
@Json(name = "reason") val reason: String
|
||||||
|
)
|
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.session.room.reporting
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||||
|
import org.matrix.android.sdk.internal.network.executeRequest
|
||||||
|
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||||
|
import org.matrix.android.sdk.internal.task.Task
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
internal interface ReportRoomTask : Task<ReportRoomTask.Params, Unit> {
|
||||||
|
data class Params(
|
||||||
|
val roomId: String,
|
||||||
|
val reason: String,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class DefaultReportRoomTask @Inject constructor(
|
||||||
|
private val roomAPI: RoomAPI,
|
||||||
|
private val globalErrorReceiver: GlobalErrorReceiver
|
||||||
|
) : ReportRoomTask {
|
||||||
|
|
||||||
|
override suspend fun execute(params: ReportRoomTask.Params) {
|
||||||
|
return executeRequest(globalErrorReceiver) {
|
||||||
|
roomAPI.reportRoom(params.roomId, ReportRoomBody(params.reason))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -184,17 +184,7 @@ class RoomProfileViewModel @AssistedInject constructor(
|
|||||||
_viewEvents.post(RoomProfileViewEvents.Loading())
|
_viewEvents.post(RoomProfileViewEvents.Loading())
|
||||||
session.coroutineScope.launch {
|
session.coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
// When reporting a user, use the user state event if available (it should always be available)
|
room.reportingService().reportRoom(reason = reason)
|
||||||
val createStateEventId = room.stateService()
|
|
||||||
.getStateEvent(EventType.STATE_ROOM_CREATE, QueryStringValue.IsEmpty)
|
|
||||||
?.eventId
|
|
||||||
?: throw IllegalStateException("Failure: m.room.create event not found.")
|
|
||||||
room.reportingService()
|
|
||||||
.reportContent(
|
|
||||||
eventId = createStateEventId,
|
|
||||||
score = -100,
|
|
||||||
reason = reason,
|
|
||||||
)
|
|
||||||
_viewEvents.post(
|
_viewEvents.post(
|
||||||
RoomProfileViewEvents.Success(
|
RoomProfileViewEvents.Success(
|
||||||
stringProvider.getString(CommonStrings.room_profile_section_more_report_success_content)
|
stringProvider.getString(CommonStrings.room_profile_section_more_report_success_content)
|
||||||
|
Reference in New Issue
Block a user