Enable LabelRepository.kt to get all labels per user
MAILAND-1502
This commit is contained in:
parent
f614a4cca2
commit
e317e6fea1
|
@ -386,7 +386,7 @@ class MessageDetailsRepository @Inject constructor(
|
|||
|
||||
fun getAllLabelsLiveData() = messagesDao.getAllLabelsLiveData()
|
||||
|
||||
suspend fun getAllLabels(): List<Label> = messagesDao.getAllLabels()
|
||||
suspend fun getAllLabels(): List<Label> = messagesDao.getAllLabels().first()
|
||||
|
||||
fun findAllLabelsWithIds(labelIds: List<String>): List<Label> = messagesDao.findAllLabelsWithIds(labelIds)
|
||||
|
||||
|
|
|
@ -20,8 +20,16 @@
|
|||
package ch.protonmail.android.data
|
||||
|
||||
import ch.protonmail.android.data.local.model.Label
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import me.proton.core.domain.entity.UserId
|
||||
|
||||
interface LabelRepository {
|
||||
|
||||
fun getAllLabels(userId: UserId): Flow<List<Label>>
|
||||
|
||||
suspend fun saveLabel(userId: UserId, label: Label)
|
||||
|
||||
@Deprecated("Save with userId", ReplaceWith("saveLabel(userId, label)"))
|
||||
suspend fun saveLabel(label: Label)
|
||||
|
||||
}
|
||||
|
|
|
@ -19,16 +19,32 @@
|
|||
|
||||
package ch.protonmail.android.data
|
||||
|
||||
import android.content.Context
|
||||
import ch.protonmail.android.data.local.MessageDao
|
||||
import ch.protonmail.android.data.local.MessageDatabase
|
||||
import ch.protonmail.android.data.local.model.Label
|
||||
import ch.protonmail.android.domain.entity.Id
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import me.proton.core.domain.entity.UserId
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomLabelRepository @Inject constructor(
|
||||
private val context: Context,
|
||||
private val messageDatabaseFactory: MessageDatabase.Factory,
|
||||
private val messageDao: MessageDao
|
||||
) : LabelRepository {
|
||||
|
||||
override fun getAllLabels(userId: UserId): Flow<List<Label>> =
|
||||
getDao(userId).getAllLabels()
|
||||
|
||||
override suspend fun saveLabel(userId: UserId, label: Label) {
|
||||
getDao(userId).saveLabel(label)
|
||||
}
|
||||
|
||||
override suspend fun saveLabel(label: Label) {
|
||||
messageDao.saveLabel(label)
|
||||
}
|
||||
|
||||
private fun getDao(userId: UserId): MessageDao =
|
||||
messageDatabaseFactory.getInstance(context, Id(userId.id)).getDao()
|
||||
}
|
||||
|
|
|
@ -420,10 +420,11 @@ abstract class MessageDao {
|
|||
|
||||
//region Labels
|
||||
@Query("SELECT * FROM $TABLE_LABELS")
|
||||
@Deprecated("Use with Flow", ReplaceWith("this.getAllLabels()"))
|
||||
abstract fun getAllLabelsLiveData(): LiveData<List<Label>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_LABELS")
|
||||
abstract suspend fun getAllLabels(): List<Label>
|
||||
abstract fun getAllLabels(): Flow<List<Label>>
|
||||
|
||||
// Folders
|
||||
@Query("SELECT * FROM $TABLE_LABELS WHERE `Exclusive` = 1 ORDER BY `LabelOrder`")
|
||||
|
|
Loading…
Reference in New Issue