iPhone

Remove unread messages

I have an old iPhone and I sometimes save old messages so I'll read them later. But then sometimes I forget and now they are very old and they just show a notification and I can't find it. It is very annoying. So there are a few options:

Searching messages[2]

The iMessage search is bullshit. Turns out they save everything as a SQLite database, so you can query it. You should copy the file before querying it to make sure you don't corrupt it.

# Copy the database to protect the data and bypass access/security issues
cp ~/Library/Messages/chat.db ~/Desktop/chat.db
# Test that it works
sqlite3 ~/Desktop/messages.db ".tables"

Use a DB viewer like TablePlus to make this experience a lot nicer.

Search for message by content

SELECT
    datetime (message.date / 1000000000 + strftime ("%s", "2001-01-01"), "unixepoch", "localtime") AS message_date,
    message.text,
    message.is_from_me,
    chat.chat_identifier
FROM
    chat
    JOIN chat_message_join ON chat. "ROWID" = chat_message_join.chat_id
    JOIN message ON chat_message_join.message_id = message. "ROWID"
WHERE
    -- Put your query here; surround it with wildcard `%`for good search
    message.text like '%river%'
ORDER BY
    message_date ASC;

References

  1. https://www.reddit.com/r/ios/comments/17r73df/why_does_imessage_show_72_unread_messages_when_i/
  2. https://spin.atomicobject.com/search-imessage-sql/

Last modified: 202610110325