mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-02 08:07:11 +00:00
fix: look for new mail when a push names changes it can't read #34
The native push router and the push task decided separately whether a push may carry mail, and disagreed. For an account entry that is not an object, or a map that names no type, the router started the mail task as possible mail, but the task's guard read the same payload as "no mail" and returned, so new mail it announced was never looked for. A push without a kind was judged by its map in the router but taken for mail by the task. Both now apply the same rules: anything but a StateChange, a map that is missing, unreadable or names no type, an unreadable account entry, or a mail type means the mail task runs. Only a readable StateChange naming contact, calendar or other non-mail types skips it. Checked with one table of payloads run against the router's decision and the task's guard alike.
This commit is contained in:
@@ -13,9 +13,11 @@ import org.json.JSONObject
|
||||
* The relay forwards the JMAP StateChange's `changed` map verbatim (FCM data
|
||||
* key `changed`: JMAP account id → type → state; only its first account is
|
||||
* repeated as `accountId`), so every account key is looked at. The mail task
|
||||
* runs only for mail: when some account's map has a mail type, for an
|
||||
* EmailPush, or when `changed` is missing or unreadable (older relays), so a
|
||||
* contact change never ends in a mail notification.
|
||||
* runs only for mail: when some account's map has a mail type, for anything
|
||||
* but a StateChange (an EmailPush), when `changed` is missing, unreadable or
|
||||
* names no type (older relays), or when an account's entry is unreadable, so
|
||||
* a contact change never ends in a mail notification. The push task's guard
|
||||
* (`carriesNoMail` in src/lib/push-background-task.ts) applies the same rules.
|
||||
*/
|
||||
object PushRouting {
|
||||
/** An Android account and the authorities it syncs, fed by one JMAP account. */
|
||||
@@ -27,7 +29,7 @@ object PushRouting {
|
||||
val startMailTask: Boolean,
|
||||
)
|
||||
|
||||
private const val EMAIL_PUSH_KIND = "jmap-email-push"
|
||||
private const val STATE_CHANGE_KIND = "jmap-state-change"
|
||||
|
||||
/**
|
||||
* Types that may mean new mail: `EmailDelivery`, and `Email`/`Mailbox`,
|
||||
@@ -42,7 +44,8 @@ object PushRouting {
|
||||
|
||||
fun decide(data: Map<String, String>, routes: Map<String, List<Route>>): Decision {
|
||||
val changed = data["changed"]?.let(::parseChanged)
|
||||
var mail = data["kind"] == EMAIL_PUSH_KIND || changed == null
|
||||
// Only a StateChange can say it carries no mail.
|
||||
var mail = data["kind"] != STATE_CHANGE_KIND || changed == null
|
||||
val syncs = LinkedHashSet<Pair<String, String>>()
|
||||
for ((jmapAccountId, types) in changed.orEmpty()) {
|
||||
if (types == null) {
|
||||
|
||||
Reference in New Issue
Block a user