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: 1 addition & 1 deletion BlipView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "") !== ""
Expand Down
4 changes: 3 additions & 1 deletion bridge/mac/imsg
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion bridge/mac/test_read_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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')
Expand Down
12 changes: 10 additions & 2 deletions collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -490,6 +491,11 @@ export function mergeTapbacks(a?: Tapback[] | null, b?: Tapback[] | null): Tapba
});
}

function sentReceipt(a: Partial<ImsgMessage> | 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}`;
Expand All @@ -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<string, Partial<ImsgMessage>>();
const emptySentTapbacks = new Map<string, Tapback[] | undefined>();
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));
}
}
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions delivery.test.ts
Original file line number Diff line number Diff line change
@@ -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});
}
});
7 changes: 7 additions & 0 deletions docs/delivery.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),
Expand All @@ -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", () => {
Expand Down
6 changes: 3 additions & 3 deletions thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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(
Expand Down
Loading