From e9adb10fd617fca1c93bc03ff8643b6ced19b40a Mon Sep 17 00:00:00 2001 From: Marcus Vorwaller Date: Mon, 9 Nov 2026 20:07:40 -0800 Subject: [PATCH] Show Delivered until the newest sent message is read Expose device acknowledgements for iMessage and RCS, preserve them when folding self echoes, and hide older receipts when a newer send arrives. Keep upstream timestamp formatting and theme. No send or read-mark behavior changes. --- BlipView.qml | 2 +- bridge/mac/imsg | 4 +++- bridge/mac/test_read_sync.py | 24 +++++++++++++++++++++++- collector.ts | 12 ++++++++++-- delivery.test.ts | 20 ++++++++++++++++++++ docs/delivery.md | 7 +++++++ thread.test.ts | 4 ++-- thread.ts | 6 +++--- 8 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 delivery.test.ts create mode 100644 docs/delivery.md diff --git a/BlipView.qml b/BlipView.qml index 2847d05b..e3f26326 100644 --- a/BlipView.qml +++ b/BlipView.qml @@ -3918,7 +3918,7 @@ FocusScope { Item { Layout.fillWidth: true; visible: !bubbleRow.mine } } - // "Read 4:42 PM" — only ever under the newest read from-me bubble + // Delivered becomes Read under the newest sent message. RowLayout { Layout.fillWidth: true visible: String(modelData.receipt || "") !== "" diff --git a/bridge/mac/imsg b/bridge/mac/imsg index cfce590e..ade00c10 100755 --- a/bridge/mac/imsg +++ b/bridge/mac/imsg @@ -1116,6 +1116,8 @@ def enrich(con, rows, with_names: bool): e = extras[r["ROWID"]] if r["is_from_me"] and r["date_read"]: e["read_at"] = fmt_ts(r["date_read"]) + if r["is_from_me"] and r["is_delivered"] and r["service"] in ("iMessage", "RCS"): + e["delivered"] = True if has_edit: e.update(_edit_flags(r["date_edited"], r["date_retracted"], r["message_summary_info"])) if r["orig_guid"] and r["orig_guid"] in osnip: @@ -1286,7 +1288,7 @@ def base_select(con) -> str: _BASE_SELECT_CACHE = f""" SELECT m.ROWID, m.date, m.is_from_me, m.text, m.attributedBody, m.service, h.id AS handle, c.chat_identifier, c.room_name, - m.guid, m.date_read, m.is_read, m.error, {edit_cols} {sched_cols} + m.guid, m.date_read, m.is_delivered, m.is_read, m.error, {edit_cols} {sched_cols} m.associated_message_type AS assoc_type, m.thread_originator_guid AS orig_guid, m.expressive_send_style_id AS style_id, diff --git a/bridge/mac/test_read_sync.py b/bridge/mac/test_read_sync.py index 1f3f9161..0372803b 100644 --- a/bridge/mac/test_read_sync.py +++ b/bridge/mac/test_read_sync.py @@ -129,7 +129,8 @@ class ReactionReadBoundary(unittest.TestCase): def test_folded_reactions_and_removals_keep_their_activity_timestamp(self): imsg = load_tool('imsg') target = {"ROWID": 1, "guid": "target", "assoc_type": 0, - "date_read": 0, "is_from_me": 1, "orig_guid": None, + "date_read": 0, "is_delivered": 0, "service": "iMessage", + "is_from_me": 1, "orig_guid": None, "style_id": None, "is_audio_message": 0, "balloon_bundle_id": None, "payload_data": None} for kind in [2004, 3004]: @@ -143,6 +144,27 @@ def test_folded_reactions_and_removals_keep_their_activity_timestamp(self): self.assertEqual(len(extras[1].get('tapbacks', [])), 1 if kind == 2004 else 0) +class DeliveryState(unittest.TestCase): + def delivered(self, service, is_delivered=1, is_from_me=1): + imsg = load_tool('imsg') + row = {"ROWID": 1, "guid": "m", "assoc_type": 0, "date_read": 0, + "is_delivered": is_delivered, "service": service, "is_from_me": is_from_me, + "orig_guid": None, "style_id": None, "is_audio_message": 0, + "balloon_bundle_id": None, "payload_data": None} + con = Mock() + con.execute.return_value = [] + with patch.object(imsg, '_has_col', return_value=False), patch.object(imsg, '_chunked_in', return_value=[]): + _, extras = imsg.enrich(con, [row], with_names=False) + return extras[1].get('delivered', False) + + def test_only_own_imessage_and_rcs_report_delivery(self): + self.assertTrue(self.delivered('iMessage')) + self.assertTrue(self.delivered('RCS')) + self.assertFalse(self.delivered('SMS')) + self.assertFalse(self.delivered('iMessage', is_delivered=0)) + self.assertFalse(self.delivered('iMessage', is_from_me=0)) + + class Actions(unittest.TestCase): def setUp(self): self.tool = load_tool('imsg-read') diff --git a/collector.ts b/collector.ts index 438f75af..703c1094 100644 --- a/collector.ts +++ b/collector.ts @@ -88,6 +88,7 @@ export interface ImsgMessage { scheduled?: boolean | null; // ---- imsg --rich extras (claude-on-mac ≥ 1.5.0); absent on plain fetches read_at?: string | null; + delivered?: boolean | null; tapbacks?: Tapback[] | null; attachments?: AttachmentMeta[] | null; reply_to?: { text: string; from_me: boolean } | null; @@ -490,6 +491,11 @@ export function mergeTapbacks(a?: Tapback[] | null, b?: Tapback[] | null): Tapba }); } +function sentReceipt(a: Partial | undefined, b: ImsgMessage) { + const read_at = a?.read_at ?? b.read_at; + return { ...(a?.delivered || b.delivered ? { delivered: true } : {}), ...(read_at ? { read_at } : {}) }; +} + export function dedupeSelfEcho(msgs: ImsgMessage[], knownSelfChats: string[] = []): ImsgMessage[] { const contextKey = (m: ImsgMessage) => `${chatKey(m)}\u0000${m.handle || ""}\u0000${m.ts}`; const contentKey = (m: ImsgMessage) => `${contextKey(m)}\u0000${m.text}`; @@ -502,10 +508,12 @@ export function dedupeSelfEcho(msgs: ImsgMessage[], knownSelfChats: string[] = [ // message — whichever the reacting device considers the message. Whatever // is dropped below hands its tapbacks to the row that stays, so a reaction // on your own note is seen no matter which twin carried it. + const emptySentReceipt = new Map>(); const emptySentTapbacks = new Map(); for (const m of msgs) { if (selfChats.has(chatKey(m)) && m.from_me && m.text === "") { const k = contextKey(m); + emptySentReceipt.set(k, sentReceipt(emptySentReceipt.get(k), m)); emptySentTapbacks.set(k, mergeTapbacks(emptySentTapbacks.get(k), m.tapbacks)); } } @@ -536,14 +544,14 @@ export function dedupeSelfEcho(msgs: ImsgMessage[], knownSelfChats: string[] = [ const idx = selfText.get(key); if (idx !== undefined && out[idx]!.from_me !== m.from_me) { const kept = out[idx]!; - out[idx] = { ...kept, from_me: kept.from_me || m.from_me, tapbacks: mergeTapbacks(kept.tapbacks, m.tapbacks) }; + out[idx] = { ...kept, ...sentReceipt(kept, m), from_me: kept.from_me || m.from_me, tapbacks: mergeTapbacks(kept.tapbacks, m.tapbacks) }; continue; } selfText.set(key, out.length); } if (emptySent.has(context) && !m.from_me) { - out.push({ ...m, from_me: true, tapbacks: mergeTapbacks(m.tapbacks, emptySentTapbacks.get(context)) }); + out.push({ ...m, ...emptySentReceipt.get(context), from_me: true, tapbacks: mergeTapbacks(m.tapbacks, emptySentTapbacks.get(context)) }); continue; } out.push(m); diff --git a/delivery.test.ts b/delivery.test.ts new file mode 100644 index 00000000..2a35a3c4 --- /dev/null +++ b/delivery.test.ts @@ -0,0 +1,20 @@ +import { test, expect } from "bun:test"; +import { decorate } from "./thread"; +import { dedupeSelfEcho } from "./collector"; +const base = { id: 1, ts: "2026-08-31T10:00:00Z", from_me: true, text: "hello", chat: "self", handle: "+15551234567", service: "iMessage" }; +test("Delivered becomes Read only on the newest sent message", () => { + const first = { ...base, delivered: true, read_at: "2026-08-31T10:01:00Z" }; + const last = { ...base, id: 2, ts: "2026-08-31T10:02:00Z", delivered: true }; + expect(decorate([first, last], "2026-08-31").map(b => b.receipt)).toEqual(["", "Delivered"]); + expect(decorate([{...last, read_at: "2026-08-31T10:03:00Z"}], "2026-08-31")[0]!.receipt).toBe("Read 10:03 AM"); + for (const extra of [{delivered: false}, {error: 22}, {retracted: true}, {scheduled: true}]) + expect(decorate([{...last, ...extra}], "2026-08-31")[0]!.receipt).toBe(""); +}); +test("self echo preserves sent receipt in either order, including empty text", () => { + for (const text of ["hello", ""]) { + const sent = {...base, text, delivered: true, read_at: "2026-08-31T10:01:00Z"}; + const echo = {...base, id: 2, text, from_me: false}; + for (const rows of [[sent, echo], [echo, sent]]) + expect(dedupeSelfEcho(rows, ["self"])[0]).toMatchObject({from_me: true, delivered: true, read_at: sent.read_at}); + } +}); diff --git a/docs/delivery.md b/docs/delivery.md new file mode 100644 index 00000000..50d86f35 --- /dev/null +++ b/docs/delivery.md @@ -0,0 +1,7 @@ +# Delivery receipts + +The newest sent message shows **Delivered** after the recipient device acknowledges an iMessage or RCS, then **Read** with the existing timestamp format when a read receipt arrives. Carrier SMS has no delivery receipt. Older gateways that omit `delivered` keep working and show only read receipts. + +Failed, retracted and scheduled messages do not show Delivered. Self-thread echo folding preserves the sent row’s receipt metadata. No new setting, message content storage, or send path is introduced. + +Run `bun test` and `python3 bridge/mac/test_read_sync.py`. All fixtures are synthetic; no live send is needed. diff --git a/thread.test.ts b/thread.test.ts index 199bdc63..851b2314 100644 --- a/thread.test.ts +++ b/thread.test.ts @@ -527,7 +527,7 @@ describe("linkify", () => { describe("rich decoration", () => { const today = "2026-08-31"; - test("receipt lands only on the NEWEST read from-me bubble", () => { + test("receipt belongs only to the newest sent message", () => { const out = decorate( [ msg({ ts: "2026-08-31T10:00:00Z", from_me: true, read_at: "2026-08-31T10:00:30Z" }), @@ -537,7 +537,7 @@ describe("rich decoration", () => { ], today, ); - expect(out.map((b) => b.receipt)).toEqual(["", "", "Read 10:07 AM", ""]); + expect(out.map((b) => b.receipt)).toEqual(["", "", "", ""]); }); test("receipt from an earlier day carries the day label", () => { diff --git a/thread.ts b/thread.ts index 9ff6b5c7..13468763 100644 --- a/thread.ts +++ b/thread.ts @@ -277,10 +277,10 @@ export function minutesBetween(a: string, b: string): number { export function decorate(msgs: ImsgMessage[], today: string, formats = DEFAULT_FORMATS): Bubble[] { const out: Bubble[] = []; - // iMessage shows "Read" under only the newest read message you sent. + // Only the newest sent message owns the delivery/read receipt. let receiptIdx = -1; for (let i = msgs.length - 1; i >= 0; i--) { - if (msgs[i]!.from_me && msgs[i]!.read_at) { receiptIdx = i; break; } + if (msgs[i]!.from_me && !msgs[i]!.retracted && !msgs[i]!.scheduled) { receiptIdx = i; break; } } for (let i = 0; i < msgs.length; i++) { @@ -321,7 +321,7 @@ export function decorate(msgs: ImsgMessage[], today: string, formats = DEFAULT_F groupStart, groupEnd, time: groupEnd ? clockLabel(m.ts, formats.time) : "", - receipt: i === receiptIdx ? receiptLabel(m.read_at!, today, formats) : "", + receipt: i === receiptIdx && !(m.error ?? 0) ? (m.read_at ? receiptLabel(m.read_at, today, formats) : m.delivered ? "Delivered" : "") : "", tapbacks: m.tapbacks ?? [], // Belt to imsg 1.5.1's suspenders: link-preview payloads are not files. attachments: (m.attachments ?? []).filter(