2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2021-11-07 18:38:48 +00:00
|
|
|
<div class="qglefbjs" :class="notification.type" v-size="{ max: [500, 600] }" ref="elRef">
|
2020-01-29 19:37:25 +00:00
|
|
|
<div class="head">
|
2020-10-17 11:12:00 +00:00
|
|
|
<MkAvatar v-if="notification.user" class="icon" :user="notification.user"/>
|
|
|
|
<img v-else-if="notification.icon" class="icon" :src="notification.icon" alt=""/>
|
2020-03-28 09:07:41 +00:00
|
|
|
<div class="sub-icon" :class="notification.type">
|
2021-04-20 14:22:59 +00:00
|
|
|
<i v-if="notification.type === 'follow'" class="fas fa-plus"></i>
|
|
|
|
<i v-else-if="notification.type === 'receiveFollowRequest'" class="fas fa-clock"></i>
|
|
|
|
<i v-else-if="notification.type === 'followRequestAccepted'" class="fas fa-check"></i>
|
|
|
|
<i v-else-if="notification.type === 'groupInvited'" class="fas fa-id-card-alt"></i>
|
|
|
|
<i v-else-if="notification.type === 'renote'" class="fas fa-retweet"></i>
|
|
|
|
<i v-else-if="notification.type === 'reply'" class="fas fa-reply"></i>
|
|
|
|
<i v-else-if="notification.type === 'mention'" class="fas fa-at"></i>
|
|
|
|
<i v-else-if="notification.type === 'quote'" class="fas fa-quote-left"></i>
|
|
|
|
<i v-else-if="notification.type === 'pollVote'" class="fas fa-poll-h"></i>
|
2021-10-22 17:44:52 +00:00
|
|
|
<!-- notification.reaction が null になることはまずないが、ここでoptional chaining使うと一部ブラウザで刺さるので念の為 -->
|
2021-11-07 18:38:48 +00:00
|
|
|
<XReactionIcon v-else-if="notification.type === 'reaction'"
|
|
|
|
:reaction="notification.reaction ? notification.reaction.replace(/^:(\w+):$/, ':$1@.:') : notification.reaction"
|
|
|
|
:custom-emojis="notification.note.emojis"
|
|
|
|
:no-style="true"
|
|
|
|
@touchstart.passive="onReactionMouseover"
|
|
|
|
@mouseover="onReactionMouseover"
|
|
|
|
@mouseleave="onReactionMouseleave"
|
|
|
|
@touchend="onReactionMouseleave"
|
|
|
|
ref="reactionRef"
|
|
|
|
/>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="tail">
|
|
|
|
<header>
|
2020-10-24 16:21:41 +00:00
|
|
|
<MkA v-if="notification.user" class="name" :to="userPage(notification.user)" v-user-preview="notification.user.id"><MkUserName :user="notification.user"/></MkA>
|
2020-03-28 09:07:41 +00:00
|
|
|
<span v-else>{{ notification.header }}</span>
|
2020-10-27 09:11:41 +00:00
|
|
|
<MkTime :time="notification.createdAt" v-if="withTime" class="time"/>
|
2020-01-29 19:37:25 +00:00
|
|
|
</header>
|
2020-10-24 16:21:41 +00:00
|
|
|
<MkA v-if="notification.type === 'reaction'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-left"></i>
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.emojis"/>
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-right"></i>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
|
|
|
<MkA v-if="notification.type === 'renote'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note.renote)">
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-left"></i>
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note.renote)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.renote.emojis"/>
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-right"></i>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
|
|
|
<MkA v-if="notification.type === 'reply'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.emojis"/>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
|
|
|
<MkA v-if="notification.type === 'mention'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.emojis"/>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
|
|
|
<MkA v-if="notification.type === 'quote'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.emojis"/>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
|
|
|
<MkA v-if="notification.type === 'pollVote'" class="text" :to="notePage(notification.note)" :title="getNoteSummary(notification.note)">
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-left"></i>
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="getNoteSummary(notification.note)" :plain="true" :nowrap="!full" :custom-emojis="notification.note.emojis"/>
|
2021-04-20 14:22:59 +00:00
|
|
|
<i class="fas fa-quote-right"></i>
|
2020-10-24 16:21:41 +00:00
|
|
|
</MkA>
|
2020-12-26 01:47:36 +00:00
|
|
|
<span v-if="notification.type === 'follow'" class="text" style="opacity: 0.6;">{{ $ts.youGotNewFollower }}<div v-if="full"><MkFollowButton :user="notification.user" :full="true"/></div></span>
|
|
|
|
<span v-if="notification.type === 'followRequestAccepted'" class="text" style="opacity: 0.6;">{{ $ts.followRequestAccepted }}</span>
|
|
|
|
<span v-if="notification.type === 'receiveFollowRequest'" class="text" style="opacity: 0.6;">{{ $ts.receiveFollowRequest }}<div v-if="full && !followRequestDone"><button class="_textButton" @click="acceptFollowRequest()">{{ $ts.accept }}</button> | <button class="_textButton" @click="rejectFollowRequest()">{{ $ts.reject }}</button></div></span>
|
|
|
|
<span v-if="notification.type === 'groupInvited'" class="text" style="opacity: 0.6;">{{ $ts.groupInvited }}: <b>{{ notification.invitation.group.name }}</b><div v-if="full && !groupInviteDone"><button class="_textButton" @click="acceptGroupInvitation()">{{ $ts.accept }}</button> | <button class="_textButton" @click="rejectGroupInvitation()">{{ $ts.reject }}</button></div></span>
|
2020-03-28 09:07:41 +00:00
|
|
|
<span v-if="notification.type === 'app'" class="text">
|
2020-10-17 11:12:00 +00:00
|
|
|
<Mfm :text="notification.body" :nowrap="!full"/>
|
2020-03-28 09:07:41 +00:00
|
|
|
</span>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-11-07 18:38:48 +00:00
|
|
|
import { defineComponent, ref, onMounted, onUnmounted } from 'vue';
|
2021-03-23 08:43:07 +00:00
|
|
|
import { getNoteSummary } from '@/misc/get-note-summary';
|
2020-01-29 19:37:25 +00:00
|
|
|
import XReactionIcon from './reaction-icon.vue';
|
2020-01-31 02:35:18 +00:00
|
|
|
import MkFollowButton from './follow-button.vue';
|
2021-11-07 18:38:48 +00:00
|
|
|
import XReactionTooltip from './reaction-tooltip.vue';
|
2021-08-05 07:34:18 +00:00
|
|
|
import notePage from '@client/filters/note';
|
|
|
|
import { userPage } from '@client/filters/user';
|
2021-03-23 08:30:14 +00:00
|
|
|
import { i18n } from '@client/i18n';
|
|
|
|
import * as os from '@client/os';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-01-29 19:37:25 +00:00
|
|
|
components: {
|
2020-01-31 02:35:18 +00:00
|
|
|
XReactionIcon, MkFollowButton
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
2021-11-07 18:38:48 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
props: {
|
|
|
|
notification: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
withTime: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-01-31 02:38:52 +00:00
|
|
|
full: {
|
2020-01-29 19:37:25 +00:00
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2020-01-31 02:38:52 +00:00
|
|
|
default: false,
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
},
|
2020-05-31 05:57:22 +00:00
|
|
|
|
2021-11-07 18:38:48 +00:00
|
|
|
setup(props) {
|
|
|
|
const elRef = ref<HTMLElement>(null);
|
|
|
|
const reactionRef = ref(null);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
let readObserver: IntersectionObserver = null;
|
|
|
|
let connection = null;
|
|
|
|
|
|
|
|
if (!props.notification.isRead) {
|
|
|
|
readObserver = new IntersectionObserver((entries, observer) => {
|
|
|
|
if (!entries.some(entry => entry.isIntersecting)) return;
|
|
|
|
os.stream.send('readNotification', {
|
|
|
|
id: props.notification.id
|
|
|
|
});
|
|
|
|
entries.map(({ target }) => observer.unobserve(target));
|
2020-05-26 05:34:49 +00:00
|
|
|
});
|
2021-11-07 18:38:48 +00:00
|
|
|
|
|
|
|
readObserver.observe(elRef.value);
|
|
|
|
|
|
|
|
connection = os.stream.useChannel('main');
|
|
|
|
connection.on('readAllNotifications', () => readObserver.unobserve(elRef.value));
|
|
|
|
}
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
if (readObserver) readObserver.unobserve(elRef.value);
|
|
|
|
if (connection) connection.dispose();
|
2020-06-03 04:42:32 +00:00
|
|
|
});
|
2021-11-07 18:38:48 +00:00
|
|
|
});
|
2020-05-26 05:34:49 +00:00
|
|
|
|
2021-11-07 18:38:48 +00:00
|
|
|
const followRequestDone = ref(false);
|
|
|
|
const groupInviteDone = ref(false);
|
2020-05-31 05:57:22 +00:00
|
|
|
|
2021-11-07 18:38:48 +00:00
|
|
|
const acceptFollowRequest = () => {
|
|
|
|
followRequestDone.value = true;
|
|
|
|
os.api('following/requests/accept', { userId: props.notification.user.id });
|
|
|
|
};
|
2020-05-26 05:34:49 +00:00
|
|
|
|
2021-11-07 18:38:48 +00:00
|
|
|
const rejectFollowRequest = () => {
|
|
|
|
followRequestDone.value = true;
|
|
|
|
os.api('following/requests/reject', { userId: props.notification.user.id });
|
|
|
|
};
|
2020-05-26 05:34:49 +00:00
|
|
|
|
2021-11-07 18:38:48 +00:00
|
|
|
const acceptGroupInvitation = () => {
|
|
|
|
groupInviteDone.value = true;
|
|
|
|
os.apiWithDialog('users/groups/invitations/accept', { invitationId: props.notification.invitation.id });
|
|
|
|
};
|
|
|
|
|
|
|
|
const rejectGroupInvitation = () => {
|
|
|
|
groupInviteDone.value = true;
|
|
|
|
os.api('users/groups/invitations/reject', { invitationId: props.notification.invitation.id });
|
|
|
|
};
|
|
|
|
|
|
|
|
let isReactionHovering = false;
|
|
|
|
let reactionTooltipTimeoutId;
|
|
|
|
|
|
|
|
const onReactionMouseover = () => {
|
|
|
|
if (isReactionHovering) return;
|
|
|
|
isReactionHovering = true;
|
|
|
|
reactionTooltipTimeoutId = setTimeout(openReactionTooltip, 300);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onReactionMouseleave = () => {
|
|
|
|
if (!isReactionHovering) return;
|
|
|
|
isReactionHovering = false;
|
|
|
|
clearTimeout(reactionTooltipTimeoutId);
|
|
|
|
closeReactionTooltip();
|
|
|
|
};
|
|
|
|
|
|
|
|
let changeReactionTooltipShowingState: () => void;
|
|
|
|
|
|
|
|
const openReactionTooltip = () => {
|
|
|
|
closeReactionTooltip();
|
|
|
|
if (!isReactionHovering) return;
|
|
|
|
|
|
|
|
const showing = ref(true);
|
|
|
|
os.popup(XReactionTooltip, {
|
|
|
|
showing,
|
|
|
|
reaction: props.notification.reaction ? props.notification.reaction.replace(/^:(\w+):$/, ':$1@.:') : props.notification.reaction,
|
|
|
|
emojis: props.notification.note.emojis,
|
|
|
|
source: reactionRef.value.$el,
|
|
|
|
}, {}, 'closed');
|
|
|
|
|
|
|
|
changeReactionTooltipShowingState = () => {
|
|
|
|
showing.value = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const closeReactionTooltip = () => {
|
|
|
|
if (changeReactionTooltipShowingState != null) {
|
|
|
|
changeReactionTooltipShowingState();
|
|
|
|
changeReactionTooltipShowingState = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
getNoteSummary: (text: string) => getNoteSummary(text, i18n.locale),
|
|
|
|
followRequestDone,
|
|
|
|
groupInviteDone,
|
|
|
|
notePage,
|
|
|
|
userPage,
|
|
|
|
acceptFollowRequest,
|
|
|
|
rejectFollowRequest,
|
|
|
|
acceptGroupInvitation,
|
|
|
|
rejectGroupInvitation,
|
|
|
|
onReactionMouseover,
|
|
|
|
onReactionMouseleave,
|
|
|
|
elRef,
|
|
|
|
reactionRef,
|
|
|
|
};
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-05-10 08:12:19 +00:00
|
|
|
.qglefbjs {
|
2020-01-29 19:37:25 +00:00
|
|
|
position: relative;
|
|
|
|
box-sizing: border-box;
|
2020-02-18 22:00:44 +00:00
|
|
|
padding: 24px 32px;
|
2020-01-29 19:37:25 +00:00
|
|
|
font-size: 0.9em;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
display: flex;
|
2020-10-17 11:12:00 +00:00
|
|
|
contain: content;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-02-18 21:41:30 +00:00
|
|
|
&.max-width_600px {
|
|
|
|
padding: 16px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.max-width_500px {
|
2020-01-29 19:37:25 +00:00
|
|
|
padding: 12px;
|
|
|
|
font-size: 0.8em;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
clear: both;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .head {
|
|
|
|
position: sticky;
|
|
|
|
top: 0;
|
|
|
|
flex-shrink: 0;
|
|
|
|
width: 42px;
|
|
|
|
height: 42px;
|
|
|
|
margin-right: 8px;
|
|
|
|
|
2020-03-28 09:07:41 +00:00
|
|
|
> .icon {
|
2020-01-29 19:37:25 +00:00
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 6px;
|
|
|
|
}
|
|
|
|
|
2020-03-28 09:07:41 +00:00
|
|
|
> .sub-icon {
|
2020-01-29 19:37:25 +00:00
|
|
|
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);
|
|
|
|
font-size: 12px;
|
2021-11-07 14:17:51 +00:00
|
|
|
text-align: center;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-03-28 09:07:41 +00:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> * {
|
|
|
|
color: #fff;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
2020-02-12 17:17:54 +00:00
|
|
|
&.follow, &.followRequestAccepted, &.receiveFollowRequest, &.groupInvited {
|
2020-01-29 19:37:25 +00:00
|
|
|
padding: 3px;
|
|
|
|
background: #36aed2;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 11:21:05 +00:00
|
|
|
&.renote {
|
2020-01-29 19:37:25 +00:00
|
|
|
padding: 3px;
|
|
|
|
background: #36d298;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.quote {
|
|
|
|
padding: 3px;
|
|
|
|
background: #36d298;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.reply {
|
|
|
|
padding: 3px;
|
|
|
|
background: #007aff;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.mention {
|
|
|
|
padding: 3px;
|
|
|
|
background: #88a6b7;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2020-05-10 08:19:41 +00:00
|
|
|
|
|
|
|
&.pollVote {
|
|
|
|
padding: 3px;
|
|
|
|
background: #88a6b7;
|
2021-11-07 14:17:51 +00:00
|
|
|
pointer-events: none;
|
2020-05-10 08:19:41 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tail {
|
|
|
|
flex: 1;
|
|
|
|
min-width: 0;
|
|
|
|
|
|
|
|
> header {
|
|
|
|
display: flex;
|
|
|
|
align-items: baseline;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
min-width: 0;
|
2021-03-02 13:57:16 +00:00
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 09:11:41 +00:00
|
|
|
> .time {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-left: auto;
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
white-space: nowrap;
|
2021-03-02 13:57:16 +00:00
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
2021-04-20 14:22:59 +00:00
|
|
|
> i {
|
2020-01-29 19:37:25 +00:00
|
|
|
vertical-align: super;
|
|
|
|
font-size: 50%;
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
|
2021-04-20 14:22:59 +00:00
|
|
|
> i:first-child {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-right: 4px;
|
|
|
|
}
|
|
|
|
|
2021-04-20 14:22:59 +00:00
|
|
|
> i:last-child {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-left: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|