mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Update MSC3912 implementation: Redaction of related events (#8532)
This commit is contained in:
parent
bbcea97120
commit
0573915a0a
1
changelog.d/8481.misc
Normal file
1
changelog.d/8481.misc
Normal file
@ -0,0 +1 @@
|
||||
Update MSC3912 implementation: Redaction of related events
|
@ -77,9 +77,9 @@ data class HomeServerCapabilities(
|
||||
val canRemotelyTogglePushNotificationsOfDevices: Boolean = false,
|
||||
|
||||
/**
|
||||
* True if the home server supports event redaction with relations.
|
||||
* True if the home server supports redaction of related events.
|
||||
*/
|
||||
var canRedactEventWithRelations: Boolean = false,
|
||||
var canRedactRelatedEvents: Boolean = false,
|
||||
|
||||
/**
|
||||
* External account management url for use with MSC3824 delegated OIDC, provided in Wellknown.
|
||||
|
@ -158,10 +158,10 @@ interface SendService {
|
||||
* Redact (delete) the given event.
|
||||
* @param event the event to redact
|
||||
* @param reason optional reason string
|
||||
* @param withRelations the list of relation types to redact with this event
|
||||
* @param withRelTypes the list of relation types to redact with this event
|
||||
* @param additionalContent additional content to put in the event content
|
||||
*/
|
||||
fun redactEvent(event: Event, reason: String?, withRelations: List<String>? = null, additionalContent: Content? = null): Cancelable
|
||||
fun redactEvent(event: Event, reason: String?, withRelTypes: List<String>? = null, additionalContent: Content? = null): Cancelable
|
||||
|
||||
/**
|
||||
* Schedule this message to be resent.
|
||||
|
@ -59,8 +59,7 @@ private const val FEATURE_QR_CODE_LOGIN = "org.matrix.msc3882"
|
||||
private const val FEATURE_THREADS_MSC3771 = "org.matrix.msc3771"
|
||||
private const val FEATURE_THREADS_MSC3773 = "org.matrix.msc3773"
|
||||
private const val FEATURE_REMOTE_TOGGLE_PUSH_NOTIFICATIONS_MSC3881 = "org.matrix.msc3881"
|
||||
private const val FEATURE_EVENT_REDACTION_WITH_RELATIONS = "org.matrix.msc3912"
|
||||
private const val FEATURE_EVENT_REDACTION_WITH_RELATIONS_STABLE = "org.matrix.msc3912.stable"
|
||||
private const val FEATURE_REDACTION_OF_RELATED_EVENT = "org.matrix.msc3912"
|
||||
|
||||
/**
|
||||
* Return true if the SDK supports this homeserver version.
|
||||
@ -162,9 +161,8 @@ internal fun Versions.doesServerSupportRemoteToggleOfPushNotifications(): Boolea
|
||||
/**
|
||||
* Indicate if the server supports MSC3912: https://github.com/matrix-org/matrix-spec-proposals/pull/3912.
|
||||
*
|
||||
* @return true if event redaction with relations is supported
|
||||
* @return true if redaction of related events is supported
|
||||
*/
|
||||
internal fun Versions.doesServerSupportRedactEventWithRelations(): Boolean {
|
||||
return unstableFeatures?.get(FEATURE_EVENT_REDACTION_WITH_RELATIONS).orFalse() ||
|
||||
unstableFeatures?.get(FEATURE_EVENT_REDACTION_WITH_RELATIONS_STABLE).orFalse()
|
||||
internal fun Versions.doesServerSupportRedactionOfRelatedEvents(): Boolean {
|
||||
return unstableFeatures?.get(FEATURE_REDACTION_OF_RELATED_EVENT).orFalse()
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ internal interface RedactEventTask : Task<RedactEventTask.Params, String> {
|
||||
val roomId: String,
|
||||
val eventId: String,
|
||||
val reason: String?,
|
||||
val withRelations: List<String>?,
|
||||
val withRelTypes: List<String>?,
|
||||
)
|
||||
}
|
||||
|
||||
@ -41,9 +41,9 @@ internal class DefaultRedactEventTask @Inject constructor(
|
||||
) : RedactEventTask {
|
||||
|
||||
override suspend fun execute(params: RedactEventTask.Params): String {
|
||||
val withRelations = if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.canRedactEventWithRelations.orFalse() &&
|
||||
!params.withRelations.isNullOrEmpty()) {
|
||||
params.withRelations
|
||||
val withRelTypes = if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.canRedactRelatedEvents.orFalse() &&
|
||||
!params.withRelTypes.isNullOrEmpty()) {
|
||||
params.withRelTypes
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@ -55,7 +55,7 @@ internal class DefaultRedactEventTask @Inject constructor(
|
||||
eventId = params.eventId,
|
||||
body = EventRedactBody(
|
||||
reason = params.reason,
|
||||
withRelations = withRelations,
|
||||
unstableWithRelTypes = withRelTypes,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ internal object HomeServerCapabilitiesMapper {
|
||||
canLoginWithQrCode = entity.canLoginWithQrCode,
|
||||
canUseThreadReadReceiptsAndNotifications = entity.canUseThreadReadReceiptsAndNotifications,
|
||||
canRemotelyTogglePushNotificationsOfDevices = entity.canRemotelyTogglePushNotificationsOfDevices,
|
||||
canRedactEventWithRelations = entity.canRedactEventWithRelations,
|
||||
canRedactRelatedEvents = entity.canRedactEventWithRelations,
|
||||
externalAccountManagementUrl = entity.externalAccountManagementUrl,
|
||||
)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
import org.matrix.android.sdk.internal.auth.version.Versions
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportQrCodeLogin
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportRedactEventWithRelations
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportRedactionOfRelatedEvents
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportRemoteToggleOfPushNotifications
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreadUnreadNotifications
|
||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads
|
||||
@ -154,7 +154,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
||||
homeServerCapabilitiesEntity.canRemotelyTogglePushNotificationsOfDevices =
|
||||
getVersionResult.doesServerSupportRemoteToggleOfPushNotifications()
|
||||
homeServerCapabilitiesEntity.canRedactEventWithRelations =
|
||||
getVersionResult.doesServerSupportRedactEventWithRelations()
|
||||
getVersionResult.doesServerSupportRedactionOfRelatedEvents()
|
||||
}
|
||||
|
||||
if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) {
|
||||
|
@ -140,11 +140,11 @@ internal class DefaultSendService @AssistedInject constructor(
|
||||
.let { sendEvent(it) }
|
||||
}
|
||||
|
||||
override fun redactEvent(event: Event, reason: String?, withRelations: List<String>?, additionalContent: Content?): Cancelable {
|
||||
override fun redactEvent(event: Event, reason: String?, withRelTypes: List<String>?, additionalContent: Content?): Cancelable {
|
||||
// TODO manage media/attachements?
|
||||
val redactionEcho = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason, withRelations, additionalContent)
|
||||
val redactionEcho = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason, withRelTypes, additionalContent)
|
||||
.also { createLocalEcho(it) }
|
||||
return eventSenderProcessor.postRedaction(redactionEcho, reason, withRelations)
|
||||
return eventSenderProcessor.postRedaction(redactionEcho, reason, withRelTypes)
|
||||
}
|
||||
|
||||
override fun resendTextMessage(localEcho: TimelineEvent): Cancelable {
|
||||
|
@ -812,12 +812,12 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||
}
|
||||
}
|
||||
*/
|
||||
fun createRedactEvent(roomId: String, eventId: String, reason: String?, withRelations: List<String>? = null, additionalContent: Content? = null): Event {
|
||||
fun createRedactEvent(roomId: String, eventId: String, reason: String?, withRelTypes: List<String>? = null, additionalContent: Content? = null): Event {
|
||||
val localId = LocalEcho.createLocalEchoId()
|
||||
val content = if (reason != null || withRelations != null) {
|
||||
val content = if (reason != null || withRelTypes != null) {
|
||||
EventRedactBody(
|
||||
reason = reason,
|
||||
withRelations = withRelations,
|
||||
unstableWithRelTypes = withRelTypes,
|
||||
).toContent().plus(additionalContent.orEmpty())
|
||||
} else {
|
||||
additionalContent
|
||||
|
@ -43,7 +43,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters, ses
|
||||
val roomId: String,
|
||||
val eventId: String,
|
||||
val reason: String?,
|
||||
val withRelations: List<String>? = null,
|
||||
val withRelTypes: List<String>? = null,
|
||||
override val lastFailureMessage: String? = null
|
||||
) : SessionWorkerParams
|
||||
|
||||
@ -63,7 +63,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters, ses
|
||||
roomId = params.roomId,
|
||||
eventId = params.eventId,
|
||||
reason = params.reason,
|
||||
withRelations = params.withRelations,
|
||||
withRelTypes = params.withRelTypes,
|
||||
)
|
||||
)
|
||||
}.fold(
|
||||
|
@ -25,5 +25,10 @@ internal data class EventRedactBody(
|
||||
val reason: String? = null,
|
||||
|
||||
@Json(name = "org.matrix.msc3912.with_relations")
|
||||
val withRelations: List<String>? = null,
|
||||
)
|
||||
val unstableWithRelTypes: List<String>? = null,
|
||||
|
||||
@Json(name = "with_rel_types")
|
||||
val withRelTypes: List<String>? = null,
|
||||
) {
|
||||
fun getBestWithRelTypes() = withRelTypes ?: unstableWithRelTypes
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ internal interface EventSenderProcessor : SessionLifecycleObserver {
|
||||
|
||||
fun postEvent(event: Event, encrypt: Boolean): Cancelable
|
||||
|
||||
fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelations: List<String>? = null): Cancelable
|
||||
fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelTypes: List<String>? = null): Cancelable
|
||||
|
||||
fun postRedaction(redactionLocalEchoId: String, eventToRedactId: String, roomId: String, reason: String?, withRelations: List<String>? = null): Cancelable
|
||||
fun postRedaction(redactionLocalEchoId: String, eventToRedactId: String, roomId: String, reason: String?, withRelTypes: List<String>? = null): Cancelable
|
||||
|
||||
fun postTask(task: QueuedTask): Cancelable
|
||||
|
||||
|
@ -101,8 +101,8 @@ internal class EventSenderProcessorCoroutine @Inject constructor(
|
||||
return postTask(task)
|
||||
}
|
||||
|
||||
override fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelations: List<String>?): Cancelable {
|
||||
return postRedaction(redactionLocalEcho.eventId!!, redactionLocalEcho.redacts!!, redactionLocalEcho.roomId!!, reason, withRelations)
|
||||
override fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelTypes: List<String>?): Cancelable {
|
||||
return postRedaction(redactionLocalEcho.eventId!!, redactionLocalEcho.redacts!!, redactionLocalEcho.roomId!!, reason, withRelTypes)
|
||||
}
|
||||
|
||||
override fun postRedaction(
|
||||
@ -110,9 +110,9 @@ internal class EventSenderProcessorCoroutine @Inject constructor(
|
||||
eventToRedactId: String,
|
||||
roomId: String,
|
||||
reason: String?,
|
||||
withRelations: List<String>?
|
||||
withRelTypes: List<String>?
|
||||
): Cancelable {
|
||||
val task = queuedTaskFactory.createRedactTask(redactionLocalEchoId, eventToRedactId, roomId, reason, withRelations)
|
||||
val task = queuedTaskFactory.createRedactTask(redactionLocalEchoId, eventToRedactId, roomId, reason, withRelTypes)
|
||||
return postTask(task)
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ internal class QueueMemento @Inject constructor(
|
||||
eventId = it.redacts,
|
||||
roomId = it.roomId,
|
||||
reason = body?.reason,
|
||||
withRelations = body?.withRelations,
|
||||
withRelTypes = body?.getBestWithRelTypes(),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ internal class QueuedTaskFactory @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
fun createRedactTask(redactionLocalEcho: String, eventId: String, roomId: String, reason: String?, withRelations: List<String>? = null): QueuedTask {
|
||||
fun createRedactTask(redactionLocalEcho: String, eventId: String, roomId: String, reason: String?, withRelTypes: List<String>? = null): QueuedTask {
|
||||
return RedactQueuedTask(
|
||||
redactionLocalEchoId = redactionLocalEcho,
|
||||
toRedactEventId = eventId,
|
||||
roomId = roomId,
|
||||
reason = reason,
|
||||
withRelations = withRelations,
|
||||
withRelTypes = withRelTypes,
|
||||
redactEventTask = redactEventTask,
|
||||
localEchoRepository = localEchoRepository,
|
||||
cancelSendTracker = cancelSendTracker
|
||||
|
@ -26,14 +26,14 @@ internal class RedactQueuedTask(
|
||||
val redactionLocalEchoId: String,
|
||||
private val roomId: String,
|
||||
private val reason: String?,
|
||||
private val withRelations: List<String>?,
|
||||
private val withRelTypes: List<String>?,
|
||||
private val redactEventTask: RedactEventTask,
|
||||
private val localEchoRepository: LocalEchoRepository,
|
||||
private val cancelSendTracker: CancelSendTracker
|
||||
) : QueuedTask(queueIdentifier = roomId, taskIdentifier = redactionLocalEchoId) {
|
||||
|
||||
override suspend fun doExecute() {
|
||||
redactEventTask.execute(RedactEventTask.Params(redactionLocalEchoId, roomId, toRedactEventId, reason, withRelations))
|
||||
redactEventTask.execute(RedactEventTask.Params(redactionLocalEchoId, roomId, toRedactEventId, reason, withRelTypes))
|
||||
}
|
||||
|
||||
override fun onTaskFailed() {
|
||||
|
Loading…
Reference in New Issue
Block a user