From 5b2b0617a6c57f772981b57ed1241c86e3df6c2f Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 May 2023 01:49:01 +0000 Subject: [PATCH] call_on_each_event: Do not pass heartbeat events to clients. Heartbeat events are intended to be an invisible part of the Zulip longpolling protocol, not an event that an application should every process, so it makes sense to exclude them from the events we pass to this application. Reproducer: https://github.com/showell/zulip-api-examples/blob/main/heartbeat_bug.py. See https://chat.zulip.org/#narrow/stream/137-feedback/topic/api.20client.20silent.20failure for more context. --- zulip/zulip/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 1cb73bd5..7f76831d 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -819,6 +819,15 @@ class Client: for event in res["events"]: last_event_id = max(last_event_id, int(event["id"])) + + if event["type"] == "heartbeat": + # Heartbeat events are sent to clients regardless + # of the client's requested event types, and are + # intended to be an internal part of the Zulip + # longpolling protocol, not something that clients + # need to handle. + continue + callback(event) def call_on_each_message(