forked from github/wulkanowy-mirror
Normalize synchronization date ranges to fix weird notification issues (#2403)
This commit is contained in:
parent
7cdac6ede1
commit
a51a54dc7a
@ -67,14 +67,16 @@ class ExamRepository @Inject constructor(
|
||||
filterResult = { it.filter { item -> item.date in start..end } }
|
||||
)
|
||||
|
||||
fun getExamsFromDatabase(semester: Semester, start: LocalDate): Flow<List<Exam>> {
|
||||
return examDb.loadAll(
|
||||
diaryId = semester.diaryId,
|
||||
studentId = semester.studentId,
|
||||
from = start.startExamsDay,
|
||||
end = start.endExamsDay
|
||||
)
|
||||
}
|
||||
fun getExamsFromDatabase(
|
||||
semester: Semester,
|
||||
start: LocalDate,
|
||||
end: LocalDate
|
||||
): Flow<List<Exam>> = examDb.loadAll(
|
||||
diaryId = semester.diaryId,
|
||||
studentId = semester.studentId,
|
||||
from = start,
|
||||
end = end,
|
||||
)
|
||||
|
||||
suspend fun updateExam(exam: List<Exam>) = examDb.updateAll(exam)
|
||||
}
|
||||
|
@ -7,7 +7,12 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||
import io.github.wulkanowy.data.networkBoundResource
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.*
|
||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||
import io.github.wulkanowy.utils.getRefreshKey
|
||||
import io.github.wulkanowy.utils.init
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
@ -16,17 +16,24 @@ class AttendanceWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
val startDate = now().previousOrSameSchoolDay
|
||||
val endDate = startDate.plusDays(7)
|
||||
|
||||
attendanceRepository.getAttendance(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().previousOrSameSchoolDay,
|
||||
end = now().previousOrSameSchoolDay,
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
forceRefresh = true,
|
||||
notify = notify,
|
||||
)
|
||||
.waitForResult()
|
||||
|
||||
attendanceRepository.getAttendanceFromDatabase(semester, now().minusDays(7), now())
|
||||
attendanceRepository.getAttendanceFromDatabase(
|
||||
semester = semester,
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
)
|
||||
.first()
|
||||
.filterNot { it.isNotified }
|
||||
.let {
|
||||
|
@ -5,6 +5,8 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.ExamRepository
|
||||
import io.github.wulkanowy.data.waitForResult
|
||||
import io.github.wulkanowy.services.sync.notifications.NewExamNotification
|
||||
import io.github.wulkanowy.utils.endExamsDay
|
||||
import io.github.wulkanowy.utils.startExamsDay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import java.time.LocalDate.now
|
||||
import javax.inject.Inject
|
||||
@ -15,16 +17,24 @@ class ExamWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
val startDate = now().startExamsDay
|
||||
val endDate = startDate.endExamsDay
|
||||
|
||||
examRepository.getExams(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now(),
|
||||
end = now(),
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
forceRefresh = true,
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
examRepository.getExamsFromDatabase(semester, now()).first()
|
||||
examRepository.getExamsFromDatabase(
|
||||
semester = semester,
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
)
|
||||
.first()
|
||||
.filter { !it.isNotified }.let {
|
||||
if (it.isNotEmpty()) newExamNotification.notify(it, student)
|
||||
|
||||
|
@ -5,7 +5,9 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.HomeworkRepository
|
||||
import io.github.wulkanowy.data.waitForResult
|
||||
import io.github.wulkanowy.services.sync.notifications.NewHomeworkNotification
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import kotlinx.coroutines.flow.first
|
||||
import java.time.LocalDate.now
|
||||
import javax.inject.Inject
|
||||
@ -16,16 +18,24 @@ class HomeworkWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
val startDate = now().nextOrSameSchoolDay.monday
|
||||
val endDate = startDate.sunday
|
||||
|
||||
homeworkRepository.getHomework(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().nextOrSameSchoolDay,
|
||||
end = now().nextOrSameSchoolDay,
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
forceRefresh = true,
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
homeworkRepository.getHomeworkFromDatabase(semester, now(), now().plusDays(7)).first()
|
||||
homeworkRepository.getHomeworkFromDatabase(
|
||||
semester = semester,
|
||||
start = startDate,
|
||||
end = endDate
|
||||
)
|
||||
.first()
|
||||
.filter { !it.isNotified }.let {
|
||||
if (it.isNotEmpty()) newHomeworkNotification.notify(it, student)
|
||||
|
||||
|
@ -16,17 +16,24 @@ class TimetableWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
val startDate = now().nextOrSameSchoolDay
|
||||
val endDate = startDate.plusDays(7)
|
||||
|
||||
timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().nextOrSameSchoolDay,
|
||||
end = now().nextOrSameSchoolDay,
|
||||
start = startDate,
|
||||
end = endDate,
|
||||
forceRefresh = true,
|
||||
notify = notify,
|
||||
)
|
||||
.waitForResult()
|
||||
|
||||
timetableRepository.getTimetableFromDatabase(semester, now(), now().plusDays(7))
|
||||
timetableRepository.getTimetableFromDatabase(
|
||||
semester = semester,
|
||||
from = startDate,
|
||||
end = endDate,
|
||||
)
|
||||
.first()
|
||||
.filterNot { it.isNotified }
|
||||
.let {
|
||||
|
@ -435,13 +435,13 @@ class DashboardPresenter @Inject constructor(
|
||||
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
||||
flatResourceFlow {
|
||||
val semester = semesterRepository.getCurrentSemester(student)
|
||||
val date = LocalDate.now()
|
||||
val date = LocalDate.now().nextOrSameSchoolDay
|
||||
|
||||
timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = date,
|
||||
end = date.plusDays(1),
|
||||
end = date,
|
||||
forceRefresh = forceRefresh
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user