commit 647593c61eb0eb8fbe6876e4bd6cd2e6cb3cb7d4
parent 57e51c54fa225ba8161f75cc3d9559a9d149a27b
Author: notamitgamer-bot <bot@notamitgamer.dev>
Date: Sat, 12 Sep 2026 12:36:07 +0000
Revert edit-history tracking feature entirely
Reported as not working after merging #8 (messages.update listener):
edited messages still show no edited/edits/editCount/lastEditedAt
fields in Firestore, and the text field itself never updated to the
new content either.
Rather than attempt a fourth diagnosis blind, reverting src/whatsapp.js
back to its state before #5 (commit 579be0d) - removes all
edit-detection code (both the incorrect messages.upsert/protocolMessage
version and the messages.update version) and leaves normal message
logging untouched. Confirmed via diff that the only change across
#5/#6/#7/#8 combined was the additive edit-handling block; this
removes exactly that block and nothing else.
The frontend edit-history UI (badge + expandable history) added via
Gemini to the separate frontend repo is unaffected by this revert -
it will simply never render since edited/edits fields will no longer
be written. No action needed there unless it should be cleaned up too.
Diffstat:
| M | src/whatsapp.js | | | 83 | ------------------------------------------------------------------------------- |
1 file changed, 0 insertions(+), 83 deletions(-)
diff --git a/src/whatsapp.js b/src/whatsapp.js
@@ -154,89 +154,6 @@ async function startWhatsApp() {
} catch (err) {}
}
});
-
- // --- Edited message handling ---
- // Unlike a regular new message, an edit to an existing message arrives
- // via messages.update (not messages.upsert). Baileys already unwraps it:
- // `key` is the ORIGINAL message's key, and `update.message` is the new
- // content directly — there's no protocolMessage/editedMessage nesting on
- // the receiving side (that shape is only for constructing an outgoing
- // edit yourself via sock.sendMessage(..., { edit: key })).
- //
- // We keep the original text plus every subsequent edit in `edits`
- // (oldest first) so the UI can show original -> edit 1 -> edit 2 ...
- // instead of overwriting history.
- sock.ev.on('messages.update', async (updates) => {
- for (const { key, update } of updates) {
- try {
- if (!update.message) continue; // not an edit (e.g. a status/ack update)
-
- const remoteJid = key.remoteJid;
- const targetId = key.id;
- if (!remoteJid || !targetId || remoteJid === 'status@broadcast') continue;
-
- const editedText =
- update.message.conversation ||
- update.message.extendedTextMessage?.text ||
- update.message.imageMessage?.caption ||
- update.message.videoMessage?.caption ||
- "";
-
- if (!editedText) {
- console.error(`System: Received edit for ${targetId} with no extractable text — ignoring.`);
- continue;
- }
-
- const editTimestamp = Math.floor(Date.now() / 1000);
- const msgRef = db.collection('Chats').doc(remoteJid).collection('Messages').doc(targetId);
-
- // Guard against a race: if this edit arrives before the original
- // message's own write has committed (e.g. someone edits within
- // ~1s of sending), the doc won't exist yet. Retry briefly instead
- // of silently dropping the edit.
- let applied = false;
- for (let attempt = 0; attempt < 3 && !applied; attempt++) {
- if (attempt > 0) await new Promise(r => setTimeout(r, 500 * attempt));
-
- try {
- applied = await db.runTransaction(async (tx) => {
- const snap = await tx.get(msgRef);
- if (!snap.exists) return false;
-
- const data = snap.data();
- const priorEdits = Array.isArray(data.edits) ? data.edits : [];
-
- // On the first edit, seed history with the pre-edit text so
- // the original is preserved alongside every later revision.
- const history = priorEdits.length > 0
- ? priorEdits
- : [{ text: data.text, timestamp: data.timestamp }];
-
- history.push({ text: editedText, timestamp: editTimestamp });
-
- tx.set(msgRef, {
- text: editedText, // latest text — existing UI keeps working unchanged
- edited: true,
- editCount: history.length - 1,
- lastEditedAt: editTimestamp,
- edits: history // full chronological history, oldest (original) first
- }, { merge: true });
-
- return true;
- });
- } catch (err) {
- console.error(`System: Edit-history transaction failed for ${targetId} (attempt ${attempt + 1}):`, err.message);
- }
- }
-
- if (applied) {
- console.log(`System: Recorded edit for message ${targetId} in ${remoteJid}.`);
- } else {
- console.error(`System: Could not attach edit for message ${targetId} in ${remoteJid} — original was never found (gave up after retries).`);
- }
- } catch (err) {}
- }
- });
}
module.exports = {