1
0
Fork 0
Commit Graph

146 Commits

Author SHA1 Message Date
nicoco c0184186d8 chore: update poetry.lock 2023-08-12 11:52:08 +01:00
Alex Palaistras 0d575171cc Also re-subscribe to contact presences on refresh
Background presence refresh appears to be insufficient if only applied
to our *own* presence; contact presences must also be re-subscribed to.
2023-08-12 11:08:42 +01:00
nicoco d0d691eb4a fix: gateway status stuck at 'QR scan needed' on re-pair
Fixes: https://todo.sr.ht/~nicoco/slidge-whatsapp/12
2023-08-06 23:37:35 +02:00
Alex Palaistras f9880e35d7 Handle sent contact messages as vCard attachments
Incoming contact messages, with are represented as their own message
type in WhatsApp, are now handled as bog-standard attachments of the
equivalent contact vCard, which is helpfully provided by WhatsApp
itself.
2023-08-06 22:17:38 +01:00
Alex Palaistras 366413e4d3 Update to latest version of WhatsMeow 2023-08-06 21:29:37 +01:00
Alex Palaistras ac4e9ac2af Return original attachment on conversion failure
Failure to convert media is intended to be non-fatal, as original media
may still be usefully displayed to remote contacts; this commit fixes
an oversight in returning the original attachment in failures to convert
media.
2023-08-06 21:22:25 +01:00
Alex Palaistras 9ddc4d5823 Reduce presence refresh interval to 6 hours
This is reduced from 24 hours, and is intended as an experimental fix
for issues seen where contact presences will stop updating after an
approximate 24 hours.
2023-08-04 19:44:21 +01:00
Alex Palaistras 5473f25a24 Implement on-the-fly outgoing media conversion
WhatsApp clients are set to accept only a specific set of media files as
image, audio, or video messages, specifically:

  - Images must be in JPEG (non-progressive) format.
  - Audio messages must be in Opus-encoded Ogg if sent as voice messages,
    otherwise may be in MP3 or AAC format if not (though client support
    may vary).
  - Video messages must be in h264-encoded MP4, with some additional
    constraints on color format and profile used.

Several edge-cases exist, e.g. with GIF files needing to be re-encoded
as MP4 in order to be animated (and requiring extra metadata in messages
to be called out as such).

This commit implements a somewhat comprehensive media conversion scheme,
built upon FFmpeg for audio and video, and native Go facilities for
images, based on the source format. Specifically:

  - Audio files in `audio/mp4` or `audio/aac` format (corresponding to
    formats commonly used in Android and iOS XMPP clients, respectively)
    are automatically re-encoded as Opus-encoded voice messages.

  - Audio files in `audio/mpeg` (i.e. MP3 files) or `audio/ogg` format
    are sent as plain audio files in their own format, with varying client
    support assumed.

  - Images in `image/png` or `image/webp` format are automatically
    re-encoded as JPEG image messages. Conversely, images in `image/gif`
    format are re-encoded as MP4 video messages with auto-play enabled.

  - Videos in `video/webm` or `video/mp4` format are automatically
    re-encoded as MP4 video messages (the latter is re-encoded to ensure
    option compatibility).

As stated above, all audio and video conversions require FFmpeg and
FFprobe to be installed, and, if missing, will leave attachments
unchanged (which may result these being sent as binary files). Image
conversions do not rely on any external functionality, however.

Current limits are: 10MiB for images and 20MiB for audio and video
files; above these conversions will fail and original files will be sent
instead.

Future commits may see compatibility improved, or semantics corrected
where these do not match expectations on the WhatsApp side.
2023-07-22 09:58:22 +01:00
Alex Palaistras e7ae695531 Periodically refresh own presence with WhatsApp
Our presence is always initially set to "available" when connecting to
WhatsApp, but can also be set manually by users via the `presence`
ad-hoc command. Irrespective of its value, however, it seems that we're
required to periodically re-send our presence to WhatsApp, as it
otherwise will consider our session inactive and will stop sending
presence information for contacts, among other things.

This commit implements a background refresh task that operates on a
rolling interval of 24±12 hours, each iteration happening somewhere in
that range. It is intended that this interval is low enough to fulfil
requirements set by remote WhatsApp servers, while being high enough to
avoid inundating with requests; future commits may amend this value.
2023-07-14 21:19:13 +01:00
Alex Palaistras 576929bdf2 Use `PresenceKind` for `EventPresence`
This helps make use of presence consistent between incoming and outgoing
events.
2023-07-14 19:03:37 +01:00
nicoco d6e178605b fix: mypy
dammit commit-hook, how did you let that slip through?
2023-07-14 15:02:16 +02:00
nicoco 9526b39fc3 bump poetry.lock 2023-07-13 09:21:49 +02:00
nicoco b278abc485 bump whatsmeow 2023-07-13 09:19:30 +02:00
nicoco 924bc88e92 Add user commands for presence and presence subscription handling
References: https://todo.sr.ht/~nicoco/slidge-whatsapp/7
References: https://todo.sr.ht/~nicoco/slidge-whatsapp/1
2023-07-13 09:19:30 +02:00
nicoco 0179740b87 Expose SendPresence to python 2023-07-12 17:08:40 +02:00
Alex Palaistras b357cc911f Handle all exception types in URL preview failures 2023-07-11 20:50:59 +01:00
nicoco 6e57e0f8b3 Do not fail to send URL if previewing fails
This can happen when sending URLs pointing
to images, for instance.
2023-07-01 20:54:01 +02:00
nicoco 516d4d2647 Bump whatsmeow 2023-07-01 20:52:21 +02:00
nicoco c8fb2d9a33 Do not try to remove files that have been moved 2023-06-26 06:40:35 +02:00
nicoco 35918a627b update copier template 2023-06-23 23:24:29 +02:00
nicoco a40f397a71 update copier-answers 2023-06-23 23:24:29 +02:00
nicoco a14eb9f1a0 bump deps 2023-06-23 22:52:45 +02:00
nicoco 4c133c353b Write temp files to disk for WA->XMPP attachments
instead of passing bytes via RAM
cf https://github.com/go-python/gopy/issues/323

References: https://todo.sr.ht/~nicoco/slidge-whatsapp/5
2023-06-23 22:52:22 +02:00
nicoco d7b8105d88 Add gofmt pre-commit hook 2023-06-23 22:52:02 +02:00
Alex Palaistras cb55ab1d7e Update dependencies 2023-06-21 11:55:56 +01:00
Alex Palaistras 7140b36b24 Implement message correction support
Recent WhatsApp versions have begun allowing for message
correction/editing support; this commit integrates this official support
into pre-existing support for XEP-0308 (Message Correction) in Slidge.

Both incoming and outgoing message corrections are supported. However,
there are currently known issues with corrections made on own messages
in the official WhatsApp client, which are not reflected in XMPP
clients; these will be corrected in future commits.
2023-06-20 13:47:26 +01:00
Alex Palaistras a83b656779 Update poetry.lock
This updates Slidge to the latest `master` tag.
2023-06-18 21:45:28 +01:00
Alex Palaistras 868dd3f6ae Use local Slidge Core mount for development
Core changes are reflected in our development containers via a
locally-cloned `slidge` repository, adjacent to this repository.
2023-06-18 21:43:35 +01:00
Alex Palaistras 1f50157537 Add support for incoming sticker messages
These are simply parsed as image attachments for their given MIME type
and a random filename.
2023-06-16 20:57:57 +01:00
Alex Palaistras f7e06e9828 Update Go module name for consistency
The module name itself is only really used internally, but is worth
keeping up-to-date with overarching changes to code organization.
2023-06-16 20:08:57 +01:00
Alex Palaistras ab6192436c Clean up Dockerfile for local development
Local development was subtly broken with our recent split, and this
commit fixes this.
2023-06-16 20:04:23 +01:00
nicoco 0f84ff3d58 Fix mentions in quoted body 2023-06-12 08:52:56 +02:00
nicoco c624925af8 Refactor: improve logout/unregister
https://todo.sr.ht/~nicoco/slidge-whatsapp/3
2023-06-11 15:40:58 +02:00
nicoco b155fb0ef7 Update whatsmeow 2023-06-11 14:59:07 +02:00
nicoco 93497e8616 Update copier 2023-06-11 14:59:07 +02:00
nicoco 72c62c9bb6 DOAP: add note about markers in groups 2023-06-11 14:06:02 +02:00
nicoco 49f140d74b Update poetry.lock 2023-06-11 14:05:46 +02:00
nicoco ca80140a12 Use session-wide lock in (some) whatsapp event handler
Fixe: https://todo.sr.ht/~nicoco/slidge/164
2023-06-03 11:25:38 +02:00
nicoco 4aee8e0417 Update poetry.lock 2023-05-14 14:04:41 +02:00
nicoco febae23902 Use slidge master branch 2023-05-14 14:04:13 +02:00
nicoco 5d5d1d39fb fix dev container 2023-05-13 17:09:53 +02:00
nicoco 441ce5f10e bump dependencies 2023-05-06 09:34:53 +02:00
nicoco 241923e205 Fix doap.xml 2023-05-06 09:27:21 +02:00
nicoco 9e59c331e2 Parse mentions in captions of attachments 2023-05-02 17:35:44 +02:00
nicoco cc7706e4b2 Parse mentions in reply to fallback body 2023-05-01 17:31:56 +02:00
nicoco f0ffdaa0be Initial commit (split from slidge core) 2023-05-02 16:35:30 +02:00