Skip to content

Commit

Permalink
Add: #920 アンテナ・リストに「お気に入りに登録」設定 (#946)
Browse files Browse the repository at this point in the history
* Add: #920 アンテナ・リストに「お気に入りに登録」設定

* Fix test

* Fix test

* Add fedibird capabilities

* Add kmyblue_favourite_antenna
  • Loading branch information
kmycode authored Dec 9, 2024
1 parent ee49518 commit 9201eb1
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/antennas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def set_antenna
end

def antenna_params
params.permit(:title, :list_id, :insert_feeds, :stl, :ltl, :with_media_only, :ignore_reblog)
params.permit(:title, :list_id, :insert_feeds, :stl, :ltl, :with_media_only, :ignore_reblog, :favourite)
end
end
12 changes: 11 additions & 1 deletion app/controllers/api/v1/lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,23 @@ def destroy
render_empty
end

def favourite
@list.favourite!
render json: @list, serializer: REST::ListSerializer
end

def unfavourite
@list.unfavourite!
render json: @list, serializer: REST::ListSerializer
end

private

def set_list
@list = List.where(account: current_account).find(params[:id])
end

def list_params
params.permit(:title, :replies_policy, :exclusive, :notify)
params.permit(:title, :replies_policy, :exclusive, :notify, :favourite)
end
end
2 changes: 2 additions & 0 deletions app/helpers/kmyblue_capabilities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def fedibird_capabilities
kmyblue_circle_history
kmyblue_list_notification
kmyblue_server_features
favourite_list
kmyblue_favourite_antenna
)

capabilities << :full_text_search if Chewy.enabled?
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/api_types/antennas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ApiAntennaJSON {
insert_feeds: boolean;
with_media_only: boolean;
ignore_reblog: boolean;
favourite: boolean;
list: ApiListJSON | null;

list_id: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/api_types/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export interface ApiListJSON {
exclusive: boolean;
replies_policy: RepliesPolicyType;
notify: boolean;
favourite: boolean;
antennas?: ApiAntennaJSON[];
}
42 changes: 42 additions & 0 deletions app/javascript/mastodon/features/antennas/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const NewAntenna: React.FC<{
const [ignoreReblog, setIgnoreReblog] = useState(false);
const [mode, setMode] = useState('filtering');
const [destination, setDestination] = useState('timeline');
const [favourite, setFavourite] = useState(true);
const [submitting, setSubmitting] = useState(false);

useEffect(() => {
Expand All @@ -80,6 +81,7 @@ const NewAntenna: React.FC<{
setListId(antenna.list?.id ?? '0');
setWithMediaOnly(antenna.with_media_only);
setIgnoreReblog(antenna.ignore_reblog);
setFavourite(antenna.favourite);

if (antenna.stl) {
setMode('stl');
Expand Down Expand Up @@ -109,6 +111,7 @@ const NewAntenna: React.FC<{
setIgnoreReblog,
setMode,
setDestination,
setFavourite,
id,
antenna,
lists,
Expand Down Expand Up @@ -179,6 +182,13 @@ const NewAntenna: React.FC<{
[setIgnoreReblog],
);

const handleFavouriteChange = useCallback(
({ target: { checked } }: React.ChangeEvent<HTMLInputElement>) => {
setFavourite(checked);
},
[setFavourite],
);

const handleSubmit = useCallback(() => {
setSubmitting(true);

Expand All @@ -193,6 +203,7 @@ const NewAntenna: React.FC<{
list_id: destination === 'list' ? listId : '0',
with_media_only: withMediaOnly,
ignore_reblog: ignoreReblog,
favourite,
}),
).then(() => {
setSubmitting(false);
Expand All @@ -208,6 +219,7 @@ const NewAntenna: React.FC<{
list_id: destination === 'list' ? listId : '0',
with_media_only: withMediaOnly,
ignore_reblog: ignoreReblog,
favourite,
}),
).then((result) => {
setSubmitting(false);
Expand All @@ -233,6 +245,7 @@ const NewAntenna: React.FC<{
withMediaOnly,
ignoreReblog,
destination,
favourite,
]);

return (
Expand Down Expand Up @@ -460,6 +473,35 @@ const NewAntenna: React.FC<{
</>
)}

<div className='fields-group'>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label className='app-form__toggle'>
<div className='app-form__toggle__label'>
<strong>
<FormattedMessage
id='antennas.favourite'
defaultMessage='Favorite'
/>
</strong>
<span className='hint'>
<FormattedMessage
id='antennas.favourite_hint'
defaultMessage='When opening the Web Client on a PC, this antenna appears in the navigation.'
/>
</span>
</div>

<div className='app-form__toggle__toggle'>
<div>
<Toggle
checked={favourite}
onChange={handleFavouriteChange}
/>
</div>
</div>
</label>
</div>

<div className='actions'>
<button className='button' type='submit'>
{submitting ? (
Expand Down
51 changes: 50 additions & 1 deletion app/javascript/mastodon/features/lists/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const NewList: React.FC<{
const [exclusive, setExclusive] = useState(false);
const [repliesPolicy, setRepliesPolicy] = useState<RepliesPolicyType>('list');
const [notify, setNotify] = useState(false);
const [favourite, setFavourite] = useState(true);
const [submitting, setSubmitting] = useState(false);

useEffect(() => {
Expand All @@ -96,8 +97,17 @@ const NewList: React.FC<{
setExclusive(list.exclusive);
setRepliesPolicy(list.replies_policy);
setNotify(list.notify);
setFavourite(list.favourite);
}
}, [setTitle, setExclusive, setRepliesPolicy, setNotify, id, list]);
}, [
setTitle,
setExclusive,
setRepliesPolicy,
setNotify,
setFavourite,
id,
list,
]);

const handleTitleChange = useCallback(
({ target: { value } }: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -127,6 +137,13 @@ const NewList: React.FC<{
[setNotify],
);

const handleFavouriteChange = useCallback(
({ target: { checked } }: React.ChangeEvent<HTMLInputElement>) => {
setFavourite(checked);
},
[setFavourite],
);

const handleSubmit = useCallback(() => {
setSubmitting(true);

Expand All @@ -138,6 +155,7 @@ const NewList: React.FC<{
exclusive,
replies_policy: repliesPolicy,
notify,
favourite,
}),
).then(() => {
setSubmitting(false);
Expand All @@ -150,6 +168,7 @@ const NewList: React.FC<{
exclusive,
replies_policy: repliesPolicy,
notify,
favourite,
}),
).then((result) => {
setSubmitting(false);
Expand All @@ -171,6 +190,7 @@ const NewList: React.FC<{
exclusive,
repliesPolicy,
notify,
favourite,
]);

return (
Expand Down Expand Up @@ -324,6 +344,35 @@ const NewList: React.FC<{
</label>
</div>

<div className='fields-group'>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label className='app-form__toggle'>
<div className='app-form__toggle__label'>
<strong>
<FormattedMessage
id='lists.favourite'
defaultMessage='Favorite'
/>
</strong>
<span className='hint'>
<FormattedMessage
id='lists.favourite_hint'
defaultMessage='When opening the Web Client on a PC, this list appears in the navigation.'
/>
</span>
</div>

<div className='app-form__toggle__toggle'>
<div>
<Toggle
checked={favourite}
onChange={handleFavouriteChange}
/>
</div>
</div>
</label>
</div>

<div className='actions'>
<button className='button' type='submit'>
{submitting ? (
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/features/ui/components/list_panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const getOrderedLists = createSelector([state => state.get('lists')], lists => {
return lists;
}

return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title'))).take(8);
return lists.toList().filter(item => !!item && item.get('favourite')).sort((a, b) => a.get('title').localeCompare(b.get('title'))).take(8);
});

const getOrderedAntennas = createSelector([state => state.get('antennas')], antennas => {
if (!antennas) {
return antennas;
}

return antennas.toList().filter(item => !!item && !item.get('insert_feeds') && item.get('title') !== undefined).sort((a, b) => a.get('title').localeCompare(b.get('title'))).take(8);
return antennas.toList().filter(item => !!item && item.get('favourite') && item.get('title') !== undefined).sort((a, b) => a.get('title').localeCompare(b.get('title'))).take(8);
});

export const ListPanel = () => {
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
"antennas.exclude_domains": "Exclude domains",
"antennas.exclude_keywords": "Exclude keywords",
"antennas.exclude_tags": "Exclude tags",
"antennas.favourite": "Favorite",
"antennas.favourite_hint": "When opening the Web Client on a PC, this antenna appears in the navigation.",
"antennas.filter_items": "Move to antenna filter setting",
"antennas.filter_not": "Filter Not",
"antennas.find_users_to_add": "Find users to add",
Expand Down Expand Up @@ -630,6 +632,8 @@
"lists.edit": "Edit list",
"lists.exclusive": "Hide members in Home",
"lists.exclusive_hint": "If someone is on this list, hide them in your Home feed to avoid seeing their posts twice.",
"lists.favourite": "Favorite",
"lists.favourite_hint": "When opening the Web Client on a PC, this list appears in the navigation.",
"lists.find_users_to_add": "Find users to add",
"lists.list_members": "List members",
"lists.list_members_count": "{count, plural, one {# member} other {# members}}",
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"antennas.exclude_domains": "除外するドメイン",
"antennas.exclude_keywords": "除外するキーワード",
"antennas.exclude_tags": "除外するタグ",
"antennas.favourite": "お気に入りに登録",
"antennas.favourite_hint": "お気に入りに登録したアンテナは、Webクライアントでナビゲーションに表示されます",
"antennas.filter_items": "絞り込み条件の設定に移動",
"antennas.filter_not": "絞り込み条件の例外",
"antennas.ignore_reblog": "ブーストを除外",
Expand Down Expand Up @@ -579,6 +581,8 @@
"lists.antennas": "関連付けられたアンテナ",
"lists.delete": "リストを削除",
"lists.edit": "リストを編集",
"lists.favourite": "お気に入りに登録",
"lists.favourite_hint": "お気に入りに登録したリストは、Webクライアントでナビゲーションに表示されます",
"lists.memo_related_antenna": "アンテナ: {title}",
"lists.notify": "これらの投稿を通知する",
"lists.replies_policy.followed": "フォロー中のユーザー全員",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/models/antenna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const AntennaFactory = Record<AntennaShape>({
insert_feeds: false,
with_media_only: false,
ignore_reblog: false,
favourite: true,
list: null,
list_id: undefined,
});
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/models/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ListFactory = Record<ListShape>({
exclusive: false,
replies_policy: 'list',
notify: false,
favourite: true,
antennas: [],
});

Expand Down
27 changes: 14 additions & 13 deletions app/models/antenna.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
# Table name: antennas
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# list_id :bigint(8) not null
# title :string default(""), not null
# keywords :jsonb
# exclude_keywords :jsonb
# any_domains :boolean default(TRUE), not null
# any_tags :boolean default(TRUE), not null
# any_accounts :boolean default(TRUE), not null
# any_domains :boolean default(TRUE), not null
# any_keywords :boolean default(TRUE), not null
# any_tags :boolean default(TRUE), not null
# available :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
# expires_at :datetime
# with_media_only :boolean default(FALSE), not null
# exclude_domains :jsonb
# exclude_accounts :jsonb
# exclude_domains :jsonb
# exclude_keywords :jsonb
# exclude_tags :jsonb
# stl :boolean default(FALSE), not null
# expires_at :datetime
# favourite :boolean default(TRUE), not null
# ignore_reblog :boolean default(FALSE), not null
# insert_feeds :boolean default(FALSE), not null
# keywords :jsonb
# ltl :boolean default(FALSE), not null
# stl :boolean default(FALSE), not null
# title :string default(""), not null
# with_media_only :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint(8) not null
# list_id :bigint(8) not null
#
class Antenna < ApplicationRecord
include Expireable
Expand Down
Loading

0 comments on commit 9201eb1

Please sign in to comment.