Use userLoginId to differentiate saved mobiles devices between accounts (#1076)

This commit is contained in:
Mikołaj Pich 2021-01-14 18:36:32 +01:00 committed by GitHub
parent a1d4b3d19e
commit 8ce59a3098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 5 deletions

View File

@ -8,6 +8,6 @@ import kotlinx.coroutines.flow.Flow
@Dao @Dao
interface MobileDeviceDao : BaseDao<MobileDevice> { interface MobileDeviceDao : BaseDao<MobileDevice> {
@Query("SELECT * FROM MobileDevices WHERE student_id = :studentId ORDER BY date DESC") @Query("SELECT * FROM MobileDevices WHERE student_id = :userLoginId ORDER BY date DESC")
fun loadAll(studentId: Int): Flow<List<MobileDevice>> fun loadAll(userLoginId: Int): Flow<List<MobileDevice>>
} }

View File

@ -10,7 +10,7 @@ import java.time.LocalDateTime
data class MobileDevice( data class MobileDevice(
@ColumnInfo(name = "student_id") @ColumnInfo(name = "student_id")
val studentId: Int, val userLoginId: Int,
@ColumnInfo(name = "device_id") @ColumnInfo(name = "device_id")
val deviceId: Int, val deviceId: Int,

View File

@ -8,7 +8,7 @@ import io.github.wulkanowy.sdk.pojo.Device as SdkDevice
fun List<SdkDevice>.mapToEntities(semester: Semester) = map { fun List<SdkDevice>.mapToEntities(semester: Semester) = map {
MobileDevice( MobileDevice(
studentId = semester.studentId, userLoginId = semester.studentId,
date = it.createDate, date = it.createDate,
deviceId = it.id, deviceId = it.id,
name = it.name name = it.name

View File

@ -27,7 +27,7 @@ class MobileDeviceRepository @Inject constructor(
fun getDevices(student: Student, semester: Semester, forceRefresh: Boolean) = networkBoundResource( fun getDevices(student: Student, semester: Semester, forceRefresh: Boolean) = networkBoundResource(
shouldFetch = { it.isEmpty() || forceRefresh || refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, student)) }, shouldFetch = { it.isEmpty() || forceRefresh || refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, student)) },
query = { mobileDb.loadAll(semester.studentId) }, query = { mobileDb.loadAll(student.userLoginId.takeIf { it != 0 } ?: student.studentId) },
fetch = { fetch = {
sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear) sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear)
.getRegisteredDevices() .getRegisteredDevices()