-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9c9619
commit da8db3a
Showing
48 changed files
with
545 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useEffect, useMemo } from 'react' | ||
import { usePostInfoDetails } from '../DataSource/usePostInfo' | ||
import { DefaultTypedMessageRenderer } from './TypedMessageRenderer' | ||
import { PluginUI } from '../../plugins/plugin' | ||
import { makeTypedMessageCompound, isTypedMessageSuspended, isTypedMessageKnown } from '../../protocols/typed-message' | ||
import { useValueRef } from '../../utils/hooks/useValueRef' | ||
import { currentPostReplacementScopeSettings, PostReplacementScope } from '../../settings/settings' | ||
import { makeStyles, Theme } from '@material-ui/core' | ||
|
||
const useStlyes = makeStyles((theme: Theme) => ({ | ||
root: { | ||
overflowWrap: 'break-word', | ||
}, | ||
})) | ||
|
||
export interface PostReplacerProps { | ||
zip?: () => void | ||
unzip?: () => void | ||
} | ||
|
||
export function PostReplacer(props: PostReplacerProps) { | ||
const classes = useStlyes() | ||
const postContent = usePostInfoDetails('postContent') | ||
const postMessage = usePostInfoDetails('postMessage') | ||
const postPayload = usePostInfoDetails('postPayload') | ||
const postRepalcementScope = useValueRef(currentPostReplacementScopeSettings) | ||
|
||
const plugins = [...PluginUI.values()] | ||
const processedPostMessage = useMemo( | ||
() => plugins.reduce((x, plugin) => plugin.messageProcessor?.(x) ?? x, postMessage), | ||
[plugins.map((x) => x.identifier).join(), postContent], | ||
) | ||
const shouldReplacePost = | ||
// replace all posts | ||
postRepalcementScope === PostReplacementScope.all || | ||
// replace posts which enhanced by plugins | ||
(postRepalcementScope === PostReplacementScope.enhancedOnly && | ||
processedPostMessage.items.some((x) => !isTypedMessageKnown(x))) || | ||
// replace posts which encrypted by maskbook | ||
(postRepalcementScope === PostReplacementScope.encryptedOnly && postPayload.ok) | ||
|
||
// zip/unzip original post | ||
useEffect(() => { | ||
if (shouldReplacePost) props.zip?.() | ||
else props.unzip?.() | ||
}, [shouldReplacePost]) | ||
|
||
return shouldReplacePost ? ( | ||
<span className={classes.root}> | ||
<DefaultTypedMessageRenderer | ||
message={makeTypedMessageCompound( | ||
processedPostMessage.items.filter((x) => !isTypedMessageSuspended(x)), | ||
)} | ||
/> | ||
</span> | ||
) : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.