Clean up code for some of the imports
This commit is contained in:
1 parent
cb129bb0c6
commit
aaf6bbad83
16 files changed
+268
-184
No files matched your search
+7
-6
@@ -1,6 +1,7 @@
|
||||
package at.torch.compose.database.converters
|
||||
|
||||
import androidx.room3.TypeConverter
|
||||
import at.torch.compose.database.model.types.SynchronizationFilter
|
||||
import co.touchlab.kermit.Logger
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.time.Instant
|
||||
@@ -72,7 +73,7 @@ class TorchConverters {
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromFilterArray(value: Array<at.torch.compose.database.model.types.SynchronizationFilter>?): String? = try {
|
||||
fun fromFilterArray(value: Array<SynchronizationFilter>?): String? = try {
|
||||
return value?.let {
|
||||
Json.encodeToString(value)
|
||||
}
|
||||
@@ -82,9 +83,9 @@ class TorchConverters {
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toFilterArray(value: String?): Array<at.torch.compose.database.model.types.SynchronizationFilter>? = try {
|
||||
fun toFilterArray(value: String?): Array<SynchronizationFilter>? = try {
|
||||
return value?.let {
|
||||
Json.decodeFromString<Array<at.torch.compose.database.model.types.SynchronizationFilter>>(it)
|
||||
Json.decodeFromString<Array<SynchronizationFilter>>(it)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
logger.e("Failed to convert to FilterArray $value", e)
|
||||
@@ -92,7 +93,7 @@ class TorchConverters {
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromSynchronizationFilter(value: at.torch.compose.database.model.types.SynchronizationFilter?): String? = try {
|
||||
fun fromSynchronizationFilter(value: SynchronizationFilter?): String? = try {
|
||||
return value?.let {
|
||||
Json.encodeToString(value)
|
||||
}
|
||||
@@ -102,9 +103,9 @@ class TorchConverters {
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toSynchronizationFilter(value: String?): at.torch.compose.database.model.types.SynchronizationFilter? = try {
|
||||
fun toSynchronizationFilter(value: String?): SynchronizationFilter? = try {
|
||||
return value?.let {
|
||||
Json.decodeFromString<at.torch.compose.database.model.types.SynchronizationFilter>(it)
|
||||
Json.decodeFromString<SynchronizationFilter>(it)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
logger.e("Failed to convert to SynchronizationFilter $value", e)
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@ import androidx.room3.Insert
|
||||
import androidx.room3.OnConflictStrategy.Companion.IGNORE
|
||||
import androidx.room3.Query
|
||||
import androidx.room3.Upsert
|
||||
import at.torch.compose.database.model.NegentropySynchronizeRequest
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
@@ -12,16 +13,16 @@ import kotlin.time.Instant
|
||||
@Dao
|
||||
interface NegentropySynchronizeRequestDao {
|
||||
@Query("SELECT * FROM NegentropySynchronizeRequest WHERE status = :status AND createdAt > :createdAt")
|
||||
fun observeNegentropySynchronizeRequestsByStatus(status: String, createdAt: Instant = Clock.System.now()): Flow<at.torch.compose.database.model.NegentropySynchronizeRequest?>
|
||||
fun observeNegentropySynchronizeRequestsByStatus(status: String, createdAt: Instant = Clock.System.now()): Flow<NegentropySynchronizeRequest?>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM NegentropySynchronizeRequest WHERE purpose = :purpose AND status IN (:status) AND createdAt > :createdAt")
|
||||
fun observeNegentropySynchronizeRequestByPurposeAndStatusCount(purpose: String, status: List<String>, createdAt: Instant = Clock.System.now()): Flow<Int>
|
||||
|
||||
@Upsert
|
||||
fun upsert(negentropySynchronizeRequest: at.torch.compose.database.model.NegentropySynchronizeRequest)
|
||||
fun upsert(negentropySynchronizeRequest: NegentropySynchronizeRequest)
|
||||
|
||||
@Insert(
|
||||
onConflict = IGNORE
|
||||
)
|
||||
fun insert(negentropySynchronizeRequests: List<at.torch.compose.database.model.NegentropySynchronizeRequest>)
|
||||
fun insert(negentropySynchronizeRequests: List<NegentropySynchronizeRequest>)
|
||||
}
|
||||
@@ -4,6 +4,10 @@ import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Ignore
|
||||
import androidx.room3.PrimaryKey
|
||||
import at.torch.compose.database.model.traits.LocalStoreEntity
|
||||
import at.torch.compose.database.model.traits.SoftDeletableEntity
|
||||
import at.torch.compose.database.model.traits.TimestampedEntity
|
||||
import at.torch.compose.database.model.traits.UserViewableEntity
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
@@ -74,10 +78,7 @@ data class GiftWrapPayload(
|
||||
override val savedAt: Instant = Clock.System.now(),
|
||||
override val viewedAt: Instant? = null,
|
||||
override val deletedAt: Instant? = null, // Who this message should be seen by (used to derive conversationId)
|
||||
): at.torch.compose.database.model.traits.TimestampedEntity,
|
||||
at.torch.compose.database.model.traits.LocalStoreEntity,
|
||||
at.torch.compose.database.model.traits.UserViewableEntity,
|
||||
at.torch.compose.database.model.traits.SoftDeletableEntity {
|
||||
): TimestampedEntity, LocalStoreEntity, UserViewableEntity, SoftDeletableEntity {
|
||||
@Ignore
|
||||
private val logger = Logger.withTag(TAG)
|
||||
|
||||
|
||||
+1
-4
@@ -90,10 +90,7 @@ data class MarmotInnerEvent( // TODO: Rename this to GiftWrapPayload...
|
||||
override val savedAt: Instant = Clock.System.now(),
|
||||
override val viewedAt: Instant? = null,
|
||||
override val deletedAt: Instant? = null, // Who this message should be seen by (used to derive conversationId)
|
||||
): TimestampedEntity,
|
||||
LocalStoreEntity,
|
||||
UserViewableEntity,
|
||||
SoftDeletableEntity {
|
||||
): TimestampedEntity, LocalStoreEntity, UserViewableEntity, SoftDeletableEntity {
|
||||
@Ignore
|
||||
private val logger = Logger.withTag(TAG)
|
||||
|
||||
|
||||
+7
-4
@@ -7,12 +7,15 @@ import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.room3.Embedded
|
||||
import androidx.room3.Relation
|
||||
import at.torch.compose.database.model.ChatRoom
|
||||
import at.torch.compose.database.model.Participant
|
||||
import at.torch.compose.ui.composable.widgets.profile.ProfileColor
|
||||
|
||||
data class LocalChatRoom(
|
||||
@Embedded val chatRoom: at.torch.compose.database.model.ChatRoom,
|
||||
@Embedded val chatRoom: ChatRoom,
|
||||
|
||||
@Relation(
|
||||
entity = at.torch.compose.database.model.Participant::class,
|
||||
entity = Participant::class,
|
||||
parentColumns = ["id"],
|
||||
entityColumns = ["chatRoomId"],
|
||||
)
|
||||
@@ -23,7 +26,7 @@ data class LocalChatRoom(
|
||||
if (chatRoom.subject != null) {
|
||||
Text(
|
||||
text = chatRoom.subject,
|
||||
color = at.torch.compose.ui.composable.widgets.profile.ProfileColor.fromPublicKey(chatRoom.id)
|
||||
color = ProfileColor.fromPublicKey(chatRoom.id)
|
||||
)
|
||||
} else {
|
||||
if (localParticipants.size == 1) {
|
||||
@@ -33,7 +36,7 @@ data class LocalChatRoom(
|
||||
} else {
|
||||
// Remove the active user publicKey from participants...
|
||||
val participantNames = localParticipants.filter { it.participant.participantPublicKey != chatRoom.userPublicKey }.map { buildAnnotatedString {
|
||||
withStyle(style = SpanStyle(color = at.torch.compose.ui.composable.widgets.profile.ProfileColor.fromPublicKey(it.participant.participantPublicKey))) {
|
||||
withStyle(style = SpanStyle(color = ProfileColor.fromPublicKey(it.participant.participantPublicKey))) {
|
||||
append(it.profile?.humanReadableNameOrPubkey() ?: "unknown participant")
|
||||
}
|
||||
} }
|
||||
|
||||
+4
-2
@@ -2,13 +2,15 @@ package at.torch.compose.database.model.intermdiate
|
||||
|
||||
import androidx.room3.Embedded
|
||||
import androidx.room3.Relation
|
||||
import at.torch.compose.database.model.NostrEvent
|
||||
import at.torch.compose.database.model.Profile
|
||||
|
||||
data class LocalProfile(
|
||||
@Embedded val nostrEvent: at.torch.compose.database.model.NostrEvent,
|
||||
@Embedded val nostrEvent: NostrEvent,
|
||||
|
||||
@Relation(
|
||||
parentColumns = ["pubKey"],
|
||||
entityColumns = ["publicKey"]
|
||||
)
|
||||
val profile: at.torch.compose.database.model.Profile,
|
||||
val profile: Profile,
|
||||
)
|
||||
+13
-9
@@ -1,5 +1,7 @@
|
||||
package at.torch.compose.database.repository
|
||||
|
||||
import at.torch.compose.database.GENESIS_AT
|
||||
import at.torch.compose.database.TorchDatabase
|
||||
import at.torch.compose.database.model.ChatMessage
|
||||
import at.torch.compose.database.model.ChatRoom
|
||||
import at.torch.compose.database.model.GiftWrapPayload
|
||||
@@ -7,6 +9,8 @@ import at.torch.compose.database.model.MarmotInnerEvent
|
||||
import at.torch.compose.database.model.MarmotKeyPackage
|
||||
import at.torch.compose.database.model.Participant
|
||||
import at.torch.compose.database.model.Profile
|
||||
import at.torch.compose.database.model.intermdiate.LocalChatMessage
|
||||
import at.torch.compose.database.model.intermdiate.LocalChatRoom
|
||||
import at.torch.compose.database.model.intermdiate.LocalProfile
|
||||
import at.torch.compose.extensions.toHex
|
||||
import at.torch.compose.nostr.Relays
|
||||
@@ -39,30 +43,30 @@ import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
|
||||
class DatabaseChatRepository(
|
||||
private val database: at.torch.compose.database.TorchDatabase,
|
||||
private val database: TorchDatabase,
|
||||
private val scope: CoroutineScope
|
||||
): at.torch.compose.repository.ChatRepository {
|
||||
val logger = Logger.withTag(TAG)
|
||||
override suspend fun observeChatRoomListByPublicKey(publicKey: String): Flow<List<at.torch.compose.database.model.intermdiate.LocalChatRoom>> {
|
||||
override suspend fun observeChatRoomListByPublicKey(publicKey: String): Flow<List<LocalChatRoom>> {
|
||||
return database.chatRoomDao().observeChatRoomListByUserPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun getChatRoomListByPublicKey(publicKey: String): List<at.torch.compose.database.model.intermdiate.LocalChatRoom> {
|
||||
override suspend fun getChatRoomListByPublicKey(publicKey: String): List<LocalChatRoom> {
|
||||
return database.chatRoomDao().getChatRoomListByUserPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun getChatRoomByIdentifier(id: HexKey): at.torch.compose.database.model.intermdiate.LocalChatRoom? {
|
||||
override suspend fun getChatRoomByIdentifier(id: HexKey): LocalChatRoom? {
|
||||
return database.chatRoomDao().findChatRoomById(id)
|
||||
}
|
||||
|
||||
override suspend fun getAllParticipantsWithPubKey(publicKey: HexKey): List<Participant> {
|
||||
return database.participantDao().findParticipantByPublicKey(publicKey)
|
||||
}
|
||||
override suspend fun getChatMessageListByChatRoomId(chatRoomId: String): List<at.torch.compose.database.model.intermdiate.LocalChatMessage> {
|
||||
override suspend fun getChatMessageListByChatRoomId(chatRoomId: String): List<LocalChatMessage> {
|
||||
return database.chatMessageDao().getChatMessagesByChatRoomId(chatRoomId)
|
||||
}
|
||||
|
||||
override suspend fun observeChatMessageListByChatRoomId(chatRoomId: String): Flow<List<at.torch.compose.database.model.intermdiate.LocalChatMessage>> {
|
||||
override suspend fun observeChatMessageListByChatRoomId(chatRoomId: String): Flow<List<LocalChatMessage>> {
|
||||
return database.chatMessageDao().observeChatMessagesByChatRoomId(chatRoomId)
|
||||
}
|
||||
|
||||
@@ -73,7 +77,7 @@ class DatabaseChatRepository(
|
||||
relayHint: String?,
|
||||
defaultSubject: String?,
|
||||
mlsGroupState: String?
|
||||
): at.torch.compose.database.model.intermdiate.LocalChatRoom? = try {
|
||||
): LocalChatRoom? = try {
|
||||
return database.nostrNip17Dao().getOrCreateChatRoom(
|
||||
chatRoomId = chatRoomId,
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
@@ -95,7 +99,7 @@ class DatabaseChatRepository(
|
||||
authors = arrayOf(
|
||||
publicKey
|
||||
),
|
||||
since = _root_ide_package_.at.torch.compose.database.GENESIS_AT,
|
||||
since = GENESIS_AT,
|
||||
limit = 5
|
||||
).firstOrNull()?.let { nostrEvent ->
|
||||
if (nostrEvent.kind != ChatMessageRelayListEvent.KIND) {
|
||||
@@ -136,7 +140,7 @@ class DatabaseChatRepository(
|
||||
|
||||
override suspend fun sendChatMessage(
|
||||
text: String,
|
||||
localChatRoom: at.torch.compose.database.model.intermdiate.LocalChatRoom,
|
||||
localChatRoom: LocalChatRoom,
|
||||
messageType: Kind
|
||||
) {
|
||||
logger.i("sendChatMessage($text): $localChatRoom")
|
||||
|
||||
Reference in new issue
Block a user