Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): key WhatsApp dedupe on content, not filename-derived chatTitle

[._.]/ Adam Eivy67e5327e9c7a
diff --git a/server/services/whatsappImport.js b/server/services/whatsappImport.js
index 789fc385be..8a631f9c31 100644
--- a/server/services/whatsappImport.js
+++ b/server/services/whatsappImport.js
@@ -135,8 +135,10 @@ function resolveYmd(msg, order) {
// A body that's only a media placeholder ("<Media omitted>", "image omitted",
// "‎<attached: …>") still carries autobiographical signal (you sent/received
// something then) — flagged so the summary can show a placeholder rather than an
-// empty line.
-const MEDIA_RE = /(<media omitted>|omitted>?$|<attached:|\bomitted\b)/i;
+// empty line. Anchored to the actual placeholder shapes (the whole body IS the
+// placeholder, or an `<attached:` token) so a normal message that merely contains
+// the word "omitted" ("I omitted that detail") isn't mis-flagged.
+const MEDIA_RE = /^\s*(<[^>]*\bomitted\b[^>]*>|(?:image|video|audio|gif|sticker|document|contact card|media)\s+omitted|<attached:[^>]*>)\s*$|<attached:/i;
// Map ONE raw WhatsApp message to an activity candidate, or null if it's a system
// notice, lacks a sender, or has an unresolvable timestamp. `timezone` anchors the
@@ -155,12 +157,19 @@ export function whatsappMessageToCandidate(msg, { order = 'mdy', chatTitle = nul
const title = chatTitle ? `WhatsApp: ${chatTitle}` : 'WhatsApp message';
const summaryText = bodyText || (hasMedia ? '(media)' : '');
- // No message id in the export — hash the identifying tuple so re-imports of the
- // same (or an overlapping) export collapse deterministically. Two identical
- // bodies from the same sender at the same second in the same chat are
- // indistinguishable in the file, so collapsing them is correct.
+ // No message id in the export — hash the message's CONTENT identity (instant +
+ // sender + body) so re-imports collapse deterministically. Deliberately NOT
+ // keyed on chatTitle: that's derived from the upload filename, which differs
+ // between a `WhatsApp Chat - Alice.zip` and the bare `_chat.txt` extracted from
+ // it (and changes on any rename), so keying on it would double-count the whole
+ // conversation across those equivalent uploads. Two identical bodies from the
+ // same sender at the same timestamp granularity are indistinguishable in the
+ // file, so collapsing them is correct — same precedent as the Spotify importer's
+ // played-at+track key. The granularity is the export's own: iOS carries seconds,
+ // but Android lines have none (second defaults to 0), so two identical Android
+ // messages within the same clock-MINUTE collapse to one event.
const dedupeKey = createHash('sha1')
- .update(`${chatTitle || ''}${happenedAt}${msg.sender}${bodyText}`)
+ .update(`${happenedAt} ${msg.sender} ${bodyText}`)
.digest('hex')
.slice(0, 24);
diff --git a/server/services/whatsappImport.test.js b/server/services/whatsappImport.test.js
index 2306de1911..d2624b2de8 100644
--- a/server/services/whatsappImport.test.js
+++ b/server/services/whatsappImport.test.js
@@ -114,6 +114,15 @@ describe('whatsappMessageToCandidate', () => {
.not.toBe(c1.dedupeKey);
});
+ it('keys the dedupe hash independent of chatTitle so upload method does not double-count', () => {
+ // Importing `WhatsApp Chat - Alice.zip` (chatTitle "Alice") then the bare
+ // `_chat.txt` extracted from it (chatTitle null) must produce the SAME key for
+ // the same message, or the whole conversation re-imports as duplicates.
+ const zipped = whatsappMessageToCandidate(msg, { order: 'ymd', chatTitle: 'Alice', timezone: UTC });
+ const bare = whatsappMessageToCandidate(msg, { order: 'ymd', chatTitle: null, timezone: UTC });
+ expect(zipped.dedupeKey).toBe(bare.dedupeKey);
+ });
+
it('flags a media-only body and shows a placeholder summary', () => {
const [media] = parseWhatsappChat('[2024-01-15, 6:30:45 PM] Bob: <Media omitted>');
const c = whatsappMessageToCandidate(media, { order: 'ymd', timezone: UTC });
@@ -121,6 +130,13 @@ describe('whatsappMessageToCandidate', () => {
expect(c.summary).toBe('<Media omitted>');
});
+ it('does not mis-flag a normal message that merely contains the word "omitted"', () => {
+ const [normal] = parseWhatsappChat('[2024-01-15, 6:30:45 PM] Bob: I omitted that detail on purpose');
+ const c = whatsappMessageToCandidate(normal, { order: 'ymd', timezone: UTC });
+ expect(c.metadata.hasMedia).toBe(false);
+ expect(c.summary).toBe('I omitted that detail on purpose');
+ });
+
it('drops system notices and messages with no sender', () => {
const [sys] = parseWhatsappChat('1/15/24, 6:30 PM - Messages are end-to-end encrypted.');
expect(whatsappMessageToCandidate(sys, { timezone: UTC })).toBeNull();