Problem
storeChat() in database.ts converts undefined timestamps to the string "undefined" instead of NULL:
last_message_time:
chat.last_message_time instanceof Date
? chat.last_message_time.toISOString()
: chat.last_message_time === null
? null
: String(chat.last_message_time), // ← String(undefined) === "undefined"
In JavaScript, String(undefined) returns the string "undefined", which gets stored in SQLite as a text value.
Impact
list_chats sorted by last_active is completely broken — SQLite sorts "undefined" > ISO dates alphabetically
- In my DB: 386/866 chats had
last_message_time = 'undefined'
- These chats sort to the top, hiding actually active conversations
Fix
One-line change in storeChat():
const lmt = chat.last_message_time;
stmt.run({
jid: chat.jid,
name: chat.name ?? null,
last_message_time:
lmt instanceof Date
? lmt.toISOString()
: (lmt == null || String(lmt) === "undefined")
? null
: String(lmt),
});
Plus a one-time cleanup on init:
UPDATE chats SET last_message_time = NULL WHERE last_message_time IN ('undefined', 'null', '');
Happy to submit a PR if you'd like.
Problem
storeChat()indatabase.tsconvertsundefinedtimestamps to the string"undefined"instead ofNULL:In JavaScript,
String(undefined)returns the string"undefined", which gets stored in SQLite as a text value.Impact
list_chatssorted bylast_activeis completely broken — SQLite sorts"undefined"> ISO dates alphabeticallylast_message_time = 'undefined'Fix
One-line change in
storeChat():Plus a one-time cleanup on init:
Happy to submit a PR if you'd like.