diff --git a/src/components/InjectedComponents/PostDummy.tsx b/src/components/InjectedComponents/PostDummy.tsx index 120fa5d70220..da5819f35239 100644 --- a/src/components/InjectedComponents/PostDummy.tsx +++ b/src/components/InjectedComponents/PostDummy.tsx @@ -2,16 +2,33 @@ import React from 'react' import { usePostInfoDetails } from '../DataSource/usePostInfo' import { DefaultTypedMessageRenderer } from './TypedMessageRenderer' import { PluginUI } from '../../plugins/plugin' -import { makeTypedMessageCompound, isTypedMessageSuspended } from '../../protocols/typed-message' +import { makeTypedMessageCompound, isTypedMessageSuspended, isTypedMessageBuiltIn } from '../../protocols/typed-message' +import { useValueRef } from '../../utils/hooks/useValueRef' +import { currentWholePostVisibilitySettings, WholePostVisibility } from '../../settings/settings' export interface PostDummyProps {} export function PostDummy(props: PostDummyProps) { - const postMessage = usePostInfoDetails('parsedPostContent') + const parsedPostContent = usePostInfoDetails('parsedPostContent') + const postPayload = usePostInfoDetails('postPayload') + const wholePostVisibilitySettings = useValueRef(currentWholePostVisibilitySettings) + const processedPostMessage = Array.from(PluginUI.values()).reduce( (x, plugin) => (plugin.postMessageProcessor ? plugin.postMessageProcessor(x) : x), - postMessage, + parsedPostContent, + ) + + // render dummy for posts which enhanced by plugins + if ( + wholePostVisibilitySettings === WholePostVisibility.enhancedOnly && + processedPostMessage.items.every(isTypedMessageBuiltIn) ) + return null + + // render dummy for posts which encrypted by maskbook + if (wholePostVisibilitySettings === WholePostVisibility.encryptedOnly && !postPayload.ok) return null + + // render dummy for all posts return ( !isTypedMessageSuspended(x)))} diff --git a/src/protocols/typed-message/types.ts b/src/protocols/typed-message/types.ts index cb6051bb529d..178124765f80 100644 --- a/src/protocols/typed-message/types.ts +++ b/src/protocols/typed-message/types.ts @@ -47,6 +47,10 @@ export interface TypedMessageSuspended ex readonly tag?: string } +export function isTypedMessageBuiltIn(x: TypedMessage) { + return ['text', 'anchor', 'unknown', 'compound', 'image', 'empty', 'suspended'].includes(x.type) +} + export function isTypedMessageText(x: TypedMessage): x is TypedMessageText { return x.type === 'text' } diff --git a/src/social-network-provider/facebook.com/UI/collectPosts.tsx b/src/social-network-provider/facebook.com/UI/collectPosts.tsx index 11e2ed595f32..53e602f2faa7 100644 --- a/src/social-network-provider/facebook.com/UI/collectPosts.tsx +++ b/src/social-network-provider/facebook.com/UI/collectPosts.tsx @@ -83,6 +83,7 @@ export function collectPostsFacebook(this: SocialNetworkUI) { info.postMetadataImages.add(url) nextTypedMessage.push(makeTypedMessageImage(url)) } + // parse post content info.parsedPostContent.value = makeTypedMessageCompound(nextTypedMessage) } collectPostInfo()