Skip to content

Commit

Permalink
fix(composer): image payload for different content
Browse files Browse the repository at this point in the history
fix promte text for normal text
  • Loading branch information
UncleBill committed Jun 11, 2022
1 parent 614bac0 commit e4e7383
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
3 changes: 2 additions & 1 deletion packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"promote": "🎭 🎭🎭 Tired of plaintext?Try to send encrypted message to you friends. Install Mask.io to send your first encrypted tweet.",
"promote_red_packet": "🧧🧧🧧 Try sending Lucky Drop to your friends with tokens or NFTs to share the joy now! Install Mask.io to send your first Lucky Drop.",
"promote_ito": "Launch decentralized assets freely and participate in token launch directly on Twitter! Install Mask.io to participate in your first token launch activity.",
"promote_ito_short": "Install Mask.io to launch dencentralized assests freely on Twitter!",
Expand Down Expand Up @@ -59,7 +60,7 @@
"additional_post_box__encrypted_post_pre_ito": "$t(promote_ito) {{encrypted}}",
"additional_post_box__encrypted_post_pre_file_service_twitter_official_account": "$t(promote_file_service)\n {{encrypted}}",
"additional_post_box__encrypted_post_pre_file_service": "$t(promote_file_service) {{encrypted}}",
"additional_post_box__steganography_post_pre": "This image is encrypted with #mask_io.\n{{random}}\n$t(promote_red_packet)\n",
"additional_post_box__steganography_post_pre": "This image is encrypted with #mask_io.\n{{random}}\n$t(promote)",
"auto_paste_failed_dialog_title": "Paste manually",
"auto_paste_failed_dialog_content": "Please copy the following text and image (if there is any) and publish it.",
"auto_paste_failed_dialog_image_caption": "Open in a new tab",
Expand Down
59 changes: 36 additions & 23 deletions packages/mask/src/components/CompositionDialog/useSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'r
activatedSocialNetworkUI.encryptionNetwork,
)
const encrypted = socialNetworkEncoder(activatedSocialNetworkUI.encryptionNetwork, _encrypted)
const decoratedText = decorateEncryptedText(encrypted, t, content.meta)
const [imageTemplateType, decoratedText] = decorateEncryptedText(encrypted, t, content.meta)

if (encode === 'image') {
const defaultText = t('additional_post_box__steganography_post_pre', {
random: new Date().toLocaleString(),
})
if (decoratedText !== null) {
await pasteImage(decoratedText.replace(encrypted, ''), encrypted, 'eth', reason)
if (decoratedText) {
await pasteImage(decoratedText.replace(encrypted, ''), encrypted, imageTemplateType, reason)
} else {
await pasteImage(defaultText, encrypted, 'v2', reason)
}
Expand Down Expand Up @@ -74,31 +74,44 @@ async function pasteImage(

// TODO: Provide API to plugin to post-process post content,
// then we can move these -PreText's and meta readers into plugin's own context
function decorateEncryptedText(encrypted: string, t: I18NFunction, meta?: Meta) {
function decorateEncryptedText(
encrypted: string,
t: I18NFunction,
meta?: Meta,
): [imageTemplateType: ImageTemplateTypes, text: string] | never[] {
const hasOfficialAccount = isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI)
const officialAccount = isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account')

if (RedPacketMetadataReader(meta).ok) {
return hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_red_packet_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_red_packet', { encrypted })
return [
'eth',
hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_red_packet_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_red_packet', { encrypted }),
]
} else if (ITO_MetadataReader(meta).ok) {
return hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_ito_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_ito', { encrypted })
return [
'v2',
hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_ito_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_ito', { encrypted }),
]
} else if (FileInfoMetadataReader(meta).ok) {
return hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_file_service_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_file_service', { encrypted })
return [
'v2',
hasOfficialAccount
? t('additional_post_box__encrypted_post_pre_file_service_twitter_official_account', {
encrypted,
account: officialAccount,
})
: t('additional_post_box__encrypted_post_pre_file_service', { encrypted }),
]
}
return null
return []
}

0 comments on commit e4e7383

Please sign in to comment.