2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2019-02-06 17:05:49 +00:00
|
|
|
<template>
|
2020-02-21 21:43:46 +00:00
|
|
|
<button
|
2023-01-08 05:28:14 +00:00
|
|
|
ref="buttonEl"
|
2021-12-27 13:59:14 +00:00
|
|
|
v-ripple="canToggle"
|
2023-01-14 08:23:49 +00:00
|
|
|
class="_button"
|
2023-09-10 08:16:50 +00:00
|
|
|
:class="[$style.root, { [$style.reacted]: note.myReaction == reaction, [$style.canToggle]: canToggle, [$style.small]: defaultStore.state.reactionsDisplaySize === 'small', [$style.large]: defaultStore.state.reactionsDisplaySize === 'large' }]"
|
2021-11-12 14:53:10 +00:00
|
|
|
@click="toggleReaction()"
|
2019-02-06 17:05:49 +00:00
|
|
|
>
|
2023-11-23 23:37:27 +00:00
|
|
|
<MkReactionIcon :class="defaultStore.state.limitWidthOfReaction ? $style.limitWidth : ''" :reaction="reaction" :emojiUrl="note.reactionEmojis[reaction.substring(1, reaction.length - 1)]"/>
|
2023-01-14 08:23:49 +00:00
|
|
|
<span :class="$style.count">{{ count }}</span>
|
2020-02-21 21:43:46 +00:00
|
|
|
</button>
|
2019-02-06 17:05:49 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
<script lang="ts" setup>
|
2023-11-03 06:35:07 +00:00
|
|
|
import { computed, inject, onMounted, shallowRef, watch } from 'vue';
|
2023-09-04 04:33:38 +00:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-08-30 15:24:33 +00:00
|
|
|
import XDetails from '@/components/MkReactionsViewer.details.vue';
|
2023-01-08 05:22:04 +00:00
|
|
|
import MkReactionIcon from '@/components/MkReactionIcon.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { useTooltip } from '@/scripts/use-tooltip.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-01-08 07:17:42 +00:00
|
|
|
import MkReactionEffect from '@/components/MkReactionEffect.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { claimAchievement } from '@/scripts/achievements.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2019-02-06 17:05:49 +00:00
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
const props = defineProps<{
|
|
|
|
reaction: string;
|
|
|
|
count: number;
|
|
|
|
isInitial: boolean;
|
2023-09-04 04:33:38 +00:00
|
|
|
note: Misskey.entities.Note;
|
2022-06-30 14:51:18 +00:00
|
|
|
}>();
|
|
|
|
|
2023-11-03 06:35:07 +00:00
|
|
|
const mock = inject<boolean>('mock', false);
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'reactionToggled', emoji: string, newCount: number): void;
|
|
|
|
}>();
|
|
|
|
|
2023-01-08 05:28:14 +00:00
|
|
|
const buttonEl = shallowRef<HTMLElement>();
|
2022-06-30 14:51:18 +00:00
|
|
|
|
|
|
|
const canToggle = computed(() => !props.reaction.match(/@\w/) && $i);
|
|
|
|
|
2023-05-19 00:15:24 +00:00
|
|
|
async function toggleReaction() {
|
2022-06-30 14:51:18 +00:00
|
|
|
if (!canToggle.value) return;
|
|
|
|
|
2023-05-19 00:48:48 +00:00
|
|
|
// TODO: その絵文字を使う権限があるかどうか確認
|
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
const oldReaction = props.note.myReaction;
|
|
|
|
if (oldReaction) {
|
2023-05-19 00:15:24 +00:00
|
|
|
const confirm = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: oldReaction !== props.reaction ? i18n.ts.changeReactionConfirm : i18n.ts.cancelReactionConfirm,
|
|
|
|
});
|
|
|
|
if (confirm.canceled) return;
|
|
|
|
|
2023-11-03 06:35:07 +00:00
|
|
|
if (mock) {
|
|
|
|
emit('reactionToggled', props.reaction, (props.count - 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
os.api('notes/reactions/delete', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
}).then(() => {
|
|
|
|
if (oldReaction !== props.reaction) {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.api('notes/reactions/create', {
|
2021-11-12 14:53:10 +00:00
|
|
|
noteId: props.note.id,
|
2022-06-30 14:51:18 +00:00
|
|
|
reaction: props.reaction,
|
2019-02-06 17:05:49 +00:00
|
|
|
});
|
|
|
|
}
|
2021-11-12 14:53:10 +00:00
|
|
|
});
|
2022-06-30 14:51:18 +00:00
|
|
|
} else {
|
2023-11-03 06:35:07 +00:00
|
|
|
if (mock) {
|
|
|
|
emit('reactionToggled', props.reaction, (props.count + 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
os.api('notes/reactions/create', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction,
|
2021-11-12 14:53:10 +00:00
|
|
|
});
|
2023-01-21 04:14:55 +00:00
|
|
|
if (props.note.text && props.note.text.length > 100 && (Date.now() - new Date(props.note.createdAt).getTime() < 1000 * 3)) {
|
|
|
|
claimAchievement('reactWithoutRead');
|
|
|
|
}
|
2022-06-30 14:51:18 +00:00
|
|
|
}
|
2023-05-19 00:15:24 +00:00
|
|
|
}
|
2021-11-12 14:53:10 +00:00
|
|
|
|
2023-05-19 00:15:24 +00:00
|
|
|
function anime() {
|
2022-06-30 14:51:18 +00:00
|
|
|
if (document.hidden) return;
|
2023-01-23 07:36:47 +00:00
|
|
|
if (!defaultStore.state.animation) return;
|
2022-06-30 14:51:18 +00:00
|
|
|
|
2023-01-08 05:28:14 +00:00
|
|
|
const rect = buttonEl.value.getBoundingClientRect();
|
|
|
|
const x = rect.left + 16;
|
|
|
|
const y = rect.top + (buttonEl.value.offsetHeight / 2);
|
2023-01-08 07:17:42 +00:00
|
|
|
os.popup(MkReactionEffect, { reaction: props.reaction, x, y }, {}, 'end');
|
2023-05-19 00:15:24 +00:00
|
|
|
}
|
2021-11-12 14:53:10 +00:00
|
|
|
|
2022-06-30 14:51:18 +00:00
|
|
|
watch(() => props.count, (newCount, oldCount) => {
|
|
|
|
if (oldCount < newCount) anime();
|
2019-02-06 17:05:49 +00:00
|
|
|
});
|
2022-06-30 14:51:18 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (!props.isInitial) anime();
|
|
|
|
});
|
|
|
|
|
2023-11-03 06:35:07 +00:00
|
|
|
if (!mock) {
|
|
|
|
useTooltip(buttonEl, async (showing) => {
|
|
|
|
const reactions = await os.apiGet('notes/reactions', {
|
|
|
|
noteId: props.note.id,
|
|
|
|
type: props.reaction,
|
2023-11-03 08:55:39 +00:00
|
|
|
limit: 10,
|
2023-11-03 06:35:07 +00:00
|
|
|
_cacheKey_: props.count,
|
|
|
|
});
|
|
|
|
|
|
|
|
const users = reactions.map(x => x.user);
|
|
|
|
|
|
|
|
os.popup(XDetails, {
|
|
|
|
showing,
|
|
|
|
reaction: props.reaction,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
targetElement: buttonEl.value,
|
|
|
|
}, {}, 'closed');
|
|
|
|
}, 100);
|
|
|
|
}
|
2019-02-06 17:05:49 +00:00
|
|
|
</script>
|
|
|
|
|
2023-01-14 08:23:49 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-29 19:37:25 +00:00
|
|
|
display: inline-block;
|
2023-09-10 08:16:50 +00:00
|
|
|
height: 42px;
|
2020-01-29 19:37:25 +00:00
|
|
|
margin: 2px;
|
|
|
|
padding: 0 6px;
|
2023-09-10 08:16:50 +00:00
|
|
|
font-size: 1.5em;
|
|
|
|
border-radius: 6px;
|
2019-09-02 21:20:04 +00:00
|
|
|
|
2020-04-15 15:47:17 +00:00
|
|
|
&.canToggle {
|
2023-02-11 04:05:36 +00:00
|
|
|
background: var(--buttonBg);
|
2019-02-06 17:05:49 +00:00
|
|
|
|
2020-04-15 15:47:17 +00:00
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 17:05:49 +00:00
|
|
|
|
2020-04-15 15:47:17 +00:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-06 17:05:49 +00:00
|
|
|
|
2023-09-10 08:16:50 +00:00
|
|
|
&.small {
|
|
|
|
height: 32px;
|
|
|
|
font-size: 1em;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
> .count {
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 03:49:23 +00:00
|
|
|
&.large {
|
2023-09-10 08:16:50 +00:00
|
|
|
height: 52px;
|
|
|
|
font-size: 2em;
|
|
|
|
border-radius: 8px;
|
2023-03-30 03:49:23 +00:00
|
|
|
|
|
|
|
> .count {
|
2023-09-10 08:16:50 +00:00
|
|
|
font-size: 0.6em;
|
|
|
|
line-height: 52px;
|
2023-03-30 03:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 08:38:41 +00:00
|
|
|
&.reacted, &.reacted:hover {
|
2023-09-18 04:25:49 +00:00
|
|
|
background: var(--accentedBg);
|
|
|
|
color: var(--accent);
|
|
|
|
box-shadow: 0 0 0px 1px var(--accent) inset;
|
2020-04-17 11:30:12 +00:00
|
|
|
|
2022-05-19 14:23:12 +00:00
|
|
|
> .count {
|
2023-07-31 08:38:41 +00:00
|
|
|
color: var(--accent);
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2022-05-19 14:23:12 +00:00
|
|
|
|
|
|
|
> .icon {
|
|
|
|
filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2023-01-14 08:23:49 +00:00
|
|
|
}
|
2019-02-06 17:05:49 +00:00
|
|
|
|
2023-11-23 23:37:27 +00:00
|
|
|
.limitWidth {
|
2023-09-21 01:29:40 +00:00
|
|
|
max-width: 150px;
|
|
|
|
}
|
|
|
|
|
2023-01-14 08:23:49 +00:00
|
|
|
.count {
|
2023-09-10 08:16:50 +00:00
|
|
|
font-size: 0.7em;
|
|
|
|
line-height: 42px;
|
2023-01-14 08:23:49 +00:00
|
|
|
margin: 0 0 0 4px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2019-02-06 17:05:49 +00:00
|
|
|
</style>
|