diff options
Diffstat (limited to 'src/state/models/content')
-rw-r--r-- | src/state/models/content/post-thread.ts | 43 | ||||
-rw-r--r-- | src/state/models/content/profile.ts | 32 |
2 files changed, 73 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 diff --git a/src/state/models/content/profile.ts b/src/state/models/content/profile.ts index ea75d19c6..dddf488a3 100644 --- a/src/state/models/content/profile.ts +++ b/src/state/models/content/profile.ts @@ -1,5 +1,6 @@ import {makeAutoObservable, runInAction} from 'mobx' import { + AtUri, ComAtprotoLabelDefs, AppBskyActorGetProfile as GetProfile, AppBskyActorProfile, @@ -23,6 +24,8 @@ export class ProfileViewerModel { muted?: boolean following?: string followedBy?: string + blockedBy?: boolean + blocking?: string constructor() { makeAutoObservable(this) @@ -86,6 +89,8 @@ export class ProfileModel { accountLabels: filterAccountLabels(this.labels), profileLabels: filterProfileLabels(this.labels), isMuted: this.viewer?.muted || false, + isBlocking: !!this.viewer?.blocking || false, + isBlockedBy: !!this.viewer?.blockedBy || false, } } @@ -185,6 +190,33 @@ export class ProfileModel { await this.refresh() } + async blockAccount() { + const res = await this.rootStore.agent.app.bsky.graph.block.create( + { + repo: this.rootStore.me.did, + }, + { + subject: this.did, + createdAt: new Date().toISOString(), + }, + ) + this.viewer.blocking = res.uri + await this.refresh() + } + + async unblockAccount() { + if (!this.viewer.blocking) { + return + } + const {rkey} = new AtUri(this.viewer.blocking) + await this.rootStore.agent.app.bsky.graph.block.delete({ + repo: this.rootStore.me.did, + rkey, + }) + this.viewer.blocking = undefined + await this.refresh() + } + // state transitions // = |