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,
|
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.
|
* External account management url for use with MSC3824 delegated OIDC, provided in Wellknown.
|
||||||
|
@ -158,10 +158,10 @@ interface SendService {
|
|||||||
* Redact (delete) the given event.
|
* Redact (delete) the given event.
|
||||||
* @param event the event to redact
|
* @param event the event to redact
|
||||||
* @param reason optional reason string
|
* @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
|
* @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.
|
* 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_MSC3771 = "org.matrix.msc3771"
|
||||||
private const val FEATURE_THREADS_MSC3773 = "org.matrix.msc3773"
|
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_REMOTE_TOGGLE_PUSH_NOTIFICATIONS_MSC3881 = "org.matrix.msc3881"
|
||||||
private const val FEATURE_EVENT_REDACTION_WITH_RELATIONS = "org.matrix.msc3912"
|
private const val FEATURE_REDACTION_OF_RELATED_EVENT = "org.matrix.msc3912"
|
||||||
private const val FEATURE_EVENT_REDACTION_WITH_RELATIONS_STABLE = "org.matrix.msc3912.stable"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the SDK supports this homeserver version.
|
* 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.
|
* 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 {
|
internal fun Versions.doesServerSupportRedactionOfRelatedEvents(): Boolean {
|
||||||
return unstableFeatures?.get(FEATURE_EVENT_REDACTION_WITH_RELATIONS).orFalse() ||
|
return unstableFeatures?.get(FEATURE_REDACTION_OF_RELATED_EVENT).orFalse()
|
||||||
unstableFeatures?.get(FEATURE_EVENT_REDACTION_WITH_RELATIONS_STABLE).orFalse()
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ internal interface RedactEventTask : Task<RedactEventTask.Params, String> {
|
|||||||
val roomId: String,
|
val roomId: String,
|
||||||
val eventId: String,
|
val eventId: String,
|
||||||
val reason: String?,
|
val reason: String?,
|
||||||
val withRelations: List<String>?,
|
val withRelTypes: List<String>?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,9 +41,9 @@ internal class DefaultRedactEventTask @Inject constructor(
|
|||||||
) : RedactEventTask {
|
) : RedactEventTask {
|
||||||
|
|
||||||
override suspend fun execute(params: RedactEventTask.Params): String {
|
override suspend fun execute(params: RedactEventTask.Params): String {
|
||||||
val withRelations = if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.canRedactEventWithRelations.orFalse() &&
|
val withRelTypes = if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.canRedactRelatedEvents.orFalse() &&
|
||||||
!params.withRelations.isNullOrEmpty()) {
|
!params.withRelTypes.isNullOrEmpty()) {
|
||||||
params.withRelations
|
params.withRelTypes
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ internal class DefaultRedactEventTask @Inject constructor(
|
|||||||
eventId = params.eventId,
|
eventId = params.eventId,
|
||||||
body = EventRedactBody(
|
body = EventRedactBody(
|
||||||
reason = params.reason,
|
reason = params.reason,
|
||||||
withRelations = withRelations,
|
unstableWithRelTypes = withRelTypes,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ internal object HomeServerCapabilitiesMapper {
|
|||||||
canLoginWithQrCode = entity.canLoginWithQrCode,
|
canLoginWithQrCode = entity.canLoginWithQrCode,
|
||||||
canUseThreadReadReceiptsAndNotifications = entity.canUseThreadReadReceiptsAndNotifications,
|
canUseThreadReadReceiptsAndNotifications = entity.canUseThreadReadReceiptsAndNotifications,
|
||||||
canRemotelyTogglePushNotificationsOfDevices = entity.canRemotelyTogglePushNotificationsOfDevices,
|
canRemotelyTogglePushNotificationsOfDevices = entity.canRemotelyTogglePushNotificationsOfDevices,
|
||||||
canRedactEventWithRelations = entity.canRedactEventWithRelations,
|
canRedactRelatedEvents = entity.canRedactEventWithRelations,
|
||||||
externalAccountManagementUrl = entity.externalAccountManagementUrl,
|
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.Versions
|
||||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices
|
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.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.doesServerSupportRemoteToggleOfPushNotifications
|
||||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreadUnreadNotifications
|
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreadUnreadNotifications
|
||||||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads
|
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads
|
||||||
@ -154,7 +154,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
|
|||||||
homeServerCapabilitiesEntity.canRemotelyTogglePushNotificationsOfDevices =
|
homeServerCapabilitiesEntity.canRemotelyTogglePushNotificationsOfDevices =
|
||||||
getVersionResult.doesServerSupportRemoteToggleOfPushNotifications()
|
getVersionResult.doesServerSupportRemoteToggleOfPushNotifications()
|
||||||
homeServerCapabilitiesEntity.canRedactEventWithRelations =
|
homeServerCapabilitiesEntity.canRedactEventWithRelations =
|
||||||
getVersionResult.doesServerSupportRedactEventWithRelations()
|
getVersionResult.doesServerSupportRedactionOfRelatedEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) {
|
if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) {
|
||||||
|
@ -140,11 +140,11 @@ internal class DefaultSendService @AssistedInject constructor(
|
|||||||
.let { sendEvent(it) }
|
.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?
|
// 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) }
|
.also { createLocalEcho(it) }
|
||||||
return eventSenderProcessor.postRedaction(redactionEcho, reason, withRelations)
|
return eventSenderProcessor.postRedaction(redactionEcho, reason, withRelTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resendTextMessage(localEcho: TimelineEvent): Cancelable {
|
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 localId = LocalEcho.createLocalEchoId()
|
||||||
val content = if (reason != null || withRelations != null) {
|
val content = if (reason != null || withRelTypes != null) {
|
||||||
EventRedactBody(
|
EventRedactBody(
|
||||||
reason = reason,
|
reason = reason,
|
||||||
withRelations = withRelations,
|
unstableWithRelTypes = withRelTypes,
|
||||||
).toContent().plus(additionalContent.orEmpty())
|
).toContent().plus(additionalContent.orEmpty())
|
||||||
} else {
|
} else {
|
||||||
additionalContent
|
additionalContent
|
||||||
|
@ -43,7 +43,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters, ses
|
|||||||
val roomId: String,
|
val roomId: String,
|
||||||
val eventId: String,
|
val eventId: String,
|
||||||
val reason: String?,
|
val reason: String?,
|
||||||
val withRelations: List<String>? = null,
|
val withRelTypes: List<String>? = null,
|
||||||
override val lastFailureMessage: String? = null
|
override val lastFailureMessage: String? = null
|
||||||
) : SessionWorkerParams
|
) : SessionWorkerParams
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters, ses
|
|||||||
roomId = params.roomId,
|
roomId = params.roomId,
|
||||||
eventId = params.eventId,
|
eventId = params.eventId,
|
||||||
reason = params.reason,
|
reason = params.reason,
|
||||||
withRelations = params.withRelations,
|
withRelTypes = params.withRelTypes,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}.fold(
|
}.fold(
|
||||||
|
@ -25,5 +25,10 @@ internal data class EventRedactBody(
|
|||||||
val reason: String? = null,
|
val reason: String? = null,
|
||||||
|
|
||||||
@Json(name = "org.matrix.msc3912.with_relations")
|
@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 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
|
fun postTask(task: QueuedTask): Cancelable
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ internal class EventSenderProcessorCoroutine @Inject constructor(
|
|||||||
return postTask(task)
|
return postTask(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelations: List<String>?): Cancelable {
|
override fun postRedaction(redactionLocalEcho: Event, reason: String?, withRelTypes: List<String>?): Cancelable {
|
||||||
return postRedaction(redactionLocalEcho.eventId!!, redactionLocalEcho.redacts!!, redactionLocalEcho.roomId!!, reason, withRelations)
|
return postRedaction(redactionLocalEcho.eventId!!, redactionLocalEcho.redacts!!, redactionLocalEcho.roomId!!, reason, withRelTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun postRedaction(
|
override fun postRedaction(
|
||||||
@ -110,9 +110,9 @@ internal class EventSenderProcessorCoroutine @Inject constructor(
|
|||||||
eventToRedactId: String,
|
eventToRedactId: String,
|
||||||
roomId: String,
|
roomId: String,
|
||||||
reason: String?,
|
reason: String?,
|
||||||
withRelations: List<String>?
|
withRelTypes: List<String>?
|
||||||
): Cancelable {
|
): Cancelable {
|
||||||
val task = queuedTaskFactory.createRedactTask(redactionLocalEchoId, eventToRedactId, roomId, reason, withRelations)
|
val task = queuedTaskFactory.createRedactTask(redactionLocalEchoId, eventToRedactId, roomId, reason, withRelTypes)
|
||||||
return postTask(task)
|
return postTask(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ internal class QueueMemento @Inject constructor(
|
|||||||
eventId = it.redacts,
|
eventId = it.redacts,
|
||||||
roomId = it.roomId,
|
roomId = it.roomId,
|
||||||
reason = body?.reason,
|
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(
|
return RedactQueuedTask(
|
||||||
redactionLocalEchoId = redactionLocalEcho,
|
redactionLocalEchoId = redactionLocalEcho,
|
||||||
toRedactEventId = eventId,
|
toRedactEventId = eventId,
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
reason = reason,
|
reason = reason,
|
||||||
withRelations = withRelations,
|
withRelTypes = withRelTypes,
|
||||||
redactEventTask = redactEventTask,
|
redactEventTask = redactEventTask,
|
||||||
localEchoRepository = localEchoRepository,
|
localEchoRepository = localEchoRepository,
|
||||||
cancelSendTracker = cancelSendTracker
|
cancelSendTracker = cancelSendTracker
|
||||||
|
@ -26,14 +26,14 @@ internal class RedactQueuedTask(
|
|||||||
val redactionLocalEchoId: String,
|
val redactionLocalEchoId: String,
|
||||||
private val roomId: String,
|
private val roomId: String,
|
||||||
private val reason: String?,
|
private val reason: String?,
|
||||||
private val withRelations: List<String>?,
|
private val withRelTypes: List<String>?,
|
||||||
private val redactEventTask: RedactEventTask,
|
private val redactEventTask: RedactEventTask,
|
||||||
private val localEchoRepository: LocalEchoRepository,
|
private val localEchoRepository: LocalEchoRepository,
|
||||||
private val cancelSendTracker: CancelSendTracker
|
private val cancelSendTracker: CancelSendTracker
|
||||||
) : QueuedTask(queueIdentifier = roomId, taskIdentifier = redactionLocalEchoId) {
|
) : QueuedTask(queueIdentifier = roomId, taskIdentifier = redactionLocalEchoId) {
|
||||||
|
|
||||||
override suspend fun doExecute() {
|
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() {
|
override fun onTaskFailed() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user