2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2019-02-06 18:05:49 +01:00
|
|
|
<template>
|
2020-02-21 22:43:46 +01:00
|
|
|
<button
|
2023-01-08 06:28:14 +01:00
|
|
|
ref="buttonEl"
|
2021-12-27 14:59:14 +01:00
|
|
|
v-ripple="canToggle"
|
2023-01-14 09:23:49 +01:00
|
|
|
class="_button"
|
2023-09-10 10:16:50 +02: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 15:53:10 +01:00
|
|
|
@click="toggleReaction()"
|
2024-01-13 07:25:11 +01:00
|
|
|
@contextmenu.prevent.stop="menu"
|
2019-02-06 18:05:49 +01:00
|
|
|
>
|
2024-01-03 02:27:45 +01:00
|
|
|
<MkReactionIcon :class="defaultStore.state.limitWidthOfReaction ? $style.limitWidth : ''" :reaction="reaction" :emojiUrl="note.reactionEmojis[reaction.substring(1, reaction.length - 1)]" @click="toggleReaction()" @click.stop/>
|
2023-01-14 09:23:49 +01:00
|
|
|
<span :class="$style.count">{{ count }}</span>
|
2020-02-21 22:43:46 +01:00
|
|
|
</button>
|
2019-02-06 18:05:49 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
<script lang="ts" setup>
|
2023-11-03 07:35:07 +01:00
|
|
|
import { computed, inject, onMounted, shallowRef, watch } from 'vue';
|
2023-09-04 06:33:38 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2024-01-30 11:53:53 +01:00
|
|
|
import MkCustomEmojiDetailedDialog from './MkCustomEmojiDetailedDialog.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import XDetails from '@/components/MkReactionsViewer.details.vue';
|
2023-01-08 06:22:04 +01:00
|
|
|
import MkReactionIcon from '@/components/MkReactionIcon.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi, misskeyApiGet } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { useTooltip } from '@/scripts/use-tooltip.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-01-08 08:17:42 +01:00
|
|
|
import MkReactionEffect from '@/components/MkReactionEffect.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { claimAchievement } from '@/scripts/achievements.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2023-11-26 05:04:44 +01:00
|
|
|
import * as sound from '@/scripts/sound.js';
|
2024-02-06 21:23:37 +01:00
|
|
|
import { checkReactionPermissions } from '@/scripts/check-reaction-permissions.js';
|
2024-03-02 17:36:49 +01:00
|
|
|
import { customEmojisMap } from '@/custom-emojis.js';
|
|
|
|
import { getUnicodeEmoji } from '@/scripts/emojilist.js';
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
reaction: string;
|
|
|
|
count: number;
|
|
|
|
isInitial: boolean;
|
2023-09-04 06:33:38 +02:00
|
|
|
note: Misskey.entities.Note;
|
2022-06-30 16:51:18 +02:00
|
|
|
}>();
|
|
|
|
|
2023-11-03 07:35:07 +01:00
|
|
|
const mock = inject<boolean>('mock', false);
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'reactionToggled', emoji: string, newCount: number): void;
|
|
|
|
}>();
|
|
|
|
|
2023-01-08 06:28:14 +01:00
|
|
|
const buttonEl = shallowRef<HTMLElement>();
|
2022-06-30 16:51:18 +02:00
|
|
|
|
2024-03-02 17:36:49 +01:00
|
|
|
const emojiName = computed(() => props.reaction.replace(/:/g, '').replace(/@\./, ''));
|
|
|
|
const emoji = computed(() => customEmojisMap.get(emojiName.value) ?? getUnicodeEmoji(props.reaction));
|
2024-02-06 21:23:37 +01:00
|
|
|
|
|
|
|
const canToggle = computed(() => {
|
2024-03-02 17:36:49 +01:00
|
|
|
return !props.reaction.match(/@\w/) && $i && emoji.value && checkReactionPermissions($i, props.note, emoji.value);
|
2024-02-06 21:23:37 +01:00
|
|
|
});
|
|
|
|
const canGetInfo = computed(() => !props.reaction.match(/@\w/) && props.reaction.includes(':'));
|
2022-06-30 16:51:18 +02:00
|
|
|
|
2023-05-19 02:15:24 +02:00
|
|
|
async function toggleReaction() {
|
2022-06-30 16:51:18 +02:00
|
|
|
if (!canToggle.value) return;
|
|
|
|
|
|
|
|
const oldReaction = props.note.myReaction;
|
|
|
|
if (oldReaction) {
|
2023-05-19 02:15:24 +02:00
|
|
|
const confirm = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: oldReaction !== props.reaction ? i18n.ts.changeReactionConfirm : i18n.ts.cancelReactionConfirm,
|
|
|
|
});
|
|
|
|
if (confirm.canceled) return;
|
|
|
|
|
2023-11-26 05:04:44 +01:00
|
|
|
if (oldReaction !== props.reaction) {
|
2024-01-09 05:25:33 +01:00
|
|
|
sound.playMisskeySfx('reaction');
|
2023-11-26 05:04:44 +01:00
|
|
|
}
|
|
|
|
|
2023-11-03 07:35:07 +01:00
|
|
|
if (mock) {
|
|
|
|
emit('reactionToggled', props.reaction, (props.count - 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('notes/reactions/delete', {
|
2022-06-30 16:51:18 +02:00
|
|
|
noteId: props.note.id,
|
|
|
|
}).then(() => {
|
|
|
|
if (oldReaction !== props.reaction) {
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('notes/reactions/create', {
|
2021-11-12 15:53:10 +01:00
|
|
|
noteId: props.note.id,
|
2022-06-30 16:51:18 +02:00
|
|
|
reaction: props.reaction,
|
2019-02-06 18:05:49 +01:00
|
|
|
});
|
|
|
|
}
|
2021-11-12 15:53:10 +01:00
|
|
|
});
|
2022-06-30 16:51:18 +02:00
|
|
|
} else {
|
2024-01-09 05:25:33 +01:00
|
|
|
sound.playMisskeySfx('reaction');
|
2023-11-26 05:04:44 +01:00
|
|
|
|
2023-11-03 07:35:07 +01:00
|
|
|
if (mock) {
|
|
|
|
emit('reactionToggled', props.reaction, (props.count + 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('notes/reactions/create', {
|
2022-06-30 16:51:18 +02:00
|
|
|
noteId: props.note.id,
|
|
|
|
reaction: props.reaction,
|
2021-11-12 15:53:10 +01:00
|
|
|
});
|
2023-01-21 05:14:55 +01: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 16:51:18 +02:00
|
|
|
}
|
2023-05-19 02:15:24 +02:00
|
|
|
}
|
2021-11-12 15:53:10 +01:00
|
|
|
|
2024-01-13 07:25:11 +01:00
|
|
|
async function menu(ev) {
|
2024-02-06 21:23:37 +01:00
|
|
|
if (!canGetInfo.value) return;
|
|
|
|
|
2024-01-13 07:25:11 +01:00
|
|
|
os.popupMenu([{
|
|
|
|
text: i18n.ts.info,
|
2024-06-21 17:27:36 +02:00
|
|
|
icon: 'ti ti-info-circle',
|
2024-01-13 07:25:11 +01:00
|
|
|
action: async () => {
|
2024-07-04 06:14:49 +02:00
|
|
|
const { dispose } = os.popup(MkCustomEmojiDetailedDialog, {
|
2024-01-13 07:25:11 +01:00
|
|
|
emoji: await misskeyApiGet('emoji', {
|
|
|
|
name: props.reaction.replace(/:/g, '').replace(/@\./, ''),
|
|
|
|
}),
|
2024-07-04 06:14:49 +02:00
|
|
|
}, {
|
|
|
|
closed: () => dispose(),
|
2024-01-13 07:25:11 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
2023-05-19 02:15:24 +02:00
|
|
|
function anime() {
|
2024-01-30 11:53:53 +01:00
|
|
|
if (document.hidden || !defaultStore.state.animation || buttonEl.value == null) return;
|
2022-06-30 16:51:18 +02:00
|
|
|
|
2023-01-08 06:28:14 +01:00
|
|
|
const rect = buttonEl.value.getBoundingClientRect();
|
|
|
|
const x = rect.left + 16;
|
|
|
|
const y = rect.top + (buttonEl.value.offsetHeight / 2);
|
2024-07-04 06:14:49 +02:00
|
|
|
const { dispose } = os.popup(MkReactionEffect, { reaction: props.reaction, x, y }, {
|
|
|
|
end: () => dispose(),
|
|
|
|
});
|
2023-05-19 02:15:24 +02:00
|
|
|
}
|
2021-11-12 15:53:10 +01:00
|
|
|
|
2022-06-30 16:51:18 +02:00
|
|
|
watch(() => props.count, (newCount, oldCount) => {
|
|
|
|
if (oldCount < newCount) anime();
|
2019-02-06 18:05:49 +01:00
|
|
|
});
|
2022-06-30 16:51:18 +02:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (!props.isInitial) anime();
|
|
|
|
});
|
|
|
|
|
2023-11-03 07:35:07 +01:00
|
|
|
if (!mock) {
|
|
|
|
useTooltip(buttonEl, async (showing) => {
|
2024-01-04 10:32:46 +01:00
|
|
|
const reactions = await misskeyApiGet('notes/reactions', {
|
2023-11-03 07:35:07 +01:00
|
|
|
noteId: props.note.id,
|
|
|
|
type: props.reaction,
|
2023-11-03 09:55:39 +01:00
|
|
|
limit: 10,
|
2023-11-03 07:35:07 +01:00
|
|
|
_cacheKey_: props.count,
|
|
|
|
});
|
|
|
|
|
|
|
|
const users = reactions.map(x => x.user);
|
|
|
|
|
2024-07-04 06:14:49 +02:00
|
|
|
const { dispose } = os.popup(XDetails, {
|
2023-11-03 07:35:07 +01:00
|
|
|
showing,
|
|
|
|
reaction: props.reaction,
|
|
|
|
users,
|
|
|
|
count: props.count,
|
|
|
|
targetElement: buttonEl.value,
|
2024-07-04 06:14:49 +02:00
|
|
|
}, {
|
|
|
|
closed: () => dispose(),
|
|
|
|
});
|
2023-11-03 07:35:07 +01:00
|
|
|
}, 100);
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
</script>
|
|
|
|
|
2023-01-14 09:23:49 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2023-12-14 08:17:01 +01:00
|
|
|
display: inline-flex;
|
2023-09-10 10:16:50 +02:00
|
|
|
height: 42px;
|
2020-01-29 20:37:25 +01:00
|
|
|
margin: 2px;
|
|
|
|
padding: 0 6px;
|
2023-09-10 10:16:50 +02:00
|
|
|
font-size: 1.5em;
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-sm);
|
2023-12-14 08:17:01 +01:00
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2019-09-02 23:20:04 +02:00
|
|
|
|
2020-04-15 17:47:17 +02:00
|
|
|
&.canToggle {
|
2023-02-11 05:05:36 +01:00
|
|
|
background: var(--buttonBg);
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2020-04-15 17:47:17 +02:00
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2020-04-15 17:47:17 +02:00
|
|
|
&:not(.canToggle) {
|
|
|
|
cursor: default;
|
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2023-09-10 10:16:50 +02:00
|
|
|
&.small {
|
|
|
|
height: 32px;
|
|
|
|
font-size: 1em;
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-xs);
|
2023-09-10 10:16:50 +02:00
|
|
|
|
|
|
|
> .count {
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 32px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 05:49:23 +02:00
|
|
|
&.large {
|
2023-09-10 10:16:50 +02:00
|
|
|
height: 52px;
|
|
|
|
font-size: 2em;
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-sm);
|
2023-03-30 05:49:23 +02:00
|
|
|
|
|
|
|
> .count {
|
2023-09-10 10:16:50 +02:00
|
|
|
font-size: 0.6em;
|
|
|
|
line-height: 52px;
|
2023-03-30 05:49:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 10:38:41 +02:00
|
|
|
&.reacted, &.reacted:hover {
|
2023-09-18 06:25:49 +02:00
|
|
|
background: var(--accentedBg);
|
|
|
|
color: var(--accent);
|
2023-12-14 08:17:01 +01:00
|
|
|
box-shadow: 0 0 0 1px var(--accent) inset;
|
2020-04-17 13:30:12 +02:00
|
|
|
|
2022-05-19 16:23:12 +02:00
|
|
|
> .count {
|
2023-07-31 10:38:41 +02:00
|
|
|
color: var(--accent);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2022-05-19 16:23:12 +02:00
|
|
|
|
|
|
|
> .icon {
|
|
|
|
filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2023-01-14 09:23:49 +01:00
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
|
2023-11-24 00:37:27 +01:00
|
|
|
.limitWidth {
|
2023-12-27 07:15:08 +01:00
|
|
|
max-width: 70px;
|
|
|
|
object-fit: contain;
|
2023-09-21 03:29:40 +02:00
|
|
|
}
|
|
|
|
|
2023-01-14 09:23:49 +01:00
|
|
|
.count {
|
2023-09-10 10:16:50 +02:00
|
|
|
font-size: 0.7em;
|
|
|
|
line-height: 42px;
|
2023-01-14 09:23:49 +01:00
|
|
|
margin: 0 0 0 4px;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2019-02-06 18:05:49 +01:00
|
|
|
</style>
|