mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
feat(acl): source-aware chat trigger ACL (#252)
This commit is contained in:
@@ -545,31 +545,62 @@ func (q *Queries) ListMessagesSince(ctx context.Context, arg ListMessagesSincePa
|
||||
}
|
||||
|
||||
const listObservedConversationsByChannelIdentity = `-- name: ListObservedConversationsByChannelIdentity :many
|
||||
WITH observed_routes AS (
|
||||
SELECT
|
||||
(i.header->>'route_id')::uuid AS route_id,
|
||||
MAX(i.created_at)::timestamptz AS last_observed_at
|
||||
FROM bot_inbox i
|
||||
WHERE i.bot_id = $1
|
||||
AND i.header->>'channel-identity-id' = $2::text
|
||||
AND COALESCE(i.header->>'route_id', '') != ''
|
||||
GROUP BY (i.header->>'route_id')::uuid
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
m.route_id,
|
||||
MAX(m.created_at)::timestamptz AS last_observed_at
|
||||
FROM bot_history_messages m
|
||||
WHERE m.bot_id = $1
|
||||
AND m.sender_channel_identity_id = $2::uuid
|
||||
AND m.route_id IS NOT NULL
|
||||
GROUP BY m.route_id
|
||||
),
|
||||
ranked_routes AS (
|
||||
SELECT
|
||||
route_id,
|
||||
MAX(last_observed_at)::timestamptz AS last_observed_at
|
||||
FROM observed_routes
|
||||
GROUP BY route_id
|
||||
)
|
||||
SELECT
|
||||
r.id AS route_id,
|
||||
r.channel_type AS channel,
|
||||
COALESCE(r.conversation_type, '') AS conversation_type,
|
||||
CASE
|
||||
WHEN LOWER(COALESCE(r.conversation_type, '')) IN ('thread', 'topic') THEN 'thread'
|
||||
ELSE 'group'
|
||||
END AS conversation_type,
|
||||
r.external_conversation_id AS conversation_id,
|
||||
COALESCE(r.external_thread_id, '') AS thread_id,
|
||||
COALESCE(r.metadata->>'conversation_name', '')::text AS conversation_name,
|
||||
MAX(m.created_at)::timestamptz AS last_observed_at
|
||||
FROM bot_history_messages m
|
||||
JOIN bot_channel_routes r ON r.id = m.route_id
|
||||
WHERE m.bot_id = $1
|
||||
AND m.sender_channel_identity_id = $2
|
||||
rr.last_observed_at
|
||||
FROM ranked_routes rr
|
||||
JOIN bot_channel_routes r ON r.id = rr.route_id
|
||||
WHERE LOWER(COALESCE(r.conversation_type, '')) NOT IN ('', 'p2p', 'private', 'direct', 'dm')
|
||||
GROUP BY
|
||||
r.id,
|
||||
r.channel_type,
|
||||
r.conversation_type,
|
||||
r.external_conversation_id,
|
||||
r.external_thread_id,
|
||||
r.metadata
|
||||
ORDER BY MAX(m.created_at) DESC
|
||||
r.metadata,
|
||||
rr.last_observed_at
|
||||
ORDER BY rr.last_observed_at DESC
|
||||
`
|
||||
|
||||
type ListObservedConversationsByChannelIdentityParams struct {
|
||||
BotID pgtype.UUID `json:"bot_id"`
|
||||
ChannelIdentityID pgtype.UUID `json:"channel_identity_id"`
|
||||
ChannelIdentityID string `json:"channel_identity_id"`
|
||||
}
|
||||
|
||||
type ListObservedConversationsByChannelIdentityRow struct {
|
||||
|
||||
Reference in New Issue
Block a user