Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Added universal macOS binaries of `nac-relay` and `extract-key` to releases
(`macoun-mac-tools-<tag>.tar.gz`). The bridge stays source only.
* Added bubble and screen effects in both directions, through the
`com.beeper.imessage.effect` content key. Outbound effects are sent on text
messages only. See [docs/effects.md](docs/effects.md).
`com.beeper.imessage.effect` content key, on text and attachments. With a
caption the effect rides on the attachment and the caption follows plain.
Not on SMS. See [docs/effects.md](docs/effects.md).
* Fixed members of an iMessage group who never post not appearing in the
Matrix room. Every live group message now joins the members on Apple's
roster.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ supported by Apple Inc. or the Corten-Matrix Project.
| Images, video, audio, files, voice messages | yes | yes |
| Replies | yes | yes |
| Reactions (tapbacks) | yes | yes |
| Bubble and screen effects ([docs/effects.md](docs/effects.md)) | yes, text only | yes |
| Bubble and screen effects ([docs/effects.md](docs/effects.md)) | yes, not on SMS | yes |
| Edits | yes | yes |
| Unsend / redaction | yes | yes |
| Read receipts | yes | yes |
Expand Down
4 changes: 2 additions & 2 deletions docs/bridge-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ iMessage bubble effects (Slam, Loud, Gentle, Invisible Ink) and screen effects
Shooting Star) are bridged both ways through one content key on the message,
`com.beeper.imessage.effect`, whose value is Apple's effect id (the key Beeper's
iMessage bridge uses). The text is unchanged; invisible ink also arrives as a
Matrix spoiler. To send one, set the key on an outgoing text message. Effects
on outgoing attachments and SMS are not sent. Ids, examples and limits:
Matrix spoiler. To send one, set the key on an outgoing text message or
attachment. Effects on SMS are not sent. Ids, examples and limits:
[effects.md](effects.md).

## FaceTime
Expand Down
15 changes: 11 additions & 4 deletions docs/effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ because the bridge reads none from CloudKit.

## Matrix to iMessage

Put the key on an outgoing text message (`m.text`, `m.notice`, `m.emote`) with
an id from the table. `body` is sent unchanged.
Put the key on an outgoing text message (`m.text`, `m.notice`, `m.emote`) or
attachment (`m.image`, `m.video`, `m.audio`, `m.file`) with an id from the
table. `body` is sent unchanged.

```json
{
Expand All @@ -86,12 +87,18 @@ an id from the table. `body` is sent unchanged.
`formatted_body` alone is not turned into invisible ink.
- An unknown id, or a value that is not a string, is logged and the message
goes out without an effect.
- Effects on attachments are not sent.
- On an attachment with a caption (a `body` that differs from `filename`),
the caption goes out as its own iMessage after the attachment, and the
effect rides on the attachment only, so it plays once. A separate `m.text`
sent after the attachment is an ordinary message: put the key on it only if
it should have its own effect.
- A message bound for the text-message relay (SMS) goes out without the
effect, which SMS cannot carry.
- A text long enough to be split carries the effect on its first part only.

Inside the bridge the Go connector passes the effect to `send_message` in
`pkg/rustpushgo/src/lib.rs` as an envelope ahead of the text,
`\x00FX\x01<effect id>\x00`, next to the existing rich-link envelope. Rust
strips it and sets the message's effect.
strips it and sets the message's effect. For an attachment the envelope alone
is `send_attachment`'s `body` argument, split off the same way
(`attachment_effect_and_subject`).
10 changes: 9 additions & 1 deletion pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6782,9 +6782,17 @@ func (c *IMClient) handleMatrixFile(ctx context.Context, msg *bridgev2.MatrixMes

replyGuid, replyPart := extractReplyInfo(msg.ReplyTo)

// An iMessage effect on the event rides on the attachment. A caption sent
// below as its own iMessage goes out plain, so the effect plays once.
var rawContent map[string]any
if msg.Event != nil {
rawContent = msg.Event.Content.Raw
}
effectBody := outboundAttachmentEffect(ctx, rawContent, conv.IsSms)

// Rust-side send_with_flap_retry handles SendTimedOut retry with a stable
// UUID — no Go-side retry here (would orphan delivery receipts).
uuid, err := c.client.SendAttachment(conv, data, mimeType, mimeToUTI(mimeType), fileName, c.handle, replyGuid, replyPart, nil)
uuid, err := c.client.SendAttachment(conv, data, mimeType, mimeToUTI(mimeType), fileName, c.handle, replyGuid, replyPart, effectBody)
if err != nil {
if errors.Is(err, rustpushgo.ErrWrappedErrorNoSmsRelay) {
return nil, errNoCarrierRoute
Expand Down
12 changes: 12 additions & 0 deletions pkg/connector/macoun_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,15 @@ func outboundTextWithEffect(ctx context.Context, raw map[string]any, isSms bool,
// out any id that holds one.
return "\x00FX\x01" + effect + "\x00" + text
}

// outboundAttachmentEffect returns the body argument for SendAttachment: the
// effect envelope alone when the message's content asks for a known effect,
// nil otherwise, under the same rules as outboundTextWithEffect.
// send_attachment splits the envelope off into the message's effect
// (attachment_effect_and_subject in lib.rs).
func outboundAttachmentEffect(ctx context.Context, raw map[string]any, isSms bool) *string {
if body := outboundTextWithEffect(ctx, raw, isSms, ""); body != "" {
return &body
}
return nil
}
20 changes: 20 additions & 0 deletions pkg/connector/macoun_effects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,23 @@ func TestOutboundEffectRefusals(t *testing.T) {
t.Errorf("SMS outbound text = %q, want plain text", sms)
}
}

// A photo or video can carry an effect as well as text: the key on an
// m.image/m.video/m.file event goes to send_attachment as the envelope alone.
func TestOutboundAttachmentEffect(t *testing.T) {
ctx := context.Background()
slam := map[string]any{imessageEffectKey: "com.apple.MobileSMS.expressivesend.impact"}
got := outboundAttachmentEffect(ctx, slam, false)
if got == nil || *got != "\x00FX\x01com.apple.MobileSMS.expressivesend.impact\x00" {
t.Fatalf("outboundAttachmentEffect = %v", got)
}
if got := outboundAttachmentEffect(ctx, slam, true); got != nil {
t.Fatalf("SMS attachment kept the effect: %q", *got)
}
if got := outboundAttachmentEffect(ctx, map[string]any{imessageEffectKey: "com.example.nope"}, false); got != nil {
t.Fatalf("unknown effect kept: %q", *got)
}
if got := outboundAttachmentEffect(ctx, nil, false); got != nil {
t.Fatalf("no effect asked for, got %q", *got)
}
}
25 changes: 20 additions & 5 deletions pkg/rustpushgo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ pub(crate) fn split_effect_envelope(text: String) -> (Option<String>, String) {
(None, text)
}

/// The effect and subject for send_attachment. Its body may start with the
/// effect envelope, which the Go side sends alone for a photo or file that
/// carries an effect; whatever follows the envelope is the subject.
pub(crate) fn attachment_effect_and_subject(body: Option<String>) -> (Option<String>, Option<String>) {
match body {
None => (None, None),
Some(body) => {
let (effect, rest) = split_effect_envelope(body);
(effect, Some(rest).filter(|s| !s.is_empty()))
}
}
}

mod manual_ford {
use super::*;
use aes_siv::{siv::CmacSiv, KeyInit};
Expand Down Expand Up @@ -10599,19 +10612,20 @@ impl Client {
}];

// Captions are sent via the subject field in the iMessage plist,
// not as a separate text part in the XML body.
let subject = body.clone().filter(|s| !s.is_empty());
// not as a separate text part in the XML body. An effect envelope
// ahead of it becomes the message's effect.
let (effect, subject) = attachment_effect_and_subject(body);

let mut msg = MessageInst::new(
conv.clone(),
&handle,
Message::Message(NormalMessage {
parts: MessageParts(parts),
effect: None,
effect,
reply_guid: reply_guid.clone(),
reply_part: reply_part.clone(),
service,
subject,
subject: subject.clone(),
app: None,
link_meta: None,
voice: is_voice,
Expand All @@ -10638,7 +10652,8 @@ impl Client {
idx: None,
ext: None,
}];
let sms_subject = body.filter(|s| !s.is_empty());
// The text-message relay carries no effects.
let sms_subject = subject;
let mut sms_msg = MessageInst::new(
conv,
&handle,
Expand Down
16 changes: 16 additions & 0 deletions pkg/rustpushgo/src/macoun_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ fn macoun_effect_envelope_absent_or_malformed() {
assert_eq!(rest, text);
}
}

#[test]
fn macoun_attachment_effect_and_subject() {
use crate::attachment_effect_and_subject;
// The Go side passes the envelope alone as send_attachment's body.
let (effect, subject) = attachment_effect_and_subject(Some("\u{0}FX\u{1}com.apple.MobileSMS.expressivesend.impact\u{0}".to_string()));
assert_eq!(effect.as_deref(), Some("com.apple.MobileSMS.expressivesend.impact"));
assert_eq!(subject, None);
// Text after the envelope stays the subject, as a body without one does.
let (effect, subject) = attachment_effect_and_subject(Some("\u{0}FX\u{1}com.apple.messages.effect.CKHeartEffect\u{0}Hi".to_string()));
assert_eq!(effect.as_deref(), Some("com.apple.messages.effect.CKHeartEffect"));
assert_eq!(subject.as_deref(), Some("Hi"));
assert_eq!(attachment_effect_and_subject(Some("Hi".to_string())), (None, Some("Hi".to_string())));
assert_eq!(attachment_effect_and_subject(Some(String::new())), (None, None));
assert_eq!(attachment_effect_and_subject(None), (None, None));
}
Loading