Sync update: 2026-06-20 16:53:51
This commit is contained in:
@@ -62,6 +62,17 @@ async function initDatabase() {
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
|
||||
// Check and add sender_jid column if it doesn't exist
|
||||
try {
|
||||
const [columns] = await connectionPool.query(`SHOW COLUMNS FROM messages LIKE 'sender_jid'`);
|
||||
if (columns.length === 0) {
|
||||
console.log('[DB] Adding column sender_jid to messages table...');
|
||||
await connectionPool.query(`ALTER TABLE messages ADD COLUMN sender_jid VARCHAR(100) NULL AFTER sender_name;`);
|
||||
}
|
||||
} catch (columnErr) {
|
||||
console.error('[DB ERROR] Failed to check/add sender_jid column:', columnErr.message);
|
||||
}
|
||||
|
||||
console.log('[DB] MySQL Tables initialized successfully.');
|
||||
} catch (err) {
|
||||
console.error('[DB ERROR] Migration failed:', err.message);
|
||||
@@ -94,15 +105,27 @@ async function archiveMessage(slotId, msg) {
|
||||
bodyText = '📷 Media/Attachment';
|
||||
}
|
||||
|
||||
let senderJid = null;
|
||||
if (msg.author) {
|
||||
senderJid = typeof msg.author === 'string' ? msg.author : msg.author._serialized;
|
||||
} else if (msg.id && msg.id.participant) {
|
||||
senderJid = typeof msg.id.participant === 'string' ? msg.id.participant : msg.id.participant._serialized;
|
||||
} else if (msg.fromMe) {
|
||||
senderJid = 'me';
|
||||
} else {
|
||||
senderJid = typeof msg.from === 'string' ? msg.from : msg.from._serialized;
|
||||
}
|
||||
|
||||
await connectionPool.query(`
|
||||
INSERT INTO messages (id, slot_id, chat_id, sender_name, body, from_me, timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO messages (id, slot_id, chat_id, sender_name, sender_jid, body, from_me, timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE body = VALUES(body);
|
||||
`, [
|
||||
msg.id._serialized || msg.id.id,
|
||||
slotId,
|
||||
msg.to || msg.from,
|
||||
msg.senderName || null,
|
||||
senderJid || null,
|
||||
bodyText,
|
||||
msg.fromMe ? 1 : 0,
|
||||
msg.timestamp
|
||||
|
||||
Reference in New Issue
Block a user