mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 19:56:29 -06:00
Fix notification spam after login (#1715)
This commit is contained in:
parent
684c258e2d
commit
496641f594
@ -74,10 +74,12 @@ class SyncManager @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun startOneTimeSyncWorker(): Flow<WorkInfo?> {
|
||||
// if quiet, no notifications will be sent
|
||||
fun startOneTimeSyncWorker(quiet: Boolean = false): Flow<WorkInfo?> {
|
||||
val work = OneTimeWorkRequestBuilder<SyncWorker>()
|
||||
.setInputData(
|
||||
Data.Builder()
|
||||
.putBoolean("quiet", quiet)
|
||||
.putBoolean("one_time", true)
|
||||
.build()
|
||||
)
|
||||
|
@ -54,7 +54,7 @@ class SyncWorker @AssistedInject constructor(
|
||||
val exceptions = works.mapNotNull { work ->
|
||||
try {
|
||||
Timber.i("${work::class.java.simpleName} is starting")
|
||||
work.doWork(student, semester)
|
||||
work.doWork(student, semester, isNotificationsEnabled())
|
||||
Timber.i("${work::class.java.simpleName} result: Success")
|
||||
null
|
||||
} catch (e: Throwable) {
|
||||
@ -75,6 +75,11 @@ class SyncWorker @AssistedInject constructor(
|
||||
return@withContext result
|
||||
}
|
||||
|
||||
private fun isNotificationsEnabled(): Boolean {
|
||||
val quiet = inputData.getBoolean("quiet", false)
|
||||
return preferencesRepository.isNotificationsEnable && !quiet
|
||||
}
|
||||
|
||||
private fun getResultFromErrors(errors: List<Throwable>): Result = when {
|
||||
errors.isNotEmpty() && inputData.getBoolean("one_time", false) -> {
|
||||
Result.failure(
|
||||
|
@ -10,7 +10,12 @@ class AttendanceSummaryWork @Inject constructor(
|
||||
private val attendanceSummaryRepository: AttendanceSummaryRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
attendanceSummaryRepository.getAttendanceSummary(student, semester, -1, true).waitForResult()
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
attendanceSummaryRepository.getAttendanceSummary(
|
||||
student = student,
|
||||
semester = semester,
|
||||
subjectId = -1,
|
||||
forceRefresh = true,
|
||||
).waitForResult()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.AttendanceRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewAttendanceNotification
|
||||
import io.github.wulkanowy.utils.previousOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
@ -14,17 +13,16 @@ import javax.inject.Inject
|
||||
class AttendanceWork @Inject constructor(
|
||||
private val attendanceRepository: AttendanceRepository,
|
||||
private val newAttendanceNotification: NewAttendanceNotification,
|
||||
private val preferencesRepository: PreferencesRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
attendanceRepository.getAttendance(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().previousOrSameSchoolDay,
|
||||
end = now().previousOrSameSchoolDay,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
)
|
||||
.waitForResult()
|
||||
|
||||
|
@ -13,7 +13,13 @@ class CompletedLessonWork @Inject constructor(
|
||||
private val completedLessonsRepository: CompletedLessonsRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
completedLessonsRepository.getCompletedLessons(student, semester, now().monday, now().sunday, true).waitForResult()
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
completedLessonsRepository.getCompletedLessons(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().monday,
|
||||
end = now().sunday,
|
||||
forceRefresh = true,
|
||||
).waitForResult()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.ConferenceRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
||||
|
||||
class ConferenceWork @Inject constructor(
|
||||
private val conferenceRepository: ConferenceRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newConferenceNotification: NewConferenceNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
conferenceRepository.getConferences(
|
||||
student = student,
|
||||
semester = semester,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify
|
||||
).waitForResult()
|
||||
|
||||
conferenceRepository.getConferenceFromDatabase(semester).first()
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.ExamRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewExamNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -12,18 +11,17 @@ import javax.inject.Inject
|
||||
|
||||
class ExamWork @Inject constructor(
|
||||
private val examRepository: ExamRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newExamNotification: NewExamNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
examRepository.getExams(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now(),
|
||||
end = now(),
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
examRepository.getExamsFromDatabase(semester, now()).first()
|
||||
|
@ -10,7 +10,7 @@ class GradeStatisticsWork @Inject constructor(
|
||||
private val gradeStatisticsRepository: GradeStatisticsRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
with(gradeStatisticsRepository) {
|
||||
getGradesPartialStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
||||
getGradesSemesterStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewGradeNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
||||
|
||||
class GradeWork @Inject constructor(
|
||||
private val gradeRepository: GradeRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newGradeNotification: NewGradeNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
gradeRepository.getGrades(
|
||||
student = student,
|
||||
semester = semester,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
gradeRepository.getGradesFromDatabase(semester).first()
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.HomeworkRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewHomeworkNotification
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
@ -13,18 +12,17 @@ import javax.inject.Inject
|
||||
|
||||
class HomeworkWork @Inject constructor(
|
||||
private val homeworkRepository: HomeworkRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newHomeworkNotification: NewHomeworkNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
homeworkRepository.getHomework(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().nextOrSameSchoolDay,
|
||||
end = now().nextOrSameSchoolDay,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
homeworkRepository.getHomeworkFromDatabase(semester, now(), now().plusDays(7)).first()
|
||||
|
@ -3,22 +3,20 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewLuckyNumberNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import javax.inject.Inject
|
||||
|
||||
class LuckyNumberWork @Inject constructor(
|
||||
private val luckyNumberRepository: LuckyNumberRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newLuckyNumberNotification: NewLuckyNumberNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
luckyNumberRepository.getLuckyNumber(
|
||||
student = student,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
|
||||
|
@ -4,7 +4,6 @@ import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.enums.MessageFolder.RECEIVED
|
||||
import io.github.wulkanowy.data.repositories.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewMessageNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -12,17 +11,16 @@ import javax.inject.Inject
|
||||
|
||||
class MessageWork @Inject constructor(
|
||||
private val messageRepository: MessageRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newMessageNotification: NewMessageNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
messageRepository.getMessages(
|
||||
student = student,
|
||||
semester = semester,
|
||||
folder = RECEIVED,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify
|
||||
).waitForResult()
|
||||
|
||||
messageRepository.getMessagesFromDatabase(student).first()
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.NoteRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewNoteNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
||||
|
||||
class NoteWork @Inject constructor(
|
||||
private val noteRepository: NoteRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newNoteNotification: NewNoteNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
noteRepository.getNotes(
|
||||
student = student,
|
||||
semester = semester,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
noteRepository.getNotesFromDatabase(student).first()
|
||||
|
@ -11,7 +11,7 @@ class RecipientWork @Inject constructor(
|
||||
private val recipientRepository: RecipientRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
reportingUnitRepository.refreshReportingUnits(student)
|
||||
|
||||
reportingUnitRepository.getReportingUnits(student).let { units ->
|
||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.SchoolAnnouncementRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewSchoolAnnouncementNotification
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
@ -11,15 +10,14 @@ import javax.inject.Inject
|
||||
|
||||
class SchoolAnnouncementWork @Inject constructor(
|
||||
private val schoolAnnouncementRepository: SchoolAnnouncementRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val newSchoolAnnouncementNotification: NewSchoolAnnouncementNotification,
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
schoolAnnouncementRepository.getSchoolAnnouncements(
|
||||
student = student,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
).waitForResult()
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ import javax.inject.Inject
|
||||
|
||||
class TeacherWork @Inject constructor(private val teacherRepository: TeacherRepository) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
teacherRepository.getTeachers(student, semester, true).waitForResult()
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.ChangeTimetableNotification
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
@ -14,17 +13,16 @@ import javax.inject.Inject
|
||||
class TimetableWork @Inject constructor(
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val changeTimetableNotification: ChangeTimetableNotification,
|
||||
private val preferencesRepository: PreferencesRepository
|
||||
) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||
timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().nextOrSameSchoolDay,
|
||||
end = now().nextOrSameSchoolDay,
|
||||
forceRefresh = true,
|
||||
notify = preferencesRepository.isNotificationsEnable
|
||||
notify = notify,
|
||||
)
|
||||
.waitForResult()
|
||||
|
||||
|
@ -5,5 +5,5 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
|
||||
interface Work {
|
||||
|
||||
suspend fun doWork(student: Student, semester: Semester)
|
||||
suspend fun doWork(student: Student, semester: Semester, notify: Boolean)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import io.github.wulkanowy.data.Status
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.services.sync.SyncManager
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
@ -16,6 +17,7 @@ import javax.inject.Inject
|
||||
class LoginStudentSelectPresenter @Inject constructor(
|
||||
studentRepository: StudentRepository,
|
||||
private val loginErrorHandler: LoginErrorHandler,
|
||||
private val syncManager: SyncManager,
|
||||
private val analytics: AnalyticsHelper
|
||||
) : BasePresenter<LoginStudentSelectView>(loginErrorHandler, studentRepository) {
|
||||
|
||||
@ -97,6 +99,7 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
}
|
||||
Status.SUCCESS -> {
|
||||
Timber.i("Registration result: Success")
|
||||
syncManager.startOneTimeSyncWorker(quiet = true)
|
||||
view?.openMainView()
|
||||
logRegisterEvent(studentsWithSemesters)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import io.github.wulkanowy.MainCoroutineRule
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.services.sync.SyncManager
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.mockk.MockKAnnotations
|
||||
@ -36,6 +37,9 @@ class LoginStudentSelectPresenterTest {
|
||||
@MockK(relaxed = true)
|
||||
lateinit var analytics: AnalyticsHelper
|
||||
|
||||
@MockK(relaxed = true)
|
||||
lateinit var syncManager: SyncManager
|
||||
|
||||
private lateinit var presenter: LoginStudentSelectPresenter
|
||||
|
||||
private val testStudent by lazy {
|
||||
@ -77,7 +81,7 @@ class LoginStudentSelectPresenterTest {
|
||||
every { loginStudentSelectView.showProgress(any()) } just Runs
|
||||
every { loginStudentSelectView.showContent(any()) } just Runs
|
||||
|
||||
presenter = LoginStudentSelectPresenter(studentRepository, errorHandler, analytics)
|
||||
presenter = LoginStudentSelectPresenter(studentRepository, errorHandler, syncManager, analytics)
|
||||
presenter.onAttachView(loginStudentSelectView, emptyList())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user