Spaces:
Running
Running
Deploy msgboard
Browse files- src/msgboard/store.py +6 -2
src/msgboard/store.py
CHANGED
|
@@ -1669,6 +1669,8 @@ def find_mention_spans(conn, body: str) -> list[tuple]:
|
|
| 1669 |
continue
|
| 1670 |
best = None
|
| 1671 |
for name, row in candidates:
|
|
|
|
|
|
|
| 1672 |
end = i + 1 + len(name)
|
| 1673 |
if best is not None and len(name) < best:
|
| 1674 |
break # every identity sharing the longest name has been collected
|
|
@@ -1703,10 +1705,12 @@ def _record_mentions(conn, channel, message_id: int, body: str, sender_id: int)
|
|
| 1703 |
continue
|
| 1704 |
conn.execute("INSERT OR IGNORE INTO message_mentions (message_id, principal_id, mentioned_as) VALUES (?, ?, ?)",
|
| 1705 |
(message_id, row["id"], text))
|
| 1706 |
-
if kinds: # @all / @agents / @humans:
|
| 1707 |
marks = ",".join("?" * len(kinds))
|
| 1708 |
group_of = {k: g for g in sorted(group_mentions(body), key=lambda g: len(GROUP_MENTIONS[g])) for k in GROUP_MENTIONS[g]}
|
| 1709 |
-
for row in conn.execute(f"SELECT * FROM principals
|
|
|
|
|
|
|
| 1710 |
if row["id"] != sender_id and can_see(conn, _principal_obj(row), channel):
|
| 1711 |
conn.execute("INSERT OR IGNORE INTO message_mentions (message_id, principal_id, mentioned_as) VALUES (?, ?, ?)",
|
| 1712 |
(message_id, row["id"], group_of[row["identity_type"]]))
|
|
|
|
| 1669 |
continue
|
| 1670 |
best = None
|
| 1671 |
for name, row in candidates:
|
| 1672 |
+
if name in GROUP_MENTIONS:
|
| 1673 |
+
continue # @all, @agents ... always mean the group, never someone named so
|
| 1674 |
end = i + 1 + len(name)
|
| 1675 |
if best is not None and len(name) < best:
|
| 1676 |
break # every identity sharing the longest name has been collected
|
|
|
|
| 1705 |
continue
|
| 1706 |
conn.execute("INSERT OR IGNORE INTO message_mentions (message_id, principal_id, mentioned_as) VALUES (?, ?, ?)",
|
| 1707 |
(message_id, row["id"], text))
|
| 1708 |
+
if kinds: # @all / @agents / @humans: the channel's members of that kind, not everyone who could read it
|
| 1709 |
marks = ",".join("?" * len(kinds))
|
| 1710 |
group_of = {k: g for g in sorted(group_mentions(body), key=lambda g: len(GROUP_MENTIONS[g])) for k in GROUP_MENTIONS[g]}
|
| 1711 |
+
for row in conn.execute(f"""SELECT p.* FROM principals p JOIN channel_members cm ON cm.principal_id = p.id
|
| 1712 |
+
WHERE cm.channel_id = ? AND p.disabled = 0 AND p.identity_type IN ({marks})""",
|
| 1713 |
+
(channel["id"], *sorted(kinds))):
|
| 1714 |
if row["id"] != sender_id and can_see(conn, _principal_obj(row), channel):
|
| 1715 |
conn.execute("INSERT OR IGNORE INTO message_mentions (message_id, principal_id, mentioned_as) VALUES (?, ?, ?)",
|
| 1716 |
(message_id, row["id"], group_of[row["identity_type"]]))
|