2022-06-20 17:38:49 +09:00
|
|
|
import { defineAsyncComponent } from 'vue';
|
2023-02-25 09:18:36 +09:00
|
|
|
import * as misskey from 'misskey-js';
|
2021-11-12 02:02:25 +09:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
2023-07-09 17:20:50 +09:00
|
|
|
import { host, url } from '@/config';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2023-05-14 10:30:46 +09:00
|
|
|
import { defaultStore, userActions } from '@/store';
|
2022-01-18 21:30:17 +09:00
|
|
|
import { $i, iAmModerator } from '@/account';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { mainRouter } from '@/router';
|
2022-07-16 16:52:12 +09:00
|
|
|
import { Router } from '@/nirax';
|
2023-03-24 16:58:57 +09:00
|
|
|
import { rolesCache, userListsCache } from '@/cache';
|
2023-07-09 17:20:50 +09:00
|
|
|
import { toUnicode } from 'punycode';
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2023-02-25 09:18:36 +09:00
|
|
|
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
|
2020-12-19 10:55:52 +09:00
|
|
|
const meId = $i ? $i.id : null;
|
2020-11-29 11:25:43 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
async function toggleMute() {
|
2022-03-04 20:23:53 +09:00
|
|
|
if (user.isMuted) {
|
|
|
|
os.apiWithDialog('mute/delete', {
|
|
|
|
userId: user.id,
|
|
|
|
}).then(() => {
|
|
|
|
user.isMuted = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const { canceled, result: period } = await os.select({
|
|
|
|
title: i18n.ts.mutePeriod,
|
|
|
|
items: [{
|
|
|
|
value: 'indefinitely', text: i18n.ts.indefinitely,
|
|
|
|
}, {
|
|
|
|
value: 'tenMinutes', text: i18n.ts.tenMinutes,
|
|
|
|
}, {
|
|
|
|
value: 'oneHour', text: i18n.ts.oneHour,
|
|
|
|
}, {
|
|
|
|
value: 'oneDay', text: i18n.ts.oneDay,
|
|
|
|
}, {
|
|
|
|
value: 'oneWeek', text: i18n.ts.oneWeek,
|
|
|
|
}],
|
|
|
|
default: 'indefinitely',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
const expiresAt = period === 'indefinitely' ? null
|
|
|
|
: period === 'tenMinutes' ? Date.now() + (1000 * 60 * 10)
|
|
|
|
: period === 'oneHour' ? Date.now() + (1000 * 60 * 60)
|
|
|
|
: period === 'oneDay' ? Date.now() + (1000 * 60 * 60 * 24)
|
|
|
|
: period === 'oneWeek' ? Date.now() + (1000 * 60 * 60 * 24 * 7)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
os.apiWithDialog('mute/create', {
|
|
|
|
userId: user.id,
|
|
|
|
expiresAt,
|
|
|
|
}).then(() => {
|
|
|
|
user.isMuted = true;
|
|
|
|
});
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
|
2023-03-08 08:56:09 +09:00
|
|
|
async function toggleRenoteMute() {
|
|
|
|
os.apiWithDialog(user.isRenoteMuted ? 'renote-mute/delete' : 'renote-mute/create', {
|
|
|
|
userId: user.id,
|
|
|
|
}).then(() => {
|
|
|
|
user.isRenoteMuted = !user.isRenoteMuted;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
async function toggleBlock() {
|
2022-01-28 11:39:49 +09:00
|
|
|
if (!await getConfirmed(user.isBlocking ? i18n.ts.unblockConfirm : i18n.ts.blockConfirm)) return;
|
2020-10-17 20:12:00 +09:00
|
|
|
|
|
|
|
os.apiWithDialog(user.isBlocking ? 'blocking/delete' : 'blocking/create', {
|
2022-06-20 17:38:49 +09:00
|
|
|
userId: user.id,
|
2020-10-17 20:12:00 +09:00
|
|
|
}).then(() => {
|
|
|
|
user.isBlocking = !user.isBlocking;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:22:55 +09:00
|
|
|
function reportAbuse() {
|
2022-08-31 00:24:33 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkAbuseReportWindow.vue')), {
|
2020-10-19 19:29:04 +09:00
|
|
|
user: user,
|
|
|
|
}, {}, 'closed');
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
async function getConfirmed(text: string): Promise<boolean> {
|
2021-11-18 18:45:58 +09:00
|
|
|
const confirm = await os.confirm({
|
2020-10-17 20:12:00 +09:00
|
|
|
type: 'warning',
|
|
|
|
title: 'confirm',
|
|
|
|
text,
|
|
|
|
});
|
|
|
|
|
|
|
|
return !confirm.canceled;
|
|
|
|
}
|
|
|
|
|
2021-12-03 11:14:44 +09:00
|
|
|
async function invalidateFollow() {
|
2023-02-24 13:08:06 +09:00
|
|
|
if (!await getConfirmed(i18n.ts.breakFollowConfirm)) return;
|
|
|
|
|
2021-12-03 11:14:44 +09:00
|
|
|
os.apiWithDialog('following/invalidate', {
|
2022-06-20 17:38:49 +09:00
|
|
|
userId: user.id,
|
2021-12-03 11:14:44 +09:00
|
|
|
}).then(() => {
|
|
|
|
user.isFollowed = !user.isFollowed;
|
2022-06-10 14:36:55 +09:00
|
|
|
});
|
2021-12-03 11:14:44 +09:00
|
|
|
}
|
|
|
|
|
2023-04-13 13:50:17 +09:00
|
|
|
async function editMemo(): Promise<void> {
|
|
|
|
const userDetailed = await os.api('users/show', {
|
|
|
|
userId: user.id,
|
|
|
|
});
|
|
|
|
const { canceled, result } = await os.form(i18n.ts.editMemo, {
|
|
|
|
memo: {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
multiline: true,
|
|
|
|
label: i18n.ts.memo,
|
|
|
|
default: userDetailed.memo,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.apiWithDialog('users/update-memo', {
|
|
|
|
memo: result.memo,
|
|
|
|
userId: user.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
let menu = [{
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-at',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.copyUsername,
|
2020-10-17 20:12:00 +09:00
|
|
|
action: () => {
|
2023-02-25 18:27:15 +09:00
|
|
|
copyToClipboard(`@${user.username}@${user.host ?? host}`);
|
2022-06-20 17:38:49 +09:00
|
|
|
},
|
2021-04-23 12:00:07 +09:00
|
|
|
}, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-info-circle',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.info,
|
2021-04-16 17:34:06 +09:00
|
|
|
action: () => {
|
2022-07-16 16:52:12 +09:00
|
|
|
router.push(`/user-info/${user.id}`);
|
2022-06-20 17:38:49 +09:00
|
|
|
},
|
2022-12-28 09:10:33 +09:00
|
|
|
}, {
|
|
|
|
icon: 'ti ti-rss',
|
|
|
|
text: i18n.ts.copyRSS,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`${user.host ?? host}/@${user.username}.atom`);
|
|
|
|
},
|
2023-07-09 17:20:50 +09:00
|
|
|
}, {
|
|
|
|
icon: 'ti ti-share',
|
|
|
|
text: i18n.ts.copyProfileUrl,
|
|
|
|
action: () => {
|
|
|
|
const canonical = user.host === null ? `@${user.username}` : `@${user.username}@${toUnicode(user.host)}`
|
|
|
|
copyToClipboard(`${url}/${canonical}`);
|
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
}, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-mail',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.sendMessage,
|
2020-10-17 20:12:00 +09:00
|
|
|
action: () => {
|
2023-03-07 17:12:46 +09:00
|
|
|
os.post({ specified: user, initialText: `@${user.username} ` });
|
2022-06-20 17:38:49 +09:00
|
|
|
},
|
2023-02-15 13:37:18 +09:00
|
|
|
}, null, {
|
2023-04-13 13:50:17 +09:00
|
|
|
icon: 'ti ti-pencil',
|
|
|
|
text: i18n.ts.editMemo,
|
|
|
|
action: () => {
|
|
|
|
editMemo();
|
|
|
|
},
|
|
|
|
}, {
|
2023-02-26 11:57:37 +09:00
|
|
|
type: 'parent',
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-list',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.addToList,
|
2023-02-26 11:57:37 +09:00
|
|
|
children: async () => {
|
2023-03-24 16:58:57 +09:00
|
|
|
const lists = await userListsCache.fetch(() => os.api('users/lists/list'));
|
2023-02-26 11:57:37 +09:00
|
|
|
|
|
|
|
return lists.map(list => ({
|
|
|
|
text: list.name,
|
|
|
|
action: () => {
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
|
|
|
listId: list.id,
|
|
|
|
userId: user.id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
},
|
2023-02-15 13:37:18 +09:00
|
|
|
}] as any;
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-05-07 14:19:15 +09:00
|
|
|
if ($i && meId !== user.id) {
|
2023-02-26 11:57:37 +09:00
|
|
|
if (iAmModerator) {
|
|
|
|
menu = menu.concat([{
|
|
|
|
type: 'parent',
|
|
|
|
icon: 'ti ti-badges',
|
|
|
|
text: i18n.ts.roles,
|
|
|
|
children: async () => {
|
2023-03-24 16:54:37 +09:00
|
|
|
const roles = await rolesCache.fetch(() => os.api('admin/roles/list'));
|
2023-02-26 11:57:37 +09:00
|
|
|
|
|
|
|
return roles.filter(r => r.target === 'manual').map(r => ({
|
|
|
|
text: r.name,
|
2023-03-01 10:20:03 +09:00
|
|
|
action: async () => {
|
|
|
|
const { canceled, result: period } = await os.select({
|
|
|
|
title: i18n.ts.period,
|
|
|
|
items: [{
|
|
|
|
value: 'indefinitely', text: i18n.ts.indefinitely,
|
|
|
|
}, {
|
|
|
|
value: 'oneHour', text: i18n.ts.oneHour,
|
|
|
|
}, {
|
|
|
|
value: 'oneDay', text: i18n.ts.oneDay,
|
|
|
|
}, {
|
|
|
|
value: 'oneWeek', text: i18n.ts.oneWeek,
|
|
|
|
}, {
|
|
|
|
value: 'oneMonth', text: i18n.ts.oneMonth,
|
|
|
|
}],
|
|
|
|
default: 'indefinitely',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
2023-07-08 07:08:16 +09:00
|
|
|
|
2023-03-01 10:20:03 +09:00
|
|
|
const expiresAt = period === 'indefinitely' ? null
|
|
|
|
: period === 'oneHour' ? Date.now() + (1000 * 60 * 60)
|
|
|
|
: period === 'oneDay' ? Date.now() + (1000 * 60 * 60 * 24)
|
|
|
|
: period === 'oneWeek' ? Date.now() + (1000 * 60 * 60 * 24 * 7)
|
|
|
|
: period === 'oneMonth' ? Date.now() + (1000 * 60 * 60 * 24 * 30)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
os.apiWithDialog('admin/roles/assign', { roleId: r.id, userId: user.id, expiresAt });
|
2023-02-26 11:57:37 +09:00
|
|
|
},
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: user.isMuted ? 'ti ti-eye' : 'ti ti-eye-off',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,
|
2022-06-20 17:38:49 +09:00
|
|
|
action: toggleMute,
|
2023-03-08 08:56:09 +09:00
|
|
|
}, {
|
|
|
|
icon: user.isRenoteMuted ? 'ti ti-repeat' : 'ti ti-repeat-off',
|
|
|
|
text: user.isRenoteMuted ? i18n.ts.renoteUnmute : i18n.ts.renoteMute,
|
|
|
|
action: toggleRenoteMute,
|
2020-10-17 20:12:00 +09:00
|
|
|
}, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-ban',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: user.isBlocking ? i18n.ts.unblock : i18n.ts.block,
|
2022-06-20 17:38:49 +09:00
|
|
|
action: toggleBlock,
|
2020-10-17 20:12:00 +09:00
|
|
|
}]);
|
|
|
|
|
2021-12-03 11:14:44 +09:00
|
|
|
if (user.isFollowed) {
|
|
|
|
menu = menu.concat([{
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-link-off',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.breakFollow,
|
2022-06-20 17:38:49 +09:00
|
|
|
action: invalidateFollow,
|
2021-12-03 11:14:44 +09:00
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:29:04 +09:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-exclamation-circle',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.reportAbuse,
|
2022-06-20 17:38:49 +09:00
|
|
|
action: reportAbuse,
|
2020-10-19 19:29:04 +09:00
|
|
|
}]);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
|
2023-05-14 10:30:46 +09:00
|
|
|
if (defaultStore.state.devMode) {
|
|
|
|
menu = menu.concat([null, {
|
|
|
|
icon: 'ti ti-id',
|
|
|
|
text: i18n.ts.copyUserId,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(user.id);
|
|
|
|
},
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2020-12-19 10:55:52 +09:00
|
|
|
if ($i && meId === user.id) {
|
2020-10-17 20:12:00 +09:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-pencil',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.editProfile,
|
2020-10-17 20:12:00 +09:00
|
|
|
action: () => {
|
2022-07-16 16:52:12 +09:00
|
|
|
router.push('/settings/profile');
|
2022-06-20 17:38:49 +09:00
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userActions.length > 0) {
|
|
|
|
menu = menu.concat([null, ...userActions.map(action => ({
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-plug',
|
2020-10-17 20:12:00 +09:00
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(user);
|
2022-06-20 17:38:49 +09:00
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
}))]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|