Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORL-3202] Add bluesky to embed options #4705

Merged
merged 16 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { FunctionComponent } from "react";

import Frame from "coral-framework/components/Frame";

import styles from "./Media.css";

interface Props {
id: string;
url: string;
siteID: string;
}

const BlueskyMedia: FunctionComponent<Props> = ({ id, url, siteID }) => {
const component = encodeURIComponent(url);
return (
<div className={styles.embed}>
<Frame
id={id}
src={`/api/oembed?type=bluesky&url=${component}&siteID=${siteID}`}
width="100%"
showFullHeight
/>
</div>
);
};

export default BlueskyMedia;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FunctionComponent } from "react";
import { graphql } from "react-relay";

import { withFragmentContainer } from "coral-framework/lib/relay";
import BlueskyMedia from "coral-stream/common/Media/BlueskyMedia";

import { MediaContainer_comment } from "coral-admin/__generated__/MediaContainer_comment.graphql";

Expand Down Expand Up @@ -48,6 +49,14 @@ const MediaContainer: FunctionComponent<Props> = ({ comment }) => {
siteID={comment.site.id}
/>
);
case "BlueskyMedia":
return (
<BlueskyMedia
id={comment.id}
url={media.url}
siteID={comment.site.id}
/>
);
case "YouTubeMedia":
return (
<YouTubeMedia
Expand Down Expand Up @@ -103,6 +112,9 @@ const enhanced = withFragmentContainer<Props>({
... on TwitterMedia {
url
}
... on BlueskyMedia {
url
}
... on YouTubeMedia {
url
still
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as MediaContainer } from "./MediaContainer";
export { default as GifMedia } from "./GifMedia";
export { default as TwitterMedia } from "./TwitterMedia";
export { default as BlueskyMedia } from "./BlueskyMedia";
export { default as YouTubeMedia } from "./YouTubeMedia";
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ graphql`
twitter {
enabled
}
bluesky {
enabled
}
youtube {
enabled
}
Expand Down Expand Up @@ -90,6 +93,26 @@ const MediaLinksConfig: FunctionComponent<Props> = ({ disabled }) => {
/>
</FormField>

<FormField>
<Localized id="configure-general-embedLinks-enableBlueskyEmbeds">
<Label component="legend">Allow Bluesky post embeds</Label>
</Localized>
<OnOffField
name="media.bluesky.enabled"
disabled={disabled}
onLabel={
<Localized id="configure-general-embedLinks-On">
<span>Yes</span>
</Localized>
}
offLabel={
<Localized id="configure-general-embedLinks-Off">
<span>No</span>
</Localized>
}
/>
</FormField>

<FormField>
<Localized id="configure-general-embedLinks-enableYouTubeEmbeds">
<Label component="legend">Allow YouTube embeds</Label>
Expand Down
1 change: 1 addition & 0 deletions client/src/core/client/admin/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const settings = createFixture<GQLSettings>({
premoderateSuspectWords: false,
media: {
twitter: { enabled: false },
bluesky: { enabled: false },
gifs: { enabled: false },
youtube: { enabled: false },
external: { enabled: false },
Expand Down
2 changes: 1 addition & 1 deletion client/src/core/client/framework/components/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Props {
isToggled?: boolean;
width?: string;
showFullHeight?: boolean;
type?: "twitter" | "youtube" | "external_media";
type?: "twitter" | "bluesky" | "youtube" | "external_media";
mobile?: boolean;
}

Expand Down
30 changes: 30 additions & 0 deletions client/src/core/client/stream/common/Media/BlueskyMedia.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FunctionComponent } from "react";

import Frame from "coral-framework/components/Frame";

interface Props {
id?: string;
url: string;
siteID: string;
isToggled?: boolean;
}

const BlueskyMedia: FunctionComponent<Props> = ({
id,
url,
siteID,
isToggled,
}) => {
const component = encodeURIComponent(url);
return (
<Frame
id={id}
width="100%"
src={`/api/oembed?type=bluesky&url=${component}&siteID=${siteID}`}
isToggled={isToggled}
type="bluesky"
/>
);
};

export default BlueskyMedia;
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function getMediaFromComment(comment: CommentData) {
type: "twitter",
url: comment.revision.media.url,
};
case "BlueskyMedia":
return {
type: "bluesky",
url: comment.revision.media.url,
};
case "ExternalMedia":
return {
type: "external",
Expand Down Expand Up @@ -211,6 +216,10 @@ const enhanced = withEditCommentMutation(
url
width
}
... on BlueskyMedia {
url
width
}
... on YouTubeMedia {
url
width
Expand Down Expand Up @@ -248,6 +257,9 @@ const enhanced = withEditCommentMutation(
twitter {
enabled
}
bluesky {
enabled
}
youtube {
enabled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const mutation = graphql`
url
width
}
... on BlueskyMedia {
url
width
}
... on YouTubeMedia {
url
width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const MediaConfirmPrompt: FunctionComponent<Props> = ({
</p>
</Localized>
)}
{media.type === "bluesky" && (
<Localized id="comments-postComment-confirmMedia-bluesky">
<p className={styles.prompt}>
Add this post to the end of your comment?
</p>
</Localized>
)}
<p className={styles.url}>{media.url}</p>
</div>
</div>
Expand All @@ -76,6 +83,17 @@ const MediaConfirmPrompt: FunctionComponent<Props> = ({
</Button>
</Localized>
)}
{media.type === "bluesky" && (
<Localized id="comments-postComment-confirmMedia-add-bluesky">
<Button
color="mono"
onClick={onConfirm}
className={styles.promptButton}
>
Add post
</Button>
</Localized>
)}
{media.type === "youtube" && (
<Localized id="comments-postComment-confirmMedia-add-video">
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FunctionComponent } from "react";

import { MediaLink } from "coral-common/common/lib/helpers/findMediaLinks";
import {
BlueskyLogoIcon,
ImageFileLandscapeIcon,
SvgIcon,
VideoPlayerIcon,
Expand All @@ -20,6 +21,9 @@ const MediaConfirmationIcon: FunctionComponent<Props> = ({ media }) => {
{media.type === "twitter" && (
<SvgIcon size="xs" filled="currentColor" Icon={XLogoTwitterIcon} />
)}
{media.type === "bluesky" && (
<SvgIcon filled="currentColor" Icon={BlueskyLogoIcon} />
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TwitterMedia,
YouTubeMedia,
} from "coral-stream/common/Media";
import BlueskyMedia from "coral-stream/common/Media/BlueskyMedia";
import { RemoveIcon, SvgIcon } from "coral-ui/components/icons";
import { Flex, HorizontalGutter, MatchMedia } from "coral-ui/components/v2";
import { Button } from "coral-ui/components/v3";
Expand Down Expand Up @@ -62,13 +63,18 @@ const MediaPreview: FunctionComponent<Props> = ({
</Flex>

{/* Show the actual media. */}
{media.type === "external" ? (
{media.type === "external" && (
<ExternalMedia url={media.url} siteID={siteID} />
) : media.type === "twitter" ? (
)}
{media.type === "twitter" && (
<TwitterMedia url={media.url} siteID={siteID} />
) : media.type === "youtube" ? (
)}
{media.type === "bluesky" && (
<BlueskyMedia url={media.url} siteID={siteID} />
)}
{media.type === "youtube" && (
<YouTubeMedia url={media.url} siteID={siteID} isToggled={true} />
) : null}
)}
</HorizontalGutter>

{/* On extra small screens, move the remove button to the bottom! */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MediaSectionContainer_comment } from "coral-stream/__generated__/MediaS
import { MediaSectionContainer_settings } from "coral-stream/__generated__/MediaSectionContainer_settings.graphql";
import { MediaSectionContainerLocal } from "coral-stream/__generated__/MediaSectionContainerLocal.graphql";

import BlueskyMedia from "coral-stream/common/Media/BlueskyMedia";
import styles from "./MediaSectionContainer.css";

interface Props {
Expand Down Expand Up @@ -84,7 +85,9 @@ const MediaSectionContainer: FunctionComponent<Props> = ({
(media.__typename === "TwitterMedia" && !settings.media.twitter.enabled) ||
(media.__typename === "YouTubeMedia" && !settings.media.youtube.enabled) ||
(media.__typename === "GiphyMedia" && !settings.media.gifs.enabled) ||
(media.__typename === "ExternalMedia" && !settings.media.external.enabled)
(media.__typename === "ExternalMedia" &&
!settings.media.external.enabled) ||
(media.__typename === "BlueskyMedia" && !settings.media.bluesky.enabled)
) {
return null;
}
Expand All @@ -103,6 +106,9 @@ const MediaSectionContainer: FunctionComponent<Props> = ({
{media.__typename === "TwitterMedia" && (
<Localized id="comments-embedLinks-show-twitter">Show post</Localized>
)}
{media.__typename === "BlueskyMedia" && (
<Localized id="comments-embedLinks-show-bluesky">Show post</Localized>
)}
{media.__typename === "YouTubeMedia" && (
<Localized id="comments-embedLinks-show-youtube">
Show video
Expand Down Expand Up @@ -144,6 +150,11 @@ const MediaSectionContainer: FunctionComponent<Props> = ({
Hide post
</Localized>
)}
{media.__typename === "BlueskyMedia" && (
<Localized id="comments-embedLinks-hide-bluesky">
Hide post
</Localized>
)}
{media.__typename === "GiphyMedia" && (
<Localized id="comments-embedLinks-hide-gif">Hide GIF</Localized>
)}
Expand Down Expand Up @@ -178,6 +189,14 @@ const MediaSectionContainer: FunctionComponent<Props> = ({
isToggled={isToggled}
/>
)}
{media.__typename === "BlueskyMedia" && (
<BlueskyMedia
id={comment.id}
url={media.url}
siteID={comment.site.id}
isToggled={isToggled}
/>
)}
{media.__typename === "YouTubeMedia" && (
<YouTubeMedia
id={comment.id}
Expand Down Expand Up @@ -224,6 +243,10 @@ const enhanced = withFragmentContainer<Props>({
url
width
}
... on BlueskyMedia {
url
width
}
... on YouTubeMedia {
url
width
Expand All @@ -242,6 +265,9 @@ const enhanced = withFragmentContainer<Props>({
twitter {
enabled
}
bluesky {
enabled
}
youtube {
enabled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const CopyCommentEmbedCodeContainer: FunctionComponent<Props> = ({
break;
// Twitter and YouTube media embeds already have links in comments
// so they don't also need to be added to the simple comment fallback
case "%other" || "TwitterMedia" || "YouTubeMedia":
case "%other" || "TwitterMedia" || "BlueskyMedia" || "YouTubeMedia":
break;
}
}
Expand Down Expand Up @@ -163,6 +163,9 @@ const enhanced = withFragmentContainer<Props>({
... on TwitterMedia {
url
}
... on BlueskyMedia {
url
}
... on YouTubeMedia {
url
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ const enhanced = withCreateCommentReplyMutation(
twitter {
enabled
}
bluesky {
enabled
}
youtube {
enabled
}
Expand Down
Loading