logger

Self-hosted WhatsApp logger using Baileys & Firebase. Archives messages instantly to catch deleted texts. Privacy-focused with silent logs.

git clone https://github.com/notamitgamer/logger.git
· rebuilt hourlyOpen on GitHub
commit a3f0aa12f88ffec052f2331ab37adaac9314fdad
parent 57e51c54fa225ba8161f75cc3d9559a9d149a27b
Author: Amit Dutta <mail@amit.is-a.dev>
Date:   Sat, 12 Sep 2026 18:06:59 +0530

Merge pull request #9 from notamitgamer/revert/edit-history-feature

Revert edit-history tracking feature
Diffstat:
Msrc/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 = {