iceshrimp/packages/client/src/components/MkRenoteButton.vue

240 lines
5.1 KiB
Vue
Raw Normal View History

<template>
2023-04-08 09:01:42 +09:00
<button
v-if="canRenote"
ref="buttonRef"
v-tooltip.noDelay.bottom="i18n.ts.renote"
class="eddddedb _button canRenote"
@click="renote(false, $event)"
>
<i class="ph-repeat ph-bold ph-lg"></i>
<p v-if="count > 0" class="count">{{ count }}</p>
</button>
<button v-else class="eddddedb _button">
<i class="ph-prohibit ph-bold ph-lg"></i>
</button>
</template>
2022-07-24 15:45:16 +09:00
<script lang="ts" setup>
2023-04-08 09:01:42 +09:00
import { computed, ref } from "vue";
import type * as misskey from "calckey-js";
import Ripple from "@/components/MkRipple.vue";
import XDetails from "@/components/MkUsersTooltip.vue";
import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os";
import { $i } from "@/account";
import { useTooltip } from "@/scripts/use-tooltip";
import { i18n } from "@/i18n";
import { defaultStore } from "@/store";
2022-07-24 15:45:16 +09:00
const props = defineProps<{
2023-04-08 09:01:42 +09:00
note: misskey.entities.Note;
count: number;
}>();
2022-07-24 15:45:16 +09:00
const buttonRef = ref<HTMLElement>();
2023-04-08 09:01:42 +09:00
const canRenote = computed(
() =>
["public", "home"].includes(props.note.visibility) ||
props.note.userId === $i.id
);
2022-07-24 15:45:16 +09:00
useTooltip(buttonRef, async (showing) => {
2023-04-08 09:01:42 +09:00
const renotes = await os.api("notes/renotes", {
2022-07-24 15:45:16 +09:00
noteId: props.note.id,
limit: 11,
});
2023-04-08 09:01:42 +09:00
const users = renotes.map((x) => x.user);
2022-07-24 15:45:16 +09:00
if (users.length < 1) return;
2023-04-08 09:01:42 +09:00
os.popup(
XDetails,
{
showing,
users,
count: props.count,
targetElement: buttonRef.value,
},
{},
"closed"
);
2022-07-24 15:45:16 +09:00
});
2022-12-02 16:19:37 +09:00
const renote = async (viaKeyboard = false, ev?: MouseEvent) => {
2022-07-24 15:45:16 +09:00
pleaseLogin();
2023-04-08 09:01:42 +09:00
const renotes = await os.api("notes/renotes", {
noteId: props.note.id,
limit: 11,
});
2023-04-08 09:01:42 +09:00
const users = renotes.map((x) => x.user.id);
const hasRenotedBefore = users.includes($i.id);
let buttonActions = [];
2023-04-08 09:01:42 +09:00
if (props.note.visibility === "public") {
buttonActions.push({
text: i18n.ts.renote,
2023-04-08 09:01:42 +09:00
textStyle: "font-weight: bold",
icon: "ph-repeat ph-bold ph-lg",
danger: false,
action: () => {
2023-04-08 09:01:42 +09:00
os.api("notes/create", {
renoteId: props.note.id,
2023-04-08 09:01:42 +09:00
visibility: "public",
});
2023-04-08 09:01:42 +09:00
const el =
ev &&
((ev.currentTarget ?? ev.target) as
| HTMLElement
| null
| undefined);
if (el) {
const rect = el.getBoundingClientRect();
2023-04-08 09:01:42 +09:00
const x = rect.left + el.offsetWidth / 2;
const y = rect.top + el.offsetHeight / 2;
os.popup(Ripple, { x, y }, {}, "end");
}
},
});
}
2023-04-08 09:01:42 +09:00
if (["public", "home"].includes(props.note.visibility)) {
buttonActions.push({
text: i18n.ts.renoteAsUnlisted,
2023-04-08 09:01:42 +09:00
icons: ["ph-repeat ph-bold ph-lg", "ph-house ph-bold ph-lg"],
danger: false,
action: () => {
2023-04-08 09:01:42 +09:00
os.api("notes/create", {
renoteId: props.note.id,
2023-04-08 09:01:42 +09:00
visibility: "home",
});
2023-04-08 09:01:42 +09:00
const el =
ev &&
((ev.currentTarget ?? ev.target) as
| HTMLElement
| null
| undefined);
if (el) {
const rect = el.getBoundingClientRect();
2023-04-08 09:01:42 +09:00
const x = rect.left + el.offsetWidth / 2;
const y = rect.top + el.offsetHeight / 2;
os.popup(Ripple, { x, y }, {}, "end");
}
},
});
}
2023-04-08 09:01:42 +09:00
if (props.note.visibility === "specified") {
buttonActions.push({
text: i18n.ts.renoteToRecipients,
2023-04-08 09:01:42 +09:00
icons: [
"ph-repeat ph-bold ph-lg",
"ph-envelope-simple-open ph-bold ph-lg",
],
danger: false,
action: () => {
2023-04-08 09:01:42 +09:00
os.api("notes/create", {
renoteId: props.note.id,
2023-04-08 09:01:42 +09:00
visibility: "specified",
visibleUserIds: props.note.visibleUserIds,
});
2023-04-08 09:01:42 +09:00
const el =
ev &&
((ev.currentTarget ?? ev.target) as
| HTMLElement
| null
| undefined);
if (el) {
const rect = el.getBoundingClientRect();
2023-04-08 09:01:42 +09:00
const x = rect.left + el.offsetWidth / 2;
const y = rect.top + el.offsetHeight / 2;
os.popup(Ripple, { x, y }, {}, "end");
}
},
});
} else {
buttonActions.push({
text: i18n.ts.renoteToFollowers,
2023-04-08 09:01:42 +09:00
icons: [
"ph-repeat ph-bold ph-lg",
"ph-lock-simple-open ph-bold ph-lg",
],
danger: false,
action: () => {
2023-04-08 09:01:42 +09:00
os.api("notes/create", {
renoteId: props.note.id,
2023-04-08 09:01:42 +09:00
visibility: "followers",
});
2023-04-08 09:01:42 +09:00
const el =
ev &&
((ev.currentTarget ?? ev.target) as
| HTMLElement
| null
| undefined);
if (el) {
const rect = el.getBoundingClientRect();
2023-04-08 09:01:42 +09:00
const x = rect.left + el.offsetWidth / 2;
const y = rect.top + el.offsetHeight / 2;
os.popup(Ripple, { x, y }, {}, "end");
}
},
});
}
2022-12-02 16:19:37 +09:00
if (!defaultStore.state.seperateRenoteQuote) {
buttonActions.push({
2022-09-29 01:22:03 +09:00
text: i18n.ts.quote,
2023-04-08 09:01:42 +09:00
icon: "ph-quotes ph-bold ph-lg",
2022-12-02 16:28:16 +09:00
danger: false,
2022-09-29 01:22:03 +09:00
action: () => {
os.post({
renote: props.note,
});
},
});
}
if (hasRenotedBefore) {
buttonActions.push({
text: i18n.ts.unrenote,
2023-04-08 09:01:42 +09:00
icon: "ph-trash ph-bold ph-lg",
danger: true,
action: () => {
2023-04-08 09:01:42 +09:00
os.api("notes/unrenote", {
noteId: props.note.id,
});
},
});
}
os.popupMenu(buttonActions, buttonRef.value, { viaKeyboard });
2022-07-24 15:45:16 +09:00
};
</script>
2023-04-08 09:01:42 +09:00
<style lang="scss" scoped>
.eddddedb {
display: inline-block;
height: 32px;
margin: 2px;
padding: 0 6px;
border-radius: 4px;
&:not(.canRenote) {
cursor: default;
}
&.renoted {
background: var(--accent);
}
> .count {
display: inline;
margin-left: 8px;
opacity: 0.7;
}
2023-04-08 09:01:42 +09:00
}
</style>