Context
wacli already stores chat state locally and exposes chats list --unread, but the local chats.unread value currently behaves like a boolean. That makes downstream read-only integrations unable to reproduce the WhatsApp unread badge/count from wacli.db.
I hit this while building against the local SQLite store: I needed to list unread conversations and know how many unread messages each chat had, without mutating WhatsApp state.
Problem
Unread state can be incomplete or too lossy today:
- history sync conversations can include an unread count, but it is not persisted as a count in the chat row;
- live incoming messages should increment local unread state for that chat;
chats list --json / chats show --json expose only unread: true|false, so integrations cannot read the actual badge count;
--unread is more useful if it means unread_count > 0, not only an exact boolean value.
Proposed behavior
Treat chats.unread as the local unread-message count while preserving the existing boolean convenience field in CLI JSON:
- add
unread_count to chat JSON output;
- keep
unread as unread_count > 0 for backward compatibility;
- persist
Conversation.unread_count during history sync;
- if WhatsApp marks a conversation as unread but count is absent/zero, store count
1;
- increment unread count for live inbound messages, excluding own messages and status broadcasts;
- keep
mark-read setting count to 0 and mark-unread setting count to at least 1;
- make
chats list --unread filter unread > 0 and --no-unread filter unread = 0;
- when PN/LID duplicate chat rows are merged for display, merge the unread counts too.
Patch reference
I have a working patch in my fork here:
drelum@2fd404e
The patch includes focused tests around:
- live sync incrementing unread count;
- history sync storing
Conversation.unread_count;
- store filtering/count behavior;
- chat display flag formatting (
unread:3);
- PN/LID display merge preserving unread totals.
Why this helps
This makes wacli.db more useful for local agents, dashboards, and read-only integrations that need to prioritize unread conversations without connecting to WhatsApp or changing read state.
Context
waclialready stores chat state locally and exposeschats list --unread, but the localchats.unreadvalue currently behaves like a boolean. That makes downstream read-only integrations unable to reproduce the WhatsApp unread badge/count fromwacli.db.I hit this while building against the local SQLite store: I needed to list unread conversations and know how many unread messages each chat had, without mutating WhatsApp state.
Problem
Unread state can be incomplete or too lossy today:
chats list --json/chats show --jsonexpose onlyunread: true|false, so integrations cannot read the actual badge count;--unreadis more useful if it meansunread_count > 0, not only an exact boolean value.Proposed behavior
Treat
chats.unreadas the local unread-message count while preserving the existing boolean convenience field in CLI JSON:unread_countto chat JSON output;unreadasunread_count > 0for backward compatibility;Conversation.unread_countduring history sync;1;mark-readsetting count to0andmark-unreadsetting count to at least1;chats list --unreadfilterunread > 0and--no-unreadfilterunread = 0;Patch reference
I have a working patch in my fork here:
drelum@2fd404e
The patch includes focused tests around:
Conversation.unread_count;unread:3);Why this helps
This makes
wacli.dbmore useful for local agents, dashboards, and read-only integrations that need to prioritize unread conversations without connecting to WhatsApp or changing read state.