1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-24 03:28:27 +09:00
MisskeyIO/packages/frontend/src/components/MkNotification.vue

293 lines
9.2 KiB
Vue
Raw Normal View History

<template>
2023-01-10 14:16:59 +09:00
<div ref="elRef" :class="$style.root">
<div :class="$style.head">
2023-01-16 14:18:11 +09:00
<MkAvatar v-if="notification.type === 'pollEnded'" :class="$style.icon" :user="notification.note.user" link preview/>
<MkAvatar v-else-if="notification.type === 'achievementEarned'" :class="$style.icon" :user="$i" link preview/>
2023-01-16 14:18:11 +09:00
<MkAvatar v-else-if="notification.user" :class="$style.icon" :user="notification.user" link preview/>
2023-01-10 14:16:59 +09:00
<img v-else-if="notification.icon" :class="$style.icon" :src="notification.icon" alt=""/>
<div :class="[$style.subIcon, $style['t_' + notification.type]]">
<i v-if="notification.type === 'follow'" class="ti ti-plus"></i>
<i v-else-if="notification.type === 'receiveFollowRequest'" class="ti ti-clock"></i>
<i v-else-if="notification.type === 'followRequestAccepted'" class="ti ti-check"></i>
<i v-else-if="notification.type === 'renote'" class="ti ti-repeat"></i>
<i v-else-if="notification.type === 'reply'" class="ti ti-arrow-back-up"></i>
<i v-else-if="notification.type === 'mention'" class="ti ti-at"></i>
<i v-else-if="notification.type === 'quote'" class="ti ti-quote"></i>
<i v-else-if="notification.type === 'pollEnded'" class="ti ti-chart-arrows"></i>
2023-01-24 14:10:26 +09:00
<i v-else-if="notification.type === 'achievementEarned'" class="ti ti-medal"></i>
<!-- notification.reaction null になることはまずないがここでoptional chaining使うと一部ブラウザで刺さるので念の為 -->
2023-01-08 14:22:04 +09:00
<MkReactionIcon
2022-06-05 12:26:36 +09:00
v-else-if="notification.type === 'reaction'"
2021-11-19 19:36:12 +09:00
ref="reactionRef"
:reaction="notification.reaction ? notification.reaction.replace(/^:(\w+):$/, ':$1@.:') : notification.reaction"
2023-05-19 13:58:09 +09:00
:customEmojis="notification.note.emojis"
:noStyle="true"
2023-01-10 14:16:59 +09:00
style="width: 100%; height: 100%;"
/>
</div>
</div>
2023-01-10 14:16:59 +09:00
<div :class="$style.tail">
<header :class="$style.header">
<span v-if="notification.type === 'pollEnded'">{{ i18n.ts._notification.pollEnded }}</span>
<span v-else-if="notification.type === 'achievementEarned'">{{ i18n.ts._notification.achievementEarned }}</span>
2023-02-08 20:07:19 +09:00
<MkA v-else-if="notification.user" v-user-preview="notification.user.id" :class="$style.headerName" :to="userPage(notification.user)"><MkUserName :user="notification.user"/></MkA>
2020-03-28 18:07:41 +09:00
<span v-else>{{ notification.header }}</span>
2023-01-10 14:16:59 +09:00
<MkTime v-if="withTime" :time="notification.createdAt" :class="$style.headerTime"/>
</header>
<div :class="$style.content">
2023-01-10 14:16:59 +09:00
<MkA v-if="notification.type === 'reaction'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
<i class="ti ti-quote" :class="$style.quote"></i>
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="true" :author="notification.note.user"/>
2023-01-10 14:16:59 +09:00
<i class="ti ti-quote" :class="$style.quote"></i>
2023-01-08 11:30:40 +09:00
</MkA>
2023-01-10 14:16:59 +09:00
<MkA v-else-if="notification.type === 'renote'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note.renote)">
<i class="ti ti-quote" :class="$style.quote"></i>
<Mfm :text="getNoteSummary(notification.note.renote)" :plain="true" :nowrap="true" :author="notification.note.renote.user"/>
2023-01-10 14:16:59 +09:00
<i class="ti ti-quote" :class="$style.quote"></i>
2023-01-08 11:30:40 +09:00
</MkA>
2023-01-10 14:16:59 +09:00
<MkA v-else-if="notification.type === 'reply'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="true" :author="notification.note.user"/>
2023-01-08 11:30:40 +09:00
</MkA>
2023-01-10 14:16:59 +09:00
<MkA v-else-if="notification.type === 'mention'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="true" :author="notification.note.user"/>
2023-01-08 11:30:40 +09:00
</MkA>
2023-01-10 14:16:59 +09:00
<MkA v-else-if="notification.type === 'quote'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="true" :author="notification.note.user"/>
2023-01-08 11:30:40 +09:00
</MkA>
2023-01-10 14:16:59 +09:00
<MkA v-else-if="notification.type === 'pollEnded'" :class="$style.text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
<i class="ti ti-quote" :class="$style.quote"></i>
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="true" :author="notification.note.user"/>
2023-01-10 14:16:59 +09:00
<i class="ti ti-quote" :class="$style.quote"></i>
2023-01-08 11:30:40 +09:00
</MkA>
<MkA v-else-if="notification.type === 'achievementEarned'" :class="$style.text" to="/my/achievements">
{{ i18n.ts._achievements._types['_' + notification.achievement].title }}
</MkA>
<template v-else-if="notification.type === 'follow'">
<span :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.youGotNewFollower }}</span>
<div v-if="full"><MkFollowButton :user="notification.user" :full="true"/></div>
</template>
2023-01-10 14:16:59 +09:00
<span v-else-if="notification.type === 'followRequestAccepted'" :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.followRequestAccepted }}</span>
<template v-else-if="notification.type === 'receiveFollowRequest'">
<span :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.receiveFollowRequest }}</span>
<div v-if="full && !followRequestDone" :class="$style.followRequestCommands">
<MkButton :class="$style.followRequestCommandButton" rounded primary @click="acceptFollowRequest()"><i class="ti ti-check"/> {{ i18n.ts.accept }}</MkButton>
<MkButton :class="$style.followRequestCommandButton" rounded danger @click="rejectFollowRequest()"><i class="ti ti-x"/> {{ i18n.ts.reject }}</MkButton>
</div>
</template>
2023-01-10 14:16:59 +09:00
<span v-else-if="notification.type === 'app'" :class="$style.text">
<Mfm :text="notification.body" :nowrap="false"/>
2023-01-08 11:30:40 +09:00
</span>
</div>
</div>
</div>
</template>
2022-06-28 14:34:44 +09:00
<script lang="ts" setup>
import { ref, shallowRef } from 'vue';
2021-11-12 21:29:59 +09:00
import * as misskey from 'misskey-js';
2023-01-08 14:22:04 +09:00
import MkReactionIcon from '@/components/MkReactionIcon.vue';
import MkFollowButton from '@/components/MkFollowButton.vue';
import XReactionTooltip from '@/components/MkReactionTooltip.vue';
import MkButton from '@/components/MkButton.vue';
2022-06-05 12:26:36 +09:00
import { getNoteSummary } from '@/scripts/get-note-summary';
import { notePage } from '@/filters/note';
2021-11-12 02:02:25 +09:00
import { userPage } from '@/filters/user';
import { i18n } from '@/i18n';
import * as os from '@/os';
import { useTooltip } from '@/scripts/use-tooltip';
import { $i } from '@/account';
2022-06-28 14:34:44 +09:00
const props = withDefaults(defineProps<{
notification: misskey.entities.Notification;
withTime?: boolean;
full?: boolean;
}>(), {
withTime: false,
full: false,
});
const elRef = shallowRef<HTMLElement>(null);
2022-06-28 14:34:44 +09:00
const reactionRef = ref(null);
const followRequestDone = ref(false);
const acceptFollowRequest = () => {
followRequestDone.value = true;
os.api('following/requests/accept', { userId: props.notification.user.id });
};
const rejectFollowRequest = () => {
followRequestDone.value = true;
os.api('following/requests/reject', { userId: props.notification.user.id });
};
useTooltip(reactionRef, (showing) => {
os.popup(XReactionTooltip, {
showing,
reaction: props.notification.reaction ? props.notification.reaction.replace(/^:(\w+):$/, ':$1@.:') : props.notification.reaction,
emojis: props.notification.note.emojis,
targetElement: reactionRef.value.$el,
}, {}, 'closed');
});
</script>
2023-01-10 14:16:59 +09:00
<style lang="scss" module>
.root {
position: relative;
box-sizing: border-box;
2020-02-19 07:00:44 +09:00
padding: 24px 32px;
font-size: 0.9em;
overflow-wrap: break-word;
display: flex;
Migrate to Vue3 (#6587) * Update reaction.vue * fix bug * wip * wip * wjio * wip * Revert "wip" This reverts commit e427f2160adf4e8a4147006e25a89854edab0033. * wip * wip * wip * Update init.ts * Update drive-window.vue * wip * wip * Use PascalCase for components * Use PascalCase for components * update dep * wip * wip * wip * Update init.ts * wip * Update paging.ts * Update test.vue * watch deep * wip * lint * wip * wip * wip * wip * wiop * wip * Update webpack.config.ts * alllow null poll * wip * wip * wip * wiop * UI redesign & refactor (#6714) * wip * wip * wip * wip * wip * Update drive.vue * Update word-mute.vue * wip * wip * wip * clean up * wip * Update default.vue * wip * Update notes.vue * Update mfm.ts * Update index.home.vue * Update post-form.vue * Update post-form-attaches.vue * wip * Update post-form.vue * Update sidebar.vue * wip * wip * Update index.vue * wip * Update default.vue * Update index.vue * Update index.vue * wip * Update post-form-attaches.vue * Update note.vue * wip * clean up * Update notes.vue * wip * wip * Update ja-JP.yml * wip * wip * Update index.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update default.vue * wip * Update _dark.json5 * wip * wip * wip * clean up * wip * wip * Update index.vue * Update test.vue * wip * wip * fix * wip * wip * wip * wip * clena yop * wip * wip * Update store.ts * Update messaging-room.vue * Update default.widgets.vue * fix * wip * wip * Update modal.vue * wip * Update os.ts * Update os.ts * Update deck.vue * Update init.ts * wip * Update ja-JP.yml * v-sizeは単にwindowのresizeを監視するだけで良いかもしれない * Update modal.vue * wip * Update tooltip.ts * wip * wip * wip * wip * wip * Update image-viewer.vue * wip * wip * Update style.scss * Update style.scss * Update visitor.vue * wip * Update init.ts * Update init.ts * wip * wip * Update visitor.vue * Update visitor.vue * Update visitor.vue * Update visitor.vue * wip * wip * Update modal.vue * Update header.vue * Update menu.vue * Update about.vue * Update about-misskey.vue * wip * wip * Update visitor.vue * Update tooltip.ts * wip * Update drive.vue * wip * Update style.scss * Update header.vue * wip * wip * Update users.user.vue * Update announcements.vue * wip * wip * wip * Update emojis.vue * wip * Update emojis.vue * Update style.scss * Update users.vue * wip * Update style.scss * wip * Update welcome.entrance.vue * Update radio.vue * Update size.ts * Update emoji-edit-dialog.vue * wip * Update emojis.vue * wip * Update emojis.vue * Update emojis.vue * Update emojis.vue * wip * wip * wip * wip * Update file-dialog.vue * wip * wip * Update token-generate-window.vue * Update notification-setting-window.vue * wip * wip * Update _error_.vue * Update ja-JP.yml * wip * wip * Update store.ts * Update emojis.vue * Update emojis.vue * Update emojis.vue * Update announcements.vue * Update store.ts * wip * Update page-editor.vue * wip * wip * Update modal.vue * wip * Update select-file.ts * Update timeline.vue * Update emojis.vue * Update os.ts * wip * Update user-select.vue * Update mfm.ts * Update get-file-info.ts * Update drive.vue * Update init.ts * Update mfm.ts * wip * wip * Update window.vue * Update note.vue * wip * wip * Update user-info.vue * wip * wip * wip * wip * wip * Update header.vue * Update header.vue * wip * Update explore.vue * wip * wip * wip * Update webpack.config.ts * wip * wip * wip * wip * wip * wip * Update autocomplete.ts * wip * wip * wip * Update toast.vue * wip * Update post-form-dialog.vue * wip * wip * wip * wip * wip * Update users.vue * wip * Update explore.vue * wip * wip * wip * Update package.json * wip * Update icon-dialog.vue * wip * wip * Update user-preview.ts * wip * wip * wip * wip * wip * Update instance.vue * Update user-name.vue * Update federation.vue * Update instance.vue * wip * wip * Update tag.vue * wip * wip * wip * wip * wip * Update instance.vue * wip * Update os.ts * Update os.ts * wip * wip * wip * Update router.ts * wip * Update init.ts * Update note.vue * Update messages.vue * wip * wip * wip * wip * wip * google * wip * wip * wip * wip * Update theme-editor.vue * wip * wip * Update room.vue * Update channel-editor.vue * wip * Update window.vue * Update window.vue * wip * Update window.vue * Update window.vue * wip * Update menu.vue * wip * wip * wip * wip * Update messaging-room.vue * wip * Update post-form.vue * Update default.widgets.vue * Update window.vue * wip
2020-10-17 20:12:00 +09:00
contain: content;
2023-01-10 14:16:59 +09:00
}
2023-01-10 14:16:59 +09:00
.head {
position: sticky;
top: 0;
flex-shrink: 0;
width: 42px;
height: 42px;
margin-right: 8px;
}
.icon {
display: block;
width: 100%;
height: 100%;
border-radius: 6px;
}
2023-01-10 14:16:59 +09:00
.subIcon {
position: absolute;
z-index: 1;
bottom: -2px;
right: -2px;
width: 20px;
height: 20px;
box-sizing: border-box;
border-radius: 100%;
background: var(--panel);
box-shadow: 0 0 0 3px var(--panel);
2023-02-09 09:32:39 +09:00
font-size: 11px;
2023-01-10 14:16:59 +09:00
text-align: center;
color: #fff;
&:empty {
display: none;
}
}
.t_follow, .t_followRequestAccepted, .t_receiveFollowRequest {
2023-01-10 14:16:59 +09:00
padding: 3px;
background: #36aed2;
pointer-events: none;
}
.t_renote {
padding: 3px;
background: #36d298;
pointer-events: none;
}
.t_quote {
padding: 3px;
background: #36d298;
pointer-events: none;
}
.t_reply {
padding: 3px;
background: #007aff;
pointer-events: none;
}
.t_mention {
padding: 3px;
background: #88a6b7;
pointer-events: none;
}
.t_pollEnded {
padding: 3px;
background: #88a6b7;
pointer-events: none;
}
.t_achievementEarned {
padding: 3px;
2023-01-24 17:26:49 +09:00
background: #cb9a11;
pointer-events: none;
}
2023-01-10 14:16:59 +09:00
.tail {
flex: 1;
min-width: 0;
}
.header {
display: flex;
align-items: baseline;
white-space: nowrap;
}
.headerName {
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
overflow: hidden;
}
.headerTime {
margin-left: auto;
font-size: 0.9em;
}
.content {
}
.text {
display: flex;
width: 100%;
overflow: clip;
2023-01-10 14:16:59 +09:00
}
.quote {
vertical-align: super;
font-size: 50%;
opacity: 0.5;
}
.quote:first-child {
margin-right: 4px;
}
.quote:last-child {
margin-left: 4px;
}
.followRequestCommands {
display: flex;
gap: 8px;
max-width: 300px;
margin-top: 8px;
}
.followRequestCommandButton {
flex: 1;
}
@container (max-width: 600px) {
2023-01-10 14:16:59 +09:00
.root {
padding: 16px;
font-size: 0.9em;
}
}
@container (max-width: 500px) {
2023-01-10 14:16:59 +09:00
.root {
padding: 12px;
font-size: 0.85em;
}
}
</style>