1
0
Fork 0
forked from gitea/nas

Add: #920 アンテナ・リストに「お気に入りに登録」設定 (#946)

* Add: #920 アンテナ・リストに「お気に入りに登録」設定

* Fix test

* Fix test

* Add fedibird capabilities

* Add kmyblue_favourite_antenna
This commit is contained in:
KMY(雪あすか) 2024-12-09 12:12:15 +09:00 committed by GitHub
parent ee49518125
commit 9201eb151b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 294 additions and 29 deletions

View file

@ -42,6 +42,6 @@ class Api::V1::AntennasController < Api::BaseController
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

View file

@ -38,6 +38,16 @@ class Api::V1::ListsController < Api::BaseController
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
@ -45,6 +55,6 @@ class Api::V1::ListsController < Api::BaseController
end
def list_params
params.permit(:title, :replies_policy, :exclusive, :notify)
params.permit(:title, :replies_policy, :exclusive, :notify, :favourite)
end
end

View file

@ -20,6 +20,8 @@ module KmyblueCapabilitiesHelper
kmyblue_circle_history
kmyblue_list_notification
kmyblue_server_features
favourite_list
kmyblue_favourite_antenna
)
capabilities << :full_text_search if Chewy.enabled?

View file

@ -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;

View file

@ -10,5 +10,6 @@ export interface ApiListJSON {
exclusive: boolean;
replies_policy: RepliesPolicyType;
notify: boolean;
favourite: boolean;
antennas?: ApiAntennaJSON[];
}

View file

@ -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(() => {
@ -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');
@ -109,6 +111,7 @@ const NewAntenna: React.FC<{
setIgnoreReblog,
setMode,
setDestination,
setFavourite,
id,
antenna,
lists,
@ -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);
@ -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);
@ -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);
@ -233,6 +245,7 @@ const NewAntenna: React.FC<{
withMediaOnly,
ignoreReblog,
destination,
favourite,
]);
return (
@ -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 ? (

View file

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

View file

@ -16,7 +16,7 @@ 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 => {
@ -24,7 +24,7 @@ const getOrderedAntennas = createSelector([state => state.get('antennas')], ante
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 = () => {

View file

@ -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",
@ -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}}",

View file

@ -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": "ブーストを除外",
@ -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": "フォロー中のユーザー全員",

View file

@ -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,
});

View file

@ -12,6 +12,7 @@ const ListFactory = Record<ListShape>({
exclusive: false,
replies_policy: 'list',
notify: false,
favourite: true,
antennas: [],
});

View file

@ -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

View file

@ -5,13 +5,14 @@
# Table name: lists
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# exclusive :boolean default(FALSE), not null
# favourite :boolean default(TRUE), not null
# notify :boolean default(FALSE), not null
# replies_policy :integer default("list"), not null
# title :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# replies_policy :integer default("list"), not null
# exclusive :boolean default(FALSE), not null
# notify :boolean default(FALSE), not null
# account_id :bigint(8) not null
#
class List < ApplicationRecord
@ -35,6 +36,14 @@ class List < ApplicationRecord
before_destroy :clean_feed_manager
def favourite!
update!(favourite: true)
end
def unfavourite!
update!(favourite: false)
end
private
def validate_account_lists_limit

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
class REST::AntennaSerializer < ActiveModel::Serializer
attributes :id, :title, :stl, :ltl, :insert_feeds, :with_media_only, :ignore_reblog, :accounts_count, :domains_count, :tags_count, :keywords_count
attributes :id, :title, :stl, :ltl, :insert_feeds, :with_media_only, :ignore_reblog, :accounts_count, :domains_count, :tags_count, :keywords_count, :favourite
class ListSerializer < ActiveModel::Serializer
attributes :id, :title

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
class REST::ListSerializer < ActiveModel::Serializer
attributes :id, :title, :replies_policy, :exclusive, :notify
attributes :id, :title, :replies_policy, :exclusive, :notify, :favourite
def id
object.id.to_s