Fetch edited event in advanced (similar to reply mode).
This commit is contained in:
parent
937391b4b9
commit
937e053d46
4 changed files with 20 additions and 13 deletions
|
|
@ -167,9 +167,14 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
)
|
)
|
||||||
is MessageComposerEvents.SetMode -> {
|
is MessageComposerEvents.SetMode -> {
|
||||||
messageComposerContext.composerMode = event.composerMode
|
messageComposerContext.composerMode = event.composerMode
|
||||||
if (event.composerMode is MessageComposerMode.Reply) {
|
when (event.composerMode) {
|
||||||
|
is MessageComposerMode.Reply -> event.composerMode.eventId
|
||||||
|
is MessageComposerMode.Edit -> event.composerMode.eventId
|
||||||
|
is MessageComposerMode.Normal -> null
|
||||||
|
is MessageComposerMode.Quote -> null
|
||||||
|
}.let { relatedEventId ->
|
||||||
appCoroutineScope.launch {
|
appCoroutineScope.launch {
|
||||||
room.enterReplyMode(event.composerMode.eventId)
|
room.enterSpecialMode(relatedEventId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ interface MatrixRoom : Closeable {
|
||||||
|
|
||||||
suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result<Unit>
|
suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, body: String, htmlBody: String?): Result<Unit>
|
||||||
|
|
||||||
suspend fun enterReplyMode(eventId: EventId): Result<Unit>
|
suspend fun enterSpecialMode(eventId: EventId?): Result<Unit>
|
||||||
|
|
||||||
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
|
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ class RustMatrixRoom(
|
||||||
roomCoroutineScope.cancel()
|
roomCoroutineScope.cancel()
|
||||||
innerRoom.destroy()
|
innerRoom.destroy()
|
||||||
roomListItem.destroy()
|
roomListItem.destroy()
|
||||||
inReplyToEventTimelineItem?.destroy()
|
specialModeEventTimelineItem?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val name: String?
|
override val name: String?
|
||||||
|
|
@ -238,12 +238,14 @@ class RustMatrixRoom(
|
||||||
withContext(roomDispatcher) {
|
withContext(roomDispatcher) {
|
||||||
if (originalEventId != null) {
|
if (originalEventId != null) {
|
||||||
runCatching {
|
runCatching {
|
||||||
innerRoom.getEventTimelineItemByEventId(originalEventId.value).use {
|
val editedEvent = specialModeEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(originalEventId.value)
|
||||||
|
editedEvent.use {
|
||||||
innerRoom.edit(
|
innerRoom.edit(
|
||||||
newContent = messageEventContentFromParts(body, htmlBody),
|
newContent = messageEventContentFromParts(body, htmlBody),
|
||||||
editItem = it,
|
editItem = it,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
specialModeEventTimelineItem = null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runCatching {
|
runCatching {
|
||||||
|
|
@ -253,23 +255,23 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var inReplyToEventTimelineItem: EventTimelineItem? = null
|
private var specialModeEventTimelineItem: EventTimelineItem? = null
|
||||||
|
|
||||||
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> = withContext(roomDispatcher) {
|
override suspend fun enterSpecialMode(eventId: EventId?): Result<Unit> = withContext(roomDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
inReplyToEventTimelineItem?.destroy()
|
specialModeEventTimelineItem?.destroy()
|
||||||
inReplyToEventTimelineItem = null
|
specialModeEventTimelineItem = null
|
||||||
inReplyToEventTimelineItem = innerRoom.getEventTimelineItemByEventId(eventId.value)
|
specialModeEventTimelineItem = eventId?.let { innerRoom.getEventTimelineItemByEventId(it.value) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
|
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> = withContext(roomDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
val inReplyTo = inReplyToEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(eventId.value)
|
val inReplyTo = specialModeEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(eventId.value)
|
||||||
inReplyTo.use { eventTimelineItem ->
|
inReplyTo.use { eventTimelineItem ->
|
||||||
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventTimelineItem)
|
innerRoom.sendReply(messageEventContentFromParts(body, htmlBody), eventTimelineItem)
|
||||||
}
|
}
|
||||||
inReplyToEventTimelineItem = null
|
specialModeEventTimelineItem = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ class FakeMatrixRoom(
|
||||||
var replyMessageParameter: Pair<String, String?>? = null
|
var replyMessageParameter: Pair<String, String?>? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override suspend fun enterReplyMode(eventId: EventId): Result<Unit> {
|
override suspend fun enterSpecialMode(eventId: EventId?): Result<Unit> {
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue