Simplify the management of inReplyToEventTimelineItem
This commit is contained in:
parent
9d0e185d1c
commit
d32a7c6ddf
4 changed files with 3 additions and 29 deletions
|
|
@ -20,7 +20,6 @@ import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
|
@ -152,23 +151,12 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
onDispose {
|
|
||||||
appCoroutineScope.launch {
|
|
||||||
room.exitReplyMode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleEvents(event: MessageComposerEvents) {
|
fun handleEvents(event: MessageComposerEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value
|
MessageComposerEvents.ToggleFullScreenState -> isFullScreen.value = !isFullScreen.value
|
||||||
MessageComposerEvents.CloseSpecialMode -> {
|
MessageComposerEvents.CloseSpecialMode -> {
|
||||||
richTextEditorState.setHtml("")
|
richTextEditorState.setHtml("")
|
||||||
messageComposerContext.composerMode = MessageComposerMode.Normal("")
|
messageComposerContext.composerMode = MessageComposerMode.Normal("")
|
||||||
appCoroutineScope.launch {
|
|
||||||
room.exitReplyMode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage(
|
is MessageComposerEvents.SendMessage -> appCoroutineScope.sendMessage(
|
||||||
message = event.message,
|
message = event.message,
|
||||||
|
|
@ -177,11 +165,9 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
)
|
)
|
||||||
is MessageComposerEvents.SetMode -> {
|
is MessageComposerEvents.SetMode -> {
|
||||||
messageComposerContext.composerMode = event.composerMode
|
messageComposerContext.composerMode = event.composerMode
|
||||||
appCoroutineScope.launch {
|
if (event.composerMode is MessageComposerMode.Reply) {
|
||||||
if (event.composerMode is MessageComposerMode.Reply) {
|
appCoroutineScope.launch {
|
||||||
room.enterReplyMode(event.composerMode.eventId)
|
room.enterReplyMode(event.composerMode.eventId)
|
||||||
} else {
|
|
||||||
room.exitReplyMode()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,6 @@ interface MatrixRoom : Closeable {
|
||||||
|
|
||||||
suspend fun enterReplyMode(eventId: EventId): Result<Unit>
|
suspend fun enterReplyMode(eventId: EventId): Result<Unit>
|
||||||
|
|
||||||
suspend fun exitReplyMode(): Result<Unit>
|
|
||||||
|
|
||||||
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
|
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit>
|
||||||
|
|
||||||
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
|
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ class RustMatrixRoom(
|
||||||
roomCoroutineScope.cancel()
|
roomCoroutineScope.cancel()
|
||||||
innerRoom.destroy()
|
innerRoom.destroy()
|
||||||
roomListItem.destroy()
|
roomListItem.destroy()
|
||||||
|
inReplyToEventTimelineItem?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val name: String?
|
override val name: String?
|
||||||
|
|
@ -272,13 +273,6 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun exitReplyMode(): Result<Unit> = withContext(roomDispatcher) {
|
|
||||||
runCatching {
|
|
||||||
inReplyToEventTimelineItem?.destroy()
|
|
||||||
inReplyToEventTimelineItem = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = inReplyToEventTimelineItem ?: innerRoom.getEventTimelineItemByEventId(eventId.value)
|
||||||
|
|
|
||||||
|
|
@ -212,10 +212,6 @@ class FakeMatrixRoom(
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun exitReplyMode(): Result<Unit> {
|
|
||||||
return Result.success(Unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> {
|
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?): Result<Unit> {
|
||||||
replyMessageParameter = body to htmlBody
|
replyMessageParameter = body to htmlBody
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue