Message queuing : introduce redactEvent on timeline object and remove retrySendMessage.
This commit is contained in:
parent
b3190590b9
commit
102cd5769e
6 changed files with 60 additions and 37 deletions
|
|
@ -160,7 +160,7 @@ interface MatrixRoom : Closeable {
|
||||||
|
|
||||||
suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit>
|
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>
|
suspend fun leave(): Result<Unit>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@ interface Timeline : AutoCloseable {
|
||||||
progressCallback: ProgressCallback?
|
progressCallback: ProgressCallback?
|
||||||
): Result<MediaUploadHandler>
|
): 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 sendAudio(file: File, audioInfo: AudioInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler>
|
||||||
|
|
||||||
suspend fun sendFile(file: File, fileInfo: FileInfo, 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 forwardEvent(eventId: EventId, roomIds: List<RoomId>): Result<Unit>
|
||||||
|
|
||||||
suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit>
|
suspend fun cancelSend(transactionId: TransactionId): Result<Boolean>
|
||||||
|
|
||||||
suspend fun cancelSend(transactionId: TransactionId): Result<Unit>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share a location message in the room.
|
* Share a location message in the room.
|
||||||
|
|
@ -162,4 +162,5 @@ interface Timeline : AutoCloseable {
|
||||||
waveform: List<Float>,
|
waveform: List<Float>,
|
||||||
progressCallback: ProgressCallback?
|
progressCallback: ProgressCallback?
|
||||||
): Result<MediaUploadHandler>
|
): Result<MediaUploadHandler>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -435,10 +435,10 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun retrySendMessage(transactionId: TransactionId): Result<Unit> {
|
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)
|
return liveTimeline.cancelSend(transactionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,27 @@ class RustTimeline(
|
||||||
messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()).use { content ->
|
messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()).use { content ->
|
||||||
runCatching {
|
runCatching {
|
||||||
inner.send(content)
|
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>,
|
mentions: List<Mention>,
|
||||||
): Result<Unit> =
|
): Result<Unit> =
|
||||||
withContext(dispatcher) {
|
withContext(dispatcher) {
|
||||||
if (originalEventId != null) {
|
runCatching {
|
||||||
runCatching {
|
when {
|
||||||
val editedEvent = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(originalEventId.value)
|
originalEventId != null -> {
|
||||||
editedEvent.use {
|
val editedEvent = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(originalEventId.value)
|
||||||
inner.edit(
|
editedEvent.use {
|
||||||
newContent = messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()),
|
inner.edit(
|
||||||
editItem = it,
|
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) {
|
override suspend fun cancelSend(transactionId: TransactionId): Result<Boolean> = redactEvent(eventId = null, transactionId = transactionId, reason = null)
|
||||||
runCatching {
|
|
||||||
inner.retrySend(transactionId.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun cancelSend(transactionId: TransactionId): Result<Unit> = withContext(dispatcher) {
|
|
||||||
runCatching {
|
|
||||||
inner.cancelSend(transactionId.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun sendLocation(
|
override suspend fun sendLocation(
|
||||||
body: String,
|
body: String,
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@ fun RustEventSendState?.map(): LocalEventSendState? {
|
||||||
RustEventSendState.NotSentYet -> LocalEventSendState.NotSentYet
|
RustEventSendState.NotSentYet -> LocalEventSendState.NotSentYet
|
||||||
is RustEventSendState.SendingFailed -> LocalEventSendState.SendingFailed(error)
|
is RustEventSendState.SendingFailed -> LocalEventSendState.SendingFailed(error)
|
||||||
is RustEventSendState.Sent -> LocalEventSendState.Sent(EventId(eventId))
|
is RustEventSendState.Sent -> LocalEventSendState.Sent(EventId(eventId))
|
||||||
RustEventSendState.Cancelled -> LocalEventSendState.Canceled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,16 @@ class FakeTimeline(
|
||||||
mentions: List<Mention>,
|
mentions: List<Mention>,
|
||||||
): Result<Unit> = sendMessageLambda(body, htmlBody, mentions)
|
): 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: (
|
var editMessageLambda: (
|
||||||
originalEventId: EventId?,
|
originalEventId: EventId?,
|
||||||
transactionId: TransactionId?,
|
transactionId: TransactionId?,
|
||||||
|
|
@ -216,11 +226,7 @@ class FakeTimeline(
|
||||||
var forwardEventLambda: (eventId: EventId, roomIds: List<RoomId>) -> Result<Unit> = { _, _ -> Result.success(Unit) }
|
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)
|
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 cancelSend(transactionId: TransactionId): Result<Boolean> = redactEvent(null, transactionId, null)
|
||||||
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)
|
|
||||||
|
|
||||||
var sendLocationLambda: (
|
var sendLocationLambda: (
|
||||||
body: String,
|
body: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue