2017-09-25 20:33:29 +02:00
|
|
|
# Typing indicators
|
|
|
|
|
|
|
|
Zulip supports a feature called "typing indicators."
|
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
Typing indicators are status messages (or visual indicators) that
|
|
|
|
tell you when another user is writing a message to you. Zulip's
|
|
|
|
typing UI is similar to what you see in other chat/text systems.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
This document describes how we have implemented the feature in
|
|
|
|
the Zulip web app, and our main audience is developers who want to
|
|
|
|
understand the system and possibly improve it. Any client should
|
|
|
|
be able follow the protocol documented here.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
Right now typing indicators are only implemented for direct
|
|
|
|
message conversations in the web app.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
There are two major roles for users in this system:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The "writing user" is composing a message.
|
|
|
|
- The "receiving user" is waiting to receive a message (or possibly
|
2017-09-25 20:33:29 +02:00
|
|
|
ready to shift their attention elsewhere).
|
|
|
|
|
|
|
|
Any Zulip user can play either one of these roles, and sometimes
|
2021-08-20 21:53:28 +02:00
|
|
|
they can be playing both roles at once. Having said that, you
|
2017-09-25 20:33:29 +02:00
|
|
|
can generally understand the system in terms of a single message
|
|
|
|
being composed by the "writing user."
|
|
|
|
|
|
|
|
On a high level the typing indicators system works like this:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The client for the "writing user" sends requests to the server.
|
|
|
|
- The server broadcasts events to other users.
|
|
|
|
- The clients for "receiving users" receive events and conditionally
|
2017-09-25 20:33:29 +02:00
|
|
|
show typing indicators, depending on where the clients are narrowed.
|
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
## Privacy settings
|
|
|
|
|
|
|
|
Note that there is a user-level privacy setting to disable sending
|
|
|
|
typing notifications that a client should check when implementing
|
|
|
|
the "writing user" protocol below. See `send_private_typing_notifications`
|
|
|
|
in the `UserBaseSettings` model in `zerver/models.py` and in the
|
|
|
|
`user_settings` object in the `POST /register` response.
|
|
|
|
|
2017-09-25 20:33:29 +02:00
|
|
|
## Writing user
|
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
When a "writing user" starts to compose a message, the client
|
|
|
|
sends a request to `POST /typing` with an `op` of `start` and
|
|
|
|
a list of potential message recipients. The web app function
|
|
|
|
that facilitates this is called `send_typing_notification_ajax`.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
If the "writing user" is composing a long message, we want to send
|
2023-08-22 16:26:44 +02:00
|
|
|
repeated updates to the server so that downstream clients know the
|
|
|
|
user is still typing. Zulip messages tend to be longer than
|
|
|
|
messages in other chat/text clients, so this detail is important.
|
|
|
|
|
|
|
|
We have a small state machine in `web/shared/src/typing_status.ts`
|
|
|
|
that makes sure subsequent "start" requests get sent out. The
|
|
|
|
frequency of these requests is determined by
|
|
|
|
`server_typing_started_wait_period_milliseconds` in the
|
|
|
|
`POST /register` response.
|
|
|
|
|
|
|
|
If the "writing user" goes for a while without any text input,
|
|
|
|
then we send a request to `POST /typing` with an `op` of `stop`.
|
|
|
|
The time period a client should wait before sending the request
|
|
|
|
is determined by `server_typing_stopped_wait_period_milliseconds`
|
|
|
|
in the `POST /register` response. We also immediately send "stop"
|
|
|
|
notification when the user explicitly aborts composing a message
|
2017-09-25 20:33:29 +02:00
|
|
|
by closing the compose box (or other actions).
|
|
|
|
|
|
|
|
A common scenario is that a user is just pausing to think for a few
|
2021-08-20 21:53:28 +02:00
|
|
|
seconds, but they still intend to finish the message. Of course,
|
2017-09-25 20:33:29 +02:00
|
|
|
that's hard to distinguish from the scenario of the user got pulled
|
2021-08-20 21:53:28 +02:00
|
|
|
away from their desk. For the former case, where the "writing user"
|
2017-09-25 20:33:29 +02:00
|
|
|
completes the message with lots of pauses for thinking, a series of
|
2021-08-20 21:53:28 +02:00
|
|
|
"start" and "stop" messages may be sent over time. Timeout values
|
2017-09-25 20:33:29 +02:00
|
|
|
reflect tradeoffs, where we have to guess how quickly people type,
|
|
|
|
how long they pause to think, and how frequently they get interrupted.
|
|
|
|
|
|
|
|
## Server
|
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
The server piece of typing notifications is currently pretty
|
2017-09-25 20:33:29 +02:00
|
|
|
straightforward, since we take advantage of Zulip's
|
2022-02-24 00:17:21 +01:00
|
|
|
[events system](events-system.md).
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
We deliberately designed the server piece to be stateless,
|
|
|
|
which minimizes the possibility of backend bugs and gives clients
|
|
|
|
more control over the user experience.
|
|
|
|
|
|
|
|
As such, the server piece here is basically a single Django view
|
|
|
|
function with a small bit of library support to send out events
|
|
|
|
to clients.
|
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
Requests come in to `send_notification_backend`, which is in
|
|
|
|
`zerver/views/typing.py`. For direct message typing notifications,
|
|
|
|
the call to `check_send_typing_notification` does the heavy lifting.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
2023-08-22 16:26:44 +02:00
|
|
|
One of the main things that the server does is to validate that
|
|
|
|
the user IDs in the `to` parameter are for valid, active users in
|
|
|
|
the realm.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
Once the request has been validated, the server sends events to
|
2021-08-20 21:53:28 +02:00
|
|
|
potential recipients of the message. The event type for that
|
|
|
|
payload is `typing`. See the function `do_send_typing_notification`
|
2023-08-22 16:26:44 +02:00
|
|
|
in `zerver/actions/typing.py` for more details.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
## Receiving user
|
|
|
|
|
|
|
|
When a user plays the role of a "receiving user," the client handles
|
|
|
|
incoming "typing" events from the server, and the client will
|
2023-08-22 16:26:44 +02:00
|
|
|
display a typing indicator only when both of these conditions are
|
2017-09-25 20:33:29 +02:00
|
|
|
true:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The "writing user" is still likely typing.
|
|
|
|
- The "receiving user" is in a view where they'd see the eventual
|
2017-09-25 20:33:29 +02:00
|
|
|
message.
|
|
|
|
|
|
|
|
The client code starts by processing events, and it maintains data
|
|
|
|
structures, and then it eventually shows or hides status messages.
|
|
|
|
|
|
|
|
We'll describe the flow of data through the web app
|
|
|
|
as a concrete example.
|
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
The events will come in to `web/src/server_events_dispatch.js`.
|
2017-09-25 20:33:29 +02:00
|
|
|
The `stop` and `start` operations get further handled by
|
2023-02-22 23:03:47 +01:00
|
|
|
`web/src/typing_events.js`.
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
The main goal is then to triage which events should lead to
|
|
|
|
display changes.
|
|
|
|
|
|
|
|
The web app client maintains a list of incoming "typists" using
|
2023-03-11 08:13:37 +01:00
|
|
|
code in `web/src/typing_data.ts`. The API here has functions
|
2017-09-25 20:33:29 +02:00
|
|
|
like the following:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `add_typist`
|
|
|
|
- `remove_typist`
|
|
|
|
- `get_group_typists`
|
2021-03-23 18:13:08 +01:00
|
|
|
- `get_all_direct_message_typists`
|
2017-09-25 20:33:29 +02:00
|
|
|
|
|
|
|
One subtle thing that the client has to do here is to maintain
|
2023-08-22 16:26:44 +02:00
|
|
|
timers for typing notifications. The value of
|
|
|
|
`server_typing_started_expiry_period_milliseconds` in the
|
|
|
|
`POST /register` response is used to determine when the
|
2021-08-20 21:53:28 +02:00
|
|
|
"writing user" has abandoned the message. Of course, the
|
2017-09-25 20:33:29 +02:00
|
|
|
"writing user" will also explicitly send us `stop` notifications
|
|
|
|
at certain times.
|
|
|
|
|
|
|
|
When it finally comes to displaying the notification, the web
|
|
|
|
app eventually calls `render_notifications_for_narrow`.
|
|
|
|
|
|
|
|
## Ecosystem
|
|
|
|
|
|
|
|
Even though the server is stateless, any developer working on
|
|
|
|
a client needs to be mindful of timing/network considerations
|
|
|
|
that affect the overall system.
|
|
|
|
|
|
|
|
In general, client developers should agree on timeout parameters
|
|
|
|
for how frequently we "kickstart" typing notifications for users
|
2021-08-20 21:53:28 +02:00
|
|
|
sending long messages. This means standardizing the "writing
|
|
|
|
user" piece of the system. It's possible that certain clients
|
2017-09-25 20:33:29 +02:00
|
|
|
will have slightly different mechanisms for detecting that users
|
|
|
|
have abandoned messages, but the re-transmit frequency should be
|
|
|
|
similar.
|
|
|
|
|
|
|
|
When implementing the "receiving user" piece, it's important to
|
|
|
|
realize how clients behave on the other end of the protocol. It's
|
|
|
|
possible, for example, to never receive a "stop" notification
|
2021-08-20 21:53:28 +02:00
|
|
|
from a client that was shut down abruptly. You should allow
|
2017-09-25 20:33:29 +02:00
|
|
|
reasonable amounts of time for the other side to send notifications,
|
|
|
|
allowing for network delays and server delays, but you should
|
|
|
|
not let the notifications become too "sticky" either.
|
|
|
|
|
|
|
|
## Roadmap
|
|
|
|
|
|
|
|
The most likely big change to typing indicators is that we will
|
2021-08-20 21:53:28 +02:00
|
|
|
add them for stream conversations. This will require some thought
|
2017-09-25 20:33:29 +02:00
|
|
|
for large streams, in terms of both usability and performance.
|
|
|
|
|
|
|
|
Another area for refinement is to tune the timing values a bit.
|
2023-08-22 16:26:44 +02:00
|
|
|
Right now, we are possibly too aggressive about sending `stop`
|
|
|
|
messages when users are just pausing to think. It's possible
|
2017-09-25 20:33:29 +02:00
|
|
|
to better account for typing speed or other heuristic things
|
|
|
|
like how much of the message has already been typed.
|