Message queuing : introduce redactEvent on timeline object and remove retrySendMessage.
This commit is contained in:
@@ -160,7 +160,7 @@ interface MatrixRoom : Closeable {
|
||||
|
||||
suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit>
|
||||
|
||||
suspend fun cancelSend(transactionId: TransactionId): Result<Unit>
|
||||
suspend fun cancelSend(transactionId: TransactionId): Result<Boolean>
|
||||
|
||||
suspend fun leave(): Result<Unit>
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ interface Timeline : AutoCloseable {
|
||||
progressCallback: ProgressCallback?
|
||||
): Result<MediaUploadHandler>
|
||||
|
||||
suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Boolean>
|
||||
|
||||
suspend fun sendAudio(file: File, audioInfo: AudioInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler>
|
||||
|
||||
suspend fun sendFile(file: File, fileInfo: FileInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler>
|
||||
@@ -85,9 +87,7 @@ interface Timeline : AutoCloseable {
|
||||
|
||||
suspend fun forwardEvent(eventId: EventId, roomIds: List<RoomId>): Result<Unit>
|
||||
|
||||
suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit>
|
||||
|
||||
suspend fun cancelSend(transactionId: TransactionId): Result<Unit>
|
||||
suspend fun cancelSend(transactionId: TransactionId): Result<Boolean>
|
||||
|
||||
/**
|
||||
* Share a location message in the room.
|
||||
@@ -162,4 +162,5 @@ interface Timeline : AutoCloseable {
|
||||
waveform: List<Float>,
|
||||
progressCallback: ProgressCallback?
|
||||
): Result<MediaUploadHandler>
|
||||
|
||||
}
|
||||
|
||||
@@ -435,10 +435,10 @@ class RustMatrixRoom(
|
||||
}
|
||||
|
||||
override suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit> {
|
||||
return liveTimeline.retrySendMessage(transactionId)
|
||||
return Result.failure(UnsupportedOperationException("Not supported"))
|
||||
}
|
||||
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> {
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> {
|
||||
return liveTimeline.cancelSend(transactionId)
|
||||
}
|
||||
|
||||
|
||||
@@ -265,6 +265,27 @@ class RustTimeline(
|
||||
messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()).use { content ->
|
||||
runCatching {
|
||||
inner.send(content)
|
||||
Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun redactEvent(eventId: EventId?, transactionId: TransactionId?, reason: String?): Result<Boolean> = withContext(dispatcher) {
|
||||
runCatching {
|
||||
when {
|
||||
eventId != null -> {
|
||||
inner.getEventTimelineItemByEventId(eventId.value).use {
|
||||
inner.redactEvent(item = it, reason = reason)
|
||||
}
|
||||
}
|
||||
transactionId != null -> {
|
||||
inner.getEventTimelineItemByTransactionId(transactionId.value).use {
|
||||
inner.redactEvent(item = it, reason = reason)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
error("Either eventId or transactionId must be non-null")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,21 +298,27 @@ class RustTimeline(
|
||||
mentions: List<Mention>,
|
||||
): Result<Unit> =
|
||||
withContext(dispatcher) {
|
||||
if (originalEventId != null) {
|
||||
runCatching {
|
||||
val editedEvent = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(originalEventId.value)
|
||||
editedEvent.use {
|
||||
inner.edit(
|
||||
newContent = messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()),
|
||||
editItem = it,
|
||||
)
|
||||
runCatching {
|
||||
when {
|
||||
originalEventId != null -> {
|
||||
val editedEvent = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(originalEventId.value)
|
||||
editedEvent.use {
|
||||
inner.edit(
|
||||
newContent = messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()),
|
||||
editItem = it,
|
||||
)
|
||||
}
|
||||
specialModeEventTimelineItem = null
|
||||
}
|
||||
transactionId != null -> {
|
||||
inner.getEventTimelineItemByTransactionId(transactionId.value).use {
|
||||
inner.redactEvent(item = it, reason = null)
|
||||
}
|
||||
Unit
|
||||
}
|
||||
else -> {
|
||||
error("Either originalEventId or transactionId must be non null")
|
||||
}
|
||||
specialModeEventTimelineItem = null
|
||||
}
|
||||
} else {
|
||||
runCatching {
|
||||
transactionId?.let { cancelSend(it) }
|
||||
inner.send(messageEventContentFromParts(body, htmlBody))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,17 +422,7 @@ class RustTimeline(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit> = withContext(dispatcher) {
|
||||
runCatching {
|
||||
inner.retrySend(transactionId.value)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> = withContext(dispatcher) {
|
||||
runCatching {
|
||||
inner.cancelSend(transactionId.value)
|
||||
}
|
||||
}
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> = redactEvent(eventId = null, transactionId = transactionId, reason = null)
|
||||
|
||||
override suspend fun sendLocation(
|
||||
body: String,
|
||||
|
||||
@@ -79,7 +79,6 @@ fun RustEventSendState?.map(): LocalEventSendState? {
|
||||
RustEventSendState.NotSentYet -> LocalEventSendState.NotSentYet
|
||||
is RustEventSendState.SendingFailed -> LocalEventSendState.SendingFailed(error)
|
||||
is RustEventSendState.Sent -> LocalEventSendState.Sent(EventId(eventId))
|
||||
RustEventSendState.Cancelled -> LocalEventSendState.Canceled
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,16 @@ class FakeTimeline(
|
||||
mentions: List<Mention>,
|
||||
): Result<Unit> = sendMessageLambda(body, htmlBody, mentions)
|
||||
|
||||
var redactEventLambda: (eventId: EventId?, transactionId: TransactionId?, reason: String?) -> Result<Boolean> = { _, _, _ ->
|
||||
Result.success(true)
|
||||
}
|
||||
|
||||
override suspend fun redactEvent(
|
||||
eventId: EventId?,
|
||||
transactionId: TransactionId?,
|
||||
reason: String?
|
||||
): Result<Boolean> = redactEventLambda(eventId, transactionId, reason)
|
||||
|
||||
var editMessageLambda: (
|
||||
originalEventId: EventId?,
|
||||
transactionId: TransactionId?,
|
||||
@@ -216,11 +226,7 @@ class FakeTimeline(
|
||||
var forwardEventLambda: (eventId: EventId, roomIds: List<RoomId>) -> Result<Unit> = { _, _ -> Result.success(Unit) }
|
||||
override suspend fun forwardEvent(eventId: EventId, roomIds: List<RoomId>): Result<Unit> = forwardEventLambda(eventId, roomIds)
|
||||
|
||||
var retrySendMessageLambda: (transactionId: TransactionId) -> Result<Unit> = { Result.success(Unit) }
|
||||
override suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit> = retrySendMessageLambda(transactionId)
|
||||
|
||||
var cancelSendLambda: (transactionId: TransactionId) -> Result<Unit> = { Result.success(Unit) }
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> = cancelSendLambda(transactionId)
|
||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> = redactEvent(null, transactionId, null)
|
||||
|
||||
var sendLocationLambda: (
|
||||
body: String,
|
||||
|
||||
Reference in New Issue
Block a user