Fix mention detection case sensitivity

This commit is contained in:
Jack Kingsman
2026-02-12 00:01:27 -08:00
parent f73fa54532
commit fe6dfd5dee
2 changed files with 12 additions and 5 deletions

View File

@@ -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

View File

@@ -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"]