Skip to content

Commit

Permalink
Hide posts from blocked/muted users from timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Oct 29, 2024
1 parent 644eb89 commit 667968a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Version 0.1.4

To be released.

- Fixed the home timeline showing the shared posts from the blocked or muted
accounts.


Version 0.1.3
-------------
Expand Down
50 changes: 50 additions & 0 deletions src/api/v1/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ app.get(
),
),
),
// Hide the posts from the muted accounts:
notInArray(
posts.accountId,
db
Expand All @@ -230,20 +231,69 @@ app.get(
),
),
),
// Hide the posts from the blocked accounts:
notInArray(
posts.accountId,
db
.select({ accountId: blocks.blockedAccountId })
.from(blocks)
.where(eq(blocks.accountId, owner.id)),
),
// Hide the posts from the accounts who blocked the owner:
notInArray(
posts.accountId,
db
.select({ accountId: blocks.accountId })
.from(blocks)
.where(eq(blocks.blockedAccountId, owner.id)),
),
// Hide the shared posts from the muted accounts:
or(
isNull(posts.sharingId),
notInArray(
posts.sharingId,
db
.select({ id: posts.id })
.from(posts)
.innerJoin(mutes, eq(mutes.mutedAccountId, posts.accountId))
.where(
and(
eq(mutes.accountId, owner.id),
or(
isNull(mutes.duration),
gt(
sql`${mutes.created} + ${mutes.duration}`,
sql`CURRENT_TIMESTAMP`,
),
),
),
),
),
),
// Hide the shared posts from the blocked accounts:
or(
isNull(posts.sharingId),
notInArray(
posts.sharingId,
db
.select({ id: posts.id })
.from(posts)
.innerJoin(blocks, eq(blocks.blockedAccountId, posts.accountId))
.where(eq(blocks.accountId, owner.id)),
),
),
// Hide the shared posts from the accounts who blocked the owner:
or(
isNull(posts.sharingId),
notInArray(
posts.sharingId,
db
.select({ id: posts.id })
.from(posts)
.innerJoin(blocks, eq(blocks.accountId, posts.accountId))
.where(eq(blocks.blockedAccountId, owner.id)),
),
),
query.max_id == null ? undefined : lt(posts.id, query.max_id),
query.min_id == null ? undefined : gt(posts.id, query.min_id),
),
Expand Down

0 comments on commit 667968a

Please sign in to comment.