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-3180]: update to not autoplay tenor gifs in mod queue #4669

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -2,7 +2,7 @@ import { Localized } from "@fluent/react/compat";
import React, { FunctionComponent, useCallback, useState } from "react";

import { ButtonPlayIcon, SvgIcon } from "coral-ui/components/icons";
import { BaseButton, Flex } from "coral-ui/components/v2";
import { BaseButton, Button, Flex } from "coral-ui/components/v2";

import styles from "./Media.css";

Expand All @@ -12,19 +12,56 @@ interface Props {
width: number | null;
height: number | null;
video: string | null;
url: string | null;
}

const GiphyMedia: FunctionComponent<Props> = ({
const GifMedia: FunctionComponent<Props> = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the name of this component since it is now used for displaying both Tenor and Giphy gifs.

still,
title,
width,
height,
video,
url,
}) => {
const [showAnimated, setShowAnimated] = useState(false);
const toggleImage = useCallback(() => {
setShowAnimated(!showAnimated);
}, [showAnimated]);

if (!still && !video) {
// Fallback to show/hide gif if there is no still and no video
return (
<>
<Button
iconLeft
variant="outlined"
color="regular"
onClick={toggleImage}
size="small"
className={styles.showHideButton}
aria-expanded="false"
>
{showAnimated ? (
<Localized id="comments-embedLinks-hide-gif">Hide GIF</Localized>
) : (
<Localized id="comments-embedLinks-show-gif">Show GIF</Localized>
)}
</Button>
{showAnimated && (
<div className={styles.embed}>
<img
src={url ?? ""}
className={styles.image}
loading="lazy"
referrerPolicy="no-referrer"
alt={title ?? ""}
/>
</div>
)}
</>
);
}

return (
<div className={styles.embed}>
{!showAnimated && still && (
Expand Down Expand Up @@ -74,4 +111,4 @@ const GiphyMedia: FunctionComponent<Props> = ({
);
};

export default GiphyMedia;
export default GifMedia;
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@
display: block;
max-width: 100%;
}

.showHideButton {
margin-top: var(--spacing-2);
margin-bottom: var(--spacing-2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { withFragmentContainer } from "coral-framework/lib/relay";
import { MediaContainer_comment } from "coral-admin/__generated__/MediaContainer_comment.graphql";

import ExternalMedia from "./ExternalMedia";
import GiphyMedia from "./GiphyMedia";
import TenorMedia from "./TenorMedia";
import GifMedia from "./GifMedia";
import TwitterMedia from "./TwitterMedia";
import YouTubeMedia from "./YouTubeMedia";

Expand All @@ -24,12 +23,13 @@ const MediaContainer: FunctionComponent<Props> = ({ comment }) => {
switch (media.__typename) {
case "GiphyMedia":
return (
<GiphyMedia
<GifMedia
still={media.still}
video={media.video}
title={media.title}
width={media.width}
height={media.height}
url={media.url}
/>
);
case "ExternalMedia":
Expand Down Expand Up @@ -59,7 +59,16 @@ const MediaContainer: FunctionComponent<Props> = ({ comment }) => {
/>
);
case "TenorMedia":
return <TenorMedia url={media.url} title={media.title} />;
return (
<GifMedia
still={media.tenorStill}
video={media.tenorVideo}
title={media.title}
width={media.width}
height={media.height}
url={media.url}
/>
);
case "%other":
return null;
}
Expand All @@ -86,6 +95,10 @@ const enhanced = withFragmentContainer<Props>({
... on TenorMedia {
url
title
width
height
tenorStill: still
tenorVideo: video
}
... on TwitterMedia {
url
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as MediaContainer } from "./MediaContainer";
export { default as GiphyMedia } from "./GiphyMedia";
export { default as GifMedia } from "./GifMedia";
export { default as TwitterMedia } from "./TwitterMedia";
export { default as YouTubeMedia } from "./YouTubeMedia";
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { graphql } from "react-relay";
import { withFragmentContainer } from "coral-framework/lib/relay";
import { HorizontalGutter, Timestamp } from "coral-ui/components/v2";
import ExternalMedia from "../MediaContainer/ExternalMedia";
import GiphyMedia from "../MediaContainer/GiphyMedia";
import GifMedia from "../MediaContainer/GifMedia";
import TwitterMedia from "../MediaContainer/TwitterMedia";
import YouTubeMedia from "../MediaContainer/YouTubeMedia";

import { CommentRevisionContainer_comment as CommentData } from "coral-admin/__generated__/CommentRevisionContainer_comment.graphql";

import { CommentContent } from "../Comment";
import TenorMedia from "../MediaContainer/TenorMedia";

interface Props {
comment: CommentData;
Expand All @@ -33,12 +32,13 @@ const CommentRevisionContainer: FunctionComponent<Props> = ({ comment }) => {
<Timestamp>{c.createdAt}</Timestamp>
<CommentContent>{c.body ? c.body : ""}</CommentContent>
{c.media && c.media.__typename === "GiphyMedia" && (
<GiphyMedia
<GifMedia
still={c.media.still}
video={c.media.video}
title={c.media.title}
width={c.media.width}
height={c.media.height}
url={c.media.url}
/>
)}
{c.media && c.media.__typename === "ExternalMedia" && (
Expand All @@ -65,7 +65,14 @@ const CommentRevisionContainer: FunctionComponent<Props> = ({ comment }) => {
/>
)}
{c.media && c.media.__typename === "TenorMedia" && (
<TenorMedia url={c.media.url} title={c.media.title} />
<GifMedia
still={c.media.tenorStill}
video={c.media.tenorVideo}
title={c.media.title}
width={c.media.width}
height={c.media.height}
url={c.media.url}
/>
)}
</div>
))}
Expand Down Expand Up @@ -100,6 +107,10 @@ const enhanced = withFragmentContainer<Props>({
... on TenorMedia {
url
title
width
height
tenorStill: still
tenorVideo: video
Comment on lines +112 to +113
Copy link
Contributor

@nick-funk nick-funk Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're aliasing these to still and video when we consume them from the API client side, do we want to call them TenorMedia > tenorStill and TenorMedia > tenorVideo? Seems like a duplication of the naming?

Maybe TenorMedia > still and TenorMedia > video?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was trying to keep this consistent with the naming for GiphyMedia, except that we might not have a still or video for some Tenor gifs, so types are different.

}
... on TwitterMedia {
url
Expand Down
44 changes: 44 additions & 0 deletions common/lib/types/tenor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export interface MediaFormat {
url: string;
duration: number;
dims: number[];
size: number;
}

export interface SearchResult {
id: string;
title: string;
created: number;
content_description: string;
itemurl: string;
url: string;
tags: string[];
flags: [];
hasaudio: boolean;
media_formats: {
webm: MediaFormat;
mp4: MediaFormat;
nanowebm: MediaFormat;
loopedmp4: MediaFormat;
gifpreview: MediaFormat;
tinygifpreview: MediaFormat;
nanomp4: MediaFormat;
nanogifpreview: MediaFormat;
tinymp4: MediaFormat;
gif: MediaFormat;
webp: MediaFormat;
mediumgif: MediaFormat;
tinygif: MediaFormat;
nanogif: MediaFormat;
tinywebm: MediaFormat;
};
}

export interface SearchPayload {
results: SearchResult[];
next: string;
}

export interface FetchPayload {
results: SearchResult[];
}
43 changes: 2 additions & 41 deletions server/src/core/server/app/handlers/api/tenor/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Joi from "joi";
import fetch from "node-fetch";

import { SearchPayload } from "coral-common/common/lib/types/tenor";
import { AppOptions } from "coral-server/app/";
import { RequestHandler, TenantCoralRequest } from "coral-server/types/express";

Expand All @@ -17,47 +18,6 @@ interface BodyPayload {
pos?: string;
}

interface MediaFormat {
url: string;
duration: number;
dims: number[];
size: number;
}

interface SearchResult {
id: string;
title: string;
created: number;
content_description: string;
itemurl: string;
url: string;
tags: string[];
flags: [];
hasaudio: boolean;
media_formats: {
webm: MediaFormat;
mp4: MediaFormat;
nanowebm: MediaFormat;
loopedmp4: MediaFormat;
gifpreview: MediaFormat;
tinygifpreview: MediaFormat;
nanomp4: MediaFormat;
nanogifpreview: MediaFormat;
tinymp4: MediaFormat;
gif: MediaFormat;
webp: MediaFormat;
mediumgif: MediaFormat;
tinygif: MediaFormat;
nanogif: MediaFormat;
tinywebm: MediaFormat;
};
}

interface SearchPayload {
results: SearchResult[];
next: string;
}

export const convertGiphyContentRatingToTenorLevel = (
rating: string | null | undefined
): string => {
Expand Down Expand Up @@ -133,6 +93,7 @@ export const tenorSearchHandler =
url.searchParams.set("key", apiKey);
url.searchParams.set("limit", `${SEARCH_LIMIT}`);
url.searchParams.set("contentfilter", contentFilter);
url.searchParams.set("media_filter", "gif,nanogif");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this media_filter to only return the response object formats that we need when we are calling the Tenor api here.


if (params.pos) {
url.searchParams.set("pos", params.pos);
Expand Down
27 changes: 26 additions & 1 deletion server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4013,6 +4013,26 @@ type TenorMedia {
title is the title of the GIF.
"""
title: String

"""
still is a thumbnail preview of the GIF.
"""
still: String

"""
video is a URL to the mp4 video of the GIF.
"""
video: String

"""
width is the width of the GIF in pixels.
"""
width: Int

"""
height is the height of the GIF in pixels.
"""
height: Int
}

"""
Expand Down Expand Up @@ -4125,7 +4145,12 @@ type ExternalMedia {
"""
CommentMedia is the various media types that can be attached to a Comment.
"""
union CommentMedia = GiphyMedia | TwitterMedia | YouTubeMedia | ExternalMedia | TenorMedia
union CommentMedia =
GiphyMedia
| TwitterMedia
| YouTubeMedia
| ExternalMedia
| TenorMedia

type CommentRevision {
"""
Expand Down
5 changes: 5 additions & 0 deletions server/src/core/server/models/comment/revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export interface TenorMedia {
type: "tenor";
id: string;
url: string;
title?: string;
still?: string;
width?: number;
height?: number;
video?: string;
}

export interface TwitterMedia {
Expand Down
Loading
Loading