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 } }
|
filterResult = { it.filter { item -> item.date in start..end } }
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getExamsFromDatabase(semester: Semester, start: LocalDate): Flow<List<Exam>> {
|
fun getExamsFromDatabase(
|
||||||
return examDb.loadAll(
|
semester: Semester,
|
||||||
|
start: LocalDate,
|
||||||
|
end: LocalDate
|
||||||
|
): Flow<List<Exam>> = examDb.loadAll(
|
||||||
diaryId = semester.diaryId,
|
diaryId = semester.diaryId,
|
||||||
studentId = semester.studentId,
|
studentId = semester.studentId,
|
||||||
from = start.startExamsDay,
|
from = start,
|
||||||
end = start.endExamsDay
|
end = end,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun updateExam(exam: List<Exam>) = examDb.updateAll(exam)
|
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.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.networkBoundResource
|
import io.github.wulkanowy.data.networkBoundResource
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
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 kotlinx.coroutines.sync.Mutex
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -16,17 +16,24 @@ class AttendanceWork @Inject constructor(
|
|||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
|
val startDate = now().previousOrSameSchoolDay
|
||||||
|
val endDate = startDate.plusDays(7)
|
||||||
|
|
||||||
attendanceRepository.getAttendance(
|
attendanceRepository.getAttendance(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().previousOrSameSchoolDay,
|
start = startDate,
|
||||||
end = now().previousOrSameSchoolDay,
|
end = endDate,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = notify,
|
notify = notify,
|
||||||
)
|
)
|
||||||
.waitForResult()
|
.waitForResult()
|
||||||
|
|
||||||
attendanceRepository.getAttendanceFromDatabase(semester, now().minusDays(7), now())
|
attendanceRepository.getAttendanceFromDatabase(
|
||||||
|
semester = semester,
|
||||||
|
start = startDate,
|
||||||
|
end = endDate,
|
||||||
|
)
|
||||||
.first()
|
.first()
|
||||||
.filterNot { it.isNotified }
|
.filterNot { it.isNotified }
|
||||||
.let {
|
.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.repositories.ExamRepository
|
||||||
import io.github.wulkanowy.data.waitForResult
|
import io.github.wulkanowy.data.waitForResult
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewExamNotification
|
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 kotlinx.coroutines.flow.first
|
||||||
import java.time.LocalDate.now
|
import java.time.LocalDate.now
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -15,16 +17,24 @@ class ExamWork @Inject constructor(
|
|||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
|
val startDate = now().startExamsDay
|
||||||
|
val endDate = startDate.endExamsDay
|
||||||
|
|
||||||
examRepository.getExams(
|
examRepository.getExams(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now(),
|
start = startDate,
|
||||||
end = now(),
|
end = endDate,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = notify,
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
examRepository.getExamsFromDatabase(semester, now()).first()
|
examRepository.getExamsFromDatabase(
|
||||||
|
semester = semester,
|
||||||
|
start = startDate,
|
||||||
|
end = endDate,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
.filter { !it.isNotified }.let {
|
.filter { !it.isNotified }.let {
|
||||||
if (it.isNotEmpty()) newExamNotification.notify(it, student)
|
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.repositories.HomeworkRepository
|
||||||
import io.github.wulkanowy.data.waitForResult
|
import io.github.wulkanowy.data.waitForResult
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewHomeworkNotification
|
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.nextOrSameSchoolDay
|
||||||
|
import io.github.wulkanowy.utils.sunday
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import java.time.LocalDate.now
|
import java.time.LocalDate.now
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -16,16 +18,24 @@ class HomeworkWork @Inject constructor(
|
|||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
|
val startDate = now().nextOrSameSchoolDay.monday
|
||||||
|
val endDate = startDate.sunday
|
||||||
|
|
||||||
homeworkRepository.getHomework(
|
homeworkRepository.getHomework(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().nextOrSameSchoolDay,
|
start = startDate,
|
||||||
end = now().nextOrSameSchoolDay,
|
end = endDate,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = notify,
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
homeworkRepository.getHomeworkFromDatabase(semester, now(), now().plusDays(7)).first()
|
homeworkRepository.getHomeworkFromDatabase(
|
||||||
|
semester = semester,
|
||||||
|
start = startDate,
|
||||||
|
end = endDate
|
||||||
|
)
|
||||||
|
.first()
|
||||||
.filter { !it.isNotified }.let {
|
.filter { !it.isNotified }.let {
|
||||||
if (it.isNotEmpty()) newHomeworkNotification.notify(it, student)
|
if (it.isNotEmpty()) newHomeworkNotification.notify(it, student)
|
||||||
|
|
||||||
|
@ -16,17 +16,24 @@ class TimetableWork @Inject constructor(
|
|||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
|
val startDate = now().nextOrSameSchoolDay
|
||||||
|
val endDate = startDate.plusDays(7)
|
||||||
|
|
||||||
timetableRepository.getTimetable(
|
timetableRepository.getTimetable(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().nextOrSameSchoolDay,
|
start = startDate,
|
||||||
end = now().nextOrSameSchoolDay,
|
end = endDate,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = notify,
|
notify = notify,
|
||||||
)
|
)
|
||||||
.waitForResult()
|
.waitForResult()
|
||||||
|
|
||||||
timetableRepository.getTimetableFromDatabase(semester, now(), now().plusDays(7))
|
timetableRepository.getTimetableFromDatabase(
|
||||||
|
semester = semester,
|
||||||
|
from = startDate,
|
||||||
|
end = endDate,
|
||||||
|
)
|
||||||
.first()
|
.first()
|
||||||
.filterNot { it.isNotified }
|
.filterNot { it.isNotified }
|
||||||
.let {
|
.let {
|
||||||
|
@ -435,13 +435,13 @@ class DashboardPresenter @Inject constructor(
|
|||||||
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
||||||
flatResourceFlow {
|
flatResourceFlow {
|
||||||
val semester = semesterRepository.getCurrentSemester(student)
|
val semester = semesterRepository.getCurrentSemester(student)
|
||||||
val date = LocalDate.now()
|
val date = LocalDate.now().nextOrSameSchoolDay
|
||||||
|
|
||||||
timetableRepository.getTimetable(
|
timetableRepository.getTimetable(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = date,
|
start = date,
|
||||||
end = date.plusDays(1),
|
end = date,
|
||||||
forceRefresh = forceRefresh
|
forceRefresh = forceRefresh
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user