forked from github/wulkanowy-mirror
Fix message loading if student and parent are logged in (#319)
Fixes #316
This commit is contained in:
parent
8daea5c900
commit
7d97d71066
@ -9,6 +9,7 @@ class Migration13 : Migration(12, 13) {
|
||||
addClassNameToStudents(database, getStudentsIds(database))
|
||||
updateSemestersTable(database)
|
||||
markAtLeastAndOnlyOneSemesterAtCurrent(database, getStudentsAndClassIds(database))
|
||||
clearMessagesTable(database)
|
||||
}
|
||||
|
||||
private fun addClassNameToStudents(database: SupportSQLiteDatabase, students: List<Pair<Int, String>>) {
|
||||
@ -56,4 +57,8 @@ class Migration13 : Migration(12, 13) {
|
||||
database.execSQL("UPDATE Semesters SET is_current = 1 WHERE id = (SELECT id FROM Semesters WHERE student_id = '$studentId' AND class_id = '$classId' ORDER BY semester_id DESC)")
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearMessagesTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Messages")
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ class MessageLocal @Inject constructor(private val messagesDb: MessagesDao) {
|
||||
}
|
||||
|
||||
fun getMessage(student: Student, id: Int): Maybe<Message> {
|
||||
return messagesDb.load(student.studentId, id)
|
||||
return messagesDb.load(student.id.toInt(), id)
|
||||
}
|
||||
|
||||
fun getMessages(student: Student, folder: MessageFolder): Maybe<List<Message>> {
|
||||
return when (folder) {
|
||||
TRASHED -> messagesDb.loadDeleted(student.studentId)
|
||||
else -> messagesDb.loadAll(student.studentId, folder.id)
|
||||
TRASHED -> messagesDb.loadDeleted(student.id.toInt())
|
||||
else -> messagesDb.loadAll(student.id.toInt(), folder.id)
|
||||
}.filter { it.isNotEmpty() }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.github.wulkanowy.api.messages.Folder
|
||||
import io.github.wulkanowy.api.messages.SentMessage
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.db.entities.Recipient
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDateTime.now
|
||||
@ -16,11 +17,11 @@ import io.github.wulkanowy.api.messages.Recipient as ApiRecipient
|
||||
@Singleton
|
||||
class MessageRemote @Inject constructor(private val api: Api) {
|
||||
|
||||
fun getMessages(studentId: Int, folder: MessageFolder): Single<List<Message>> {
|
||||
fun getMessages(student: Student, folder: MessageFolder): Single<List<Message>> {
|
||||
return api.getMessages(Folder.valueOf(folder.name)).map { messages ->
|
||||
messages.map {
|
||||
Message(
|
||||
studentId = studentId,
|
||||
studentId = student.id.toInt(),
|
||||
realId = it.id ?: 0,
|
||||
messageId = it.messageId ?: 0,
|
||||
sender = it.sender.orEmpty(),
|
||||
|
@ -28,7 +28,7 @@ class MessageRepository @Inject constructor(
|
||||
local.getMessages(student, folder).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) remote.getMessages(student.studentId, folder)
|
||||
if (it) remote.getMessages(student, folder)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getMessages(student, folder).toSingle(emptyList())
|
||||
|
Loading…
Reference in New Issue
Block a user