diff --git a/app/repository.py b/app/repository.py index 665d047..5cafc07 100644 --- a/app/repository.py +++ b/app/repository.py @@ -580,7 +580,10 @@ class MessageRepository: SELECT m.conversation_key, COUNT(*) as unread_count, MAX(m.received_at) as last_message_time, - SUM(CASE WHEN ? <> '' AND INSTR(m.text, ?) > 0 THEN 1 ELSE 0 END) > 0 as has_mention + SUM(CASE + WHEN ? <> '' AND INSTR(LOWER(m.text), LOWER(?)) > 0 THEN 1 + ELSE 0 + END) > 0 as has_mention FROM messages m JOIN channels c ON m.conversation_key = c.key WHERE m.type = 'CHAN' AND m.outgoing = 0 @@ -602,7 +605,10 @@ class MessageRepository: SELECT m.conversation_key, COUNT(*) as unread_count, MAX(m.received_at) as last_message_time, - SUM(CASE WHEN ? <> '' AND INSTR(m.text, ?) > 0 THEN 1 ELSE 0 END) > 0 as has_mention + SUM(CASE + WHEN ? <> '' AND INSTR(LOWER(m.text), LOWER(?)) > 0 THEN 1 + ELSE 0 + END) > 0 as has_mention FROM messages m JOIN contacts ct ON m.conversation_key = ct.public_key WHERE m.type = 'PRIV' AND m.outgoing = 0 diff --git a/tests/test_api.py b/tests/test_api.py index d560f52..402707e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -663,7 +663,7 @@ class TestReadStateEndpoints: ) await conn.execute( "INSERT INTO messages (type, conversation_key, text, received_at, outgoing) VALUES (?, ?, ?, ?, ?)", - ("CHAN", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1", "Bob: @[TestUser] hey", 1002, 0), + ("CHAN", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1", "Bob: @[testuser] hey", 1002, 0), ) await conn.execute( "INSERT INTO messages (type, conversation_key, text, received_at, outgoing) VALUES (?, ?, ?, ?, ?)", @@ -677,7 +677,7 @@ class TestReadStateEndpoints: # Insert 1 unread DM await conn.execute( "INSERT INTO messages (type, conversation_key, text, received_at, outgoing) VALUES (?, ?, ?, ?, ?)", - ("PRIV", "abcd" * 16, "hi there", 1005, 0), + ("PRIV", "abcd" * 16, "hi @[TeStUsEr] there", 1005, 0), ) await conn.commit() @@ -691,8 +691,9 @@ class TestReadStateEndpoints: assert result["counts"]["channel-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1"] == 2 assert result["mentions"]["channel-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1"] is True - # Contact: 1 unread + # Contact: 1 unread with mention (also case-insensitive) assert result["counts"][f"contact-{'abcd' * 16}"] == 1 + assert result["mentions"][f"contact-{'abcd' * 16}"] is True # Last message times should include all conversations assert "channel-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1" in result["last_message_times"]