2021-11-11 09:02:25 -08:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { host } from '@/config';
|
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { userActions } from '@/store';
|
|
|
|
import { router } from '@/router';
|
2022-01-18 04:30:17 -08:00
|
|
|
import { $i, iAmModerator } from '@/account';
|
2022-05-01 06:51:07 -07:00
|
|
|
import { defineAsyncComponent } from 'vue';
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
|
|
export function getUserMenu(user) {
|
2020-12-18 17:55:52 -08:00
|
|
|
const meId = $i ? $i.id : null;
|
2020-11-28 18:25:43 -08:00
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
async function pushList() {
|
2022-01-27 18:39:49 -08:00
|
|
|
const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
|
2020-10-17 04:12:00 -07:00
|
|
|
const lists = await os.api('users/lists/list');
|
|
|
|
if (lists.length === 0) {
|
2021-11-18 01:45:58 -08:00
|
|
|
os.alert({
|
2020-10-17 04:12:00 -07:00
|
|
|
type: 'error',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.youHaveNoLists
|
2020-10-17 04:12:00 -07:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 01:45:58 -08:00
|
|
|
const { canceled, result: listId } = await os.select({
|
2020-10-17 04:12:00 -07:00
|
|
|
title: t,
|
2021-11-18 01:45:58 -08:00
|
|
|
items: lists.map(list => ({
|
|
|
|
value: list.id, text: list.name
|
|
|
|
}))
|
2020-10-17 04:12:00 -07:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/lists/push', {
|
|
|
|
listId: listId,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function inviteGroup() {
|
|
|
|
const groups = await os.api('users/groups/owned');
|
|
|
|
if (groups.length === 0) {
|
2021-11-18 01:45:58 -08:00
|
|
|
os.alert({
|
2020-10-17 04:12:00 -07:00
|
|
|
type: 'error',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.youHaveNoGroups
|
2020-10-17 04:12:00 -07:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 01:45:58 -08:00
|
|
|
const { canceled, result: groupId } = await os.select({
|
2022-01-27 18:39:49 -08:00
|
|
|
title: i18n.ts.group,
|
2021-11-18 01:45:58 -08:00
|
|
|
items: groups.map(group => ({
|
|
|
|
value: group.id, text: group.name
|
|
|
|
}))
|
2020-10-17 04:12:00 -07:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
os.apiWithDialog('users/groups/invite', {
|
|
|
|
groupId: groupId,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleMute() {
|
2022-03-04 03:23:53 -08: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 04:12:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleBlock() {
|
2022-01-27 18:39:49 -08:00
|
|
|
if (!await getConfirmed(user.isBlocking ? i18n.ts.unblockConfirm : i18n.ts.blockConfirm)) return;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
|
|
os.apiWithDialog(user.isBlocking ? 'blocking/delete' : 'blocking/create', {
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
user.isBlocking = !user.isBlocking;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleSilence() {
|
2020-12-25 17:51:00 -08:00
|
|
|
if (!await getConfirmed(i18n.t(user.isSilenced ? 'unsilenceConfirm' : 'silenceConfirm'))) return;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
|
|
os.apiWithDialog(user.isSilenced ? 'admin/unsilence-user' : 'admin/silence-user', {
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
user.isSilenced = !user.isSilenced;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleSuspend() {
|
2020-12-25 17:51:00 -08:00
|
|
|
if (!await getConfirmed(i18n.t(user.isSuspended ? 'unsuspendConfirm' : 'suspendConfirm'))) return;
|
2020-10-17 04:12:00 -07:00
|
|
|
|
|
|
|
os.apiWithDialog(user.isSuspended ? 'admin/unsuspend-user' : 'admin/suspend-user', {
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
user.isSuspended = !user.isSuspended;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-02 22:22:55 -08:00
|
|
|
function reportAbuse() {
|
2022-05-01 06:51:07 -07:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/abuse-report-window.vue')), {
|
2020-10-19 03:29:04 -07:00
|
|
|
user: user,
|
|
|
|
}, {}, 'closed');
|
|
|
|
}
|
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
async function getConfirmed(text: string): Promise<boolean> {
|
2021-11-18 01:45:58 -08:00
|
|
|
const confirm = await os.confirm({
|
2020-10-17 04:12:00 -07:00
|
|
|
type: 'warning',
|
|
|
|
title: 'confirm',
|
|
|
|
text,
|
|
|
|
});
|
|
|
|
|
|
|
|
return !confirm.canceled;
|
|
|
|
}
|
|
|
|
|
2021-12-02 18:14:44 -08:00
|
|
|
async function invalidateFollow() {
|
|
|
|
os.apiWithDialog('following/invalidate', {
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
user.isFollowed = !user.isFollowed;
|
2022-06-09 22:36:55 -07:00
|
|
|
});
|
2021-12-02 18:14:44 -08:00
|
|
|
}
|
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
let menu = [{
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-at',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.copyUsername,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`@${user.username}@${user.host || host}`);
|
|
|
|
}
|
2021-04-22 20:00:07 -07:00
|
|
|
}, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-info-circle',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.info,
|
2021-04-16 01:34:06 -07:00
|
|
|
action: () => {
|
|
|
|
os.pageWindow(`/user-info/${user.id}`);
|
|
|
|
}
|
2020-10-17 04:12:00 -07:00
|
|
|
}, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-envelope',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.sendMessage,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: () => {
|
|
|
|
os.post({ specified: user });
|
|
|
|
}
|
2022-05-06 22:19:15 -07:00
|
|
|
}, meId !== user.id ? {
|
2020-11-02 17:43:50 -08:00
|
|
|
type: 'link',
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-comments',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.startMessaging,
|
2021-11-11 09:02:25 -08:00
|
|
|
to: '/my/messaging/' + Acct.toString(user),
|
2020-10-17 04:12:00 -07:00
|
|
|
} : undefined, null, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-list-ul',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.addToList,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: pushList
|
2022-05-06 22:19:15 -07:00
|
|
|
}, meId !== user.id ? {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-users',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.inviteToGroup,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: inviteGroup
|
|
|
|
} : undefined] as any;
|
|
|
|
|
2022-05-06 22:19:15 -07:00
|
|
|
if ($i && meId !== user.id) {
|
2020-10-17 04:12:00 -07:00
|
|
|
menu = menu.concat([null, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: user.isMuted ? 'fas fa-eye' : 'fas fa-eye-slash',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: toggleMute
|
|
|
|
}, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-ban',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: user.isBlocking ? i18n.ts.unblock : i18n.ts.block,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: toggleBlock
|
|
|
|
}]);
|
|
|
|
|
2021-12-02 18:14:44 -08:00
|
|
|
if (user.isFollowed) {
|
|
|
|
menu = menu.concat([{
|
|
|
|
icon: 'fas fa-unlink',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.breakFollow,
|
2021-12-02 18:14:44 -08:00
|
|
|
action: invalidateFollow
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
2020-10-19 03:29:04 -07:00
|
|
|
menu = menu.concat([null, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-exclamation-circle',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.reportAbuse,
|
2020-10-19 03:29:04 -07:00
|
|
|
action: reportAbuse
|
|
|
|
}]);
|
|
|
|
|
2022-01-18 04:30:17 -08:00
|
|
|
if (iAmModerator) {
|
2020-10-17 04:12:00 -07:00
|
|
|
menu = menu.concat([null, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-microphone-slash',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: user.isSilenced ? i18n.ts.unsilence : i18n.ts.silence,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: toggleSilence
|
|
|
|
}, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-snowflake',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: user.isSuspended ? i18n.ts.unsuspend : i18n.ts.suspend,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: toggleSuspend
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 17:55:52 -08:00
|
|
|
if ($i && meId === user.id) {
|
2020-10-17 04:12:00 -07:00
|
|
|
menu = menu.concat([null, {
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-pencil-alt',
|
2022-01-27 18:39:49 -08:00
|
|
|
text: i18n.ts.editProfile,
|
2020-10-17 04:12:00 -07:00
|
|
|
action: () => {
|
|
|
|
router.push('/settings/profile');
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userActions.length > 0) {
|
|
|
|
menu = menu.concat([null, ...userActions.map(action => ({
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-plug',
|
2020-10-17 04:12:00 -07:00
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(user);
|
|
|
|
}
|
|
|
|
}))]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|