feat(feed): include remote following posts in home feed
This commit is contained in:
@@ -67,6 +67,19 @@ struct FeedRow {
|
|||||||
boosted_by_viewer: bool,
|
boosted_by_viewer: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn federation_following_clause(follower: Option<uuid::Uuid>) -> String {
|
||||||
|
match follower {
|
||||||
|
Some(fid) => format!(
|
||||||
|
" OR t.user_id IN (
|
||||||
|
SELECT u2.id FROM users u2
|
||||||
|
JOIN federation_following ff ON u2.ap_id = ff.remote_actor_url
|
||||||
|
WHERE ff.local_user_id = '{fid}'
|
||||||
|
)"
|
||||||
|
),
|
||||||
|
None => String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn feed_select(viewer: Option<uuid::Uuid>) -> String {
|
fn feed_select(viewer: Option<uuid::Uuid>) -> String {
|
||||||
let viewer_checks = match viewer {
|
let viewer_checks = match viewer {
|
||||||
Some(uid) => format!(
|
Some(uid) => format!(
|
||||||
@@ -146,16 +159,19 @@ impl FeedRepository for PgFeedRepository {
|
|||||||
) -> Result<Paginated<FeedEntry>, DomainError> {
|
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||||
let ids: Vec<uuid::Uuid> = following_ids.iter().map(|id| id.as_uuid()).collect();
|
let ids: Vec<uuid::Uuid> = following_ids.iter().map(|id| id.as_uuid()).collect();
|
||||||
let viewer = viewer_id.map(|v| v.as_uuid());
|
let viewer = viewer_id.map(|v| v.as_uuid());
|
||||||
let total: i64 = sqlx::query_scalar(
|
let fed_clause = federation_following_clause(viewer);
|
||||||
"SELECT COUNT(*) FROM thoughts t WHERE t.user_id=ANY($1) AND t.visibility != 'direct'",
|
let count_sql = format!(
|
||||||
)
|
"SELECT COUNT(*) FROM thoughts t WHERE (t.user_id=ANY($1){}) AND t.visibility != 'direct'",
|
||||||
|
fed_clause
|
||||||
|
);
|
||||||
|
let total: i64 = sqlx::query_scalar(&count_sql)
|
||||||
.bind(&ids)
|
.bind(&ids)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
.map_err(|e| DomainError::Internal(e.to_string()))?;
|
||||||
|
|
||||||
let sel = feed_select(viewer);
|
let sel = feed_select(viewer);
|
||||||
let sql = format!("{sel} WHERE t.user_id=ANY($1) AND t.visibility != 'direct' ORDER BY t.created_at DESC LIMIT $2 OFFSET $3");
|
let sql = format!("{sel} WHERE (t.user_id=ANY($1){}) AND t.visibility != 'direct' ORDER BY t.created_at DESC LIMIT $2 OFFSET $3", fed_clause);
|
||||||
let rows = sqlx::query_as::<_, FeedRow>(&sql)
|
let rows = sqlx::query_as::<_, FeedRow>(&sql)
|
||||||
.bind(&ids)
|
.bind(&ids)
|
||||||
.bind(page.limit())
|
.bind(page.limit())
|
||||||
|
|||||||
Reference in New Issue
Block a user