Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.1' into released
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Apr 3, 2019
2 parents f9efcff + 703e856 commit be43caf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/components/InjectedComponents/AdditionalPostContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const _AdditionalContent = withStylesTyped({})<Props>(props => {
<>
<Divider style={{ marginBottom: 6 }} />
<Typography variant="caption" style={{ display: 'flex' }}>
<img
src={chrome.runtime.getURL('/maskbook-icon-padded.png')}
style={{ transform: 'translate(-1px, -1px)' }}
width={16}
height={16}
/>
{props.title}
</Typography>
<Typography variant="body1" style={{ marginBottom: 6, marginTop: 6, lineHeight: 1.2 }}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/InjectedComponents/DecryptedPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ interface Props {
encryptedText: string
}
export function DecryptPost({ postBy, whoAmI, encryptedText }: Props) {
const [_, a] = encryptedText.split('🎼')
const [b, _2] = a.split(':||')
return (
<AsyncComponent
promise={async (encryptedString: string) => CryptoService.decryptFrom(encryptedString, postBy, whoAmI)}
promise={async (encryptedString: string) => CryptoService.decryptFrom(b, postBy, whoAmI)}
values={[encryptedText]}
awaitingComponent={DecryptPostAwaiting}
completeComponent={DecryptPostSuccess}
Expand Down
7 changes: 4 additions & 3 deletions src/extension/background-script/CryptoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ async function decryptFrom(
by: string,
whoAmI: string,
): Promise<{ signatureVerifyResult: boolean; content: string }> {
const [version, ownersAESKeyEncrypted, salt, encryptedText, _signature] = encrypted.split('|')
const signature = _signature.replace(/:$/, '')
const [version, ownersAESKeyEncrypted, salt, encryptedText, signature] = encrypted.split('|')
if (!version || !ownersAESKeyEncrypted || !salt || !encryptedText || !signature)
throw new TypeError('This post is not complete, you need to view the full post.')
// 1/4 === version 41
if (version !== '1/4') throw new TypeError('Unknown post type')
if (!ownersAESKeyEncrypted || !salt || !encryptedText || !signature) throw new TypeError('Invalid post')
Expand Down Expand Up @@ -118,7 +119,7 @@ async function decryptFrom(
const aesKeyEncrypted = await queryPostAESKey(salt, whoAmI)
if (aesKeyEncrypted === undefined) {
throw new Error(
'Maskbook does not find key that you can used to decrypt this post. Maybe this post is not send to you?',
'Maskbook does not find the key used to decrypt this post. Maybe this post is not intended to share with you?',
)
}
const content = decodeText(
Expand Down
32 changes: 22 additions & 10 deletions src/extension/content-script/injections/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ const posts = new LiveSelector().querySelectorAll<HTMLDivElement>('.userContent'
return true
})

const PostInspector = (props: { post: string; postBy: string; postId: string }) => {
const PostInspector = (props: { post: string; postBy: string; postId: string; needZip(): void }) => {
const { post, postBy, postId } = props
const type = {
encryptedPost: post.match(/Maskbook.io:🎼?(?<text>.+)(?<!See More)( .+)?$/)!,
encryptedPost: post.match('Maskbook.io:🎼') && post.match(':||'),
provePost: post.match(/🔒(.+)🔒/)!,
}

if (type.encryptedPost) {
return (
<DecryptPost
encryptedText={type.encryptedPost.groups!.text!}
whoAmI={myUsername.evaluateOnce()[0]!}
postBy={postBy}
/>
)
props.needZip()
return <DecryptPost encryptedText={post} whoAmI={myUsername.evaluateOnce()[0]!} postBy={postBy} />
} else if (type.provePost) {
PeopleService.uploadProvePostUrl(postBy, postId)
return <AddToKeyStore postBy={postBy} provePost={post} />
Expand Down Expand Up @@ -75,7 +70,24 @@ new MutationObserverWatcher(posts)
}
// Render it
const render = () => {
ReactDOM.render(<PostInspector postId={postId} post={node.current.innerText} postBy={postBy} />, node.after)
console.log(node)
ReactDOM.render(
<PostInspector
needZip={() => {
const pe = node.current.parentElement
if (!pe) return
const p = pe.querySelector('p')
if (!p) return
p.style.display = 'block'
p.style.maxHeight = '20px'
p.style.overflow = 'hidden'
}}
postId={postId}
post={node.current.innerText}
postBy={postBy}
/>,
node.after,
)
}
render()
return {
Expand Down

0 comments on commit be43caf

Please sign in to comment.