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