Skip to main content

should_push

Function should_push 

Source
pub async fn should_push<B: ChatBackend>(
    backend: &B,
    caller: &B::CallerCtx,
    account_id: &Id,
    cfg: &ChatPushConfig,
    caps: &HashMap<Id, ChatPushCapability>,
    msg: &Message,
    owner: OwnerFlags,
) -> Result<bool, B::Error>
Expand description

Whether a ChatMessagePush for the new inbound message msg goes to a subscription whose chatPush entry for account_id is cfg.

caps maps each account that advertises urn:ietf:params:jmap:chat:push to its capability object; a cfg for an account not in caps counts as absent and gets false (draft-atwood-jmap-chat-push-00 §PushSubscription Extension). owner is the owner’s standing at delivery time, as for build_chat_message_push.

Returns true only when the Chat matches cfg and none of the §Delivery exclusions applies:

  • cfg.kinds and cfg.chatIds both match when present. §ChatPushConfig: “If both kinds and chatIds are present, a Chat matches only if its id appears in chatIds and its kind appears in kinds.”
  • The sender is not the owner: senderId is not account_id.
  • The owner is still a member of the Chat. The account must hold the Chat; for a group Chat its members must have an entry whose id is account_id, and for a channel Chat its Space’s members must.
  • The Chat is not muted, unless the owner is targeted by one of the message’s broadcast mentions. Direct mentions never bypass a mute, and neither does an encrypted message (§End-to-End Encrypted Deployments: “never bypasses mute suppression”). When muteUntil is set, the Chat is muted until that time whatever muted says, because draft-atwood-jmap-chat-00 §Chat muteUntil says “Muting expires at this time” and clearing muted afterwards is only a SHOULD. Otherwise the Chat is muted when muted is true. A muteUntil that is not a seconds-precision UTCDate, or a system clock before 1970, counts as an active mute.
  • The sender’s ChatContact is not blocked, per ChatBackend::is_contact_blocked.

§Messages stored before the subscription

§Delivery: “The server MUST NOT deliver a ChatMessagePush in any of the following cases: The message was stored before the PushSubscription was created.” This function cannot see creation order. The caller MUST read the set of subscriptions under the same lock or transaction as the message write, and call this function only for subscriptions in that set, including when delivery fans out asynchronously afterwards.

§Errors

Returns the backend’s error if reading the Chat, its Space or the sender’s blocked status fails.