diff --git a/CHANGELOG.md b/CHANGELOG.md index 5280b940ee..0a32b14065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [4.6.2] - 2026-06-25 + +### Security + +- Update FFMpeg version used in the container image to fix [CVE-2026-8461](https://github.com/advisories/GHSA-qff7-4q6c-m8h6) (critical severity) + ## [4.6.1] - 2026-06-24 ### Security diff --git a/app/controllers/disputes/appeals_controller.rb b/app/controllers/disputes/appeals_controller.rb index 00034e1ab2..797f31cf78 100644 --- a/app/controllers/disputes/appeals_controller.rb +++ b/app/controllers/disputes/appeals_controller.rb @@ -8,7 +8,7 @@ class Disputes::AppealsController < Disputes::BaseController @appeal = AppealService.new.call(@strike, appeal_params[:text]) - redirect_to admin_disputes_strike_path(@strike), notice: I18n.t('disputes.strikes.appealed_msg') + redirect_to disputes_strike_path(@strike), notice: I18n.t('disputes.strikes.appealed_msg') rescue ActiveRecord::RecordInvalid => e @appeal = e.record render 'disputes/strikes/show' diff --git a/app/javascript/mastodon/actions/picture_in_picture.ts b/app/javascript/mastodon/actions/picture_in_picture.ts index d34b508a33..26cdb17fa7 100644 --- a/app/javascript/mastodon/actions/picture_in_picture.ts +++ b/app/javascript/mastodon/actions/picture_in_picture.ts @@ -29,3 +29,8 @@ export const deployPictureInPicture = createAppAsyncThunk( } }, ); + +export type DeployPictureInPictureCallback = ( + type: 'audio' | 'video', + props: PIPMediaProps, +) => void; diff --git a/app/javascript/mastodon/components/account_header/fields.tsx b/app/javascript/mastodon/components/account_header/fields.tsx index e949f848f4..ba8c9f39f8 100644 --- a/app/javascript/mastodon/components/account_header/fields.tsx +++ b/app/javascript/mastodon/components/account_header/fields.tsx @@ -220,7 +220,7 @@ const FieldHTML: FC = ({ }; function useColumnWrap() { - const listRef = useRef(null); + const listRef = useRef(null); const handleRecalculate = useCallback(() => { const listEle = listRef.current; @@ -330,7 +330,7 @@ function useFieldOverflow() { const [isLabelOverflowing, setIsLabelOverflowing] = useState(false); const [isValueOverflowing, setIsValueOverflowing] = useState(false); - const wrapperRef = useRef(null); + const wrapperRef = useRef(null); const handleRecalculate = useCallback(() => { const wrapperEle = wrapperRef.current; diff --git a/app/javascript/mastodon/components/account_header/name.tsx b/app/javascript/mastodon/components/account_header/name.tsx index 5bd2ed80db..e66affae1b 100644 --- a/app/javascript/mastodon/components/account_header/name.tsx +++ b/app/javascript/mastodon/components/account_header/name.tsx @@ -111,7 +111,7 @@ const AccountNameHelp: FC<{ } onHide={handleClick} offset={[5, 5]} > diff --git a/app/javascript/mastodon/components/account_header/subscription_form.tsx b/app/javascript/mastodon/components/account_header/subscription_form.tsx index e09e7d4b14..346f8181f3 100644 --- a/app/javascript/mastodon/components/account_header/subscription_form.tsx +++ b/app/javascript/mastodon/components/account_header/subscription_form.tsx @@ -90,7 +90,7 @@ export const AccountSubscriptionForm: React.FC<{ accountId: string }> = ({ [], ); - const handleSubmit = useCallback( + const handleSubmit = useCallback( (e) => { e.preventDefault(); diff --git a/app/javascript/mastodon/components/alt_text_badge/index.tsx b/app/javascript/mastodon/components/alt_text_badge/index.tsx index a33325dee5..535ba3d1b6 100644 --- a/app/javascript/mastodon/components/alt_text_badge/index.tsx +++ b/app/javascript/mastodon/components/alt_text_badge/index.tsx @@ -64,7 +64,7 @@ export const AltTextBadge: React.FC<{ rootClose onHide={handleClose} show={open} - target={buttonRef} + target={buttonRef as React.RefObject} placement='top-end' flip offset={offset} diff --git a/app/javascript/mastodon/components/autosuggest/utils.ts b/app/javascript/mastodon/components/autosuggest/utils.ts new file mode 100644 index 0000000000..bef96374bf --- /dev/null +++ b/app/javascript/mastodon/components/autosuggest/utils.ts @@ -0,0 +1,29 @@ +export const textAtCursorMatchesToken = ( + str: string, + caretPosition: number, + searchTokens: string[], +) => { + let word: string; + + const regex = new RegExp(`[${searchTokens.join('')}\\w]+(\\s[\\w]+)?$`); + const left = str.slice(0, caretPosition).search(regex); + const right = str.slice(caretPosition).search(/\s/); + + if (right < 0) { + word = str.slice(left); + } else { + word = str.slice(left, right + caretPosition); + } + + word = word.trim(); + + if (word.length < 3 || (word[0] && !searchTokens.includes(word[0]))) { + return [null, null]; + } + + if (word.length > 0) { + return [left + 1, word]; + } else { + return [null, null]; + } +}; diff --git a/app/javascript/mastodon/components/autosuggest_input.jsx b/app/javascript/mastodon/components/autosuggest_input.jsx index 4a3b7d9040..b3062ec383 100644 --- a/app/javascript/mastodon/components/autosuggest_input.jsx +++ b/app/javascript/mastodon/components/autosuggest_input.jsx @@ -12,31 +12,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg import { AutosuggestEmoji } from './autosuggest_emoji'; import { AutosuggestHashtag } from './autosuggest_hashtag'; import { LocalCustomEmojiProvider } from './emoji/context'; - -const textAtCursorMatchesToken = (str, caretPosition, searchTokens) => { - let word; - - let left = str.slice(0, caretPosition).search(/\S+$/); - let right = str.slice(caretPosition).search(/\s/); - - if (right < 0) { - word = str.slice(left); - } else { - word = str.slice(left, right + caretPosition); - } - - if (!word || word.trim().length < 3 || searchTokens.indexOf(word[0]) === -1) { - return [null, null]; - } - - word = word.trim(); - - if (word.length > 0) { - return [left + 1, word]; - } else { - return [null, null]; - } -}; +import { textAtCursorMatchesToken } from './autosuggest/utils'; export default class AutosuggestInput extends ImmutablePureComponent { diff --git a/app/javascript/mastodon/components/autosuggest_textarea.jsx b/app/javascript/mastodon/components/autosuggest_textarea.jsx index fb99f62a73..333c195447 100644 --- a/app/javascript/mastodon/components/autosuggest_textarea.jsx +++ b/app/javascript/mastodon/components/autosuggest_textarea.jsx @@ -13,31 +13,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg import { AutosuggestEmoji } from './autosuggest_emoji'; import { AutosuggestHashtag } from './autosuggest_hashtag'; import { LocalCustomEmojiProvider } from './emoji/context'; - -const textAtCursorMatchesToken = (str, caretPosition) => { - let word; - - let left = str.slice(0, caretPosition).search(/\S+$/); - let right = str.slice(caretPosition).search(/\s/); - - if (right < 0) { - word = str.slice(left); - } else { - word = str.slice(left, right + caretPosition); - } - - if (!word || word.trim().length < 3 || ['@', '@', ':', '#', '#'].indexOf(word[0]) === -1) { - return [null, null]; - } - - word = word.trim(); - - if (word.length > 0) { - return [left + 1, word]; - } else { - return [null, null]; - } -}; +import { textAtCursorMatchesToken } from './autosuggest/utils'; const AutosuggestTextarea = forwardRef(({ value, @@ -64,7 +40,7 @@ const AutosuggestTextarea = forwardRef(({ const tokenStartRef = useRef(0); const handleChange = useCallback((e) => { - const [ tokenStart, token ] = textAtCursorMatchesToken(e.target.value, e.target.selectionStart); + const [ tokenStart, token ] = textAtCursorMatchesToken(e.target.value, e.target.selectionStart, ['@', '@', ':', '#', '#']); if (token !== null && lastTokenRef.current !== token) { tokenStartRef.current = tokenStart; diff --git a/app/javascript/mastodon/components/carousel/index.tsx b/app/javascript/mastodon/components/carousel/index.tsx index bc287aa969..391e7fa7c5 100644 --- a/app/javascript/mastodon/components/carousel/index.tsx +++ b/app/javascript/mastodon/components/carousel/index.tsx @@ -106,7 +106,7 @@ export const Carousel = < [items.length, onChangeSlide], ); - const observerRef = useRef(null); + const observerRef = useRef(null); observerRef.current ??= new ResizeObserver(() => { handleSlideChange(0); }); @@ -235,7 +235,7 @@ const CarouselSlideWrapper = ({ className={className} role='group' aria-roledescription='slide' - inert={active ? undefined : ''} + inert={active} data-index={index} > {children} diff --git a/app/javascript/mastodon/components/dropdown/index.tsx b/app/javascript/mastodon/components/dropdown/index.tsx index 4edc78f50b..eec14bdc52 100644 --- a/app/javascript/mastodon/components/dropdown/index.tsx +++ b/app/javascript/mastodon/components/dropdown/index.tsx @@ -109,7 +109,7 @@ export const Dropdown: FC< placement='bottom-start' onHide={handleClose} flip - target={buttonRef} + target={buttonRef as React.RefObject} popperConfig={{ strategy: 'fixed', modifiers: [matchWidth], diff --git a/app/javascript/mastodon/components/dropdown_menu.tsx b/app/javascript/mastodon/components/dropdown_menu.tsx index 107b256e18..7394ad5638 100644 --- a/app/javascript/mastodon/components/dropdown_menu.tsx +++ b/app/javascript/mastodon/components/dropdown_menu.tsx @@ -352,7 +352,7 @@ export const Dropdown = ({ ); const [currentId] = useState(id++); const open = currentId === openDropdownId; - const buttonRef = useRef(null); + const buttonRef = useRef(null); const menuId = useId(); const prefetchAccountId = status ? status.getIn(['account', 'id']) @@ -518,7 +518,7 @@ export const Dropdown = ({ offset={offset} placement={placement} flip - target={buttonRef} + target={buttonRef as React.RefObject} popperConfig={popperConfig} > {({ props, arrowProps, placement }) => ( diff --git a/app/javascript/mastodon/components/form_fields/checkbox_field.tsx b/app/javascript/mastodon/components/form_fields/checkbox_field.tsx index c08b81ca36..78bbb32e4f 100644 --- a/app/javascript/mastodon/components/form_fields/checkbox_field.tsx +++ b/app/javascript/mastodon/components/form_fields/checkbox_field.tsx @@ -30,7 +30,7 @@ CheckboxField.displayName = 'CheckboxField'; export const Checkbox = forwardRef( ({ className, size, indeterminate, ...otherProps }, ref) => { - const inputRef = useRef(null); + const inputRef = useRef(null); const handleRef = useCallback( (element: HTMLInputElement | null) => { diff --git a/app/javascript/mastodon/components/form_fields/combobox_field.tsx b/app/javascript/mastodon/components/form_fields/combobox_field.tsx index 9c7d259571..5fcc1ce70f 100644 --- a/app/javascript/mastodon/components/form_fields/combobox_field.tsx +++ b/app/javascript/mastodon/components/form_fields/combobox_field.tsx @@ -236,7 +236,7 @@ const ComboboxWithRef = ( ) => { const intl = useIntl(); const wrapperRef = useRef(null); - const inputRef = useRef(); + const inputRef = useRef(null); const popoverRef = useRef(null); // This ref tracks whether the menu was just closed following a @@ -558,7 +558,7 @@ const ComboboxWithRef = ( onHide={closeMenu} ref={popoverRef} target={inputRef as React.RefObject} - container={wrapperRef} + container={wrapperRef as React.RefObject} popperConfig={{ modifiers: [matchWidth], }} diff --git a/app/javascript/mastodon/components/form_fields/copy_link_field.tsx b/app/javascript/mastodon/components/form_fields/copy_link_field.tsx index ab8849d45a..062a9074a3 100644 --- a/app/javascript/mastodon/components/form_fields/copy_link_field.tsx +++ b/app/javascript/mastodon/components/form_fields/copy_link_field.tsx @@ -26,7 +26,7 @@ export const CopyLinkField = forwardRef( ref, ) => { const intl = useIntl(); - const inputRef = useRef(); + const inputRef = useRef(null); const handleFocus = useCallback(() => { inputRef.current?.select(); }, []); diff --git a/app/javascript/mastodon/components/form_fields/emoji_text_field.tsx b/app/javascript/mastodon/components/form_fields/emoji_text_field.tsx index 6e65d22fc7..874ec91f79 100644 --- a/app/javascript/mastodon/components/form_fields/emoji_text_field.tsx +++ b/app/javascript/mastodon/components/form_fields/emoji_text_field.tsx @@ -120,7 +120,7 @@ const EmojiFieldWrapper: FC< children: ( inputProps: InputProps & { onChange: ChangeEventHandler }, ) => ReactNode; - inputRef: RefObject; + inputRef: RefObject; } > = ({ value, diff --git a/app/javascript/mastodon/components/hotkeys/index.tsx b/app/javascript/mastodon/components/hotkeys/index.tsx index 246255dcbe..e8390b7255 100644 --- a/app/javascript/mastodon/components/hotkeys/index.tsx +++ b/app/javascript/mastodon/components/hotkeys/index.tsx @@ -184,7 +184,7 @@ export type HandlerMap = Partial>; export function useHotkeys(handlers: HandlerMap) { const ref = useRef(null); const bufferedKeys = useRef([]); - const sequenceTimer = useRef | null>(null); + const sequenceTimer = useRef>(null); /** * Store the latest handlers object in a ref so we don't need to diff --git a/app/javascript/mastodon/components/hover_card_controller.tsx b/app/javascript/mastodon/components/hover_card_controller.tsx index 9f89bafe78..44ee6bedd6 100644 --- a/app/javascript/mastodon/components/hover_card_controller.tsx +++ b/app/javascript/mastodon/components/hover_card_controller.tsx @@ -27,7 +27,7 @@ export const HoverCardController: React.FC = () => { const [open, setOpen] = useState(false); const [accountId, setAccountId] = useState(); const [anchor, setAnchor] = useState(null); - const cardRef = useRef(null); + const cardRef = useRef(null); const [setLeaveTimeout, cancelLeaveTimeout] = useTimeout(); const [setEnterTimeout, cancelEnterTimeout, delayEnterTimeout] = useTimeout(); const [setScrollTimeout] = useTimeout(); diff --git a/app/javascript/mastodon/components/learn_more_link.tsx b/app/javascript/mastodon/components/learn_more_link.tsx index 8d22bb7a3b..a721ad2747 100644 --- a/app/javascript/mastodon/components/learn_more_link.tsx +++ b/app/javascript/mastodon/components/learn_more_link.tsx @@ -9,7 +9,7 @@ export const LearnMoreLink: React.FC<{ children: React.ReactNode }> = ({ }) => { const accessibilityId = useId(); const [open, setOpen] = useState(false); - const triggerRef = useRef(null); + const triggerRef = useRef(null); const handleClick = useCallback(() => { setOpen(!open); @@ -37,7 +37,7 @@ export const LearnMoreLink: React.FC<{ children: React.ReactNode }> = ({ onHide={handleClick} offset={[5, 5]} placement='bottom-end' - target={triggerRef} + target={triggerRef as React.RefObject} > {({ props }) => (
| null>(null); +const FocusTargetContext = createContext | null>( + null, +); /** * `FocusTargetProvider` keeps track of whether focus should be diff --git a/app/javascript/mastodon/components/status/attachments.tsx b/app/javascript/mastodon/components/status/attachments.tsx new file mode 100644 index 0000000000..f830a1e0dd --- /dev/null +++ b/app/javascript/mastodon/components/status/attachments.tsx @@ -0,0 +1,279 @@ +import { lazy, Suspense, useCallback, useState } from 'react'; + +import { openModal } from '@/mastodon/actions/modal'; +import type { DeployPictureInPictureCallback } from '@/mastodon/actions/picture_in_picture'; +import { deployPictureInPicture } from '@/mastodon/actions/picture_in_picture'; +import { CollectionPreviewCard } from '@/mastodon/features/collections/components/collection_preview_card'; +import Card from '@/mastodon/features/status/components/card'; +import { displayMedia } from '@/mastodon/initial_state'; +import type { + MediaAttachment, + MediaAttachmentShape, +} from '@/mastodon/models/status'; +import { isMediaAttachmentOfType } from '@/mastodon/models/status'; +import { + selectExpandedStatus, + selectMediaMatchFilters, + selectPictureInPicture, +} from '@/mastodon/selectors/statuses'; +import { useAppDispatch, useAppSelector } from '@/mastodon/store'; +import { compareUrls } from '@/mastodon/utils/compare_urls'; + +import { PictureInPicturePlaceholder } from '../picture_in_picture_placeholder'; + +export const StatusAttachments: React.FC<{ + statusId: string; + contextType?: string; +}> = ({ statusId, contextType }) => { + // Selectors + const status = useAppSelector((state) => + selectExpandedStatus(state, statusId), + ); + + if (!status) { + return null; + } + + const attachment = status.media_attachments[0]; + if (attachment) { + return ( + + ); + } + + // Don't display the card or collection if this is a quote. + if (status.quote) { + return null; + } + + const card = status.card; + const collection = card?.url + ? status.tagged_collections.find(({ url }) => compareUrls(url, card.url)) + : status.tagged_collections[0]; + if (card && !collection) { + return ( + + ); + } + + if (collection) { + return ; + } + + return null; +}; + +type TMediaGallery = React.ComponentClass< + { + media: Immutable.List; + height: number; + onOpenMedia: (index: number) => void; + onToggleVisibility?: () => void; + sensitive?: boolean; + lang?: string; + visible?: boolean; + autoplay?: boolean; + matchedFilters?: (string | null | undefined)[]; + cacheWidth?: () => void; + defaultWidth?: number; + }, + { visible: boolean; width?: number } +>; + +const MediaGallery = lazy( + () => import('@/mastodon/components/media_gallery'), +); +const Audio = lazy(() => import('@/mastodon/features/audio')); +const Video = lazy(() => import('@/mastodon/features/video')); + +const MediaAttachments: React.FC<{ + statusId: string; + accountId: string; + contextType?: string; + sensitive: boolean; + language: string; + attachment: MediaAttachmentShape; + restAttachments: MediaAttachmentShape[]; + defaultPosterUrl: string; +}> = ({ + statusId, + accountId, + contextType, + sensitive, + language, + attachment, + defaultPosterUrl, +}) => { + const description = + attachment.translation?.description ?? attachment.description; + + const immutableAttachments = useAppSelector( + (state) => + state.statuses.getIn( + statusId, + 'media_attachments', + ) as Immutable.List, + ); + const mediaFilters = useAppSelector((state) => + selectMediaMatchFilters(state, { statusId, contextType }), + ); + const pictureInPicture = useAppSelector((state) => + selectPictureInPicture(state, statusId), + ); + + const [showMedia, setShowMedia] = useState( + () => + mediaFilters.length === 0 && + ((displayMedia !== 'hide_all' && !sensitive) || + displayMedia === 'show_all'), + ); + + const dispatch = useAppDispatch(); + const handleToggleMediaVisibility = useCallback(() => { + setShowMedia((prev) => !prev); + }, []); + const handleOpenMedia = useCallback( + (index: number) => { + dispatch( + openModal({ + modalType: 'MEDIA', + modalProps: { statusId, media: attachment, index, lang: language }, + }), + ); + }, + [attachment, dispatch, language, statusId], + ); + const handleOpenVideo = useCallback( + (options: { + startTime: number; + autoPlay: boolean; + defaultVolume: number; + }) => { + dispatch( + openModal({ + modalType: 'VIDEO', + modalProps: { + statusId, + options, + media: attachment, + lang: language, + }, + }), + ); + }, + [attachment, dispatch, language, statusId], + ); + const handleDeployPictureInPicture: DeployPictureInPictureCallback = + useCallback( + (type, props) => { + if (!accountId || !pictureInPicture.available) { + return; + } + void dispatch( + deployPictureInPicture({ + statusId, + accountId, + playerType: type, + props, + }), + ); + }, + [dispatch, pictureInPicture.available, accountId, statusId], + ); + + let aspectRatio = '3 / 2'; + if ( + isMediaAttachmentOfType(attachment, 'image') || + isMediaAttachmentOfType(attachment, 'video') || + isMediaAttachmentOfType(attachment, 'gifv') + ) { + aspectRatio = `${attachment.meta.original.width} / ${attachment.meta.original.height}`; + } else if (isMediaAttachmentOfType(attachment, 'audio')) { + aspectRatio = '16 / 9'; + } + + if (pictureInPicture.inUse) { + return ; + } + + if (isMediaAttachmentOfType(attachment, 'audio')) { + const { colors, original } = attachment.meta; + return ( + } + > + + ); + } + + if (isMediaAttachmentOfType(attachment, 'video')) { + const { original } = attachment.meta; + return ( + } + > + + ); + } + + return ( + } + > + + + ); +}; diff --git a/app/javascript/mastodon/components/status_action_bar/remove_quote_hint.tsx b/app/javascript/mastodon/components/status_action_bar/remove_quote_hint.tsx index cfa72feb68..ba3cdf0ac1 100644 --- a/app/javascript/mastodon/components/status_action_bar/remove_quote_hint.tsx +++ b/app/javascript/mastodon/components/status_action_bar/remove_quote_hint.tsx @@ -65,8 +65,8 @@ export const RemoveQuoteHint: React.FC<{ flip offset={[12, 10]} placement='bottom-end' - target={anchorRef} - container={anchorRef} + target={anchorRef as React.RefObject} + container={anchorRef as React.RefObject} > {({ props, placement }) => (
= ({ }) => { const scrollBehaviorContext = useContext(ScrollBehaviorContext); - const containerRef = useRef(); + const containerRef = useRef(null); /** * If a childRef is passed, sync it with the containerRef. This * is necessary because in this component's return statement, * we're overwriting the immediate child component's ref prop. */ - useImperativeHandle(childRef, () => containerRef.current, []); + useImperativeHandle(childRef, () => containerRef.current ?? undefined, []); /** * Register/unregister scrollable element with ScrollBehavior @@ -71,6 +72,10 @@ export const ScrollContainer: React.FC = ({ }, []); return React.Children.only( - React.cloneElement(children, { ref: containerRef }), + isValidElement<{ + ref: React.RefObject; + }>(children) + ? React.cloneElement(children, { ref: containerRef }) + : children, ); }; diff --git a/app/javascript/mastodon/features/account_timeline/components/featured_tags.tsx b/app/javascript/mastodon/features/account_timeline/components/featured_tags.tsx index c4d43bb2b9..7fd271b7f6 100644 --- a/app/javascript/mastodon/features/account_timeline/components/featured_tags.tsx +++ b/app/javascript/mastodon/features/account_timeline/components/featured_tags.tsx @@ -56,7 +56,7 @@ export const FeaturedTags: FC<{ accountId: string }> = ({ accountId }) => { 0 && index >= hiddenIndex ? '' : undefined} + inert={hiddenIndex > 0 && index >= hiddenIndex} onClick={onClick} active={currentTag === name} data-name={name} diff --git a/app/javascript/mastodon/features/account_timeline/components/filters.tsx b/app/javascript/mastodon/features/account_timeline/components/filters.tsx index e24ca64209..ebbf103261 100644 --- a/app/javascript/mastodon/features/account_timeline/components/filters.tsx +++ b/app/javascript/mastodon/features/account_timeline/components/filters.tsx @@ -99,11 +99,11 @@ const FilterDropdown: FC = () => { } placement='bottom-start' rootClose onHide={handleHide} - container={containerRef} + container={containerRef as React.RefObject} > {({ props }) => (
{ placement='top' onHide={handleClick} offset={[5, 5]} - target={triggerRef} + target={triggerRef as React.RefObject} > {({ props }) => (
void; }> = ({ mediaId, position, onPositionChange }) => { - const nodeRef = useRef(null); + const nodeRef = useRef(null); const [dragging, setDragging] = useState<'started' | 'moving' | null>(null); diff --git a/app/javascript/mastodon/features/audio/index.tsx b/app/javascript/mastodon/features/audio/index.tsx index fa0d976377..676f497a7c 100644 --- a/app/javascript/mastodon/features/audio/index.tsx +++ b/app/javascript/mastodon/features/audio/index.tsx @@ -6,6 +6,7 @@ import classNames from 'classnames'; import { useSpring, animated, config } from '@react-spring/web'; +import type { DeployPictureInPictureCallback } from '@/mastodon/actions/picture_in_picture'; import DownloadIcon from '@/material-icons/400-24px/download.svg?react'; import Forward5Icon from '@/material-icons/400-24px/forward_5-fill.svg?react'; import PauseIcon from '@/material-icons/400-24px/pause-fill.svg?react'; @@ -68,19 +69,7 @@ export const Audio: React.FC<{ startPlaying?: boolean; startVolume?: number; startMuted?: boolean; - deployPictureInPicture?: ( - type: string, - mediaProps: { - src: string; - muted: boolean; - volume: number; - currentTime: number; - poster?: string; - backgroundColor: string; - foregroundColor: string; - accentColor: string; - }, - ) => void; + deployPictureInPicture?: DeployPictureInPictureCallback; matchedFilters?: string[]; }> = ({ src, @@ -114,10 +103,10 @@ export const Audio: React.FC<{ const [revealed, setRevealed] = useState(false); const playerRef = useRef(null); - const audioRef = useRef(null); + const audioRef = useRef(null); const seekRef = useRef(null); const volumeRef = useRef(null); - const hoverTimeoutRef = useRef | null>(); + const hoverTimeoutRef = useRef>(null); const { audioContextRef, sourceRef, gainNodeRef, playAudio, pauseAudio } = useAudioContext({ audioElementRef: audioRef }); diff --git a/app/javascript/mastodon/features/collections/detail/index.tsx b/app/javascript/mastodon/features/collections/detail/index.tsx index 98ce518cf5..a2d328e539 100644 --- a/app/javascript/mastodon/features/collections/detail/index.tsx +++ b/app/javascript/mastodon/features/collections/detail/index.tsx @@ -170,7 +170,7 @@ const SensitiveContentNote: React.FC<{ onReveal: () => void }> = ({ const CollectionHeader: React.FC<{ collection: ApiCollectionJSON; withDescription: boolean; - headingRef: React.RefObject; + headingRef: React.RefObject; }> = ({ collection, withDescription, headingRef }) => { const intl = useIntl(); const { name, description, tag, account_id, items } = collection; diff --git a/app/javascript/mastodon/features/collections/editor/accounts.tsx b/app/javascript/mastodon/features/collections/editor/accounts.tsx index 78acd6a720..0ead92b1c7 100644 --- a/app/javascript/mastodon/features/collections/editor/accounts.tsx +++ b/app/javascript/mastodon/features/collections/editor/accounts.tsx @@ -1,3 +1,4 @@ +import type React from 'react'; import { useCallback, useId, useMemo, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; @@ -339,8 +340,8 @@ export const CollectionAccounts: React.FC<{ [addAccountItem, instantAddAccountItem, isEditMode, resetAccounts], ); - const handleSubmit = useCallback( - (e: React.FormEvent) => { + const handleSubmit: React.SubmitEventHandler = useCallback( + (e) => { e.preventDefault(); if (!id) { diff --git a/app/javascript/mastodon/features/collections/editor/details.tsx b/app/javascript/mastodon/features/collections/editor/details.tsx index 7fe25245c4..117ec82116 100644 --- a/app/javascript/mastodon/features/collections/editor/details.tsx +++ b/app/javascript/mastodon/features/collections/editor/details.tsx @@ -1,3 +1,4 @@ +import type React from 'react'; import { useCallback, useMemo } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; @@ -108,8 +109,8 @@ export const CollectionDetails: React.FC = () => { const accountId = useCurrentAccountId(); const { acct: currentUserName } = useAccount(accountId) ?? {}; - const handleSubmit = useCallback( - (e: React.FormEvent) => { + const handleSubmit: React.SubmitEventHandler = useCallback( + (e) => { e.preventDefault(); if (id) { diff --git a/app/javascript/mastodon/features/compose/components/language_dropdown.tsx b/app/javascript/mastodon/features/compose/components/language_dropdown.tsx index 8f75c3dd09..44641c9ed7 100644 --- a/app/javascript/mastodon/features/compose/components/language_dropdown.tsx +++ b/app/javascript/mastodon/features/compose/components/language_dropdown.tsx @@ -328,8 +328,8 @@ export const LanguageDropdown: React.FC = () => { const [open, setOpen] = useState(false); const [placement, setPlacement] = useState('bottom'); const [guess, setGuess] = useState(''); - const activeElementRef = useRef(null); - const targetRef = useRef(null); + const activeElementRef = useRef(null); + const targetRef = useRef(null); const intl = useIntl(); @@ -421,7 +421,7 @@ export const LanguageDropdown: React.FC = () => { offset={[5, 5]} placement={placement} flip - target={targetRef} + target={targetRef as React.RefObject} popperConfig={{ strategy: 'fixed', onFirstUpdate: handleOverlayEnter }} > {({ props, placement }) => ( diff --git a/app/javascript/mastodon/features/compose/components/privacy_dropdown.tsx b/app/javascript/mastodon/features/compose/components/privacy_dropdown.tsx index 5a463d86e7..5f698bef60 100644 --- a/app/javascript/mastodon/features/compose/components/privacy_dropdown.tsx +++ b/app/javascript/mastodon/features/compose/components/privacy_dropdown.tsx @@ -70,8 +70,8 @@ const PrivacyDropdown: React.FC = ({ disabled, }) => { const intl = useIntl(); - const overlayTargetRef = useRef(null); - const previousFocusTargetRef = useRef(null); + const overlayTargetRef = useRef(null); + const previousFocusTargetRef = useRef(null); const [isOpen, setIsOpen] = useState(false); const handleClose = useCallback(() => { @@ -171,7 +171,7 @@ const PrivacyDropdown: React.FC = ({ offset={[5, 5]} placement='bottom' flip - target={overlayTargetRef} + target={overlayTargetRef as React.RefObject} container={container} popperConfig={{ strategy: 'fixed' }} > diff --git a/app/javascript/mastodon/features/emoji/emoji_picker.tsx b/app/javascript/mastodon/features/emoji/emoji_picker.tsx index 15adf9fdc8..2e4441e4d0 100644 --- a/app/javascript/mastodon/features/emoji/emoji_picker.tsx +++ b/app/javascript/mastodon/features/emoji/emoji_picker.tsx @@ -51,15 +51,16 @@ export const Emoji: FC = ({ const { mode } = useEmojiAppState(); return ( ); diff --git a/app/javascript/mastodon/features/interaction_modal/index.tsx b/app/javascript/mastodon/features/interaction_modal/index.tsx index 128fb3ff5e..4e8707e5d5 100644 --- a/app/javascript/mastodon/features/interaction_modal/index.tsx +++ b/app/javascript/mastodon/features/interaction_modal/index.tsx @@ -153,7 +153,7 @@ const LoginForm: React.FC<{ const inputRef = useRef(null); const iframeRef = useRef(null); - const searchRequestRef = useRef(null); + const searchRequestRef = useRef(null); useEffect(() => { const handleMessage = (event: MessageEvent) => { diff --git a/app/javascript/mastodon/features/navigation_panel/index.tsx b/app/javascript/mastodon/features/navigation_panel/index.tsx index da5041ff4f..1eb268a601 100644 --- a/app/javascript/mastodon/features/navigation_panel/index.tsx +++ b/app/javascript/mastodon/features/navigation_panel/index.tsx @@ -429,7 +429,7 @@ export const CollapsibleNavigationPanel: React.FC = () => { const dispatch = useAppDispatch(); const openable = useBreakpoint('openable'); const location = useLocation(); - const overlayRef = useRef(null); + const overlayRef = useRef(null); useEffect(() => { dispatch(closeNavigation()); @@ -515,7 +515,7 @@ export const CollapsibleNavigationPanel: React.FC = () => { }, ); - const previouslyFocusedElementRef = useRef(); + const previouslyFocusedElementRef = useRef(null); useEffect(() => { if (open) { diff --git a/app/javascript/mastodon/features/notifications/components/select_with_label.tsx b/app/javascript/mastodon/features/notifications/components/select_with_label.tsx index 0b755702d9..8b260cf73d 100644 --- a/app/javascript/mastodon/features/notifications/components/select_with_label.tsx +++ b/app/javascript/mastodon/features/notifications/components/select_with_label.tsx @@ -86,7 +86,7 @@ const Dropdown: React.FC = ({ offset={[5, 5]} placement={placement} flip - target={containerRef} + target={containerRef as React.RefObject} popperConfig={{ strategy: 'fixed', onFirstUpdate: handleOverlayEnter }} > {({ props, placement }) => ( diff --git a/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx b/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx index e8a55bb338..5a783ecc38 100644 --- a/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx +++ b/app/javascript/mastodon/features/notifications_v2/components/embedded_status.tsx @@ -26,7 +26,7 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({ statusId, }) => { const history = useHistory(); - const clickCoordinatesRef = useRef<[number, number] | null>(); + const clickCoordinatesRef = useRef<[number, number]>(null); const dispatch = useAppDispatch(); const status = useAppSelector((state) => state.statuses.get(statusId)); diff --git a/app/javascript/mastodon/features/notifications_v2/components/notification_severed_relationships.tsx b/app/javascript/mastodon/features/notifications_v2/components/notification_severed_relationships.tsx index fd92498ea3..70f07eaa9c 100644 --- a/app/javascript/mastodon/features/notifications_v2/components/notification_severed_relationships.tsx +++ b/app/javascript/mastodon/features/notifications_v2/components/notification_severed_relationships.tsx @@ -11,5 +11,6 @@ export const NotificationSeveredRelationships: React.FC<{ followersCount={event.followers_count} followingCount={event.following_count} unread={unread} + hidden={false} /> ); diff --git a/app/javascript/mastodon/features/onboarding/follows.tsx b/app/javascript/mastodon/features/onboarding/follows.tsx index 910d105183..e79b4fe988 100644 --- a/app/javascript/mastodon/features/onboarding/follows.tsx +++ b/app/javascript/mastodon/features/onboarding/follows.tsx @@ -61,7 +61,7 @@ export const Follows: React.FC<{ setIsSearching(false); }, [setMode, setIsSearching]); - const searchRequestRef = useRef(null); + const searchRequestRef = useRef(null); const handleSearch = useDebouncedCallback( (value: string) => { diff --git a/app/javascript/mastodon/features/status/components/card.tsx b/app/javascript/mastodon/features/status/components/card.tsx index 525929625e..2452ab6494 100644 --- a/app/javascript/mastodon/features/status/components/card.tsx +++ b/app/javascript/mastodon/features/status/components/card.tsx @@ -1,9 +1,11 @@ -import { useCallback, useId, useState } from 'react'; +import { useCallback, useId, useMemo, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; +import { isMap } from 'immutable'; + import punycode from 'punycode/'; import DescriptionIcon from '@/material-icons/400-24px/description-fill.svg?react'; @@ -14,7 +16,7 @@ import { Icon } from 'mastodon/components/icon'; import { MoreFromAuthor } from 'mastodon/components/more_from_author'; import { RelativeTimestamp } from 'mastodon/components/relative_timestamp'; import { displayMedia, useBlurhash } from 'mastodon/initial_state'; -import type { Card as CardType } from 'mastodon/models/status'; +import type { CardShape, Card as CardType } from 'mastodon/models/status'; const IDNA_PREFIX = 'xn--'; @@ -66,27 +68,26 @@ const handleIframeUrl = (html: string, url: string, providerName: string) => { const hideAllMedia = displayMedia === 'hide_all'; interface CardProps { - card: CardType | null; + card: CardType | CardShape | null; sensitive?: boolean; } -const CardVideo: React.FC> = ({ card }) => ( +const CardVideo: React.FC<{ card: CardShape }> = ({ card }) => (
); -const Card: React.FC = ({ card, sensitive }) => { +const Card: React.FC = ({ card: rawCard, sensitive }) => { + const card: CardShape | null = useMemo( + () => (isMap(rawCard) ? (rawCard.toJS() as CardShape) : rawCard), + [rawCard], + ); + const [previewLoaded, setPreviewLoaded] = useState(false); const [embedded, setEmbedded] = useState(false); const [revealed, setRevealed] = useState(!sensitive && !hideAllMedia); @@ -116,52 +117,43 @@ const Card: React.FC = ({ card, sensitive }) => { } const provider = - card.get('provider_name').length === 0 - ? decodeIDNA(getHostname(card.get('url'))) - : card.get('provider_name'); - const interactive = card.get('type') === 'video'; - const language = card.get('language') ?? ''; - const hasImage = (card.get('image')?.length ?? 0) > 0; - const largeImage = - (hasImage && card.get('width') > card.get('height')) || interactive; - const showAuthor = !!card.getIn(['authors', 0, 'accountId']); + card.provider_name.length === 0 + ? decodeIDNA(getHostname(card.url)) + : card.provider_name; + const interactive = card.type === 'video'; + const language = card.language ?? ''; + const hasImage = (card.image?.length ?? 0) > 0; + const largeImage = (hasImage && card.width > card.height) || interactive; + const author = card.authors.at(0)?.accountId; const description = (
{provider} - {card.get('published_at') && ( + {card.published_at && ( <> {' '} - ·{' '} - + · )} - - {card.get('title')} + + {card.title} - {!showAuthor && - (card.get('author_name').length > 0 ? ( + {!author && + (card.author_name.length > 0 ? ( {card.get('author_name')} }} + values={{ name: {card.author_name} }} /> ) : ( - {card.get('description')} + {card.description} ))}
@@ -172,7 +164,7 @@ const Card: React.FC = ({ card, sensitive }) => { aspectRatio: '1', }; - if (largeImage && card.get('type') === 'video') { + if (largeImage && card.type === 'video') { thumbnailStyle.aspectRatio = `16 / 9`; } else if (largeImage) { thumbnailStyle.aspectRatio = '1.91 / 1'; @@ -185,15 +177,15 @@ const Card: React.FC = ({ card, sensitive }) => { className={classNames('status-card__image-preview', { 'status-card__image-preview--hidden': revealed && previewLoaded, })} - hash={card.get('blurhash')} + hash={card.blurhash} dummy={!useBlurhash} /> ); - const thumbnailDescription = card.get('image_description'); + const thumbnailDescription = card.image_description; const thumbnail = ( {thumbnailDescription} = ({ card, sensitive }) => { = ({ card, sensitive }) => { ); - } else if (card.get('image')) { + } else if (card.image) { embed = (
{canvas} @@ -300,10 +292,10 @@ const Card: React.FC = ({ card, sensitive }) => { return ( <> = ({ card, sensitive }) => { {description} - {showAuthor && ( - - )} + {author && } ); }; diff --git a/app/javascript/mastodon/features/status/components/detailed_status.tsx b/app/javascript/mastodon/features/status/components/detailed_status.tsx index ba0ce8b8c5..0463643c7a 100644 --- a/app/javascript/mastodon/features/status/components/detailed_status.tsx +++ b/app/javascript/mastodon/features/status/components/detailed_status.tsx @@ -80,7 +80,7 @@ export const DetailedStatus: React.FC<{ const properStatus = status?.get('reblog') ?? status; const [height, setHeight] = useState(0); const [showDespiteFilter, setShowDespiteFilter] = useState(false); - const nodeRef = useRef(); + const nodeRef = useRef(null); const { signedIn } = useIdentity(); diff --git a/app/javascript/mastodon/features/ui/components/columns_area.tsx b/app/javascript/mastodon/features/ui/components/columns_area.tsx index cd94f34ec0..be91d5dccc 100644 --- a/app/javascript/mastodon/features/ui/components/columns_area.tsx +++ b/app/javascript/mastodon/features/ui/components/columns_area.tsx @@ -3,6 +3,7 @@ import { cloneElement, createContext, forwardRef, + isValidElement, useCallback, useContext, } from 'react'; @@ -179,7 +180,9 @@ export const ColumnsArea = forwardRef< {Children.map(children, (child) => - cloneElement(child, { multiColumn: true }), + isValidElement<{ multiColumn?: boolean }>(child) + ? cloneElement(child, { multiColumn: true }) + : child, )} diff --git a/app/javascript/mastodon/features/ui/components/embed_modal.tsx b/app/javascript/mastodon/features/ui/components/embed_modal.tsx index 29e83e47bb..a6c87a3336 100644 --- a/app/javascript/mastodon/features/ui/components/embed_modal.tsx +++ b/app/javascript/mastodon/features/ui/components/embed_modal.tsx @@ -18,7 +18,7 @@ const EmbedModal: React.FC<{ onClose: () => void; }> = ({ id, onClose }) => { const iframeRef = useRef(null); - const intervalRef = useRef>(); + const intervalRef = useRef>(null); const [oembed, setOembed] = useState(null); const dispatch = useAppDispatch(); diff --git a/app/javascript/mastodon/features/ui/components/zoomable_image.tsx b/app/javascript/mastodon/features/ui/components/zoomable_image.tsx index 1297d243d0..1eb374cca7 100644 --- a/app/javascript/mastodon/features/ui/components/zoomable_image.tsx +++ b/app/javascript/mastodon/features/ui/components/zoomable_image.tsx @@ -120,8 +120,8 @@ export const ZoomableImage: React.FC = ({ const containerRef = useRef(null); const imageRef = useRef(null); - const doubleClickTimeoutRef = useRef | null>(); - const zoomMatrixRef = useRef(null); + const doubleClickTimeoutRef = useRef>(null); + const zoomMatrixRef = useRef(null); const [style, api] = useSpring(() => ({ x: 0, diff --git a/app/javascript/mastodon/features/video/index.tsx b/app/javascript/mastodon/features/video/index.tsx index 6721b5c96a..6c6b34a4e1 100644 --- a/app/javascript/mastodon/features/video/index.tsx +++ b/app/javascript/mastodon/features/video/index.tsx @@ -7,6 +7,7 @@ import classNames from 'classnames'; import { useSpring, animated, config } from '@react-spring/web'; import { throttle } from 'lodash'; +import type { DeployPictureInPictureCallback } from '@/mastodon/actions/picture_in_picture'; import Forward5Icon from '@/material-icons/400-24px/forward_5-fill.svg?react'; import FullscreenIcon from '@/material-icons/400-24px/fullscreen.svg?react'; import FullscreenExitIcon from '@/material-icons/400-24px/fullscreen_exit.svg?react'; @@ -174,15 +175,7 @@ export const Video: React.FC<{ alwaysVisible?: boolean; visible?: boolean; onToggleVisibility?: () => void; - deployPictureInPicture?: ( - type: string, - mediaProps: { - src: string; - muted: boolean; - volume: number; - currentTime: number; - }, - ) => void; + deployPictureInPicture?: DeployPictureInPictureCallback; blurhash?: string; startPlaying?: boolean; startTime?: number; @@ -225,11 +218,11 @@ export const Video: React.FC<{ const [hotkeyEvents, setHotkeyEvents] = useState([]); const playerRef = useRef(null); - const videoRef = useRef(null); + const videoRef = useRef(null); const seekRef = useRef(null); const volumeRef = useRef(null); - const doubleClickTimeoutRef = useRef | null>(); - const hoverTimeoutRef = useRef | null>(); + const doubleClickTimeoutRef = useRef>(null); + const hoverTimeoutRef = useRef>(null); const [style, api] = useSpring(() => ({ progress: '0%', @@ -241,7 +234,7 @@ export const Video: React.FC<{ (c: HTMLVideoElement | null) => { if (videoRef.current && !videoRef.current.paused && c === null) { deployPictureInPicture?.('video', { - src: src, + src, currentTime: videoRef.current.currentTime, muted: videoRef.current.muted, volume: videoRef.current.volume, diff --git a/app/javascript/mastodon/hooks/useAudioContext.ts b/app/javascript/mastodon/hooks/useAudioContext.ts index 2cad7ee3a5..65b20ff101 100644 --- a/app/javascript/mastodon/hooks/useAudioContext.ts +++ b/app/javascript/mastodon/hooks/useAudioContext.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useRef } from 'react'; interface AudioContextOptions { - audioElementRef: React.MutableRefObject; + audioElementRef: React.RefObject; } /** @@ -13,9 +13,9 @@ interface AudioContextOptions { */ export const useAudioContext = ({ audioElementRef }: AudioContextOptions) => { - const audioContextRef = useRef(); - const sourceRef = useRef(); - const gainNodeRef = useRef(); + const audioContextRef = useRef(null); + const sourceRef = useRef(null); + const gainNodeRef = useRef(null); useEffect(() => { if (!audioElementRef.current || typeof AudioContext === 'undefined') { diff --git a/app/javascript/mastodon/hooks/useAudioVisualizer.ts b/app/javascript/mastodon/hooks/useAudioVisualizer.ts index efc0647d8d..fefb1a2c4d 100644 --- a/app/javascript/mastodon/hooks/useAudioVisualizer.ts +++ b/app/javascript/mastodon/hooks/useAudioVisualizer.ts @@ -11,8 +11,8 @@ const normalizeFrequencies = (arr: Float32Array): number[] => { }; interface AudioVisualiserOptions { - audioContextRef: React.MutableRefObject; - sourceRef: React.MutableRefObject; + audioContextRef: React.RefObject; + sourceRef: React.RefObject; numBands: number; } @@ -21,7 +21,7 @@ export const useAudioVisualizer = ({ sourceRef, numBands, }: AudioVisualiserOptions) => { - const analyzerRef = useRef(); + const analyzerRef = useRef(null); const [frequencyBands, setFrequencyBands] = useState( new Array(numBands).fill(0), diff --git a/app/javascript/mastodon/hooks/useObserver.ts b/app/javascript/mastodon/hooks/useObserver.ts index 4b979f6d32..f7bd9454cf 100644 --- a/app/javascript/mastodon/hooks/useObserver.ts +++ b/app/javascript/mastodon/hooks/useObserver.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; export function useResizeObserver(callback: ResizeObserverCallback) { - const observerRef = useRef(null); + const observerRef = useRef(null); observerRef.current ??= new ResizeObserver(callback); useEffect(() => { @@ -15,7 +15,7 @@ export function useResizeObserver(callback: ResizeObserverCallback) { } export function useMutationObserver(callback: MutationCallback) { - const observerRef = useRef(null); + const observerRef = useRef(null); observerRef.current ??= new MutationObserver(callback); useEffect(() => { diff --git a/app/javascript/mastodon/hooks/useOnClickOutside.ts b/app/javascript/mastodon/hooks/useOnClickOutside.ts index ad964978c8..788441e7d9 100644 --- a/app/javascript/mastodon/hooks/useOnClickOutside.ts +++ b/app/javascript/mastodon/hooks/useOnClickOutside.ts @@ -2,10 +2,10 @@ * Handle clicks that occur outside of the element(s) provided in the first parameter */ -import type { MutableRefObject } from 'react'; +import type { RefObject } from 'react'; import { useEffect } from 'react'; -type ElementRef = MutableRefObject; +type ElementRef = RefObject; export function useOnClickOutside( excludedElementRef: ElementRef | ElementRef[] | null, diff --git a/app/javascript/mastodon/hooks/useOverflow.ts b/app/javascript/mastodon/hooks/useOverflow.ts index b85222cf56..40d9cd0775 100644 --- a/app/javascript/mastodon/hooks/useOverflow.ts +++ b/app/javascript/mastodon/hooks/useOverflow.ts @@ -1,4 +1,4 @@ -import type { MutableRefObject, RefCallback } from 'react'; +import type { RefObject, RefCallback } from 'react'; import { useState, useRef, useCallback, useEffect } from 'react'; import { useMutationObserver, useResizeObserver } from './useObserver'; @@ -20,7 +20,7 @@ export function useOverflowButton({ const [maxWidth, setMaxWidth] = useState('none'); // This is the item container element. - const listRef = useRef(null); + const listRef = useRef(null); // The main recalculation function. const handleRecalculate = useCallback(() => { @@ -102,7 +102,7 @@ export function useOverflowScroll({ const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(false); - const bodyRef = useRef(null); + const bodyRef = useRef(null); // Recalculate scrollable state const handleRecalculate = useCallback(() => { @@ -176,13 +176,11 @@ export function useOverflowObservers({ onWrapperRef, }: { onRecalculate: () => void; - onListRef?: RefCallback | MutableRefObject; - onWrapperRef?: - | RefCallback - | MutableRefObject; + onListRef?: RefCallback | RefObject; + onWrapperRef?: RefCallback | RefObject; }) { // This is the item container element. - const listRef = useRef(null); + const listRef = useRef(null); const resizeObserver = useResizeObserver(onRecalculate); @@ -213,7 +211,7 @@ export function useOverflowObservers({ }, [handleChildrenChange, mutationObserver, resizeObserver]); // Watch the wrapper for size changes, and recalculate when it resizes. - const wrapperRef = useRef(null); + const wrapperRef = useRef(null); const wrapperRefCallback = useCallback( (node: HTMLElement | null) => { if (node) { diff --git a/app/javascript/mastodon/hooks/useSearchAccounts.ts b/app/javascript/mastodon/hooks/useSearchAccounts.ts index 1c26fe19ae..7dac0ef7c5 100644 --- a/app/javascript/mastodon/hooks/useSearchAccounts.ts +++ b/app/javascript/mastodon/hooks/useSearchAccounts.ts @@ -30,7 +30,7 @@ export function useSearchAccounts({ 'idle' | 'loading' | 'error' >('idle'); - const searchRequestRef = useRef(null); + const searchRequestRef = useRef(null); const searchAccounts = useDebouncedCallback( async (value: string) => { diff --git a/app/javascript/mastodon/hooks/useSearchTags.ts b/app/javascript/mastodon/hooks/useSearchTags.ts index 78fc85ed51..b55ad21c1e 100644 --- a/app/javascript/mastodon/hooks/useSearchTags.ts +++ b/app/javascript/mastodon/hooks/useSearchTags.ts @@ -44,7 +44,7 @@ export function useSearchTags({ 'idle' | 'loading' | 'error' >('idle'); - const searchRequestRef = useRef(null); + const searchRequestRef = useRef(null); const searchTags = useDebouncedCallback( (value: string) => { diff --git a/app/javascript/mastodon/hooks/useSelectableClick.ts b/app/javascript/mastodon/hooks/useSelectableClick.ts index c8f16f0b0f..10a589dafc 100644 --- a/app/javascript/mastodon/hooks/useSelectableClick.ts +++ b/app/javascript/mastodon/hooks/useSelectableClick.ts @@ -6,7 +6,7 @@ export const useSelectableClick = ( onClick: React.MouseEventHandler, maxDelta = 5, ) => { - const clickPositionRef = useRef(null); + const clickPositionRef = useRef(null); const handleMouseDown = useCallback((e: React.MouseEvent) => { clickPositionRef.current = [e.clientX, e.clientY]; diff --git a/app/javascript/mastodon/hooks/useTimeout.ts b/app/javascript/mastodon/hooks/useTimeout.ts index bb1e8848dd..285d98a4e8 100644 --- a/app/javascript/mastodon/hooks/useTimeout.ts +++ b/app/javascript/mastodon/hooks/useTimeout.ts @@ -1,8 +1,8 @@ import { useRef, useCallback, useEffect } from 'react'; export const useTimeout = () => { - const timeoutRef = useRef>(); - const callbackRef = useRef<() => void>(); + const timeoutRef = useRef>(null); + const callbackRef = useRef<() => void>(null); const set = useCallback((callback: () => void, delay: number) => { if (timeoutRef.current) { @@ -28,8 +28,8 @@ export const useTimeout = () => { const cancel = useCallback(() => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); - timeoutRef.current = undefined; - callbackRef.current = undefined; + timeoutRef.current = null; + callbackRef.current = null; } }, []); diff --git a/app/javascript/mastodon/models/account.ts b/app/javascript/mastodon/models/account.ts index f2523cf334..ccb6f47621 100644 --- a/app/javascript/mastodon/models/account.ts +++ b/app/javascript/mastodon/models/account.ts @@ -55,6 +55,14 @@ export interface AccountShape extends Required< moved: string | null; url: string; } +export type AccountShapeFull = Omit< + AccountShape, + 'emojis' | 'fields' | 'roles' +> & { + emojis: CustomEmoji[]; + fields: AccountFieldShape[]; + roles: AccountRoleShape[]; +}; export type Account = RecordOf; diff --git a/app/javascript/mastodon/models/status.ts b/app/javascript/mastodon/models/status.ts index dc4138330f..666d644266 100644 --- a/app/javascript/mastodon/models/status.ts +++ b/app/javascript/mastodon/models/status.ts @@ -2,7 +2,15 @@ import type { RecordOf } from 'immutable'; import type { ApiCollectionJSON } from '@/mastodon/api_types/collections'; import type { ApiCustomEmojiJSON } from '@/mastodon/api_types/custom_emoji'; -import type { ApiMediaAttachmentJSON } from '@/mastodon/api_types/media_attachments'; +import type { + ApiAudioAttachmentJSON, + ApiGifvAttachmentJSON, + ApiImageAttachmentJSON, + ApiMediaAttachmentJSON, + ApiUnknownAttachmentJSON, + ApiVideoAttachmentJSON, + MediaAttachmentType, +} from '@/mastodon/api_types/media_attachments'; import type { ApiQuoteJSON, ApiQuotePolicyJSON, @@ -17,6 +25,8 @@ import type { StatusVisibility, } from '@/mastodon/api_types/statuses'; +import type { AccountShapeFull } from './account'; + export type { StatusVisibility } from '@/mastodon/api_types/statuses'; // Temporary until we type it correctly @@ -75,6 +85,10 @@ export interface StatusShape { replies_count: number; visibility: StatusVisibility; } +export type ExpandedStatusShape = Omit & { + account: AccountShapeFull; + reblog?: Omit; +}; export type CardShape = Omit & { authors: (Omit & { @@ -86,14 +100,42 @@ export type Card = RecordOf; export type MediaAttachment = Immutable.Map; -export type MediaAttachmentShape = Omit< - ApiMediaAttachmentJSON, - 'remote_url' -> & { +export type MediaAttachmentShape< + TAttachmentJSON extends ApiMediaAttachmentJSON = ApiMediaAttachmentJSON, +> = Omit & { remote_url: string | null; - translation?: string; + translation?: { + description: string; + }; }; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: 'image', +): attachment is MediaAttachmentShape; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: 'video', +): attachment is MediaAttachmentShape; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: 'gifv', +): attachment is MediaAttachmentShape; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: 'audio', +): attachment is MediaAttachmentShape; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: 'unknown', +): attachment is MediaAttachmentShape; +export function isMediaAttachmentOfType( + attachment: MediaAttachmentShape, + type: MediaAttachmentType, +) { + return attachment.type === type; +} + export type CollectionAttachment = RecordOf; export type FilterResult = Omit & { diff --git a/app/javascript/mastodon/reducers/picture_in_picture.ts b/app/javascript/mastodon/reducers/picture_in_picture.ts index 10d4f1fae5..b26844c63d 100644 --- a/app/javascript/mastodon/reducers/picture_in_picture.ts +++ b/app/javascript/mastodon/reducers/picture_in_picture.ts @@ -11,10 +11,10 @@ export interface PIPMediaProps { muted: boolean; volume: number; currentTime: number; - poster: string; - backgroundColor: string; - foregroundColor: string; - accentColor: string; + poster?: string; + backgroundColor?: string; + foregroundColor?: string; + accentColor?: string; } interface PIPStateWithValue extends Partial { @@ -34,7 +34,7 @@ const initialState = { muted: false, volume: 0, currentTime: 0, -}; +} satisfies PIPStateEmpty; export const pictureInPictureReducer: Reducer = ( state = initialState, diff --git a/app/javascript/mastodon/selectors/accounts.ts b/app/javascript/mastodon/selectors/accounts.ts index bf608fec4e..74538d366a 100644 --- a/app/javascript/mastodon/selectors/accounts.ts +++ b/app/javascript/mastodon/selectors/accounts.ts @@ -3,7 +3,11 @@ import { Record as ImmutableRecord, List as ImmutableList } from 'immutable'; import { me } from 'mastodon/initial_state'; import { accountDefaultValues } from 'mastodon/models/account'; -import type { Account, AccountShape } from 'mastodon/models/account'; +import type { + Account, + AccountShape, + AccountShapeFull, +} from 'mastodon/models/account'; import type { Relationship } from 'mastodon/models/relationship'; import { createAppSelector } from 'mastodon/store'; import type { RootState } from 'mastodon/store'; @@ -50,6 +54,11 @@ export function makeGetAccount() { ); } +export const selectPlainAccount = createAppSelector( + [(state, accountId: string) => state.accounts.get(accountId)], + (account) => (account ? (account.toJS() as AccountShapeFull) : null), +); + export const getAccountHidden = createAppSelector( [ (state, id: string) => state.accounts.get(id)?.hidden, diff --git a/app/javascript/mastodon/selectors/filters.ts b/app/javascript/mastodon/selectors/filters.ts index f84d01216a..0520c768c3 100644 --- a/app/javascript/mastodon/selectors/filters.ts +++ b/app/javascript/mastodon/selectors/filters.ts @@ -3,6 +3,14 @@ import { createSelector } from '@reduxjs/toolkit'; import type { RootState } from 'mastodon/store'; import { toServerSideType } from 'mastodon/utils/filters'; +export interface FilterShape { + id: string; + title: string; + context: string[]; + expires_at: string | null; + filter_action: 'hide' | 'blur' | 'warn'; +} + // TODO: move to `app/javascript/mastodon/models` and use more globally type Filter = Immutable.Map; @@ -12,7 +20,7 @@ type FilterResult = Immutable.Map; export const getFilters = createSelector( [ (state: RootState) => state.filters as Immutable.Map, - (_, { contextType }: { contextType: string }) => contextType, + (_, { contextType }: { contextType?: string }) => contextType, ], (filters, contextType) => { if (!contextType) { diff --git a/app/javascript/mastodon/selectors/statuses.ts b/app/javascript/mastodon/selectors/statuses.ts index dde0b8b227..4f9962d09f 100644 --- a/app/javascript/mastodon/selectors/statuses.ts +++ b/app/javascript/mastodon/selectors/statuses.ts @@ -2,7 +2,11 @@ import type { OrderedSet as ImmutableOrderedSet } from 'immutable'; import { createAppSelector } from 'mastodon/store'; -import type { StatusShape } from '../models/status'; +import type { ExpandedStatusShape, StatusShape } from '../models/status'; + +import { selectPlainAccount } from './accounts'; +import type { FilterShape } from './filters'; +import { getFilters } from './filters'; export const getStatusList = createAppSelector( [ @@ -21,3 +25,84 @@ export const selectPlainStatus = createAppSelector( return status.toJS() as unknown as StatusShape; }, ); + +export const selectAccountStatus = createAppSelector( + [ + selectPlainStatus, + (state, statusId: string) => { + const accountId = state.statuses.getIn(statusId, 'account'); + if (typeof accountId !== 'string') { + return null; + } + return selectPlainAccount(state, accountId); + }, + ], + (status, account) => { + if (!status || !account) { + return null; + } + return { + ...status, + account, + }; + }, +); + +export const selectExpandedStatus = createAppSelector( + [ + selectAccountStatus, + (state, statusId: string) => { + const reblogId = state.statuses.getIn(statusId, 'reblog'); + if (typeof reblogId !== 'string') { + return null; + } + return selectAccountStatus(state, reblogId); + }, + ], + (status, reblog): ExpandedStatusShape | null => { + if (!status) { + return null; + } + + return { + ...status, + reblog: reblog ?? undefined, + }; + }, +); + +export const selectPictureInPicture = createAppSelector( + [ + (state, statusId: string) => + state.picture_in_picture.type !== null && + state.picture_in_picture.statusId === statusId, + (state) => state.meta.get('layout') !== 'mobile', + ], + (inUse, available) => ({ + inUse: inUse && available, + available, + }), +); + +export const selectMediaMatchFilters = createAppSelector( + [ + (state, { statusId }: { statusId: string }) => + selectPlainStatus(state, statusId), + getFilters, + ], + (status, immutableFilters) => { + const filters = immutableFilters + ? (immutableFilters.toJS() as unknown as Record) + : null; + const mediaFilters: string[] = []; + if (status?.filtered && filters) { + for (const { filter } of status.filtered) { + if (filters[filter]?.filter_action === 'blur') { + mediaFilters.push(filters[filter].title); + } + } + } + + return mediaFilters; + }, +); diff --git a/app/javascript/mastodon/utils/html.ts b/app/javascript/mastodon/utils/html.ts index c87b5a34cf..c5d770ce79 100644 --- a/app/javascript/mastodon/utils/html.ts +++ b/app/javascript/mastodon/utils/html.ts @@ -20,7 +20,7 @@ interface AllowedTag { } type AllowedTagsType = { - [Tag in keyof React.ReactHTML]?: AllowedTag; + [Tag in keyof React.JSX.IntrinsicElements]?: AllowedTag; }; const globalAttributes: Record = htmlConfig.global; @@ -70,7 +70,7 @@ export function htmlStringToComponents>( const wrapper = document.createElement('template'); wrapper.innerHTML = htmlString; - const rootChildren: React.ReactNode[] = []; + const rootChildren: Awaited[] = []; const queue: QueueItem[] = [ { node: wrapper.content, parent: rootChildren, depth: 0 }, ]; diff --git a/app/javascript/types/dom.d.ts b/app/javascript/types/dom.d.ts deleted file mode 100644 index fcb1b0346f..0000000000 --- a/app/javascript/types/dom.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare namespace React { - interface HTMLAttributes extends AriaAttributes, DOMAttributes { - // Add inert attribute support, which is only in React 19.2. See: https://github.com/facebook/react/pull/24730 - inert?: ''; - } -} diff --git a/config/vite.json b/config/vite.json index 3ef44bcd10..702d2f3761 100644 --- a/config/vite.json +++ b/config/vite.json @@ -18,7 +18,7 @@ }, "test": { "autoBuild": true, - "publicOutputDir": "packs-test", + "publicOutputDir": "packs", "port": 3037 } } diff --git a/docker-compose.yml b/docker-compose.yml index b19f34b240..8e7f0726e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,7 +60,7 @@ services: web: # You can uncomment the following line if you want to not use the prebuilt image, for example if you have local code changes # build: . - image: ghcr.io/glitch-soc/mastodon:v4.6.1 + image: ghcr.io/glitch-soc/mastodon:v4.6.2 restart: always env_file: .env.production command: bundle exec puma -C config/puma.rb @@ -84,7 +84,7 @@ services: # build: # dockerfile: ./streaming/Dockerfile # context: . - image: ghcr.io/glitch-soc/mastodon-streaming:v4.6.1 + image: ghcr.io/glitch-soc/mastodon-streaming:v4.6.2 restart: always env_file: .env.production command: node ./streaming/index.js @@ -103,7 +103,7 @@ services: sidekiq: # You can uncomment the following line if you want to not use the prebuilt image, for example if you have local code changes # build: . - image: ghcr.io/glitch-soc/mastodon:v4.6.1 + image: ghcr.io/glitch-soc/mastodon:v4.6.2 restart: always env_file: .env.production command: bundle exec sidekiq diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index d97f62b409..4092132f56 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -13,7 +13,7 @@ module Mastodon end def patch - 1 + 0 end def default_prerelease diff --git a/package.json b/package.json index ba48e5b3d0..ba977b8066 100644 --- a/package.json +++ b/package.json @@ -187,8 +187,6 @@ "vitest": "^4.1.7" }, "resolutions": { - "@types/react": "^18.2.7", - "@types/react-dom": "^18.2.4", "kind-of": "^6.0.3" }, "peerDependenciesMeta": { diff --git a/vite.config.mts b/vite.config.mts index 81e83f4be5..ba78d6708c 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -33,9 +33,7 @@ export const config: UserConfigFnPromise = async ({ mode, command }) => { const isProdBuild = mode === 'production' && command === 'build'; let outDirName = 'packs-dev'; - if (mode === 'test') { - outDirName = 'packs-test'; - } else if (mode === 'production') { + if (mode === 'test' || mode === 'production') { outDirName = 'packs'; } const outDir = path.resolve('public', outDirName); diff --git a/yarn.lock b/yarn.lock index fbb5f717d4..ac3ee00f67 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4822,12 +4822,12 @@ __metadata: languageName: node linkType: hard -"@types/react-dom@npm:^18.2.4": - version: 18.3.7 - resolution: "@types/react-dom@npm:18.3.7" +"@types/react-dom@npm:^19.2.0": + version: 19.2.3 + resolution: "@types/react-dom@npm:19.2.3" peerDependencies: - "@types/react": ^18.0.0 - checksum: 10c0/8bd309e2c3d1604a28a736a24f96cbadf6c05d5288cfef8883b74f4054c961b6b3a5e997fd5686e492be903c8f3380dba5ec017eff3906b1256529cd2d39603e + "@types/react": ^19.2.0 + checksum: 10c0/b486ebe0f4e2fb35e2e108df1d8fc0927ca5d6002d5771e8a739de11239fe62d0e207c50886185253c99eb9dedfeeb956ea7429e5ba17f6693c7acb4c02f8cd1 languageName: node linkType: hard @@ -4880,13 +4880,12 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:^18.2.7": - version: 18.3.28 - resolution: "@types/react@npm:18.3.28" +"@types/react@npm:*, @types/react@npm:>=16.9.11, @types/react@npm:^19.2.0": + version: 19.2.17 + resolution: "@types/react@npm:19.2.17" dependencies: - "@types/prop-types": "npm:*" csstype: "npm:^3.2.2" - checksum: 10c0/683e19cd12b5c691215529af2e32b5ffbaccae3bf0ba93bfafa0e460e8dfee18423afed568be2b8eadf4b837c3749dd296a4f64e2d79f68fa66962c05f5af661 + checksum: 10c0/bc2c4af96b3e480604424de70d5ebda90c5f4b485df471858c0bc2d7d70364b606ec3c4d8579f94f01aa0c6c0591f56bcf14cba5689f5eea4b74250ccdc3a232 languageName: node linkType: hard