-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
628 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
shared/src/commonMain/kotlin/dev/dimension/flare/data/database/cache/dao/MessageDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dev.dimension.flare.data.database.cache.dao | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import dev.dimension.flare.data.database.cache.model.DbDirectMessageTimeline | ||
import dev.dimension.flare.data.database.cache.model.DbDirectMessageTimelineWithRoom | ||
import dev.dimension.flare.data.database.cache.model.DbMessageItem | ||
import dev.dimension.flare.data.database.cache.model.DbMessageItemWithUser | ||
import dev.dimension.flare.data.database.cache.model.DbMessageRoom | ||
import dev.dimension.flare.data.database.cache.model.DbMessageRoomReference | ||
import dev.dimension.flare.model.MicroBlogKey | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface MessageDao { | ||
@Transaction | ||
@Query("SELECT * FROM DbDirectMessageTimeline WHERE accountKey = :accountKey ORDER BY sortId DESC") | ||
fun getRoomPagingSource(accountKey: MicroBlogKey): PagingSource<Int, DbDirectMessageTimelineWithRoom> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM DbMessageItem WHERE roomKey = :roomKey ORDER BY timestamp DESC") | ||
fun getRoomMessagesPagingSource(roomKey: MicroBlogKey): PagingSource<Int, DbMessageItemWithUser> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM DbDirectMessageTimeline WHERE roomKey = :roomKey AND accountKey = :accountKey") | ||
fun getRoomInfo( | ||
roomKey: MicroBlogKey, | ||
accountKey: MicroBlogKey, | ||
): Flow<DbDirectMessageTimelineWithRoom?> | ||
|
||
@Insert(onConflict = androidx.room.OnConflictStrategy.REPLACE) | ||
suspend fun insert(items: List<DbMessageRoom>) | ||
|
||
@Insert(onConflict = androidx.room.OnConflictStrategy.REPLACE) | ||
suspend fun insertReferences(items: List<DbMessageRoomReference>) | ||
|
||
@Insert(onConflict = androidx.room.OnConflictStrategy.REPLACE) | ||
suspend fun insertMessages(items: List<DbMessageItem>) | ||
|
||
@Insert(onConflict = androidx.room.OnConflictStrategy.REPLACE) | ||
suspend fun insertTimeline(items: List<DbDirectMessageTimeline>) | ||
|
||
@Query("DELETE FROM DbDirectMessageTimeline WHERE roomKey = :roomKey AND accountKey = :accountKey") | ||
suspend fun deleteTimeline( | ||
roomKey: MicroBlogKey, | ||
accountKey: MicroBlogKey, | ||
) | ||
|
||
@Query("DELETE FROM DbMessageItem WHERE messageKey = :messageKey") | ||
suspend fun deleteMessage(messageKey: MicroBlogKey) | ||
|
||
@Query("SELECT * FROM DbMessageItem WHERE messageKey = :messageKey") | ||
suspend fun getMessage(messageKey: MicroBlogKey): DbMessageItem? | ||
|
||
@Query("SELECT * FROM DbMessageItem WHERE roomKey = :roomKey AND isLocal = 0 ORDER BY timestamp DESC") | ||
suspend fun getLatestMessage(roomKey: MicroBlogKey): DbMessageItem? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.