2022-06-20 08:38:49 +00:00
|
|
|
import { defineAsyncComponent } from 'vue';
|
2023-02-25 00:18:36 +00:00
|
|
|
import * as misskey from 'misskey-js';
|
2021-11-11 17:02:25 +00:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { host } from '@/config';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { userActions } from '@/store';
|
2022-01-18 12:30:17 +00:00
|
|
|
import { $i, iAmModerator } from '@/account';
|
2022-06-20 08:38:49 +00:00
|
|
|
import { mainRouter } from '@/router';
|
2022-07-16 07:52:12 +00:00
|
|
|
import { Router } from '@/nirax';
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2023-02-25 00:18:36 +00:00
|
|
|
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
|
2020-12-19 01:55:52 +00:00
|
|
|
const meId = $i ? $i.id : null;
|
2020-11-29 02:25:43 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
async function pushList() {
|
2022-01-28 02:39:49 +00:00
|
|
|
const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
|
2020-10-17 11:12:00 +00:00
|
|
|
const lists = await os.api('users/lists/list');
|
|
|
|
if (lists.length === 0) {
|
2021-11-18 09:45:58 +00:00
|
|
|
os.alert({
|
2020-10-17 11:12:00 +00:00
|
|
|
type: 'error',
|
2022-06-20 08:38:49 +00:00
|
|
|
text: i18n.ts.youHaveNoLists,
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 09:45:58 +00:00
|
|
|
const { canceled, result: listId } = await os.select({
|
2020-10-17 11:12:00 +00:00
|
|
|
title: t,
|
2021-11-18 09:45:58 +00:00
|
|
|
items: lists.map(list => ({
|
2022-06-20 08:38:49 +00:00
|
|
|
value: list.id, text: list.name,
|
|
|
|
})),
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
|
|
|
listId: listId,
|
2022-06-20 08:38:49 +00:00
|
|
|
userId: user.id,
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleMute() {
|
2022-03-04 11:23:53 +00: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 11:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleBlock() {
|
2022-01-28 02:39:49 +00:00
|
|
|
if (!await getConfirmed(user.isBlocking ? i18n.ts.unblockConfirm : i18n.ts.blockConfirm)) return;
|
2020-10-17 11:12:00 +00:00
|
|
|
|
|
|
|
os.apiWithDialog(user.isBlocking ? 'blocking/delete' : 'blocking/create', {
|
2022-06-20 08:38:49 +00:00
|
|
|
userId: user.id,
|
2020-10-17 11:12:00 +00:00
|
|
|
}).then(() => {
|
|
|
|
user.isBlocking = !user.isBlocking;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-03 06:22:55 +00:00
|
|
|
function reportAbuse() {
|
2022-08-30 15:24:33 +00:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkAbuseReportWindow.vue')), {
|
2020-10-19 10:29:04 +00:00
|
|
|
user: user,
|
|
|
|
}, {}, 'closed');
|
|
|
|
}
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
async function getConfirmed(text: string): Promise<boolean> {
|
2021-11-18 09:45:58 +00:00
|
|
|
const confirm = await os.confirm({
|
2020-10-17 11:12:00 +00:00
|
|
|
type: 'warning',
|
|
|
|
title: 'confirm',
|
|
|
|
text,
|
|
|
|
});
|
|
|
|
|
|
|
|
return !confirm.canceled;
|
|
|
|
}
|
|
|
|
|
2021-12-03 02:14:44 +00:00
|
|
|
async function invalidateFollow() {
|
2023-02-24 04:08:06 +00:00
|
|
|
if (!await getConfirmed(i18n.ts.breakFollowConfirm)) return;
|
|
|
|
|
2021-12-03 02:14:44 +00:00
|
|
|
os.apiWithDialog('following/invalidate', {
|
2022-06-20 08:38:49 +00:00
|
|
|
userId: user.id,
|
2021-12-03 02:14:44 +00:00
|
|
|
}).then(() => {
|
|
|
|
user.isFollowed = !user.isFollowed;
|
2022-06-10 05:36:55 +00:00
|
|
|
});
|
2021-12-03 02:14:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
let menu = [{
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-at',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.copyUsername,
|
2020-10-17 11:12:00 +00:00
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`@${user.username}@${user.host || host}`);
|
2022-06-20 08:38:49 +00:00
|
|
|
},
|
2021-04-23 03:00:07 +00:00
|
|
|
}, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-info-circle',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.info,
|
2021-04-16 08:34:06 +00:00
|
|
|
action: () => {
|
2022-07-16 07:52:12 +00:00
|
|
|
router.push(`/user-info/${user.id}`);
|
2022-06-20 08:38:49 +00:00
|
|
|
},
|
2022-12-28 00:10:33 +00:00
|
|
|
}, {
|
|
|
|
icon: 'ti ti-rss',
|
|
|
|
text: i18n.ts.copyRSS,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`${user.host ?? host}/@${user.username}.atom`);
|
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
}, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-mail',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.sendMessage,
|
2020-10-17 11:12:00 +00:00
|
|
|
action: () => {
|
|
|
|
os.post({ specified: user });
|
2022-06-20 08:38:49 +00:00
|
|
|
},
|
2023-02-15 04:37:18 +00:00
|
|
|
}, null, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-list',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.addToList,
|
2022-06-20 08:38:49 +00:00
|
|
|
action: pushList,
|
2023-02-15 04:37:18 +00:00
|
|
|
}] as any;
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2022-05-07 05:19:15 +00:00
|
|
|
if ($i && meId !== user.id) {
|
2020-10-17 11:12:00 +00:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: user.isMuted ? 'ti ti-eye' : 'ti ti-eye-off',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,
|
2022-06-20 08:38:49 +00:00
|
|
|
action: toggleMute,
|
2020-10-17 11:12:00 +00:00
|
|
|
}, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-ban',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: user.isBlocking ? i18n.ts.unblock : i18n.ts.block,
|
2022-06-20 08:38:49 +00:00
|
|
|
action: toggleBlock,
|
2020-10-17 11:12:00 +00:00
|
|
|
}]);
|
|
|
|
|
2021-12-03 02:14:44 +00:00
|
|
|
if (user.isFollowed) {
|
|
|
|
menu = menu.concat([{
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-link-off',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.breakFollow,
|
2022-06-20 08:38:49 +00:00
|
|
|
action: invalidateFollow,
|
2021-12-03 02:14:44 +00:00
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2020-10-19 10:29:04 +00:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-exclamation-circle',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.reportAbuse,
|
2022-06-20 08:38:49 +00:00
|
|
|
action: reportAbuse,
|
2020-10-19 10:29:04 +00:00
|
|
|
}]);
|
|
|
|
|
2022-01-18 12:30:17 +00:00
|
|
|
if (iAmModerator) {
|
2020-10-17 11:12:00 +00:00
|
|
|
menu = menu.concat([null, {
|
2023-02-11 03:55:22 +00:00
|
|
|
icon: 'ti ti-badges',
|
|
|
|
text: i18n.ts.roles,
|
|
|
|
action: async () => {
|
|
|
|
const roles = await os.api('admin/roles/list');
|
|
|
|
|
|
|
|
const { canceled, result: roleId } = await os.select({
|
|
|
|
title: i18n.ts._role.chooseRoleToAssign,
|
|
|
|
items: roles.map(r => ({ text: r.name, value: r.id })),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.apiWithDialog('admin/roles/assign', { roleId, userId: user.id });
|
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
}]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:55:52 +00:00
|
|
|
if ($i && meId === user.id) {
|
2020-10-17 11:12:00 +00:00
|
|
|
menu = menu.concat([null, {
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-pencil',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.editProfile,
|
2020-10-17 11:12:00 +00:00
|
|
|
action: () => {
|
2022-07-16 07:52:12 +00:00
|
|
|
router.push('/settings/profile');
|
2022-06-20 08:38:49 +00:00
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userActions.length > 0) {
|
|
|
|
menu = menu.concat([null, ...userActions.map(action => ({
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-plug',
|
2020-10-17 11:12:00 +00:00
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(user);
|
2022-06-20 08:38:49 +00:00
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
}))]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|