mirror of
https://github.com/nextcloud/talk-android
synced 2025-08-18 17:35:02 +01:00
Fixes to offline caching
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
7bd0918bd7
commit
124c2951d9
@ -57,9 +57,9 @@ class NextcloudTalkOfflineRepositoryImpl(val nextcloudTalkDatabase: TalkDatabase
|
|||||||
.deleteConversation(userId, conversationId)
|
.deleteConversation(userId, conversationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationsForUser(user: UserEntity): LiveData<List<Conversation>> {
|
override fun getConversationsForUser(userId: Long): LiveData<List<Conversation>> {
|
||||||
return nextcloudTalkDatabase.conversationsDao()
|
return nextcloudTalkDatabase.conversationsDao()
|
||||||
.getConversationsForUser(user.id)
|
.getConversationsForUser(userId)
|
||||||
.map { data ->
|
.map { data ->
|
||||||
data.map {
|
data.map {
|
||||||
it.toConversation()
|
it.toConversation()
|
||||||
@ -71,18 +71,18 @@ class NextcloudTalkOfflineRepositoryImpl(val nextcloudTalkDatabase: TalkDatabase
|
|||||||
return nextcloudTalkDatabase
|
return nextcloudTalkDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clearConversationsForUser(user: UserEntity) {
|
override suspend fun clearConversationsForUser(userId: Long) {
|
||||||
nextcloudTalkDatabase.conversationsDao()
|
nextcloudTalkDatabase.conversationsDao()
|
||||||
.clearConversationsForUser(user.id)
|
.clearConversationsForUser(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveConversationsForUser(
|
override suspend fun saveConversationsForUser(
|
||||||
user: UserEntity,
|
userId: Long,
|
||||||
conversations: List<Conversation>
|
conversations: List<Conversation>
|
||||||
) {
|
) {
|
||||||
nextcloudTalkDatabase.conversationsDao()
|
nextcloudTalkDatabase.conversationsDao()
|
||||||
.updateConversationsForUser(
|
.updateConversationsForUser(
|
||||||
user.id,
|
userId,
|
||||||
conversations.map {
|
conversations.map {
|
||||||
it.toConversationEntity()
|
it.toConversationEntity()
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
@ -90,10 +90,10 @@ class NextcloudTalkOfflineRepositoryImpl(val nextcloudTalkDatabase: TalkDatabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteConversationForUserWithTimestamp(
|
override suspend fun deleteConversationForUserWithTimestamp(
|
||||||
user: UserEntity,
|
userId: Long,
|
||||||
timestamp: Long
|
timestamp: Long
|
||||||
) {
|
) {
|
||||||
nextcloudTalkDatabase.conversationsDao()
|
nextcloudTalkDatabase.conversationsDao()
|
||||||
.deleteConversationsForUserWithTimestamp(user.id, timestamp)
|
.deleteConversationsForUserWithTimestamp(userId, timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ import com.nextcloud.talk.models.database.UserEntity
|
|||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
|
|
||||||
interface NextcloudTalkOfflineRepository {
|
interface NextcloudTalkOfflineRepository {
|
||||||
fun getConversationsForUser(user: UserEntity): LiveData<List<Conversation>>
|
fun getConversationsForUser(userId: Long): LiveData<List<Conversation>>
|
||||||
suspend fun clearConversationsForUser(user: UserEntity)
|
suspend fun clearConversationsForUser(userId: Long)
|
||||||
suspend fun saveConversationsForUser(
|
suspend fun saveConversationsForUser(
|
||||||
user: UserEntity,
|
userId: Long,
|
||||||
conversations: List<Conversation>
|
conversations: List<Conversation>
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ interface NextcloudTalkOfflineRepository {
|
|||||||
)
|
)
|
||||||
|
|
||||||
suspend fun deleteConversationForUserWithTimestamp(
|
suspend fun deleteConversationForUserWithTimestamp(
|
||||||
user: UserEntity,
|
userId: Long,
|
||||||
timestamp: Long
|
timestamp: Long
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class ConversationsListViewModel constructor(
|
|||||||
val searchQuery = MutableLiveData<String>()
|
val searchQuery = MutableLiveData<String>()
|
||||||
val currentUserLiveData: MutableLiveData<UserEntity> = MutableLiveData()
|
val currentUserLiveData: MutableLiveData<UserEntity> = MutableLiveData()
|
||||||
val conversationsLiveData = Transformations.switchMap(currentUserLiveData) {
|
val conversationsLiveData = Transformations.switchMap(currentUserLiveData) {
|
||||||
offlineRepository.getConversationsForUser(it)
|
offlineRepository.getConversationsForUser(it.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUserAvatar: MutableLiveData<Drawable> = MutableLiveData()
|
var currentUserAvatar: MutableLiveData<Drawable> = MutableLiveData()
|
||||||
@ -189,7 +189,7 @@ class ConversationsListViewModel constructor(
|
|||||||
it.user = currentUserLiveData.value!!.id
|
it.user = currentUserLiveData.value!!.id
|
||||||
}
|
}
|
||||||
|
|
||||||
offlineRepository.saveConversationsForUser(currentUserLiveData.value!!, mutableList)
|
offlineRepository.saveConversationsForUser(currentUserLiveData.value!!.id, mutableList)
|
||||||
messageData = ""
|
messageData = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user