diff --git a/app/components/HoverPreview/HoverPreviewDocument.tsx b/app/components/HoverPreview/HoverPreviewDocument.tsx index 23a52bf875..1688eb629f 100644 --- a/app/components/HoverPreview/HoverPreviewDocument.tsx +++ b/app/components/HoverPreview/HoverPreviewDocument.tsx @@ -13,10 +13,7 @@ import { Description, } from "./Components"; -type Props = Omit< - UnfurlResponse[UnfurlResourceType.Document], - "type" | "fetchedAt" ->; +type Props = Omit; const HoverPreviewDocument = React.forwardRef(function _HoverPreviewDocument( { url, id, title, summary, lastActivityByViewer }: Props, diff --git a/app/components/HoverPreview/HoverPreviewIssue.tsx b/app/components/HoverPreview/HoverPreviewIssue.tsx index 30b82bbd89..032328ffa0 100644 --- a/app/components/HoverPreview/HoverPreviewIssue.tsx +++ b/app/components/HoverPreview/HoverPreviewIssue.tsx @@ -16,10 +16,7 @@ import { Info, } from "./Components"; -type Props = Omit< - UnfurlResponse[UnfurlResourceType.Issue], - "type" | "fetchedAt" ->; +type Props = Omit; const HoverPreviewIssue = React.forwardRef(function _HoverPreviewIssue( { url, id, title, description, author, labels, state, createdAt }: Props, diff --git a/app/components/HoverPreview/HoverPreviewMention.tsx b/app/components/HoverPreview/HoverPreviewMention.tsx index 47291fe380..4c44fdab3d 100644 --- a/app/components/HoverPreview/HoverPreviewMention.tsx +++ b/app/components/HoverPreview/HoverPreviewMention.tsx @@ -4,10 +4,7 @@ import { Avatar, AvatarSize } from "~/components/Avatar"; import Flex from "~/components/Flex"; import { Preview, Title, Info, Card, CardContent } from "./Components"; -type Props = Omit< - UnfurlResponse[UnfurlResourceType.Mention], - "type" | "fetchedAt" ->; +type Props = Omit; const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention( { avatarUrl, name, lastActive, color, email }: Props, diff --git a/app/components/HoverPreview/HoverPreviewPullRequest.tsx b/app/components/HoverPreview/HoverPreviewPullRequest.tsx index 16eb8200f5..6393695134 100644 --- a/app/components/HoverPreview/HoverPreviewPullRequest.tsx +++ b/app/components/HoverPreview/HoverPreviewPullRequest.tsx @@ -15,7 +15,7 @@ import { Info, } from "./Components"; -type Props = Omit; +type Props = Omit; const HoverPreviewPullRequest = React.forwardRef( function _HoverPreviewPullRequest( diff --git a/app/stores/UnfurlsStore.ts b/app/stores/UnfurlsStore.ts index 6d90d0cedf..42692e90c9 100644 --- a/app/stores/UnfurlsStore.ts +++ b/app/stores/UnfurlsStore.ts @@ -70,7 +70,7 @@ class UnfurlsStore extends Store> { return this.add({ id: url, type: data.type, - fetchedAt: data.fetchedAt, + fetchedAt: new Date().toISOString(), data, } as Unfurl); } catch (err) { diff --git a/server/presenters/unfurl.ts b/server/presenters/unfurl.ts index 376b990b85..0a7826bbee 100644 --- a/server/presenters/unfurl.ts +++ b/server/presenters/unfurl.ts @@ -10,35 +10,23 @@ async function presentUnfurl( data: Record, options?: { includeEmail: boolean } ) { - let unfurl: Omit; - switch (data.type) { - case UnfurlResourceType.Mention: { - unfurl = await presentMention(data, options); - break; - } - case UnfurlResourceType.Document: { - unfurl = presentDocument(data); - break; - } - case UnfurlResourceType.PR: { - unfurl = presentPR(data); - break; - } - case UnfurlResourceType.Issue: { - unfurl = presentIssue(data); - break; - } + case UnfurlResourceType.Mention: + return presentMention(data, options); + case UnfurlResourceType.Document: + return presentDocument(data); + case UnfurlResourceType.PR: + return presentPR(data); + case UnfurlResourceType.Issue: + return presentIssue(data); default: - unfurl = presentOEmbed(data); + return presentOEmbed(data); } - - return { ...unfurl, fetchedAt: new Date() }; } const presentOEmbed = ( data: Record -): Omit => ({ +): UnfurlResponse[UnfurlResourceType.OEmbed] => ({ type: UnfurlResourceType.OEmbed, url: data.url, title: data.title, @@ -49,7 +37,7 @@ const presentOEmbed = ( const presentMention = async ( data: Record, options?: { includeEmail: boolean } -): Promise> => { +): Promise => { const user: User = data.user; const document: Document = data.document; @@ -68,7 +56,7 @@ const presentMention = async ( const presentDocument = ( data: Record -): Omit => { +): UnfurlResponse[UnfurlResourceType.Document] => { const document: Document = data.document; const viewer: User = data.viewer; return { @@ -83,7 +71,7 @@ const presentDocument = ( const presentPR = ( data: Record -): Omit => ({ +): UnfurlResponse[UnfurlResourceType.PR] => ({ url: data.html_url, type: UnfurlResourceType.PR, id: `#${data.number}`, @@ -102,7 +90,7 @@ const presentPR = ( const presentIssue = ( data: Record -): Omit => ({ +): UnfurlResponse[UnfurlResourceType.Issue] => ({ url: data.html_url, type: UnfurlResourceType.Issue, id: `#${data.number}`, diff --git a/shared/types.ts b/shared/types.ts index 8a7d482836..15d0ab4e61 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -377,8 +377,6 @@ export type UnfurlResponse = { description: string; /** A URL to a thumbnail image representing the resource */ thumbnailUrl: string; - /** Unfurl fetched time */ - fetchedAt: string; }; [UnfurlResourceType.Mention]: { /** The resource type */ @@ -393,8 +391,6 @@ export type UnfurlResponse = { color: string; /** Mentiond user's recent activity */ lastActive: string; - /** Unfurl fetched time */ - fetchedAt: string; }; [UnfurlResourceType.Document]: { /** The resource type */ @@ -409,8 +405,6 @@ export type UnfurlResponse = { summary: string; /** Viewer's last activity on this document */ lastActivityByViewer: string; - /** Unfurl fetched time */ - fetchedAt: string; }; [UnfurlResourceType.Issue]: { /** The resource type */ @@ -431,8 +425,6 @@ export type UnfurlResponse = { state: { name: string; color: string }; /** Issue's creation time */ createdAt: string; - /** Unfurl fetched time */ - fetchedAt: string; }; [UnfurlResourceType.PR]: { /** The resource type */ @@ -451,8 +443,6 @@ export type UnfurlResponse = { state: { name: string; color: string }; /** Pull Request creation time */ createdAt: string; - /** Unfurl fetched time */ - fetchedAt: string; }; };