mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +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)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
fun addServer(server: JellyfinServer): Long
|
fun addServer(server: JellyfinServer): Long
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.ABORT)
|
@Update
|
||||||
fun updateServer(server: JellyfinServer): Int
|
fun updateServer(server: JellyfinServer): Int
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
fun addOrUpdateServer(server: JellyfinServer) {
|
||||||
|
val result = addServer(server)
|
||||||
|
if (result == -1L) {
|
||||||
|
updateServer(server)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun addUser(user: JellyfinUser)
|
fun addUser(user: JellyfinUser)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.Jellyfin
|
import org.jellyfin.sdk.Jellyfin
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
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.api.client.extensions.userApi
|
||||||
import org.jellyfin.sdk.model.api.AuthenticationResult
|
import org.jellyfin.sdk.model.api.AuthenticationResult
|
||||||
import org.jellyfin.sdk.model.api.UserDto
|
import org.jellyfin.sdk.model.api.UserDto
|
||||||
|
|
@ -42,7 +43,7 @@ class ServerRepository
|
||||||
*/
|
*/
|
||||||
suspend fun addAndChangeServer(server: JellyfinServer) {
|
suspend fun addAndChangeServer(server: JellyfinServer) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
serverDao.addServer(server)
|
serverDao.addOrUpdateServer(server)
|
||||||
}
|
}
|
||||||
changeServer(server)
|
changeServer(server)
|
||||||
}
|
}
|
||||||
|
|
@ -74,14 +75,15 @@ class ServerRepository
|
||||||
apiClient.userApi
|
apiClient.userApi
|
||||||
.getCurrentUser()
|
.getCurrentUser()
|
||||||
.content
|
.content
|
||||||
|
val sysInfo by apiClient.systemApi.getSystemInfo()
|
||||||
|
|
||||||
val updatedServer = server.copy(name = userDto.serverName)
|
val updatedServer = server.copy(name = sysInfo.serverName)
|
||||||
val updatedUser =
|
val updatedUser =
|
||||||
user.copy(
|
user.copy(
|
||||||
id = userDto.id.toString(),
|
id = userDto.id.toString(),
|
||||||
name = userDto.name,
|
name = userDto.name,
|
||||||
)
|
)
|
||||||
serverDao.addServer(updatedServer)
|
serverDao.addOrUpdateServer(updatedServer)
|
||||||
serverDao.addUser(updatedUser)
|
serverDao.addUser(updatedUser)
|
||||||
userPreferencesDataStore.updateData {
|
userPreferencesDataStore.updateData {
|
||||||
it
|
it
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue