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

Merge upstream changes up to cd0ca4b99473f54464e5134f91b7b1c8d5544011 #2791

Merged
merged 12 commits into from
Jul 24, 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
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ GEM
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-active_support (~> 0.1)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_job (0.7.2)
opentelemetry-instrumentation-active_job (0.7.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_model_serializers (0.20.1)
Expand Down Expand Up @@ -607,7 +607,7 @@ GEM
railties (>= 7.0.0)
psych (5.1.2)
stringio
public_suffix (6.0.0)
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
pundit (2.3.2)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def index
def show
authorize :instance, :show?
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
@action_logs = Admin::ActionLogFilter.new(target_domain: @instance.domain).results.limit(5)
end

def destroy
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/entrypoints/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ function loaded() {

const message =
statusEl.dataset.spoiler === 'expanded'
? localeData['status.show_less'] ?? 'Show less'
: localeData['status.show_more'] ?? 'Show more';
? (localeData['status.show_less'] ?? 'Show less')
: (localeData['status.show_more'] ?? 'Show more');
spoilerLink.textContent = new IntlMessageFormat(
message,
locale,
Expand Down
12 changes: 12 additions & 0 deletions app/javascript/flavours/glitch/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { browserHistory } from 'flavours/glitch/components/router';

import api, { getLinks } from '../api';

import {
Expand Down Expand Up @@ -722,6 +724,16 @@ export const updateAccount = ({ displayName, note, avatar, header, discoverable,
});
};

export const navigateToProfile = (accountId) => {
return (_dispatch, getState) => {
const acct = getState().accounts.getIn([accountId, 'acct']);

if (acct) {
browserHistory.push(`/@${acct}`);
}
};
};

export function fetchPinnedAccountsSuggestions(q) {
return (dispatch) => {
dispatch(fetchPinnedAccountsSuggestionsRequest());
Expand Down
18 changes: 18 additions & 0 deletions app/javascript/flavours/glitch/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ export function replyCompose(status) {
};
}

export function replyComposeById(statusId) {
return (dispatch, getState) => {
const state = getState();
const status = state.statuses.get(statusId);

if (status) {
const account = state.accounts.get(status.get('account'));
dispatch(replyCompose(status.set('account', account)));
}
};
}

export function cancelReplyCompose() {
return {
type: COMPOSE_REPLY_CANCEL,
Expand Down Expand Up @@ -163,6 +175,12 @@ export function mentionCompose(account) {
};
}

export function mentionComposeById(accountId) {
return (dispatch, getState) => {
dispatch(mentionCompose(getState().accounts.get(accountId)));
};
}

export function directCompose(account) {
return (dispatch, getState) => {
dispatch({
Expand Down
14 changes: 14 additions & 0 deletions app/javascript/flavours/glitch/actions/statuses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { browserHistory } from 'flavours/glitch/components/router';

import api from '../api';

import { ensureComposeIsVisible, setComposeToStatus } from './compose';
Expand Down Expand Up @@ -364,3 +366,15 @@ export const undoStatusTranslation = (id, pollId) => ({
id,
pollId,
});

export const navigateToStatus = (statusId) => {
return (_dispatch, getState) => {
const state = getState();
const accountId = state.statuses.getIn([statusId, 'account']);
const acct = state.accounts.getIn([accountId, 'acct']);

if (acct) {
browserHistory.push(`/@${acct}/${statusId}`);
}
};
};
14 changes: 7 additions & 7 deletions app/javascript/flavours/glitch/components/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class Status extends ImmutablePureComponent {
}

render () {
const { intl, hidden, featured, unread, pictureInPicture, previousId, nextInReplyToId, rootId, skipPrepend, avatarSize = 46 } = this.props;
const { intl, hidden, featured, unfocusable, unread, pictureInPicture, previousId, nextInReplyToId, rootId, skipPrepend, avatarSize = 46 } = this.props;

const {
parseClick,
Expand Down Expand Up @@ -585,8 +585,8 @@ class Status extends ImmutablePureComponent {

if (hidden) {
return (
<HotKeys handlers={handlers}>
<div ref={this.handleRef} className='status focusable' tabIndex={0}>
<HotKeys handlers={handlers} tabIndex={unfocusable ? null : -1}>
<div ref={this.handleRef} className='status focusable' tabIndex={unfocusable ? null : 0}>
<span>{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}</span>
<span>{status.get('content')}</span>
</div>
Expand All @@ -606,8 +606,8 @@ class Status extends ImmutablePureComponent {
};

return (
<HotKeys handlers={minHandlers}>
<div className='status__wrapper status__wrapper--filtered focusable' tabIndex={0} ref={this.handleRef}>
<HotKeys handlers={minHandlers} tabIndex={unfocusable ? null : -1}>
<div className='status__wrapper status__wrapper--filtered focusable' tabIndex={unfocusable ? null : 0} ref={this.handleRef}>
<FormattedMessage id='status.filtered' defaultMessage='Filtered' />: {matchedFilters.join(', ')}.
{' '}
<button className='status__wrapper--filtered__button' onClick={this.handleUnfilterClick}>
Expand Down Expand Up @@ -786,11 +786,11 @@ class Status extends ImmutablePureComponent {
contentMedia.push(hashtagBar);

return (
<HotKeys handlers={handlers}>
<HotKeys handlers={handlers} tabIndex={unfocusable ? null : -1}>
<div
className={classNames('status__wrapper', 'focusable', `status__wrapper-${status.get('visibility')}`, { 'status__wrapper-reply': !!status.get('in_reply_to_id'), unread, collapsed: isCollapsed })}
{...selectorAttribs}
tabIndex={0}
tabIndex={unfocusable ? null : 0}
data-featured={featured ? 'true' : null}
aria-label={textForScreenReader(intl, status, rebloggedByText, !status.get('hidden'))}
ref={this.handleRef}
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/flavours/glitch/entrypoints/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ function loaded() {

const message =
statusEl.dataset.spoiler === 'expanded'
? localeData['status.show_less'] ?? 'Show less'
: localeData['status.show_more'] ?? 'Show more';
? (localeData['status.show_less'] ?? 'Show less')
: (localeData['status.show_more'] ?? 'Show more');
spoilerLink.textContent = new IntlMessageFormat(
message,
locale,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react';
import { useCallback, useRef } from 'react';

import { FormattedMessage } from 'react-intl';

Expand All @@ -22,6 +22,7 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({
statusId,
}) => {
const history = useHistory();
const clickCoordinatesRef = useRef<[number, number] | null>();

const status = useAppSelector(
(state) => state.statuses.get(statusId) as Status | undefined,
Expand All @@ -31,11 +32,69 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({
state.accounts.get(status?.get('account') as string),
);

const handleClick = useCallback(() => {
if (!account) return;
const handleMouseDown = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ clientX, clientY }) => {
clickCoordinatesRef.current = [clientX, clientY];
},
[clickCoordinatesRef],
);

const handleMouseUp = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ clientX, clientY, target, button }) => {
const [startX, startY] = clickCoordinatesRef.current ?? [0, 0];
const [deltaX, deltaY] = [
Math.abs(clientX - startX),
Math.abs(clientY - startY),
];

let element: HTMLDivElement | null = target as HTMLDivElement;

while (element) {
if (
element.localName === 'button' ||
element.localName === 'a' ||
element.localName === 'label'
) {
return;
}

element = element.parentNode as HTMLDivElement | null;
}

if (deltaX + deltaY < 5 && button === 0 && account) {
history.push(`/@${account.acct}/${statusId}`);
}

clickCoordinatesRef.current = null;
},
[clickCoordinatesRef, statusId, account, history],
);

history.push(`/@${account.acct}/${statusId}`);
}, [statusId, account, history]);
const handleMouseEnter = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ currentTarget }) => {
const emojis =
currentTarget.querySelectorAll<HTMLImageElement>('.custom-emoji');

for (const emoji of emojis) {
const newSrc = emoji.getAttribute('data-original');
if (newSrc) emoji.src = newSrc;
}
},
[],
);

const handleMouseLeave = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ currentTarget }) => {
const emojis =
currentTarget.querySelectorAll<HTMLImageElement>('.custom-emoji');

for (const emoji of emojis) {
const newSrc = emoji.getAttribute('data-static');
if (newSrc) emoji.src = newSrc;
}
},
[],
);

if (!status) {
return null;
Expand All @@ -51,7 +110,15 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({
).size;

return (
<div className='notification-group__embedded-status'>
<div
className='notification-group__embedded-status'
role='button'
tabIndex={-1}
onMouseDown={handleMouseDown}
onMouseUp={handleMouseUp}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className='notification-group__embedded-status__account'>
<Avatar account={account} size={16} />
<DisplayName account={account} />
Expand All @@ -62,7 +129,6 @@ export const EmbeddedStatus: React.FC<{ statusId: string }> = ({
content={contentHtml}
language={language}
mentions={mentions}
onClick={handleClick}
/>

{(poll || mediaAttachmentsSize > 0) && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useRef } from 'react';
import { useCallback } from 'react';

import { useHistory } from 'react-router-dom';

Expand Down Expand Up @@ -34,76 +34,10 @@ export const EmbeddedStatusContent: React.FC<{
content: string;
mentions: List<Mention>;
language: string;
onClick?: () => void;
className?: string;
}> = ({ content, mentions, language, onClick, className }) => {
const clickCoordinatesRef = useRef<[number, number] | null>();
}> = ({ content, mentions, language, className }) => {
const history = useHistory();

const handleMouseDown = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ clientX, clientY }) => {
clickCoordinatesRef.current = [clientX, clientY];
},
[clickCoordinatesRef],
);

const handleMouseUp = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ clientX, clientY, target, button }) => {
const [startX, startY] = clickCoordinatesRef.current ?? [0, 0];
const [deltaX, deltaY] = [
Math.abs(clientX - startX),
Math.abs(clientY - startY),
];

let element: HTMLDivElement | null = target as HTMLDivElement;

while (element) {
if (
element.localName === 'button' ||
element.localName === 'a' ||
element.localName === 'label'
) {
return;
}

element = element.parentNode as HTMLDivElement | null;
}

if (deltaX + deltaY < 5 && button === 0 && onClick) {
onClick();
}

clickCoordinatesRef.current = null;
},
[clickCoordinatesRef, onClick],
);

const handleMouseEnter = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ currentTarget }) => {
const emojis =
currentTarget.querySelectorAll<HTMLImageElement>('.custom-emoji');

for (const emoji of emojis) {
const newSrc = emoji.getAttribute('data-original');
if (newSrc) emoji.src = newSrc;
}
},
[],
);

const handleMouseLeave = useCallback<React.MouseEventHandler<HTMLDivElement>>(
({ currentTarget }) => {
const emojis =
currentTarget.querySelectorAll<HTMLImageElement>('.custom-emoji');

for (const emoji of emojis) {
const newSrc = emoji.getAttribute('data-static');
if (newSrc) emoji.src = newSrc;
}
},
[],
);

const handleContentRef = useCallback(
(node: HTMLDivElement | null) => {
if (!node) {
Expand Down Expand Up @@ -150,16 +84,10 @@ export const EmbeddedStatusContent: React.FC<{

return (
<div
role='button'
tabIndex={0}
className={className}
ref={handleContentRef}
lang={language}
dangerouslySetInnerHTML={{ __html: content }}
onMouseDown={handleMouseDown}
onMouseUp={handleMouseUp}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>
);
};
Loading