README.md

1aebd1afe96d6b9a2f26ca598c88d5aae0ba5008
weechat-matrix-rs/README.md rendered · source · history · blame · raw

327 lines · 12954 bytes

11 symbols in this file
  1[![build-test-release](https://github.com/poljar/weechat-matrix-rs/actions/workflows/release.yml/badge.svg?event=push)](https://github.com/poljar/weechat-matrix-rs/actions/workflows/release.yml)
  2[![#weechat-matrix](https://img.shields.io/badge/matrix-%23weechat--matrix:termina.org.uk-blue.svg?style=flat-square)](https://matrix.to/#/!twcBhHVdZlQWuuxBhN:termina.org.uk?via=termina.org.uk&via=matrix.org)
  3[![license](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)](https://github.com/poljar/weechat-matrix-rs/blob/master/LICENSE)
  4
  5# What is weechat-matrix?
  6
  7[Weechat](https://weechat.org/) is an extensible chat client.
  8
  9[Matrix](https://matrix.org/blog/home) is an open network for secure,
 10decentralized communication.
 11
 12weechat-matrix-rs is a Rust plugin for Weechat that lets Weechat communicate
 13over the Matrix protocol. This is a Rust rewrite of the
 14[weechat-matrix](https://github.com/poljar/weechat-matrix) Python script.
 15
 16# Project status
 17
 18This project is a work in progress and doesn't do much yet. It can connect
 19to a Matrix server and send messages.
 20
 21It is not an IRC relay or bridge: IRC clients connected through WeeChat's relay
 22plugin cannot use Matrix rooms as IRC channels. Remote WeeChat interfaces using
 23WeeChat relay protocols can access plugin buffers, but Matrix features that
 24rewrite already-printed lines, such as message edits and redactions, depend on
 25the remote client supporting WeeChat relay line-update events.
 26
 27If you are interested in helping out take a look at the issue tracker.
 28
 29# Build
 30
 31Install Rust and the native build dependencies first. On Debian or Ubuntu a
 32typical build environment needs:
 33
 34    sudo apt install \
 35      build-essential \
 36      clang \
 37      libclang-dev \
 38      libsqlite3-dev \
 39      pkg-config \
 40      weechat-dev
 41
 42Other distributions use different package names, but the important native
 43pieces are a C/C++ compiler, `clang`/`libclang`, and SQLite development headers.
 44The `weechat-sys` dependency has a bundled WeeChat plugin header
 45(`weechat-plugin.h`) fallback. If you want to build against the exact WeeChat
 46API installed on your system, install the matching development package
 47(`weechat-dev` on Debian/Ubuntu) or point `WEECHAT_PLUGIN_FILE` at the full
 48path to that header:
 49
 50    export WEECHAT_PLUGIN_FILE=/usr/include/weechat/weechat-plugin.h
 51
 52Use the same WeeChat API headers as the WeeChat binary that will load the
 53plugin. If WeeChat reports an API mismatch while loading `matrix.so`, rebuild
 54after installing the matching development package or setting
 55`WEECHAT_PLUGIN_FILE`. Set `WEECHAT_BUNDLED=1` only when you deliberately want
 56to build against the bundled fallback header, for example in a controlled test
 57or package build.
 58
 59If `bindgen` reports that `stddef.h`, `libclang`, or `libLLVM` is missing, check
 60that the `clang` command-line tools, C/C++ compiler headers, and matching
 61`libclang` package are installed. On minimal distributions the library package
 62alone may not provide the compiler include paths that `bindgen` needs.
 63Use a coherent `clang`/`libclang`/`libLLVM` set from the same toolchain; copying
 64only one shared library from another package or SDK can leave `bindgen` loading
 65an incompatible LLVM library.
 66
 67After the dependencies are installed the plugin can be compiled with:
 68
 69    cargo build --release
 70
 71You do not need to clean the `target/` directory before each build. Reusing it
 72lets Cargo keep compiled dependencies and makes rebuilds faster. Use
 73`cargo clean` or `make clean` only when you deliberately want to discard build
 74artifacts.
 75
 76If you are developing on weechat-matrix-rs, use debug builds which are faster at
 77the expense of plugin performance:
 78
 79    cargo build
 80
 81On Linux this creates a `libmatrix.so` file in the `target/release/`
 82(`target/debug` for dev builds) folder. Rename it to `matrix.so` and copy it to
 83your WeeChat plugin directory.
 84
 85`make install` installs the plugin systemwide:
 86
 87    sudo make install
 88
 89On Debian-like multiarch systems this installs the release build to:
 90
 91    /usr/lib/${DEB_HOST_MULTIARCH}/weechat/plugins/matrix.so
 92
 93On other systems it defaults to:
 94
 95    /usr/lib/weechat/plugins/matrix.so
 96
 97Set `WEECHAT_PLUGIN_DIR` if your distribution uses another system plugin
 98directory:
 99
100    sudo make install WEECHAT_PLUGIN_DIR=/path/to/weechat/plugins
101
102To install only for the current user, use:
103
104    make install-user
105
106This installs the release build to:
107
108    ${XDG_DATA_HOME:-$HOME/.local/share}/weechat/plugins/matrix.so
109
110Use `PROFILE=debug` for a debug build:
111
112    make install-user PROFILE=debug
113
114The matching uninstall targets are:
115
116    sudo make uninstall
117    make uninstall-user
118
119On older WeeChat setups the plugin directory may instead live under
120`$WEECHAT_HOME/plugins`, commonly `~/.weechat/plugins/`. Create the directory if
121needed and copy the renamed plugin there.
122
123On macOS the built library extension is usually `.dylib`. WeeChat may need this
124extension enabled before it loads the plugin:
125
126    /set weechat.plugin.extension ".so,.dll,.dylib"
127
128Rename `target/release/libmatrix.dylib` to `matrix.dylib` before copying it to
129your WeeChat plugin directory.
130
131# Debian / Ubuntu package
132
133A `.deb` package can be built using `cargo-deb`. This requires
134[Rust installed](https://rustup.rs/) (via rustup, the recommended method).
135
136First ensure `cargo-deb` is available:
137
138    cargo install cargo-deb
139
140Then build the package with:
141
142    make deb
143
144The resulting `.deb` package is placed in `target/debian/`. Install it with:
145
146    sudo dpkg -i target/debian/weechat-matrix-rs_*.deb
147
148# Loading the plugin
149
150Restart WeeChat after installing the plugin, or load it manually:
151
152    /plugin load matrix
153
154Check that it is loaded with:
155
156    /plugin list
157
158If WeeChat cannot find the plugin, check that the file is named `matrix.so`
159(`matrix.dylib` on macOS), that it is in a directory from WeeChat's plugin
160search path, and that `.so`/`.dylib` is enabled in
161`weechat.plugin.extension`.
162
163# Configuration
164
165Configuration is completed primarily through the Weechat interface. First start
166WeeChat, make sure the plugin is loaded, and then issue the following commands
167_(replace the placeholders in brackets [] with your own details)_:
168
1691. Add a server _(make sure the url includes the scheme e.g. 'https://matrix.org')_:
170
171       /matrix server add [server-name] [server-url]
172
1732. Set your username and password:
174
175       /set matrix-rust.server.[server-name].username [username]
176       /set matrix-rust.server.[server-name].password [password]
177
178   If the homeserver advertises single sign-on, leave the password empty to use
179   it. WeeChat will print a login URL when you connect.
180
181   The SSO callback listens on `127.0.0.1:29325` on the WeeChat host. When
182   WeeChat runs on another machine, create an SSH tunnel before connecting so
183   the browser's localhost callback reaches it:
184
185       ssh -L 29325:127.0.0.1:29325 user@weechat-host
186
1873. Now try to connect. The first connection can take a few minutes while the
188   client syncs the account:
189
190       /matrix connect [server-name]
191
1924. Automatically connect to the server:
193
194       /set matrix-rust.server.[server-name].autoconnect on
195
1965. If everything works, save the configuration:
197
198       /save
199
200To hide join/leave noise from users who have not been active recently, add a WeeChat
201filter for Matrix smart-filter tags:
202
203       /filter add matrix_smart * matrix_smart_filter *
204
205The inactivity delay defaults to five minutes and can be changed with:
206
207       /set matrix-rust.look.smart_filter_delay 300000
208
209Recent replies can be rendered on one line in the form `> Alice: message`. By
210default, weechat-matrix-rs keeps the Matrix reply fallback quote when one is
211available. Set a positive threshold to render replies to recently printed lines
212in the compact one-line form:
213
214       /set matrix-rust.look.reply_full_quote_threshold 20
215
216# Room Status And Verification
217
218The `buffer_modes` bar item shows Matrix room state. Encrypted rooms show
219`matrix-rust.look.encrypted_room_sign`; encrypted rooms that still contain
220unverified devices also show `matrix-rust.look.encryption_warning_sign`. Public
221rooms show `matrix-rust.look.public_room_sign`, and busy rooms show
222`matrix-rust.look.busy_sign`.
223
224Interactive verification requests can be accepted, confirmed, or cancelled from
225the room or verification buffer:
226
227       /verification accept
228       /verification confirm
229       /verification cancel
230
231The plugin renders in-room SAS verification requests and shows the emoji or
232decimal short authentication string when it is ready.
233
234# Matrix Spaces
235
236Space buffers use a `+` prefix in their short name, while ordinary room buffers
237keep the `#` prefix and direct-message buffers stay unprefixed.
238
239Room buffers expose Matrix parent Spaces as WeeChat local variables. Switch to a
240room buffer that belongs to a Space and run:
241
242       /buffer listvar
243
244Look for `space`, `space_id`, `spaces`, and `space_ids`. The singular variables
245hold the first parent Space name and room id; the plural variables contain all
246known parent Spaces as comma-separated lists.
247
248The buflist plugin will not reorganize Matrix rooms under Spaces by itself.
249These variables are available to scripts and custom buflist formats. For
250example, to prefix Matrix room names with their first parent Space:
251
252       /set buflist.format.name "${if:${space}?${space}/${name}:${name}}"
253       /buflist refresh
254
255Remove that prefix again with:
256
257       /unset buflist.format.name
258
259Matrix rooms can belong to more than one Space. WeeChat buffers cannot be shown
260as the same room under multiple server-like parents at the same time, so the
261plugin exposes all known parent Spaces as metadata instead of moving room
262buffers into a fake hierarchy. Matrix Space buffers use a `+` short-name prefix;
263ordinary rooms keep the usual room/channel naming rules.
264
265# Storage
266
267The plugin keeps Matrix state and encryption data in
268`$WEECHAT_HOME/matrix-rust/<server>/`. It keeps the Matrix SDK event cache in
269`$WEECHAT_HOME/matrix-rust/<server>-cache/`.
270
271If the cache grows or causes too much disk I/O, disconnect WeeChat and remove
272only the `-cache` directory. Do not remove the main server directory unless you
273want to reset stored Matrix state.
274
275# Troubleshooting
276
277If startup or login fails with a Matrix SDK state-store decode error, first make
278sure the plugin was built from current sources and try starting WeeChat again so
279SDK migrations can run. If the same error still stops login, disconnect WeeChat
280and move `$WEECHAT_HOME/matrix-rust/<server>/` aside before reconnecting. This
281resets the stored Matrix state for that server, including encryption/session
282data, so keep the old directory until the new login is verified.
283
284For crashes, aborts, or a blocked WeeChat UI during startup or `/quit`, collect
285a full thread backtrace from another shell while the process is still stopped or
286blocked:
287
288       gdb -p $(pidof weechat) -batch -ex 'thread apply all bt'
289
290A short `bt` from the crashing thread is often not enough to tell whether the
291Matrix plugin, WeeChat itself, another plugin, or shutdown cleanup owns the
292block.
293
294Nick prefix colors for Matrix power levels can be changed with:
295
296       /set matrix-rust.color.nick_prefix_admin lightgreen
297       /set matrix-rust.color.nick_prefix_moderator lightmagenta
298       /set matrix-rust.color.nick_prefix_power yellow
299
300Existing nicklist entries may need a member update or plugin restart before the new colors or nick format are visible.
301
302Matrix member nicknames default to display names. To include MXID parts in chat,
303the nicklist, `/names`, and nick completion, set `matrix-rust.look.nick_format`:
304
305       /set matrix-rust.look.nick_format "%u (%d)"
306
307Supported placeholders are `%d` for display name, `%m` for full MXID, `%u` for
308MXID localpart, and `%h` for homeserver.
309
310# Helpful Commands
311
312`/help matrix` will print information about the `/matrix` command.
313
314`/matrix help [command]` will print information for subcommands, such as `/matrix help server`.
315
316`/matrix threads list [all|participated]` lists the thread roots of the current room, most recent activity first, using the `/_matrix/client/v1/rooms/{roomId}/threads` endpoint. `/matrix threads more` fetches the next page of that listing and `/matrix threads open <n>` opens one of the listed threads in a thread buffer.
317
318Room buffers accept normal message input after `/matrix connect [server-name]`
319has completed.
320
321`/matrix media download <mxc-uri> [file]` downloads Matrix media through the logged-in client, including homeservers that require authenticated media. It refuses to overwrite an existing file. When `[file]` is omitted, the media id is saved with the configured prefix, which defaults to `matrix-media-`:
322
323       /set matrix-rust.media.download_prefix matrix-media-
324
325The prefix may include a directory and supports `~`, `$XDG_STATE_HOME`, and `${XDG_STATE_HOME}`. Parent directories are created automatically:
326
327       /set matrix-rust.media.download_prefix "$XDG_STATE_HOME/weechat-matrix/media/matrix-media-"