mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 16:28:59 +00:00
Merge commit 'edd7fd98722a0d49ea486aa790a186735e491f35' into glitch-soc/merge-upstream
This commit is contained in:
@@ -2,9 +2,12 @@ import type { EmojiProps, PickerProps } from 'emoji-mart';
|
|||||||
import EmojiRaw from 'emoji-mart/dist-es/components/emoji/nimble-emoji';
|
import EmojiRaw from 'emoji-mart/dist-es/components/emoji/nimble-emoji';
|
||||||
import PickerRaw from 'emoji-mart/dist-es/components/picker/nimble-picker';
|
import PickerRaw from 'emoji-mart/dist-es/components/picker/nimble-picker';
|
||||||
|
|
||||||
|
import { isModernEmojiEnabled } from '@/mastodon/utils/environment';
|
||||||
import { assetHost } from 'mastodon/utils/config';
|
import { assetHost } from 'mastodon/utils/config';
|
||||||
|
|
||||||
|
import { EMOJI_MODE_NATIVE } from './constants';
|
||||||
import EmojiData from './emoji_data.json';
|
import EmojiData from './emoji_data.json';
|
||||||
|
import { useEmojiAppState } from './hooks';
|
||||||
|
|
||||||
const backgroundImageFnDefault = () => `${assetHost}/emoji/sheet_15_1.png`;
|
const backgroundImageFnDefault = () => `${assetHost}/emoji/sheet_15_1.png`;
|
||||||
|
|
||||||
@@ -16,6 +19,7 @@ const Emoji = ({
|
|||||||
backgroundImageFn = backgroundImageFnDefault,
|
backgroundImageFn = backgroundImageFnDefault,
|
||||||
...props
|
...props
|
||||||
}: EmojiProps) => {
|
}: EmojiProps) => {
|
||||||
|
const { mode } = useEmojiAppState();
|
||||||
return (
|
return (
|
||||||
<EmojiRaw
|
<EmojiRaw
|
||||||
data={EmojiData}
|
data={EmojiData}
|
||||||
@@ -23,6 +27,7 @@ const Emoji = ({
|
|||||||
sheetSize={sheetSize}
|
sheetSize={sheetSize}
|
||||||
sheetColumns={sheetColumns}
|
sheetColumns={sheetColumns}
|
||||||
sheetRows={sheetRows}
|
sheetRows={sheetRows}
|
||||||
|
native={mode === EMOJI_MODE_NATIVE && isModernEmojiEnabled()}
|
||||||
backgroundImageFn={backgroundImageFn}
|
backgroundImageFn={backgroundImageFn}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -37,6 +42,7 @@ const Picker = ({
|
|||||||
backgroundImageFn = backgroundImageFnDefault,
|
backgroundImageFn = backgroundImageFnDefault,
|
||||||
...props
|
...props
|
||||||
}: PickerProps) => {
|
}: PickerProps) => {
|
||||||
|
const { mode } = useEmojiAppState();
|
||||||
return (
|
return (
|
||||||
<PickerRaw
|
<PickerRaw
|
||||||
data={EmojiData}
|
data={EmojiData}
|
||||||
@@ -45,6 +51,7 @@ const Picker = ({
|
|||||||
sheetColumns={sheetColumns}
|
sheetColumns={sheetColumns}
|
||||||
sheetRows={sheetRows}
|
sheetRows={sheetRows}
|
||||||
backgroundImageFn={backgroundImageFn}
|
backgroundImageFn={backgroundImageFn}
|
||||||
|
native={mode === EMOJI_MODE_NATIVE && isModernEmojiEnabled()}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
|
import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { useAppSelector } from '@/mastodon/store';
|
import { createAppSelector, useAppSelector } from '@/mastodon/store';
|
||||||
import { isModernEmojiEnabled } from '@/mastodon/utils/environment';
|
import { isModernEmojiEnabled } from '@/mastodon/utils/environment';
|
||||||
|
|
||||||
import { toSupportedLocale } from './locale';
|
import { toSupportedLocale } from './locale';
|
||||||
@@ -58,13 +58,16 @@ export function useEmojify({
|
|||||||
return emojifiedText;
|
return emojifiedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modeSelector = createAppSelector(
|
||||||
|
[(state) => state.meta.get('emoji_style') as string],
|
||||||
|
(emoji_style) => determineEmojiMode(emoji_style),
|
||||||
|
);
|
||||||
|
|
||||||
export function useEmojiAppState(): EmojiAppState {
|
export function useEmojiAppState(): EmojiAppState {
|
||||||
const locale = useAppSelector((state) =>
|
const locale = useAppSelector((state) =>
|
||||||
toSupportedLocale(state.meta.get('locale') as string),
|
toSupportedLocale(state.meta.get('locale') as string),
|
||||||
);
|
);
|
||||||
const mode = useAppSelector((state) =>
|
const mode = useAppSelector(modeSelector);
|
||||||
determineEmojiMode(state.meta.get('emoji_style') as string),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentLocale: locale,
|
currentLocale: locale,
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ class PermalinkRedirector
|
|||||||
@object ||= begin
|
@object ||= begin
|
||||||
if at_username_status_request? || statuses_status_request?
|
if at_username_status_request? || statuses_status_request?
|
||||||
status = Status.find_by(id: second_segment)
|
status = Status.find_by(id: second_segment)
|
||||||
status if status&.distributable? && !status&.local?
|
status if status&.distributable? && !status&.local? && !status&.account&.suspended?
|
||||||
elsif at_username_request?
|
elsif at_username_request?
|
||||||
username, domain = first_segment.delete_prefix('@').split('@')
|
username, domain = first_segment.delete_prefix('@').split('@')
|
||||||
domain = nil if TagManager.instance.local_domain?(domain)
|
domain = nil if TagManager.instance.local_domain?(domain)
|
||||||
account = Account.find_remote(username, domain)
|
account = Account.find_remote(username, domain)
|
||||||
account unless account&.local?
|
account if !account&.local? && !account&.suspended?
|
||||||
elsif accounts_request? && record_integer_id_request?
|
elsif accounts_request? && record_integer_id_request?
|
||||||
account = Account.find_by(id: second_segment)
|
account = Account.find_by(id: second_segment)
|
||||||
account unless account&.local?
|
account if !account&.local? && !account&.suspended?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,39 +10,77 @@ RSpec.describe PermalinkRedirector do
|
|||||||
Fabricate(:status, account: remote_account, id: 123, url: 'https://example.com/status-123')
|
Fabricate(:status, account: remote_account, id: 123, url: 'https://example.com/status-123')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns path for legacy account links' do
|
|
||||||
redirector = described_class.new('accounts/2')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for legacy status links' do
|
|
||||||
redirector = described_class.new('statuses/123')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty account links' do
|
|
||||||
redirector = described_class.new('@alice@example.com')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty status links' do
|
|
||||||
redirector = described_class.new('@alice/123')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for legacy status links with a query param' do
|
|
||||||
redirector = described_class.new('statuses/123?foo=bar')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for pretty status links with a query param' do
|
|
||||||
redirector = described_class.new('@alice/123?foo=bar')
|
|
||||||
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns path for deck URLs with query params' do
|
it 'returns path for deck URLs with query params' do
|
||||||
redirector = described_class.new('/deck/directory?local=true')
|
redirector = described_class.new('/deck/directory?local=true')
|
||||||
expect(redirector.redirect_path).to eq '/directory?local=true'
|
expect(redirector.redirect_path).to eq '/directory?local=true'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when account is not suspended' do
|
||||||
|
it 'returns path for legacy account links' do
|
||||||
|
redirector = described_class.new('accounts/2')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for legacy status links' do
|
||||||
|
redirector = described_class.new('statuses/123')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty account links' do
|
||||||
|
redirector = described_class.new('@alice@example.com')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/@alice'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty status links' do
|
||||||
|
redirector = described_class.new('@alice/123')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for legacy status links with a query param' do
|
||||||
|
redirector = described_class.new('statuses/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns path for pretty status links with a query param' do
|
||||||
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to eq 'https://example.com/status-123'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when account is suspended' do
|
||||||
|
before do
|
||||||
|
remote_account.suspend!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy account links' do
|
||||||
|
redirector = described_class.new('accounts/2')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy status links' do
|
||||||
|
redirector = described_class.new('statuses/123')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty account links' do
|
||||||
|
redirector = described_class.new('@alice@example.com')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty status links' do
|
||||||
|
redirector = described_class.new('@alice/123')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for legacy status links with a query param' do
|
||||||
|
redirector = described_class.new('statuses/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for pretty status links with a query param' do
|
||||||
|
redirector = described_class.new('@alice/123?foo=bar')
|
||||||
|
expect(redirector.redirect_path).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user