Skip to content

Commit c18e7c0

Browse files
committed
Merge branch 'main' into temp3_for-taruntarun
2 parents 4a51f74 + 24d3599 commit c18e7c0

143 files changed

Lines changed: 875 additions & 317 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ GEM
124124
binding_of_caller (1.0.1)
125125
debug_inspector (>= 1.2.0)
126126
blurhash (0.1.8)
127-
bootsnap (1.18.4)
127+
bootsnap (1.18.5)
128128
msgpack (~> 1.2)
129129
brakeman (7.0.2)
130130
racc
@@ -171,7 +171,7 @@ GEM
171171
css_parser (1.21.1)
172172
addressable
173173
csv (3.3.4)
174-
database_cleaner-active_record (2.2.0)
174+
database_cleaner-active_record (2.2.1)
175175
activerecord (>= 5.a)
176176
database_cleaner-core (~> 2.0.0)
177177
database_cleaner-core (2.0.1)

app/controllers/admin/rules_controller.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
module Admin
44
class RulesController < BaseController
5-
before_action :set_rule, except: [:index, :create]
5+
before_action :set_rule, except: [:index, :new, :create]
66

77
def index
88
authorize :rule, :index?
99

1010
@rules = Rule.ordered
11-
@rule = Rule.new
11+
end
12+
13+
def new
14+
authorize :rule, :create?
15+
@rule = Rule.new
1216
end
1317

1418
def edit
@@ -24,7 +28,7 @@ def create
2428
redirect_to admin_rules_path
2529
else
2630
@rules = Rule.ordered
27-
render :index
31+
render :new
2832
end
2933
end
3034

app/javascript/mastodon/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default function api(withAuthorization = true) {
8383
return instance;
8484
}
8585

86+
type ApiUrl = `v${1 | 2}/${string}`;
8687
type RequestParamsOrData = Record<string, unknown>;
8788

8889
export async function apiRequest<ApiResponse = unknown>(
@@ -105,28 +106,28 @@ export async function apiRequest<ApiResponse = unknown>(
105106
}
106107

107108
export async function apiRequestGet<ApiResponse = unknown>(
108-
url: string,
109+
url: ApiUrl,
109110
params?: RequestParamsOrData,
110111
) {
111112
return apiRequest<ApiResponse>('GET', url, { params });
112113
}
113114

114115
export async function apiRequestPost<ApiResponse = unknown>(
115-
url: string,
116+
url: ApiUrl,
116117
data?: RequestParamsOrData,
117118
) {
118119
return apiRequest<ApiResponse>('POST', url, { data });
119120
}
120121

121122
export async function apiRequestPut<ApiResponse = unknown>(
122-
url: string,
123+
url: ApiUrl,
123124
data?: RequestParamsOrData,
124125
) {
125126
return apiRequest<ApiResponse>('PUT', url, { data });
126127
}
127128

128129
export async function apiRequestDelete<ApiResponse = unknown>(
129-
url: string,
130+
url: ApiUrl,
130131
params?: RequestParamsOrData,
131132
) {
132133
return apiRequest<ApiResponse>('DELETE', url, { params });

app/javascript/mastodon/api/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ export const apiGetEndorsedAccounts = (id: string) =>
3636
apiRequestGet<ApiAccountJSON>(`v1/accounts/${id}/endorsements`);
3737

3838
export const apiGetFamiliarFollowers = (id: string) =>
39-
apiRequestGet<ApiFamiliarFollowersJSON>('/v1/accounts/familiar_followers', {
39+
apiRequestGet<ApiFamiliarFollowersJSON>('v1/accounts/familiar_followers', {
4040
id,
4141
});

app/javascript/mastodon/api/polls.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { apiRequestGet, apiRequestPost } from 'mastodon/api';
22
import type { ApiPollJSON } from 'mastodon/api_types/polls';
33

44
export const apiGetPoll = (pollId: string) =>
5-
apiRequestGet<ApiPollJSON>(`/v1/polls/${pollId}`);
5+
apiRequestGet<ApiPollJSON>(`v1/polls/${pollId}`);
66

77
export const apiPollVote = (pollId: string, choices: string[]) =>
8-
apiRequestPost<ApiPollJSON>(`/v1/polls/${pollId}/votes`, {
8+
apiRequestPost<ApiPollJSON>(`v1/polls/${pollId}/votes`, {
99
choices,
1010
});

app/javascript/mastodon/components/__tests__/avatar-test.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { fromJS } from 'immutable';
21

32
import renderer from 'react-test-renderer';
43

4+
import { accountDefaultValues, createAccountFromServerJSON } from '@/mastodon/models/account';
5+
56
import { Avatar } from '../avatar';
67

78
describe('<Avatar />', () => {
8-
const account = fromJS({
9+
const account = createAccountFromServerJSON({
10+
...accountDefaultValues,
911
username: 'alice',
1012
acct: 'alice',
1113
display_name: 'Alice',

app/javascript/mastodon/components/avatar.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { useState, useCallback } from 'react';
22

33
import classNames from 'classnames';
4+
import { Link } from 'react-router-dom';
45

56
import { useHovering } from 'mastodon/hooks/useHovering';
67
import { autoPlayGif } from 'mastodon/initial_state';
78
import type { Account } from 'mastodon/models/account';
89

910
interface Props {
10-
account: Account | undefined; // FIXME: remove `undefined` once we know for sure its always there
11-
size: number;
11+
account:
12+
| Pick<Account, 'id' | 'acct' | 'avatar' | 'avatar_static'>
13+
| undefined; // FIXME: remove `undefined` once we know for sure its always there
14+
size?: number;
1215
style?: React.CSSProperties;
1316
inline?: boolean;
1417
animate?: boolean;
18+
withLink?: boolean;
1519
counter?: number | string;
1620
counterBorderColor?: string;
1721
}
@@ -21,6 +25,7 @@ export const Avatar: React.FC<Props> = ({
2125
animate = autoPlayGif,
2226
size = 20,
2327
inline = false,
28+
withLink = false,
2429
style: styleFromParent,
2530
counter,
2631
counterBorderColor,
@@ -35,10 +40,7 @@ export const Avatar: React.FC<Props> = ({
3540
height: `${size}px`,
3641
};
3742

38-
const src =
39-
hovering || animate
40-
? account?.get('avatar')
41-
: account?.get('avatar_static');
43+
const src = hovering || animate ? account?.avatar : account?.avatar_static;
4244

4345
const handleLoad = useCallback(() => {
4446
setLoading(false);
@@ -48,7 +50,7 @@ export const Avatar: React.FC<Props> = ({
4850
setError(true);
4951
}, [setError]);
5052

51-
return (
53+
const avatar = (
5254
<div
5355
className={classNames('account__avatar', {
5456
'account__avatar--inline': inline,
@@ -72,4 +74,18 @@ export const Avatar: React.FC<Props> = ({
7274
)}
7375
</div>
7476
);
77+
78+
if (withLink) {
79+
return (
80+
<Link
81+
to={`/@${account?.acct}`}
82+
title={`@${account?.acct}`}
83+
data-hover-card-account={account?.id}
84+
>
85+
{avatar}
86+
</Link>
87+
);
88+
}
89+
90+
return avatar;
7591
};
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
import classNames from 'classnames';
2-
import { Link } from 'react-router-dom';
32

4-
import { Avatar } from 'mastodon/components/avatar';
5-
import { useAppSelector } from 'mastodon/store';
6-
7-
const AvatarWrapper: React.FC<{ accountId: string }> = ({ accountId }) => {
8-
const account = useAppSelector((state) => state.accounts.get(accountId));
9-
10-
if (!account) return null;
11-
12-
return (
13-
<Link
14-
to={`/@${account.acct}`}
15-
title={`@${account.acct}`}
16-
data-hover-card-account={account.id}
17-
>
18-
<Avatar account={account} size={28} />
19-
</Link>
20-
);
21-
};
3+
/**
4+
* Wrapper for displaying a number of Avatar components horizontally,
5+
* either spaced out (default) or overlapping (using the `compact` prop).
6+
*/
227

238
export const AvatarGroup: React.FC<{
24-
accountIds: string[];
259
compact?: boolean;
26-
}> = ({ accountIds, compact = false }) => (
10+
children: React.ReactNode;
11+
}> = ({ children, compact = false }) => (
2712
<div
2813
className={classNames('avatar-group', { 'avatar-group--compact': compact })}
2914
>
30-
{accountIds.map((accountId) => (
31-
<AvatarWrapper key={accountId} accountId={accountId} />
32-
))}
15+
{children}
3316
</div>
3417
);

app/javascript/mastodon/components/status.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ class Status extends ImmutablePureComponent {
171171
}
172172
};
173173

174-
handleMouseUp = e => {
174+
handleHeaderClick = e => {
175175
// Only handle clicks on the empty space above the content
176-
177176
if (e.target !== e.currentTarget && e.detail >= 1) {
178177
return;
179178
}
@@ -525,7 +524,7 @@ class Status extends ImmutablePureComponent {
525524
<div className={classNames('status', `status-${status.get('visibility')}`, { 'status-reply': !!status.get('in_reply_to_id'), 'status--in-thread': !!rootId, 'status--first-in-thread': previousId && (!connectUp || connectToRoot), muted: this.props.muted })} data-id={status.get('id')}>
526525
{(connectReply || connectUp || connectToRoot) && <div className={classNames('status__line', { 'status__line--full': connectReply, 'status__line--first': !status.get('in_reply_to_id') && !connectToRoot })} />}
527526

528-
<div onMouseUp={this.handleMouseUp} className='status__info'>
527+
<div onClick={this.handleHeaderClick} onAuxClick={this.handleHeaderClick} className='status__info'>
529528
<Link to={`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`} className='status__relative-time'>
530529
<RelativeTimestamp timestamp={status.get('created_at')} />{status.get('edited_at') && <abbr title={intl.formatMessage(messages.edited, { date: intl.formatDate(status.get('edited_at'), { year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }) })}> *</abbr>}
531530
</Link>

app/javascript/mastodon/features/account_timeline/components/account_header.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ export const AccountHeader: React.FC<{
912912
<div className='account__header__badges'>{badges}</div>
913913
)}
914914

915+
{account.id !== me && signedIn && (
916+
<FamiliarFollowers accountId={accountId} />
917+
)}
918+
915919
{!(suspended || hidden) && (
916920
<div className='account__header__extra'>
917921
<div
@@ -1023,7 +1027,6 @@ export const AccountHeader: React.FC<{
10231027
/>
10241028
</NavLink>
10251029
</div>
1026-
{signedIn && <FamiliarFollowers accountId={accountId} />}
10271030
</div>
10281031
)}
10291032
</div>

0 commit comments

Comments
 (0)