Skip to content

Commit

Permalink
chore: improve withReplies toggle for user following
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed May 27, 2024
1 parent 934f9f8 commit 171a18e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/frontend/src/scripts/get-user-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { $i, iAmModerator } from '@/account.js';
import { IRouter } from '@/nirax.js';
import { antennasCache, rolesCache, userListsCache } from '@/cache.js';
import { mainRouter } from '@/router/main.js';
import { MenuItem } from '@/types/menu.js';

export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter = mainRouter) {
const meId = $i ? $i.id : null;
Expand Down Expand Up @@ -81,15 +82,6 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter
});
}

async function toggleWithReplies() {
os.apiWithDialog('following/update', {
userId: user.id,
withReplies: !user.withReplies,
}).then(() => {
user.withReplies = !user.withReplies;
});
}

async function toggleNotify() {
os.apiWithDialog('following/update', {
userId: user.id,
Expand Down Expand Up @@ -152,7 +144,7 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter
});
}

let menu = [{
let menu: MenuItem[] = [{
icon: 'ti ti-at',
text: i18n.ts.copyUsername,
action: () => {
Expand Down Expand Up @@ -304,15 +296,25 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter

// フォローしたとしても user.isFollowing はリアルタイム更新されないので不便なため
//if (user.isFollowing) {
const withRepliesRef = ref(user.withReplies);
menu = menu.concat([{
icon: user.withReplies ? 'ti ti-messages-off' : 'ti ti-messages',
text: user.withReplies ? i18n.ts.hideRepliesToOthersInTimeline : i18n.ts.showRepliesToOthersInTimeline,
action: toggleWithReplies,
type: 'switch',
icon: 'ti ti-messages',
text: i18n.ts.showRepliesToOthersInTimeline,
ref: withRepliesRef,
}, {
icon: user.notify === 'none' ? 'ti ti-bell' : 'ti ti-bell-off',
text: user.notify === 'none' ? i18n.ts.notifyNotes : i18n.ts.unnotifyNotes,
action: toggleNotify,
}]);
watch(withRepliesRef, (withReplies) => {
misskeyApi('following/update', {
userId: user.id,
withReplies,
}).then(() => {
user.withReplies = withReplies;
});
});
//}

menu = menu.concat([{ type: 'divider' }, {
Expand Down

0 comments on commit 171a18e

Please sign in to comment.