2023-01-12 21:40:33 -07:00
|
|
|
import * as Acct from "calckey-js/built/acct";
|
|
|
|
import { defineAsyncComponent } from "vue";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import copyToClipboard from "@/scripts/copy-to-clipboard";
|
|
|
|
import { host } from "@/config";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { userActions } from "@/store";
|
|
|
|
import { $i, iAmModerator } from "@/account";
|
|
|
|
import { mainRouter } from "@/router";
|
|
|
|
import { Router } from "@/nirax";
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2022-07-16 01:52:12 -06:00
|
|
|
export function getUserMenu(user, router: Router = mainRouter) {
|
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() {
|
2022-01-27 19:39:49 -07:00
|
|
|
const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
|
2023-01-12 21:40:33 -07:00
|
|
|
const lists = await os.api("users/lists/list");
|
2020-10-17 05:12:00 -06:00
|
|
|
if (lists.length === 0) {
|
2021-11-18 02:45:58 -07:00
|
|
|
os.alert({
|
2023-01-12 21:40:33 -07:00
|
|
|
type: "error",
|
2022-06-20 02:38:49 -06:00
|
|
|
text: i18n.ts.youHaveNoLists,
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 02:45:58 -07:00
|
|
|
const { canceled, result: listId } = await os.select({
|
2020-10-17 05:12:00 -06:00
|
|
|
title: t,
|
2023-01-12 21:40:33 -07:00
|
|
|
items: lists.map((list) => ({
|
|
|
|
value: list.id,
|
|
|
|
text: list.name,
|
2022-06-20 02:38:49 -06:00
|
|
|
})),
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog("users/lists/push", {
|
2020-10-17 05:12:00 -06:00
|
|
|
listId: listId,
|
2022-06-20 02:38:49 -06:00
|
|
|
userId: user.id,
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function inviteGroup() {
|
2023-01-12 21:40:33 -07:00
|
|
|
const groups = await os.api("users/groups/owned");
|
2020-10-17 05:12:00 -06:00
|
|
|
if (groups.length === 0) {
|
2021-11-18 02:45:58 -07:00
|
|
|
os.alert({
|
2023-01-12 21:40:33 -07:00
|
|
|
type: "error",
|
2022-06-20 02:38:49 -06:00
|
|
|
text: i18n.ts.youHaveNoGroups,
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 02:45:58 -07:00
|
|
|
const { canceled, result: groupId } = await os.select({
|
2022-01-27 19:39:49 -07:00
|
|
|
title: i18n.ts.group,
|
2023-01-12 21:40:33 -07:00
|
|
|
items: groups.map((group) => ({
|
|
|
|
value: group.id,
|
|
|
|
text: group.name,
|
2022-06-20 02:38:49 -06:00
|
|
|
})),
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog("users/groups/invite", {
|
2020-10-17 05:12:00 -06:00
|
|
|
groupId: groupId,
|
2022-06-20 02:38:49 -06:00
|
|
|
userId: user.id,
|
2020-10-17 05:12:00 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleMute() {
|
2022-03-04 04:23:53 -07:00
|
|
|
if (user.isMuted) {
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog("mute/delete", {
|
2022-03-04 04:23:53 -07:00
|
|
|
userId: user.id,
|
|
|
|
}).then(() => {
|
|
|
|
user.isMuted = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const { canceled, result: period } = await os.select({
|
|
|
|
title: i18n.ts.mutePeriod,
|
2023-01-12 21:40:33 -07:00
|
|
|
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",
|
2022-03-04 04:23:53 -07:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
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;
|
2022-03-04 04:23:53 -07:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog("mute/create", {
|
2022-03-04 04:23:53 -07:00
|
|
|
userId: user.id,
|
|
|
|
expiresAt,
|
|
|
|
}).then(() => {
|
|
|
|
user.isMuted = true;
|
|
|
|
});
|
|
|
|
}
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleBlock() {
|
2023-01-12 21:40:33 -07:00
|
|
|
if (
|
|
|
|
!(await getConfirmed(
|
|
|
|
user.isBlocking ? i18n.ts.unblockConfirm : i18n.ts.blockConfirm,
|
|
|
|
))
|
|
|
|
)
|
|
|
|
return;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2023-02-10 16:41:19 -07:00
|
|
|
await os.apiWithDialog(
|
|
|
|
user.isBlocking ? "blocking/delete" : "blocking/create",
|
|
|
|
{
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
);
|
2023-02-09 10:46:32 -07:00
|
|
|
user.isBlocking = !user.isBlocking;
|
2023-02-09 10:17:14 -07:00
|
|
|
await os.api(user.isBlocking ? "mute/create" : "mute/delete", {
|
|
|
|
userId: user.id,
|
2023-02-10 16:41:19 -07:00
|
|
|
});
|
2023-02-09 10:17:14 -07:00
|
|
|
user.isMuted = user.isBlocking;
|
|
|
|
if (user.isBlocking) {
|
2023-02-10 16:41:19 -07:00
|
|
|
await os.api("following/delete", {
|
2023-02-09 10:17:14 -07:00
|
|
|
userId: user.id,
|
2023-02-09 10:46:32 -07:00
|
|
|
});
|
2023-02-10 16:41:19 -07:00
|
|
|
user.isFollowing = false;
|
2023-02-09 10:17:14 -07:00
|
|
|
}
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleSilence() {
|
2023-01-12 21:40:33 -07:00
|
|
|
if (
|
|
|
|
!(await getConfirmed(
|
|
|
|
i18n.t(user.isSilenced ? "unsilenceConfirm" : "silenceConfirm"),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
return;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog(
|
|
|
|
user.isSilenced ? "admin/unsilence-user" : "admin/silence-user",
|
|
|
|
{
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
).then(() => {
|
2020-10-17 05:12:00 -06:00
|
|
|
user.isSilenced = !user.isSilenced;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleSuspend() {
|
2023-01-12 21:40:33 -07:00
|
|
|
if (
|
|
|
|
!(await getConfirmed(
|
|
|
|
i18n.t(user.isSuspended ? "unsuspendConfirm" : "suspendConfirm"),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
return;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog(
|
|
|
|
user.isSuspended ? "admin/unsuspend-user" : "admin/suspend-user",
|
|
|
|
{
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
).then(() => {
|
2020-10-17 05:12:00 -06:00
|
|
|
user.isSuspended = !user.isSuspended;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-02 23:22:55 -07:00
|
|
|
function reportAbuse() {
|
2023-01-12 21:40:33 -07:00
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(
|
|
|
|
() => import("@/components/MkAbuseReportWindow.vue"),
|
|
|
|
),
|
|
|
|
{
|
|
|
|
user: user,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
"closed",
|
|
|
|
);
|
2020-10-19 04:29:04 -06:00
|
|
|
}
|
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
async function getConfirmed(text: string): Promise<boolean> {
|
2021-11-18 02:45:58 -07:00
|
|
|
const confirm = await os.confirm({
|
2023-01-12 21:40:33 -07:00
|
|
|
type: "warning",
|
|
|
|
title: "confirm",
|
2020-10-17 05:12:00 -06:00
|
|
|
text,
|
|
|
|
});
|
|
|
|
|
|
|
|
return !confirm.canceled;
|
|
|
|
}
|
|
|
|
|
2021-12-02 19:14:44 -07:00
|
|
|
async function invalidateFollow() {
|
2023-02-04 13:46:48 -07:00
|
|
|
if (!(await getConfirmed(i18n.ts.breakFollowConfirm))) return;
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
os.apiWithDialog("following/invalidate", {
|
2022-06-20 02:38:49 -06:00
|
|
|
userId: user.id,
|
2021-12-02 19:14:44 -07:00
|
|
|
}).then(() => {
|
|
|
|
user.isFollowed = !user.isFollowed;
|
2022-06-09 23:36:55 -06:00
|
|
|
});
|
2021-12-02 19:14:44 -07:00
|
|
|
}
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
let menu = [
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-at ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.copyUsername,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`@${user.username}@${user.host || host}`);
|
|
|
|
},
|
2022-06-20 02:38:49 -06:00
|
|
|
},
|
2023-01-12 21:40:33 -07:00
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-info ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.info,
|
|
|
|
action: () => {
|
|
|
|
router.push(`/user-info/${user.id}`);
|
|
|
|
},
|
2022-06-20 02:38:49 -06:00
|
|
|
},
|
2023-01-12 21:40:33 -07:00
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-envelope-simple-open ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.sendMessage,
|
|
|
|
action: () => {
|
|
|
|
os.post({ specified: user });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
meId !== user.id
|
|
|
|
? {
|
|
|
|
type: "link",
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-chats-teardrop ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.startMessaging,
|
|
|
|
to: `/my/messaging/${Acct.toString(user)}`,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
null,
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-list-bullets ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.addToList,
|
|
|
|
action: pushList,
|
2022-06-20 02:38:49 -06:00
|
|
|
},
|
2023-01-12 21:40:33 -07:00
|
|
|
meId !== user.id
|
|
|
|
? {
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-users-three ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.inviteToGroup,
|
|
|
|
action: inviteGroup,
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
] as any;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2022-05-06 23:19:15 -06:00
|
|
|
if ($i && meId !== user.id) {
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
null,
|
|
|
|
{
|
2023-03-30 20:10:03 -06:00
|
|
|
icon: user.isMuted
|
|
|
|
? "ph-eye ph-bold ph-lg"
|
|
|
|
: "ph-eye-slash ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,
|
2023-02-09 10:46:32 -07:00
|
|
|
hidden: user.isBlocking === true,
|
2023-01-12 21:40:33 -07:00
|
|
|
action: toggleMute,
|
|
|
|
},
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-prohibit ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: user.isBlocking ? i18n.ts.unblock : i18n.ts.block,
|
|
|
|
action: toggleBlock,
|
|
|
|
},
|
|
|
|
]);
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2021-12-02 19:14:44 -07:00
|
|
|
if (user.isFollowed) {
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-link-break ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.breakFollow,
|
|
|
|
action: invalidateFollow,
|
|
|
|
},
|
|
|
|
]);
|
2021-12-02 19:14:44 -07:00
|
|
|
}
|
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
null,
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-warning-circle ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.reportAbuse,
|
|
|
|
action: reportAbuse,
|
|
|
|
},
|
|
|
|
]);
|
2020-10-19 04:29:04 -06:00
|
|
|
|
2022-01-18 05:30:17 -07:00
|
|
|
if (iAmModerator) {
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
null,
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-microphone-slash ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: user.isSilenced ? i18n.ts.unsilence : i18n.ts.silence,
|
|
|
|
action: toggleSilence,
|
|
|
|
},
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-snowflake ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: user.isSuspended ? i18n.ts.unsuspend : i18n.ts.suspend,
|
|
|
|
action: toggleSuspend,
|
|
|
|
},
|
|
|
|
]);
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:55:52 -07:00
|
|
|
if ($i && meId === user.id) {
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
null,
|
|
|
|
{
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-pencil ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: i18n.ts.editProfile,
|
|
|
|
action: () => {
|
|
|
|
router.push("/settings/profile");
|
|
|
|
},
|
2022-06-20 02:38:49 -06:00
|
|
|
},
|
2023-01-12 21:40:33 -07:00
|
|
|
]);
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (userActions.length > 0) {
|
2023-01-12 21:40:33 -07:00
|
|
|
menu = menu.concat([
|
|
|
|
null,
|
|
|
|
...userActions.map((action) => ({
|
2023-03-11 14:01:04 -07:00
|
|
|
icon: "ph-plug ph-bold ph-lg",
|
2023-01-12 21:40:33 -07:00
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(user);
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
]);
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|