aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 00:52:23 -0700
committerGitHub <noreply@github.com>2019-08-06 00:52:23 -0700
commitd500d1dd6e05c6128dcb15fe8e15acb2aaf979cd (patch)
tree98caedbfd7a6b154ca6401c6a389cb5a08bdee3d /app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
parentc78e670c2ac74e0c1b1fda4259cdcf69949e0d95 (diff)
parent59a462e6f23d046236bc20e6ac9c9464ed670f58 (diff)
downloadfrost-d500d1dd6e05c6128dcb15fe8e15acb2aaf979cd.tar.gz
frost-d500d1dd6e05c6128dcb15fe8e15acb2aaf979cd.tar.bz2
frost-d500d1dd6e05c6128dcb15fe8e15acb2aaf979cd.zip
Merge pull request #1503 from AllanWang/format
Format
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt47
1 files changed, 24 insertions, 23 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index 1d983f14..95726974 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -84,32 +84,33 @@ class NotificationService : BaseJobService() {
return true
}
- private suspend fun sendNotifications(params: JobParameters?): Unit = withContext(Dispatchers.Default) {
- val currentId = Prefs.userId
- val cookies = cookieDao.selectAll()
- yield()
- val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1
- var notifCount = 0
- for (cookie in cookies) {
+ private suspend fun sendNotifications(params: JobParameters?): Unit =
+ withContext(Dispatchers.Default) {
+ val currentId = Prefs.userId
+ val cookies = cookieDao.selectAll()
yield()
- val current = cookie.id == currentId
- if (Prefs.notificationsGeneral &&
- (current || Prefs.notificationAllAccounts)
- )
- notifCount += fetch(jobId, NotificationType.GENERAL, cookie)
- if (Prefs.notificationsInstantMessages &&
- (current || Prefs.notificationsImAllAccounts)
- )
- notifCount += fetch(jobId, NotificationType.MESSAGE, cookie)
- }
+ val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1
+ var notifCount = 0
+ for (cookie in cookies) {
+ yield()
+ val current = cookie.id == currentId
+ if (Prefs.notificationsGeneral &&
+ (current || Prefs.notificationAllAccounts)
+ )
+ notifCount += fetch(jobId, NotificationType.GENERAL, cookie)
+ if (Prefs.notificationsInstantMessages &&
+ (current || Prefs.notificationsImAllAccounts)
+ )
+ notifCount += fetch(jobId, NotificationType.MESSAGE, cookie)
+ }
- L.i { "Sent $notifCount notifications" }
- if (notifCount == 0 && jobId == NOTIFICATION_JOB_NOW)
- generalNotification(665, R.string.no_new_notifications, BuildConfig.DEBUG)
- if (notifCount > 0) {
- NotificationWidget.forceUpdate(this@NotificationService)
+ L.i { "Sent $notifCount notifications" }
+ if (notifCount == 0 && jobId == NOTIFICATION_JOB_NOW)
+ generalNotification(665, R.string.no_new_notifications, BuildConfig.DEBUG)
+ if (notifCount > 0) {
+ NotificationWidget.forceUpdate(this@NotificationService)
+ }
}
- }
/**
* Implemented fetch to also notify when an error occurs