Repository navigation
p1: feat(relay): support explicit operator listener thread watches #8877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcdickenson
wants to merge
7
commits into
block:main
Choose a base branch
from
mcdickenson:airspace/bk-thread-webhooks-1031-883db6fa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,229
−66
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4796031
feat(relay): add target-consented listener thread watches
mcdickenson c92f912
Merge main and align listener thread migration and access context
mcdickenson 48a703d
Merge main and resolve listener thread migration conflicts
mcdickenson 180377e
Merge main and renumber operator_listener_threads migration to 0112
mcdickenson 2f248b0
Fix merge: add operator_listener_threads to never_fenced list and car…
mcdickenson 7c17ca9
Merge remote-tracking branch 'origin/main' into airspace/bk-thread-we…
mcdickenson d6ffed5
fix(db): include operator_listener_threads in pre-retirement drift as…
mcdickenson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,8 @@ pub struct ClaimedDelivery { | |
| pub event_id: Vec<u8>, | ||
| /// Mentioning event kind. | ||
| pub event_kind: i32, | ||
| /// Present only for a delivery authorized by an explicit thread watch. | ||
| pub thread_root_event_id: Option<Vec<u8>>, | ||
| /// Author-controlled event timestamp. | ||
| pub event_created_at: DateTime<Utc>, | ||
| /// Attempt number, starting at one. | ||
|
|
@@ -101,7 +103,7 @@ pub(crate) async fn enqueue_mentions_in_transaction( | |
| } | ||
| let targets = event_targets(event); | ||
| if targets.is_empty() { | ||
| return Ok(0); | ||
| return super::operator_listener_threads::enqueue_thread_replies(tx, event).await; | ||
| } | ||
| let event_created_at = DateTime::from_timestamp(event.created_at.as_secs() as i64, 0).ok_or( | ||
| crate::error::DbError::InvalidTimestamp(event.created_at.as_secs() as i64), | ||
|
|
@@ -127,7 +129,9 @@ pub(crate) async fn enqueue_mentions_in_transaction( | |
| } | ||
| separated.push_unseparated(") ON CONFLICT DO NOTHING"); | ||
|
|
||
| Ok(query.build().execute(tx.conn()).await?.rows_affected()) | ||
| let mentions = query.build().execute(tx.conn()).await?.rows_affected(); | ||
| let replies = super::operator_listener_threads::enqueue_thread_replies(tx, event).await?; | ||
| Ok(mentions + replies) | ||
| } | ||
|
|
||
| /// Register target pubkeys for one deployment-global listener. | ||
|
|
@@ -229,7 +233,7 @@ pub async fn claim_deliveries( | |
| JOIN communities community ON community.id = c.community_id \ | ||
| WHERE o.id = c.id \ | ||
| RETURNING o.id, o.claim_id, o.listener_pubkey, o.target_pubkey, o.community_id, \ | ||
| community.host, o.event_id, o.event_kind, o.event_created_at, o.attempts", | ||
| community.host, o.event_id, o.event_kind, o.thread_root_event_id, o.event_created_at, o.attempts", | ||
| ) | ||
| .bind(claim_id) | ||
| .bind(MAX_DELIVERY_ATTEMPTS) | ||
|
|
@@ -250,6 +254,7 @@ pub async fn claim_deliveries( | |
| community_host: row.try_get("host")?, | ||
| event_id: row.try_get("event_id")?, | ||
| event_kind: row.try_get("event_kind")?, | ||
| thread_root_event_id: row.try_get("thread_root_event_id")?, | ||
| event_created_at: row.try_get("event_created_at")?, | ||
| attempt: row.try_get("attempts")?, | ||
| }) | ||
|
|
@@ -298,6 +303,22 @@ pub async fn load_deliverable_event( | |
| JOIN events e ON e.community_id = $3 AND e.created_at = $4 AND e.id = $5 \ | ||
| WHERE r.listener_pubkey = $1 AND r.target_pubkey = $2 \ | ||
| AND e.deleted_at IS NULL \ | ||
| AND ($9::bytea IS NULL OR EXISTS ( \ | ||
| SELECT 1 FROM operator_listener_threads w \ | ||
| JOIN channels wc ON wc.community_id = w.community_id AND wc.id = w.channel_id \ | ||
| AND wc.deleted_at IS NULL AND wc.archived_at IS NULL \ | ||
| JOIN users wu ON wu.community_id = w.community_id AND wu.pubkey = w.target_pubkey AND wu.deactivated_at IS NULL \ | ||
| JOIN channel_members wm ON wm.community_id = w.community_id AND wm.channel_id = w.channel_id \ | ||
| AND wm.pubkey = w.target_pubkey AND wm.removed_at IS NULL \ | ||
| JOIN events root ON root.community_id = w.community_id AND root.channel_id = w.channel_id \ | ||
| AND root.id = w.root_event_id AND root.deleted_at IS NULL \ | ||
| JOIN thread_metadata tm ON tm.community_id = w.community_id AND tm.channel_id = w.channel_id \ | ||
| AND tm.event_id = e.id AND tm.event_created_at = e.created_at \ | ||
| AND tm.parent_event_id IS NOT NULL \ | ||
| AND COALESCE(tm.root_event_id, tm.parent_event_id) = w.root_event_id \ | ||
| WHERE w.community_id = $3 AND w.listener_pubkey = $1 AND w.target_pubkey = $2 \ | ||
| AND w.root_event_id = $9 AND w.channel_id = e.channel_id AND w.expires_at > now() \ | ||
| AND r.created_at >= now() - interval '30 days')) \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 nit: this hard-codes |
||
| AND (NOT $8 OR EXISTS ( \ | ||
| SELECT 1 FROM pubkey_allowlist a \ | ||
| WHERE a.community_id = $3 AND a.pubkey = $2)) \ | ||
|
|
@@ -327,6 +348,7 @@ pub async fn load_deliverable_event( | |
| .bind(admission.require_membership) | ||
| .bind(admission.allow_owner_membership) | ||
| .bind(admission.require_allowlist) | ||
| .bind(&delivery.thread_root_event_id) | ||
| .fetch_optional(&mut *connection) | ||
| .await?; | ||
| match row { | ||
|
|
@@ -1237,6 +1259,7 @@ mod postgres_tests { | |
| community_host: String::new(), | ||
| event_id: event.id.as_bytes().to_vec(), | ||
| event_kind: 9, | ||
| thread_root_event_id: None, | ||
| event_created_at: DateTime::from_timestamp( | ||
| event.created_at.as_secs() as i64, | ||
| 0, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 this runs the thread-watch
INSERT ... SELECTfor every top-level message too, inside the event's write transaction, even though only replies can match. could we gate it on the event actually being a reply? passing in the root thatinsert_event_with_thread_metadata_txalready resolved would skip the call for top-level messages and also remove thethread_metadatalookup insideenqueue_thread_replies. same applies to the early return at line 106.