forked from github/szkolny
[Sync] Fix showing notifications. Implement notifications web push.
This commit is contained in:
parent
9978a11c52
commit
92e0fc2847
@ -337,6 +337,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
DataNotifications(this)
|
DataNotifications(this)
|
||||||
|
db.notificationDao().addAll(notifications)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
error(ApiError(TAG, EXCEPTION_NOTIFY)
|
error(ApiError(TAG, EXCEPTION_NOTIFY)
|
||||||
|
@ -52,6 +52,7 @@ class SzkolnyApi(val app: App) {
|
|||||||
|
|
||||||
fun getEvents(profiles: List<ProfileFull>): List<EventFull> {
|
fun getEvents(profiles: List<ProfileFull>): List<EventFull> {
|
||||||
val teams = app.db.teamDao().allNow
|
val teams = app.db.teamDao().allNow
|
||||||
|
val notifications = app.db.notificationDao().getNotPostedNow()
|
||||||
|
|
||||||
val response = api.serverSync(ServerSyncRequest(
|
val response = api.serverSync(ServerSyncRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
@ -74,7 +75,8 @@ class SzkolnyApi(val app: App) {
|
|||||||
profile.loginStoreType,
|
profile.loginStoreType,
|
||||||
teams.filter { it.profileId == profile.id }.map { it.code }
|
teams.filter { it.profileId == profile.id }.map { it.code }
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
notifications = notifications.map { ServerSyncRequest.Notification(it.profileName ?: "", it.type, it.text) }
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
|
|
||||||
val events = mutableListOf<EventFull>()
|
val events = mutableListOf<EventFull>()
|
||||||
|
@ -10,7 +10,9 @@ data class ServerSyncRequest(
|
|||||||
val device: Device? = null,
|
val device: Device? = null,
|
||||||
|
|
||||||
val userCodes: List<String>,
|
val userCodes: List<String>,
|
||||||
val users: List<User>? = null
|
val users: List<User>? = null,
|
||||||
|
|
||||||
|
val notifications: List<Notification>? = null
|
||||||
) {
|
) {
|
||||||
data class Device(
|
data class Device(
|
||||||
val osType: String,
|
val osType: String,
|
||||||
@ -30,4 +32,10 @@ data class ServerSyncRequest(
|
|||||||
val loginType: Int,
|
val loginType: Int,
|
||||||
val teamCodes: List<String>
|
val teamCodes: List<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class Notification(
|
||||||
|
val profileName: String,
|
||||||
|
val type: Int,
|
||||||
|
val text: String
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class NotifyTask : IApiTask(-1) {
|
|||||||
|
|
||||||
fun run(app: App, taskCallback: EdziennikCallback) {
|
fun run(app: App, taskCallback: EdziennikCallback) {
|
||||||
val list = app.db.notificationDao().getNotPostedNow()
|
val list = app.db.notificationDao().getNotPostedNow()
|
||||||
val notificationList = list.subList(0, min(15, list.size))
|
val notificationList = list.subList(0, min(10, list.size))
|
||||||
|
|
||||||
var unreadCount = list.size
|
var unreadCount = list.size
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user