mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix some issues with local db
This commit is contained in:
parent
9d67b9a3ca
commit
ba45c3f509
2 changed files with 14 additions and 4 deletions
|
|
@ -55,9 +55,17 @@ interface JellyfinServerDao {
|
|||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun addServer(server: JellyfinServer): Long
|
||||
|
||||
@Update(onConflict = OnConflictStrategy.ABORT)
|
||||
@Update
|
||||
fun updateServer(server: JellyfinServer): Int
|
||||
|
||||
@Transaction
|
||||
fun addOrUpdateServer(server: JellyfinServer) {
|
||||
val result = addServer(server)
|
||||
if (result == -1L) {
|
||||
updateServer(server)
|
||||
}
|
||||
}
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun addUser(user: JellyfinUser)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.withContext
|
||||
import org.jellyfin.sdk.Jellyfin
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.extensions.systemApi
|
||||
import org.jellyfin.sdk.api.client.extensions.userApi
|
||||
import org.jellyfin.sdk.model.api.AuthenticationResult
|
||||
import org.jellyfin.sdk.model.api.UserDto
|
||||
|
|
@ -42,7 +43,7 @@ class ServerRepository
|
|||
*/
|
||||
suspend fun addAndChangeServer(server: JellyfinServer) {
|
||||
withContext(Dispatchers.IO) {
|
||||
serverDao.addServer(server)
|
||||
serverDao.addOrUpdateServer(server)
|
||||
}
|
||||
changeServer(server)
|
||||
}
|
||||
|
|
@ -74,14 +75,15 @@ class ServerRepository
|
|||
apiClient.userApi
|
||||
.getCurrentUser()
|
||||
.content
|
||||
val sysInfo by apiClient.systemApi.getSystemInfo()
|
||||
|
||||
val updatedServer = server.copy(name = userDto.serverName)
|
||||
val updatedServer = server.copy(name = sysInfo.serverName)
|
||||
val updatedUser =
|
||||
user.copy(
|
||||
id = userDto.id.toString(),
|
||||
name = userDto.name,
|
||||
)
|
||||
serverDao.addServer(updatedServer)
|
||||
serverDao.addOrUpdateServer(updatedServer)
|
||||
serverDao.addUser(updatedUser)
|
||||
userPreferencesDataStore.updateData {
|
||||
it
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue