2021-07-01 11:49:45 +02:00
|
|
|
# Slash commands
|
|
|
|
|
|
|
|
Slash commands are commands (mainly for power users) to quickly do
|
|
|
|
some stuff from the compose box. The codebase refers to these as "zcommand"s,
|
|
|
|
and both these terms are often user interchangeably.
|
|
|
|
|
|
|
|
Currently supported slash commands are:
|
|
|
|
|
2021-09-12 00:39:46 +02:00
|
|
|
- `/light` and `/dark` to change the UI theme
|
2021-07-01 11:49:45 +02:00
|
|
|
- `/ping` to ping to server and get back the time for the round
|
2021-08-20 22:54:08 +02:00
|
|
|
trip. Mainly for testing.
|
2021-07-01 11:49:45 +02:00
|
|
|
- `/fluid-width` and `/fixed-width` to toggle that setting
|
|
|
|
|
|
|
|
It is important to distinguish slash commands from the
|
|
|
|
[widget system](/subsystems/widgets.md). Slash commands essentially
|
|
|
|
**do not send** messages (and could have very well had their
|
|
|
|
own "command prompt" (but don't), since they have nothing to do with
|
|
|
|
message sending), while widgets are special kinds of messages.
|
|
|
|
|
|
|
|
### Data flow
|
|
|
|
|
|
|
|
These commands have client-side support in `zcommands.js`.
|
|
|
|
They send commands to the server using the `/json/command`
|
|
|
|
endpoint.
|
|
|
|
|
|
|
|
In the case of "/ping", the server code in `zcommand.py`
|
2021-08-20 21:53:28 +02:00
|
|
|
basically just acks the client. The client then computes
|
2021-07-01 11:49:45 +02:00
|
|
|
the round trip time and shows a little message above
|
|
|
|
the compose box that the user can see and then dismiss.
|
|
|
|
|
2021-09-12 00:39:46 +02:00
|
|
|
For commands like "/light" and "/dark", the server does
|
2021-11-18 11:44:31 +01:00
|
|
|
a little bit of logic to toggle the user's dark theme
|
2021-07-01 11:49:45 +02:00
|
|
|
setting, and this is largely done inside `zcommand.py`.
|
|
|
|
The server sends a very basic response, and then
|
2021-08-20 21:53:28 +02:00
|
|
|
the client actually changes the display colors. The
|
2021-07-01 11:49:45 +02:00
|
|
|
client also shows the user a little message above
|
|
|
|
the compose box instructing them how to reverse the
|
|
|
|
change.
|
|
|
|
|
|
|
|
(It's possible that we don't really need a general
|
|
|
|
`/json/zcommand` endpoint for these, and we
|
|
|
|
may decide later to just use custom
|
2021-08-20 21:53:28 +02:00
|
|
|
API endpoints for each command. There's some logic
|
2021-07-01 11:49:45 +02:00
|
|
|
in having a central API for these, though, since they
|
|
|
|
are typically things that only UI-based clients will
|
|
|
|
invoke, and they may share validation code.)
|
|
|
|
|
|
|
|
It is the client's responsibility to correctly detect and
|
|
|
|
process when a user uses a slash command, and not instead
|
|
|
|
send a message with the raw content.
|
|
|
|
|
|
|
|
## Typeahead
|
|
|
|
|
|
|
|
Typeahead for both slash commands (and widgets) is implemented
|
|
|
|
via the `slash_commands` object in `static/js/composebox_typeahead.js`.
|