tangled
alpha
login
or
join now
parakeet.at
/
parakeet
63
fork
atom
Parakeet is a Rust-based Bluesky AppServer aiming to implement most of the functionality required to support the Bluesky client
appview
atproto
bluesky
rust
appserver
63
fork
atom
overview
issues
12
pulls
pipelines
consts for threadgate rules
mia.omg.lol
5 months ago
c0f3cd76
a3338668
verified
This commit was signed with the committer's
known signature
.
mia.omg.lol
SSH Key Fingerprint:
SHA256:eb+NhC0QEl+XKRuFP/97oH6LEz0TXTKPXGDIAI5y7CQ=
+18
-11
2 changed files
expand all
collapse all
unified
split
consumer
src
db
gates.rs
indexer
records.rs
+9
-7
consumer/src/db/gates.rs
···
1
1
use super::{PgExecResult, PgResult};
2
2
+
use crate::indexer::records::{
3
3
+
THREADGATE_RULE_FOLLOWER, THREADGATE_RULE_FOLLOWING, THREADGATE_RULE_LIST,
4
4
+
THREADGATE_RULE_MENTION,
5
5
+
};
2
6
use chrono::prelude::*;
3
7
use chrono::{DateTime, Utc};
4
8
use deadpool_postgres::GenericClient;
···
36
40
37
41
let allow: HashSet<String> = HashSet::from_iter(allow);
38
42
39
39
-
if allow.contains("app.bsky.feed.threadgate#followerRule")
40
40
-
|| allow.contains("app.bsky.feed.threadgate#followingRule")
41
41
-
{
43
43
+
if allow.contains(THREADGATE_RULE_FOLLOWER) || allow.contains(THREADGATE_RULE_FOLLOWING) {
42
44
let profile_state: Option<(bool, bool)> = conn
43
45
.query_opt(
44
46
"SELECT following IS NOT NULL, followed IS NOT NULL FROM profile_states WHERE did=$1 AND subject=$2",
···
48
50
.map(|v| (v.get(0), v.get(1)));
49
51
50
52
if let Some((following, followed)) = profile_state {
51
51
-
if allow.contains("app.bsky.feed.threadgate#followerRule") && followed {
53
53
+
if allow.contains(THREADGATE_RULE_FOLLOWER) && followed {
52
54
return Ok(false);
53
55
}
54
56
55
55
-
if allow.contains("app.bsky.feed.threadgate#followingRule") && following {
57
57
+
if allow.contains(THREADGATE_RULE_FOLLOWING) && following {
56
58
return Ok(false);
57
59
}
58
60
}
59
61
}
60
62
61
63
// check mentions
62
62
-
if allow.contains("app.bsky.feed.threadgate#mentionRule") {
64
64
+
if allow.contains(THREADGATE_RULE_MENTION) {
63
65
let mentions: Vec<String> = conn
64
66
.query_opt("SELECT mentions FROM posts WHERE at_uri=$1", &[&root])
65
67
.await?
···
71
73
}
72
74
}
73
75
74
74
-
if allow.contains("app.bsky.feed.threadgate#listRule") {
76
76
+
if allow.contains(THREADGATE_RULE_LIST) {
75
77
if allow_lists.is_empty() {
76
78
return Ok(true);
77
79
}
+9
-4
consumer/src/indexer/records.rs
···
272
272
pub hidden_replies: Vec<String>,
273
273
}
274
274
275
275
+
pub const THREADGATE_RULE_MENTION: &str = "app.bsky.feed.threadgate#mentionRule";
276
276
+
pub const THREADGATE_RULE_FOLLOWER: &str = "app.bsky.feed.threadgate#followerRule";
277
277
+
pub const THREADGATE_RULE_FOLLOWING: &str = "app.bsky.feed.threadgate#followingRule";
278
278
+
pub const THREADGATE_RULE_LIST: &str = "app.bsky.feed.threadgate#listRule";
279
279
+
275
280
#[derive(Debug, Deserialize, Serialize)]
276
281
#[serde(tag = "$type")]
277
282
pub enum ThreadgateRule {
···
288
293
impl ThreadgateRule {
289
294
pub fn as_str(&self) -> &'static str {
290
295
match self {
291
291
-
ThreadgateRule::Mention => "app.bsky.feed.threadgate#mentionRule",
292
292
-
ThreadgateRule::Follower => "app.bsky.feed.threadgate#followerRule",
293
293
-
ThreadgateRule::Following => "app.bsky.feed.threadgate#followingRule",
294
294
-
ThreadgateRule::List { .. } => "app.bsky.feed.threadgate#listRule",
296
296
+
ThreadgateRule::Mention => THREADGATE_RULE_MENTION,
297
297
+
ThreadgateRule::Follower => THREADGATE_RULE_FOLLOWER,
298
298
+
ThreadgateRule::Following => THREADGATE_RULE_FOLLOWING,
299
299
+
ThreadgateRule::List { .. } => THREADGATE_RULE_LIST,
295
300
}
296
301
}
297
302
}