diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-04-28 20:03:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 20:03:13 -0500 |
commit | a95c03e280ca153ba4a98d6b81ff9d743d4adcaa (patch) | |
tree | d3a63bcc87d24ad4c8e6e3893be0b54aca12b553 /src/state/models/content/post-thread.ts | |
parent | e68aa75429c2a0a495105f641361ee8fe22370f1 (diff) | |
download | voidsky-a95c03e280ca153ba4a98d6b81ff9d743d4adcaa.tar.zst |
Implement blocks (#554)
* Quick fix to prompt * Add blocked accounts screen * Add blocking tools to profile * Blur avis/banners of blocked users * Factor blocking state into moderation dsl * Filter post slices from the feed if any are hidden * Handle various block UIs * Filter in the client on blockedBy * Implement block list * Fix some copy * Bump deps * Fix lint
Diffstat (limited to 'src/state/models/content/post-thread.ts')
-rw-r--r-- | src/state/models/content/post-thread.ts | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/state/models/content/post-thread.ts b/src/state/models/content/post-thread.ts index 8f9a55032..18a42732c 100644 --- a/src/state/models/content/post-thread.ts +++ b/src/state/models/content/post-thread.ts @@ -13,6 +13,9 @@ import {updateDataOptimistically} from 'lib/async/revertible' import {PostLabelInfo, PostModeration} from 'lib/labeling/types' import { getEmbedLabels, + getEmbedMuted, + getEmbedBlocking, + getEmbedBlockedBy, filterAccountLabels, filterProfileLabels, getPostModeration, @@ -30,7 +33,10 @@ export class PostThreadItemModel { // data post: AppBskyFeedDefs.PostView postRecord?: FeedPost.Record - parent?: PostThreadItemModel | AppBskyFeedDefs.NotFoundPost + parent?: + | PostThreadItemModel + | AppBskyFeedDefs.NotFoundPost + | AppBskyFeedDefs.BlockedPost replies?: (PostThreadItemModel | AppBskyFeedDefs.NotFoundPost)[] richText?: RichText @@ -60,7 +66,18 @@ export class PostThreadItemModel { ), accountLabels: filterAccountLabels(this.post.author.labels), profileLabels: filterProfileLabels(this.post.author.labels), - isMuted: this.post.author.viewer?.muted || false, + isMuted: + this.post.author.viewer?.muted || + getEmbedMuted(this.post.embed) || + false, + isBlocking: + !!this.post.author.viewer?.blocking || + getEmbedBlocking(this.post.embed) || + false, + isBlockedBy: + !!this.post.author.viewer?.blockedBy || + getEmbedBlockedBy(this.post.embed) || + false, } } @@ -114,6 +131,8 @@ export class PostThreadItemModel { this.parent = parentModel } else if (AppBskyFeedDefs.isNotFoundPost(v.parent)) { this.parent = v.parent + } else if (AppBskyFeedDefs.isBlockedPost(v.parent)) { + this.parent = v.parent } } // replies @@ -218,6 +237,7 @@ export class PostThreadModel { // data thread?: PostThreadItemModel + isBlocked = false constructor( public rootStore: RootStoreModel, @@ -377,11 +397,17 @@ export class PostThreadModel { this._replaceAll(res) this._xIdle() } catch (e: any) { + console.log(e) this._xIdle(e) } } _replaceAll(res: GetPostThread.Response) { + this.isBlocked = AppBskyFeedDefs.isBlockedPost(res.data.thread) + if (this.isBlocked) { + return + } + pruneReplies(res.data.thread) sortThread(res.data.thread) const thread = new PostThreadItemModel( this.rootStore, @@ -399,7 +425,20 @@ export class PostThreadModel { type MaybePost = | AppBskyFeedDefs.ThreadViewPost | AppBskyFeedDefs.NotFoundPost + | AppBskyFeedDefs.BlockedPost | {[k: string]: unknown; $type: string} +function pruneReplies(post: MaybePost) { + if (post.replies) { + post.replies = (post.replies as MaybePost[]).filter((reply: MaybePost) => { + if (reply.blocked) { + return false + } + pruneReplies(reply) + return true + }) + } +} + function sortThread(post: MaybePost) { if (post.notFound) { return |