When replying from notification, do not interfere with specialModeEventTimelineItem

This commit is contained in:
Benoit Marty 2024-06-03 13:15:05 +02:00 committed by Benoit Marty
parent c547296656
commit 92bcf9c90e
5 changed files with 36 additions and 11 deletions

View file

@ -395,7 +395,7 @@ class MessageComposerPresenterTest {
@Test @Test
fun `present - reply message`() = runTest { fun `present - reply message`() = runTest {
val replyMessageLambda = lambdaRecorder { _: EventId, _: String, _: String?, _: List<Mention> -> val replyMessageLambda = lambdaRecorder { _: EventId, _: String, _: String?, _: List<Mention>, _: Boolean ->
Result.success(Unit) Result.success(Unit)
} }
val timeline = FakeTimeline().apply { val timeline = FakeTimeline().apply {
@ -909,7 +909,7 @@ class MessageComposerPresenterTest {
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
@Test @Test
fun `present - send messages with intentional mentions`() = runTest { fun `present - send messages with intentional mentions`() = runTest {
val replyMessageLambda = lambdaRecorder { _: EventId, _: String, _: String?, _: List<Mention> -> val replyMessageLambda = lambdaRecorder { _: EventId, _: String, _: String?, _: List<Mention>, _: Boolean ->
Result.success(Unit) Result.success(Unit)
} }
val editMessageLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String, _: String?, _: List<Mention> -> val editMessageLambda = lambdaRecorder { _: EventId?, _: TransactionId?, _: String, _: String?, _: List<Mention> ->

View file

@ -57,7 +57,13 @@ interface Timeline : AutoCloseable {
suspend fun enterSpecialMode(eventId: EventId?): Result<Unit> suspend fun enterSpecialMode(eventId: EventId?): Result<Unit>
suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?, mentions: List<Mention>): Result<Unit> suspend fun replyMessage(
eventId: EventId,
body: String,
htmlBody: String?,
mentions: List<Mention>,
fromNotification: Boolean = false,
): Result<Unit>
suspend fun sendImage( suspend fun sendImage(
file: File, file: File,

View file

@ -308,13 +308,28 @@ class RustTimeline(
} }
} }
override suspend fun replyMessage(eventId: EventId, body: String, htmlBody: String?, mentions: List<Mention>): Result<Unit> = withContext(dispatcher) { override suspend fun replyMessage(
eventId: EventId,
body: String,
htmlBody: String?,
mentions: List<Mention>,
fromNotification: Boolean,
): Result<Unit> = withContext(dispatcher) {
runCatching { runCatching {
val inReplyTo = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(eventId.value) val msg = messageEventContentFromParts(body, htmlBody).withMentions(mentions.map())
inReplyTo.use { eventTimelineItem -> if (fromNotification) {
inner.sendReply(messageEventContentFromParts(body, htmlBody).withMentions(mentions.map()), eventTimelineItem) // When replying from a notification, do not interfere with `specialModeEventTimelineItem`
val inReplyTo = inner.getEventTimelineItemByEventId(eventId.value)
inReplyTo.use { eventTimelineItem ->
inner.sendReply(msg, eventTimelineItem)
}
} else {
val inReplyTo = specialModeEventTimelineItem ?: inner.getEventTimelineItemByEventId(eventId.value)
inReplyTo.use { eventTimelineItem ->
inner.sendReply(msg, eventTimelineItem)
}
specialModeEventTimelineItem = null
} }
specialModeEventTimelineItem = null
} }
} }

View file

@ -104,7 +104,8 @@ class FakeTimeline(
body: String, body: String,
htmlBody: String?, htmlBody: String?,
mentions: List<Mention>, mentions: List<Mention>,
) -> Result<Unit> = { _, _, _, _ -> fromNotification: Boolean,
) -> Result<Unit> = { _, _, _, _, _ ->
Result.success(Unit) Result.success(Unit)
} }
@ -113,11 +114,13 @@ class FakeTimeline(
body: String, body: String,
htmlBody: String?, htmlBody: String?,
mentions: List<Mention>, mentions: List<Mention>,
fromNotification: Boolean,
): Result<Unit> = replyMessageLambda( ): Result<Unit> = replyMessageLambda(
eventId, eventId,
body, body,
htmlBody, htmlBody,
mentions mentions,
fromNotification,
) )
var sendImageLambda: ( var sendImageLambda: (

View file

@ -179,7 +179,8 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
eventId = threadId.asEventId(), eventId = threadId.asEventId(),
body = message, body = message,
htmlBody = null, htmlBody = null,
mentions = emptyList() mentions = emptyList(),
fromNotification = true,
) )
} else { } else {
room.liveTimeline.sendMessage( room.liveTimeline.sendMessage(