tangled
alpha
login
or
join now
parakeet.at
/
parakeet
62
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
62
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
use super::{PgExecResult, PgResult};
0
0
0
0
2
use chrono::prelude::*;
3
use chrono::{DateTime, Utc};
4
use deadpool_postgres::GenericClient;
···
36
37
let allow: HashSet<String> = HashSet::from_iter(allow);
38
39
-
if allow.contains("app.bsky.feed.threadgate#followerRule")
40
-
|| allow.contains("app.bsky.feed.threadgate#followingRule")
41
-
{
42
let profile_state: Option<(bool, bool)> = conn
43
.query_opt(
44
"SELECT following IS NOT NULL, followed IS NOT NULL FROM profile_states WHERE did=$1 AND subject=$2",
···
48
.map(|v| (v.get(0), v.get(1)));
49
50
if let Some((following, followed)) = profile_state {
51
-
if allow.contains("app.bsky.feed.threadgate#followerRule") && followed {
52
return Ok(false);
53
}
54
55
-
if allow.contains("app.bsky.feed.threadgate#followingRule") && following {
56
return Ok(false);
57
}
58
}
59
}
60
61
// check mentions
62
-
if allow.contains("app.bsky.feed.threadgate#mentionRule") {
63
let mentions: Vec<String> = conn
64
.query_opt("SELECT mentions FROM posts WHERE at_uri=$1", &[&root])
65
.await?
···
71
}
72
}
73
74
-
if allow.contains("app.bsky.feed.threadgate#listRule") {
75
if allow_lists.is_empty() {
76
return Ok(true);
77
}
···
1
use super::{PgExecResult, PgResult};
2
+
use crate::indexer::records::{
3
+
THREADGATE_RULE_FOLLOWER, THREADGATE_RULE_FOLLOWING, THREADGATE_RULE_LIST,
4
+
THREADGATE_RULE_MENTION,
5
+
};
6
use chrono::prelude::*;
7
use chrono::{DateTime, Utc};
8
use deadpool_postgres::GenericClient;
···
40
41
let allow: HashSet<String> = HashSet::from_iter(allow);
42
43
+
if allow.contains(THREADGATE_RULE_FOLLOWER) || allow.contains(THREADGATE_RULE_FOLLOWING) {
0
0
44
let profile_state: Option<(bool, bool)> = conn
45
.query_opt(
46
"SELECT following IS NOT NULL, followed IS NOT NULL FROM profile_states WHERE did=$1 AND subject=$2",
···
50
.map(|v| (v.get(0), v.get(1)));
51
52
if let Some((following, followed)) = profile_state {
53
+
if allow.contains(THREADGATE_RULE_FOLLOWER) && followed {
54
return Ok(false);
55
}
56
57
+
if allow.contains(THREADGATE_RULE_FOLLOWING) && following {
58
return Ok(false);
59
}
60
}
61
}
62
63
// check mentions
64
+
if allow.contains(THREADGATE_RULE_MENTION) {
65
let mentions: Vec<String> = conn
66
.query_opt("SELECT mentions FROM posts WHERE at_uri=$1", &[&root])
67
.await?
···
73
}
74
}
75
76
+
if allow.contains(THREADGATE_RULE_LIST) {
77
if allow_lists.is_empty() {
78
return Ok(true);
79
}
+9
-4
consumer/src/indexer/records.rs
···
272
pub hidden_replies: Vec<String>,
273
}
274
0
0
0
0
0
275
#[derive(Debug, Deserialize, Serialize)]
276
#[serde(tag = "$type")]
277
pub enum ThreadgateRule {
···
288
impl ThreadgateRule {
289
pub fn as_str(&self) -> &'static str {
290
match self {
291
-
ThreadgateRule::Mention => "app.bsky.feed.threadgate#mentionRule",
292
-
ThreadgateRule::Follower => "app.bsky.feed.threadgate#followerRule",
293
-
ThreadgateRule::Following => "app.bsky.feed.threadgate#followingRule",
294
-
ThreadgateRule::List { .. } => "app.bsky.feed.threadgate#listRule",
295
}
296
}
297
}
···
272
pub hidden_replies: Vec<String>,
273
}
274
275
+
pub const THREADGATE_RULE_MENTION: &str = "app.bsky.feed.threadgate#mentionRule";
276
+
pub const THREADGATE_RULE_FOLLOWER: &str = "app.bsky.feed.threadgate#followerRule";
277
+
pub const THREADGATE_RULE_FOLLOWING: &str = "app.bsky.feed.threadgate#followingRule";
278
+
pub const THREADGATE_RULE_LIST: &str = "app.bsky.feed.threadgate#listRule";
279
+
280
#[derive(Debug, Deserialize, Serialize)]
281
#[serde(tag = "$type")]
282
pub enum ThreadgateRule {
···
293
impl ThreadgateRule {
294
pub fn as_str(&self) -> &'static str {
295
match self {
296
+
ThreadgateRule::Mention => THREADGATE_RULE_MENTION,
297
+
ThreadgateRule::Follower => THREADGATE_RULE_FOLLOWER,
298
+
ThreadgateRule::Following => THREADGATE_RULE_FOLLOWING,
299
+
ThreadgateRule::List { .. } => THREADGATE_RULE_LIST,
300
}
301
}
302
}