Merge branch 'main' into dependabot/gradle/ktorVer-2.0.2

This commit is contained in:
Adam Brown 2022-06-07 20:02:30 +01:00 committed by GitHub
commit 16185e2d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 12 deletions

View File

@ -127,7 +127,7 @@ ext.kotlinTest = { dependencies ->
dependencies.testImplementation Dependencies.mavenCentral.kotlinTest
dependencies.testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.6.10"
dependencies.testImplementation 'io.mockk:mockk:1.12.4'
dependencies.testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
dependencies.testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.2'
dependencies.testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
dependencies.testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'

View File

@ -111,7 +111,7 @@ ext.Dependencies.with {
kotlinSerializationGradlePlugin = "org.jetbrains.kotlin:kotlin-serialization:${kotlinVer}"
kotlinSerializationJson = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3"
kotlinCoroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1"
kotlinCoroutinesTest = 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
kotlinCoroutinesTest = 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.2'
kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVer}"
sqldelightGradlePlugin = "com.squareup.sqldelight:gradle-plugin:${sqldelightVer}"

View File

@ -65,17 +65,13 @@ internal class TimelineEventMapper(
private suspend fun ApiTimelineEvent.TimelineMessage.handleReply(replyToId: EventId, lookup: Lookup): RoomEvent {
val relationEvent = lookup(replyToId).fold(
onApiTimelineEvent = { it.toTextMessage() },
onApiTimelineEvent = { it.toMessage() },
onRoomEvent = { it },
onEmpty = { null }
)
return when (relationEvent) {
null -> when (this.content) {
is ApiTimelineEvent.TimelineMessage.Content.Image -> this.toImageMessage()
is ApiTimelineEvent.TimelineMessage.Content.Text -> this.toFallbackTextMessage()
ApiTimelineEvent.TimelineMessage.Content.Ignored -> throw IllegalStateException()
}
null -> this.toMessage()
else -> {
RoomEvent.Reply(
message = roomEventFactory.mapToRoomEvent(this),
@ -89,6 +85,12 @@ internal class TimelineEventMapper(
}
}
private suspend fun ApiTimelineEvent.TimelineMessage.toMessage() = when (this.content) {
is ApiTimelineEvent.TimelineMessage.Content.Image -> this.toImageMessage()
is ApiTimelineEvent.TimelineMessage.Content.Text -> this.toFallbackTextMessage()
ApiTimelineEvent.TimelineMessage.Content.Ignored -> throw IllegalStateException()
}
private suspend fun ApiTimelineEvent.TimelineMessage.toFallbackTextMessage() = this.toTextMessage(content = this.asTextContent().body ?: "redacted")
private suspend fun ApiTimelineEvent.TimelineMessage.handleEdit(editedEventId: EventId, lookup: Lookup): RoomEvent? {

View File

@ -1,8 +1,8 @@
package app.dapk.st.matrix.sync.internal.sync
import app.dapk.st.matrix.common.UserCredentials
import app.dapk.st.matrix.common.AvatarUrl
import app.dapk.st.matrix.common.RoomMember
import app.dapk.st.matrix.common.UserCredentials
import app.dapk.st.matrix.common.convertMxUrToUrl
import app.dapk.st.matrix.sync.*
import app.dapk.st.matrix.sync.internal.request.ApiSyncRoom
@ -61,13 +61,18 @@ private fun ApiSyncRoom.collectMembers(userCredentials: UserCredentials): List<R
}
}
internal fun List<RoomEvent>.findLastMessage(): LastMessage? {
return this.filterIsInstance<RoomEvent.Message>().firstOrNull()?.let {
return this.firstOrNull()?.let {
LastMessage(
content = it.content,
content = it.toTextContent(),
utcTimestamp = it.utcTimestamp,
author = it.author,
)
}
}
private fun RoomEvent.toTextContent(): String = when (this) {
is RoomEvent.Image -> "\uD83D\uDCF7"
is RoomEvent.Message -> this.content
is RoomEvent.Reply -> this.message.toTextContent()
}