From dee2684737fc08df92ee5541382e214b009095cd Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 17:06:03 +0700 Subject: [PATCH 1/8] Add rules to use react-tweet only if it's a link to tweet, not profile --- src/components/chats/ChatItem/Embed.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/chats/ChatItem/Embed.tsx b/src/components/chats/ChatItem/Embed.tsx index 214469dd3..0c27f3c71 100644 --- a/src/components/chats/ChatItem/Embed.tsx +++ b/src/components/chats/ChatItem/Embed.tsx @@ -55,7 +55,8 @@ const urlMapper: { ) }, checker: (link: string) => - /(?:https?:\/\/)?(?:www\.)?(?:twitter\.com)\/(.+)/.test(link), + /(?:https?:\/\/)?(?:www\.)?(?:twitter\.com)\/(.+)/.test(link) && + /\/status\/\d+/.test(link), }, { name: 'tiktok', From 40ca88f82ae5bc00f057ef4b9f39c821ab53dc40 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 17:23:17 +0700 Subject: [PATCH 2/8] Improve message modal scroll to message button and embed overflows --- src/components/chats/ChatItem/Embed.tsx | 2 +- src/components/modals/MessageModal.tsx | 39 ++++++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/chats/ChatItem/Embed.tsx b/src/components/chats/ChatItem/Embed.tsx index 0c27f3c71..80707b980 100644 --- a/src/components/chats/ChatItem/Embed.tsx +++ b/src/components/chats/ChatItem/Embed.tsx @@ -17,7 +17,7 @@ export default function Embed({ link: url, ...props }: EmbedProps) { return ( Component && ( -
+
) diff --git a/src/components/modals/MessageModal.tsx b/src/components/modals/MessageModal.tsx index 7c0f44dd9..a6db70923 100644 --- a/src/components/modals/MessageModal.tsx +++ b/src/components/modals/MessageModal.tsx @@ -78,29 +78,34 @@ export default function MessageModal({ >
{message && ( - +
+ +
)} {scrollToMessage && ( - +
+ +
)}
{isDifferentRecipient && recipient && ( From 283b566f448c73f47c21b76b87cc4ce1c4029d89 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 17:30:15 +0700 Subject: [PATCH 3/8] Fix replicated in text area not working on edit modal --- src/components/inputs/TextArea.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/inputs/TextArea.tsx b/src/components/inputs/TextArea.tsx index 4e3330677..3a5cf10d0 100644 --- a/src/components/inputs/TextArea.tsx +++ b/src/components/inputs/TextArea.tsx @@ -52,6 +52,13 @@ const TextArea = forwardRef( replicated.textContent = (props.value ?? '') + ' ' }, [props.value]) + useEffect(() => { + const textArea = textAreaRef.current + const replicated = replicatedRef.current + if (!replicated || !textArea) return + replicated.textContent = textArea.value + ' ' + }, []) + const onKeyDown: KeyboardEventHandler = (e) => { if (!isTouchDevice() && e.key === 'Enter' && !e.shiftKey) { e.preventDefault() From 198fdd0938e9208cf031c8d493575fc43d47d412 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 17:55:50 +0700 Subject: [PATCH 4/8] Only show https images in link preview --- src/components/chats/ChatItem/LinkPreview.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/chats/ChatItem/LinkPreview.tsx b/src/components/chats/ChatItem/LinkPreview.tsx index 9858e477b..de41ed21a 100644 --- a/src/components/chats/ChatItem/LinkPreview.tsx +++ b/src/components/chats/ChatItem/LinkPreview.tsx @@ -39,6 +39,8 @@ export default function LinkPreview({ length: 300, }) + const isValidImage = linkMetadata.image?.startsWith('https://') + return (
{truncatedDesc}

- {linkMetadata.image && ( + {linkMetadata.image && isValidImage && ( Date: Mon, 28 Aug 2023 22:09:42 +0700 Subject: [PATCH 5/8] Use portal to render recaptch --- src/components/captcha/CaptchaInvisible.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/captcha/CaptchaInvisible.tsx b/src/components/captcha/CaptchaInvisible.tsx index 14ba37c16..37d94f28e 100644 --- a/src/components/captcha/CaptchaInvisible.tsx +++ b/src/components/captcha/CaptchaInvisible.tsx @@ -1,5 +1,6 @@ import { getCaptchaSiteKey } from '@/utils/env/client' import React, { useRef } from 'react' +import { createPortal } from 'react-dom' import ReCAPTCHA from 'react-google-recaptcha' import { toast } from 'react-hot-toast' import Toast from '../Toast' @@ -38,13 +39,16 @@ export default function CaptchaInvisible({ children }: CaptchaInvisibleProps) { {children(runCaptcha, (className) => ( ))} - + {createPortal( + , + document.body + )} ) } From 56d173863f4ac93e43e45b15a6f09874bd3ec476 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 22:49:18 +0700 Subject: [PATCH 6/8] Add try catch to CID parse --- src/utils/ipfs.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/utils/ipfs.ts b/src/utils/ipfs.ts index a00bce200..d0f6263ee 100644 --- a/src/utils/ipfs.ts +++ b/src/utils/ipfs.ts @@ -21,14 +21,18 @@ export function getIpfsContentUrl( if (uri.startsWith('http')) return uri - const ipfsCid = CID.parse(uri) - if (!ipfsCid) return uri - - const isCbor = ipfsCid.code === CID_KIND.CBOR - if (isCbor) { - return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/api/v0/dag/get?arg=${uri}`) - } - return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/ipfs/${uri}`) + try { + const ipfsCid = CID.parse(uri) + if (!ipfsCid) return uri + + const isCbor = ipfsCid.code === CID_KIND.CBOR + if (isCbor) { + return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/api/v0/dag/get?arg=${uri}`) + } + return urlJoin(SUBSOCIAL_IPFS_GATEWAY, `/ipfs/${uri}`) + } catch {} + + return uri } export function getCidFromMetadataLink(link: string) { From 455701de5b4464c2907e45c1906694c2b879740d Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 23:06:13 +0700 Subject: [PATCH 7/8] Remove min width from react tweet embed and fix message modal --- src/components/chats/ChatItem/Embed.module.css | 1 + src/components/modals/MessageModal.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/chats/ChatItem/Embed.module.css b/src/components/chats/ChatItem/Embed.module.css index 4ef1049e8..b60261e92 100644 --- a/src/components/chats/ChatItem/Embed.module.css +++ b/src/components/chats/ChatItem/Embed.module.css @@ -1,3 +1,4 @@ .Embed :global(.react-tweet-theme) { --tweet-body-font-size: 1rem; + min-width: auto; } diff --git a/src/components/modals/MessageModal.tsx b/src/components/modals/MessageModal.tsx index a6db70923..072a50d8e 100644 --- a/src/components/modals/MessageModal.tsx +++ b/src/components/modals/MessageModal.tsx @@ -78,7 +78,7 @@ export default function MessageModal({ >
From 951c20170f088587ca7fc6509129fcde9f382e80 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Mon, 28 Aug 2023 23:08:35 +0700 Subject: [PATCH 8/8] Cache link metadata scraping error --- src/pages/api/posts.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/api/posts.ts b/src/pages/api/posts.ts index 41e8d89f1..cb1f252ba 100644 --- a/src/pages/api/posts.ts +++ b/src/pages/api/posts.ts @@ -134,6 +134,7 @@ export async function getPostsServer(postIds: string[]): Promise { const getMetadataRedisKey = (url: string) => 'metadata:' + url const METADATA_MAX_AGE = 60 * 60 * 24 * 30 // 1 month +const METADATA_ERROR_MAX_AGE = 60 * 60 * 24 // 1 day async function getLinkMetadata(link: string): Promise { const cachedData = await redisCallWrapper((redis) => redis?.get(getMetadataRedisKey(link)) @@ -164,6 +165,14 @@ async function getLinkMetadata(link: string): Promise { return parsedMetadata } catch (err) { console.error('Error fetching page metadata for link: ', link) + redisCallWrapper((redis) => + redis?.set( + getMetadataRedisKey(link), + JSON.stringify(null), + 'EX', + METADATA_ERROR_MAX_AGE + ) + ) return null } }