Show collection preview cards and open collections links locally (#38643)

This commit is contained in:
diondiondion authored and GitHub committed 2026-04-23 09:16:54 +00:00
1 parent a8741495c4
commit 478dae0ab3
11 files changed
+92 -32

No files matched your search

+17 -7
View File
@@ -547,13 +547,23 @@ class Status extends ImmutablePureComponent {
);
}
} else if (status.get('card') && !status.get('quote')) {
media = (
<Card
key={`${status.get('id')}-${status.get('edited_at')}`}
card={status.get('card')}
sensitive={status.get('sensitive')}
/>
);
const cardUrl = status.getIn(['card', 'url']);
const taggedCollection = (
status.get('tagged_collections')
).find((item) => compareUrls(item.get('url'), cardUrl));
if (taggedCollection) {
media = <CollectionPreviewCard collection={taggedCollection} />;
} else {
media = (
<Card
key={`${status.get('id')}-${status.get('edited_at')}`}
card={status.get('card')}
sensitive={status.get('sensitive')}
/>
);
}
}
const {statusContentProps, hashtagBar} = getHashtagBarForStatus(status);
@@ -4,7 +4,9 @@ import type { ComponentProps, FC } from 'react';
import classNames from 'classnames';
import { Link } from 'react-router-dom';
import type { ApiCollectionJSON } from '@/mastodon/api_types/collections';
import type { ApiMentionJSON } from '@/mastodon/api_types/statuses';
import { getCollectionPath } from '@/mastodon/features/collections/utils';
import type { OnElementHandler } from '@/mastodon/utils/html';
export interface HandledLinkProps {
@@ -13,6 +15,7 @@ export interface HandledLinkProps {
prevText?: string;
hashtagAccountId?: string;
mention?: Pick<ApiMentionJSON, 'id' | 'acct'>;
collection?: Pick<ApiCollectionJSON, 'id'>;
}
export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
@@ -21,6 +24,7 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
prevText,
hashtagAccountId,
mention,
collection,
className,
children,
...props
@@ -57,6 +61,15 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
{children}
</Link>
);
} else if (collection) {
return (
<Link
className={classNames(className)}
to={getCollectionPath(collection.id)}
>
{children}
</Link>
);
}
// Non-absolute paths treated as internal links. This shouldn't happen, but just in case.
@@ -18,6 +18,7 @@ import { languages as preloadedLanguages } from 'mastodon/initial_state';
import { EmojiHTML } from './emoji/html';
import { injectIntl } from './intl';
import { HandledLink } from './status/handled_link';
import { compareUrls } from '../utils/compare_urls';
const MAX_HEIGHT = 706; // 22px * 32 (+ 2px padding at the top)
@@ -71,17 +72,6 @@ const mapStateToProps = state => ({
languages: state.getIn(['server', 'translationLanguages', 'items']),
});
const compareUrls = (href1, href2) => {
try {
const url1 = new URL(href1);
const url2 = new URL(href2);
return url1.origin === url2.origin && url1.pathname === url2.pathname && url1.search === url2.search;
} catch {
return false;
}
};
class StatusContent extends PureComponent {
static propTypes = {
identity: identityContextPropShape,
@@ -166,7 +156,13 @@ class StatusContent extends PureComponent {
handleElement = (element, { key, ...props }, children) => {
if (element instanceof HTMLAnchorElement) {
const mention = this.props.status.get('mentions').find(item => compareUrls(element.href, item.get('url')));
const mention = this.props.status.get('mentions').find(
item => compareUrls(element.href, item.get('url'))
);
const taggedCollection = this.props.status.get('tagged_collections').find(
item => compareUrls(element.href, item.get('url'))
)
return (
<HandledLink
{...props}
@@ -174,6 +170,7 @@ class StatusContent extends PureComponent {
text={element.innerText}
hashtagAccountId={this.props.status.getIn(['account', 'id'])}
mention={mention?.toJSON()}
collection={taggedCollection?.toJSON()}
key={key}
>
{children}