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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
sudo apt-get update -qq
sudo apt-get install -y -q qt6-declarative-dev-tools qml6-module-qttest qml6-module-qtquick qml6-module-qtquick-window qml6-module-qtqml-workerscript
python3 scripts/test-read-ui.py
- name: Send service wiring (synthetic QtTest, real BlipView functions)
run: python3 scripts/test-send-service-ui.py
- name: Composer emoji keyboard regression
run: |
sudo apt-get install -y -q qml6-module-qtquick-controls qml6-module-qtquick-templates
Expand Down
31 changes: 26 additions & 5 deletions BlipView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,26 @@ FocusScope {
// root.active can change under a multi-part send, and a later part must not
// go out on a different service from the first (war room #2).
property string sendService: ""
// What the open conversation's own rows say to send on (thread.ts `service`)
// and the chat they were loaded for. SendState.sendServiceArg prefers it over
// the list row's service, which is the Mac's chat label and goes stale when a
// contact moves to Android.
property string threadSendService: ""
property string threadSendServiceChat: ""

/** Keep thread.ts's `service` with the chat it was loaded for. It is "" when
* the rows named none: a group, or no rows under the id we send to. */
function noteThreadService(chat, service) {
root.threadSendServiceChat = String(chat || "")
root.threadSendService = String(service || "")
}

/** The --service a send to `chat` carries, through SendState.sendServiceArg:
* the loaded rows' answer when they belong to `chat`, else the list label. */
function sendServiceFor(chat) {
return SendState.sendServiceArg(String(chat), root.activeIsGroup,
String(root.active.service || ""), root.threadSendServiceChat, root.threadSendService)
}
// Sends the Mac has not written a row for yet, {chat, text, ts}. Every
// thread reload carries them to thread.ts (--pending-stdin, never argv),
// which keeps their bubbles until the real row lands. Memory only.
Expand Down Expand Up @@ -1704,8 +1724,7 @@ FocusScope {
// strictly one at a time — pumpFileSend() starts the next as each lands.
root.fileQueue = root.attachDrafts.map(function(d) { return d.path })
root.sendCaption = trimmed
var svc = String(root.active.service || "")
root.sendService = /^(SMS|RCS)$/i.test(svc) ? svc.toUpperCase() : ""
root.sendService = root.sendServiceFor(root.sendChat)
pumpFileSend()
return
}
Expand All @@ -1718,9 +1737,10 @@ FocusScope {
var target = root.activeIsGroup
? ["--chat-id", String(root.active.guid)]
: ["--to", chat]
// green-bubble (SMS/RCS) threads send on their own service (war room #2)
var svc = String(root.active.service || "")
if (!root.activeIsGroup && /^(SMS|RCS)$/i.test(svc)) target = target.concat(["--service", svc.toUpperCase()])
// green-bubble (SMS/RCS) threads send on their own service (war room #2),
// read from the conversation's own rows once they have loaded
var svc = root.sendServiceFor(chat)
if (svc !== "") target = target.concat(["--service", svc])
var localId = String(++root.nextSendId)
root.pendingRevision++
root.pendingSends = root.pendingSends.concat([{ chat: chat, text: text, ts: stamp, localId: localId }])
Expand Down Expand Up @@ -1901,6 +1921,7 @@ FocusScope {
var d = JSON.parse(text.trim())
if (d.ok === true) {
var list = Array.isArray(d.bubbles) ? d.bubbles : []
root.noteThreadService(root.threadRunningChat, d.service)
root.pendingTapback = TapbackActions.pendingAfterLoad(root.pendingTapback, root.threadRunningChat, list, root.threadTapbackDone)
// the tool is done but chat.db does not show it yet (a self-thread's echo lags): look again
if (root.threadTapbackDone && root.pendingTapback && root.pendingTapback.chat === root.threadRunningChat) {
Expand Down
19 changes: 19 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ what it is handed. Keep it that way.
bubble until a real from-me row with the same text lands, resolving one
send per row. The read watermark (`--seen`) skips pending bubbles: their ts
is THIS machine's clock. A failed send retains its bubble with a failure reason in memory. Never go back to "wait 1.5 s, then reload".
- **A DM sends on what its own messages say, never on the Mac's chat label.** `imsg chats` reports the
chat row's `service_name`. On a gateway where one row holds the whole conversation (observed on macOS
27.2), that label follows the Mac's OWN last send, Blip's included, so trusting it loops. On 2026-11-12, a
contact texting on RCS stayed labelled iMessage and every send failed with error 22. Another stayed
labelled SMS and got plain SMS. `sendServiceForMessages` decides from rows in two places. In the
collector it reads the preview window: `mergeChats` keeps that answer for every DM with rows under its
own id, and the label names only the rest. In `thread.ts` it reads the opened conversation
(`threadSendService`) and reports it as `service`, which BlipView prefers through
`SendState.sendServiceArg`. #97, #147 and #151 each guarded one direction of this same loop.
**Only rows under the id the send goes `--to` count** (`target`; `foldThreadAliases` keeps the
canonical's own service). A merged phone + email conversation carries both handles' rows. Deciding from
all of them sent SMS to the email, and iMessage to an Android number after they last wrote from the
email (#165 review). No own rows means no answer, and the label stands. An address that is not a phone
number never gets SMS. It gets RCS only after texting us on RCS, as `name@rbm.goog` business agents do.
Our iMessage that provably arrived (delivered or read) after their last text keeps a quiet blue DM
blue. A read receipt outranks `error` (`sendFailed`) only for SMS and RCS in a 1:1, because the Mac
logs error 4 on plain SMS it relays to an RCS contact and the iPhone delivers it anyway. Thread loads
are `--rich` and carry the receipt. The collector's `recent` rows are not, so its failure toast still
fires for that SMS.
- **A Mac that is signed out READS fine and cannot SEND.** Reads are sqlite over ssh and need no login; a send
needs Messages, and Launch Services starts an app only inside a GUI session, so at the login window every send
dies with -10810 (`friendlySendError` says it in plain words). `imsg session` is the read-only probe
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ prefer_imessage=on

A thread with a successful iMessage in the loaded window then stays
iMessage. A never-iMessage RCS/SMS thread stays green. A failed iMessage to
a phone still flips to SMS so the send does not stick. Groups are unchanged
a phone still flips the next send to RCS, if that is how they last texted
you, or to SMS, so the send does not stick. Groups are unchanged
(they send by chat id). Default is off.

**Tapbacks (experimental).** Right-click a message, or select it
Expand Down
11 changes: 10 additions & 1 deletion SendState.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ function markSendFailed(items, id, reason, fallback) {
const current = fallback && !items.some((item) => item.localId === id) ? items.concat([fallback]) : items;
return current.map((item) => item.localId === id ? Object.assign({}, item, { failed: true, failureReason: safeReason }) : item);
}
function sendServiceArg(chat, group, listService, loadedChat, loadedService) {
if (group)
return "";
const svc = (loadedChat === chat && loadedService !== "" ? loadedService : listService).toUpperCase();
if (svc === "RCS")
return svc;
return svc === "SMS" && /^\+?[0-9]{3,15}$/.test(chat) ? svc : "";
}
function friendlySendError(raw) {
return /(^|[^\d])-10810(\D|$)/.test(raw) ? "Messages can't start on the Mac: nobody is logged in there. Log in on the Mac, then send again." : raw;
}
export {
friendlySendError,
markSendFailed
markSendFailed,
sendServiceArg
};
147 changes: 142 additions & 5 deletions collector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,11 @@ describe("failed-delivery detection", () => {
expect(selectFailures([mine({ error: 25, ts: "2026-08-31T19:00:00Z" })], [], now).length).toBe(0);
});

test("a row the recipient has read is no failure, whatever error the Mac logged", () => {
expect(selectFailures([mine({ service: "SMS", error: 4, read_at: "2026-08-31T20:25:06Z" })], [], now).length).toBe(0);
expect(selectFailures([mine({ service: "SMS", error: 4 })], [], now).length).toBe(1);
});

test("dedupes through the toasted ring — interrupts exactly once", () => {
const first = selectFailures([mine({ error: 25 })], [], now);
const again = selectFailures([mine({ error: 25 })], first.map((f) => f.key), now);
Expand Down Expand Up @@ -1409,6 +1414,22 @@ describe("a re-keyed group is ONE conversation", () => {
expect(out).toHaveLength(1);
expect(out[0]).toMatchObject({ chat: email, last_ts: "2026-09-05T17:24:01Z", unread: 1 });
});

// #165 review: a DM sends `--to <canonical>`, so an alias's service, the
// other handle of a merged phone + email conversation, must not ride along.
test("a merged DM keeps the canonical's own service, never the alias's", () => {
const phone = "+15550100001";
const email = "pat@example.com";
const sms = (c: string, ts: string) => ({ ...(thread(c, ts, 1, 0) as object), service: "SMS" }) as never;
const newerAlias = foldThreadAliases(
[thread(email, "2026-09-04T21:32:29Z", 3, 0), sms(phone, "2026-09-05T17:24:01Z")],
{ [phone]: email },
);
expect(newerAlias[0]).toMatchObject({ chat: email, service: "iMessage" });
// the canonical has no rows in the window: unknown, so the label decides
const aliasOnly = foldThreadAliases([sms(phone, "2026-09-05T17:24:01Z")], { [phone]: email });
expect(aliasOnly[0]).toMatchObject({ chat: email, service: "" });
});
});

describe("complete conversation list (mergeChats)", () => {
Expand Down Expand Up @@ -1512,14 +1533,38 @@ describe("complete conversation list (mergeChats)", () => {
expect(mergeChats([windowThread], [unified], {}, {})[0]!.service).toBe("iMessage");
});

test("a genuinely green DM still takes its service from the list", () => {
const green = { ...windowThread, chat: "+15559990000", service: "SMS" };
expect(mergeChats([green], [chats[2]!], {}, {})[0]!.service).toBe("SMS");
test("a DM whose own id has no rows in the window takes the label", () => {
// what foldThreadAliases leaves when only an alias had rows
const unknown = { ...windowThread, service: "" };
expect(mergeChats([unknown], [{ ...chats[0]!, service: "SMS" }], {}, {})[0]!.service).toBe("SMS");
});

test("the list may still move a DM the other way, onto iMessage", () => {
// Live shapes (2026-11-12, a macOS 27.2 gateway). Two Android contacts, both
// texting on RCS, so the window says RCS. One chat row's label said
// iMessage, so with their reply the newest row, every send went out as
// iMessage and failed with error 22. The other's label said SMS, so every
// send went out as plain SMS, which the Mac logged as error 4. The label
// follows the Mac's own last send, so it never corrected itself.
test("an RCS contact whose chat row still says iMessage is sent RCS", () => {
const rcs = { ...windowThread, service: "RCS" };
const label = { ...chats[0]!, service: "iMessage", last_from_me: false };
expect(mergeChats([rcs], [label], {}, {})[0]!.service).toBe("RCS");
});

test("an RCS contact whose chat row says SMS is sent RCS", () => {
const rcs = { ...windowThread, service: "RCS" };
const label = { ...chats[0]!, service: "SMS" };
expect(mergeChats([rcs], [label], {}, {})[0]!.service).toBe("RCS");
});

test("the label cannot move a DM with rows onto iMessage either", () => {
const green = { ...windowThread, service: "SMS" };
expect(mergeChats([green], [chats[0]!], {}, {})[0]!.service).toBe("iMessage");
expect(mergeChats([green], [chats[0]!], {}, {})[0]!.service).toBe("SMS");
});

test("a quiet DM the window has no rows for still takes the list's service", () => {
const out = mergeChats([windowThread], chats, {}, {});
expect(out.find((t) => t.chat === "+15559990000")!.service).toBe("SMS");
});

// Live shape: a contact who moved from iPhone to Android, every recent
Expand Down Expand Up @@ -1825,6 +1870,98 @@ describe("which service a DM sends on (@lukejmorrison, PR #4)", () => {
])).toBe("iMessage");
});

test("after a failed iMessage, a contact who texts us on RCS is sent RCS, not SMS", () => {
// SMS to an RCS contact is what the Mac logged error 4 on (2026-11-12)
expect(sendServiceForMessages([
at(0, { from_me: false, service: "RCS" }),
at(1, { from_me: true, service: "iMessage", error: 22 }),
])).toBe("RCS");
expect(sendServiceForMessages([
at(0, { from_me: false, service: "SMS" }),
at(1, { from_me: true, service: "iMessage", error: 22 }),
])).toBe("SMS");
});

test("a read receipt clears a relayed SMS or RCS in a 1:1, and nothing else", () => {
const { sendFailed } = require("./collector") as typeof import("./collector");
const read = "2026-09-03T10:00:06Z";
expect(sendFailed(at(0, { from_me: true, service: "SMS", error: 4 }))).toBe(true);
expect(sendFailed(at(0, { from_me: true, service: "SMS", error: 4, read_at: read }))).toBe(false);
expect(sendFailed(at(0, { from_me: true, service: "RCS", error: 4, read_at: read }))).toBe(false);
expect(sendFailed(at(0, { from_me: true, service: "SMS", error: 0 }))).toBe(false);
expect(sendFailed(at(0, { from_me: true, service: "SMS" }))).toBe(false);
expect(sendFailed(at(0, { from_me: false, service: "SMS", error: 4 }))).toBe(false);
// #165 review: an iMessage keeps the Mac's verdict (a failed edit of a read
// message carries both), and so does a group, where one receipt is one member
expect(sendFailed(at(0, { from_me: true, service: "iMessage", error: 22, read_at: read }))).toBe(true);
expect(sendFailed(at(0, { chat: "chat900001", from_me: true, service: "SMS", error: 4, read_at: read }))).toBe(true);
});

// #165 review blocker: a merged phone + email conversation. The send goes
// `--to <target>`, so only the target's own rows decide.
test("only the target's own rows decide: an email is never sent SMS", () => {
const email = "pat@example.com";
const phone = "+15551234567";
const cluster = [
at(0, { chat: phone, handle: phone, from_me: false, service: "SMS" }),
at(1, { chat: email, handle: email, from_me: true, service: "iMessage", delivered: true,
read_at: "2026-09-03T11:00:09Z" }),
];
expect(sendServiceForMessages(cluster, false, email)).toBe("iMessage");
// after a failed SMS the old rule saw the same inbound SMS again and looped
expect(sendServiceForMessages([
...cluster, at(2, { chat: email, handle: email, from_me: true, service: "SMS", error: 4 }),
], false, email)).toBe("iMessage");
});

test("...and a phone whose person last wrote from their email is not sent iMessage", () => {
const email = "pat@example.com";
const phone = "+15551234567";
expect(sendServiceForMessages([
at(0, { chat: phone, handle: phone, from_me: false, service: "SMS" }),
at(1, { chat: email, handle: email, from_me: false, service: "iMessage" }),
], false, phone)).toBe("SMS");
});

test("an address that is not a number gets SMS never, and RCS only if it texted us on RCS", () => {
const email = "pat@example.com";
expect(sendServiceForMessages([at(0, { chat: email, handle: email, from_me: false, service: "SMS" })], false, email))
.toBe("iMessage");
expect(sendServiceForMessages([at(0, { chat: email, handle: email, from_me: true, service: "RCS" })], false, email))
.toBe("iMessage");
// an RCS business agent replies from an address and is answered on RCS
const agent = "verify_agent@rbm.goog";
expect(sendServiceForMessages([at(0, { chat: agent, handle: agent, from_me: false, service: "RCS" })], false, agent))
.toBe("RCS");
});

// #165 review should-fix 1: a quiet blue DM whose last inbound is an old SMS.
test("our iMessage that reached them after their last text keeps a DM on iMessage", () => {
const blue = [
msg({ ts: "2025-03-01T10:00:00Z", from_me: false, service: "SMS" }),
msg({ ts: "2026-11-01T10:00:00Z", from_me: true, service: "iMessage", delivered: true }),
msg({ ts: "2026-11-02T10:00:00Z", from_me: true, service: "iMessage", read_at: "2026-11-02T10:01:00Z" }),
msg({ ts: "2026-11-03T10:00:00Z", from_me: true, service: "iMessage", delivered: true, read_at: "2026-11-03T10:00:30Z" }),
];
expect(sendServiceForMessages(blue)).toBe("iMessage");
// an error-22 send is never delivered, so the #151 loop stays closed
expect(sendServiceForMessages([
msg({ ts: "2025-03-01T10:00:00Z", from_me: false, service: "SMS" }),
msg({ ts: "2026-11-01T10:00:00Z", from_me: true, service: "iMessage", error: 22 }),
])).toBe("SMS");
// proof older than their last text is not proof of now: they moved to RCS since
expect(sendServiceForMessages([
msg({ ts: "2026-10-01T10:00:00Z", from_me: true, service: "iMessage", delivered: true }),
msg({ ts: "2026-11-01T10:00:00Z", from_me: false, service: "RCS" }),
])).toBe("RCS");
// only our NEWEST proven send counts: an RCS that arrived after a read iMessage
expect(sendServiceForMessages([
msg({ ts: "2026-10-01T10:00:00Z", from_me: false, service: "RCS" }),
msg({ ts: "2026-10-02T10:00:00Z", from_me: true, service: "iMessage", delivered: true }),
msg({ ts: "2026-10-03T10:00:00Z", from_me: true, service: "RCS", delivered: true }),
])).toBe("RCS");
});

test("our failed iMessage to a phone, newest, means they are not on iMessage", () => {
// the case that made a thread stick: retrying iMessage forever
expect(sendServiceForMessages([
Expand Down
Loading
Loading