When replying from notification, do not interfere with specialModeEventTimelineItem
This commit is contained in:
parent
c547296656
commit
92bcf9c90e
5 changed files with 36 additions and 11 deletions
|
|
@ -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> ->
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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: (
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue