1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-14 06:38:28 +09:00
This commit is contained in:
syuilo 2018-06-01 21:55:27 +09:00
parent bae44b4708
commit 0be790fa31
6 changed files with 120 additions and 13 deletions

View File

@ -5,6 +5,7 @@
<template v-for="(notification, i) in _notifications"> <template v-for="(notification, i) in _notifications">
<div class="notification" :class="notification.type" :key="notification.id"> <div class="notification" :class="notification.type" :key="notification.id">
<mk-time :time="notification.createdAt"/> <mk-time :time="notification.createdAt"/>
<template v-if="notification.type == 'reaction'"> <template v-if="notification.type == 'reaction'">
<mk-avatar class="avatar" :user="notification.user"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
@ -17,6 +18,7 @@
</router-link> </router-link>
</div> </div>
</template> </template>
<template v-if="notification.type == 'renote'"> <template v-if="notification.type == 'renote'">
<mk-avatar class="avatar" :user="notification.note.user"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
@ -28,6 +30,7 @@
</router-link> </router-link>
</div> </div>
</template> </template>
<template v-if="notification.type == 'quote'"> <template v-if="notification.type == 'quote'">
<mk-avatar class="avatar" :user="notification.note.user"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
@ -37,6 +40,7 @@
<router-link class="note-preview" :to="notification.note | notePage">{{ getNoteSummary(notification.note) }}</router-link> <router-link class="note-preview" :to="notification.note | notePage">{{ getNoteSummary(notification.note) }}</router-link>
</div> </div>
</template> </template>
<template v-if="notification.type == 'follow'"> <template v-if="notification.type == 'follow'">
<mk-avatar class="avatar" :user="notification.user"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
@ -45,6 +49,16 @@
</p> </p>
</div> </div>
</template> </template>
<template v-if="notification.type == 'followRequest'">
<mk-avatar class="avatar" :user="notification.user"/>
<div class="text">
<p>%fa:user-clock%
<router-link :to="notification.user | userPage" v-user-preview="notification.user.id">{{ notification.user | userName }}</router-link>
</p>
</div>
</template>
<template v-if="notification.type == 'reply'"> <template v-if="notification.type == 'reply'">
<mk-avatar class="avatar" :user="notification.note.user"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
@ -54,6 +68,7 @@
<router-link class="note-preview" :to="notification.note | notePage">{{ getNoteSummary(notification.note) }}</router-link> <router-link class="note-preview" :to="notification.note | notePage">{{ getNoteSummary(notification.note) }}</router-link>
</div> </div>
</template> </template>
<template v-if="notification.type == 'mention'"> <template v-if="notification.type == 'mention'">
<mk-avatar class="avatar" :user="notification.note.user"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
@ -63,6 +78,7 @@
<a class="note-preview" :href="notification.note | notePage">{{ getNoteSummary(notification.note) }}</a> <a class="note-preview" :href="notification.note | notePage">{{ getNoteSummary(notification.note) }}</a>
</div> </div>
</template> </template>
<template v-if="notification.type == 'poll_vote'"> <template v-if="notification.type == 'poll_vote'">
<mk-avatar class="avatar" :user="notification.user"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
@ -73,6 +89,7 @@
</div> </div>
</template> </template>
</div> </div>
<p class="date" v-if="i != notifications.length - 1 && notification._date != _notifications[i + 1]._date" :key="notification.id + '-time'"> <p class="date" v-if="i != notifications.length - 1 && notification._date != _notifications[i + 1]._date" :key="notification.id + '-time'">
<span>%fa:angle-up%{{ notification._datetext }}</span> <span>%fa:angle-up%{{ notification._datetext }}</span>
<span>%fa:angle-down%{{ _notifications[i + 1]._datetext }}</span> <span>%fa:angle-down%{{ _notifications[i + 1]._datetext }}</span>
@ -251,6 +268,10 @@ root(isDark)
.text p i .text p i
color #53c7ce color #53c7ce
&.followRequest
.text p i
color #888
&.reply, &.mention &.reply, &.mention
.text p i .text p i
color #555 color #555

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="mk-notification-preview" :class="notification.type"> <div class="mk-notification-preview" :class="notification.type">
<template v-if="notification.type == 'reaction'"> <template v-if="notification.type == 'reaction'">
<img class="avatar" :src="`${notification.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
<p><mk-reaction-icon :reaction="notification.reaction"/>{{ notification.user | userName }}</p> <p><mk-reaction-icon :reaction="notification.reaction"/>{{ notification.user | userName }}</p>
<p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note) }}%fa:quote-right%</p> <p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note) }}%fa:quote-right%</p>
@ -9,7 +9,7 @@
</template> </template>
<template v-if="notification.type == 'renote'"> <template v-if="notification.type == 'renote'">
<img class="avatar" :src="`${notification.note.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
<p>%fa:retweet%{{ notification.note.user | userName }}</p> <p>%fa:retweet%{{ notification.note.user | userName }}</p>
<p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note.renote) }}%fa:quote-right%</p> <p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note.renote) }}%fa:quote-right%</p>
@ -17,7 +17,7 @@
</template> </template>
<template v-if="notification.type == 'quote'"> <template v-if="notification.type == 'quote'">
<img class="avatar" :src="`${notification.note.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
<p>%fa:quote-left%{{ notification.note.user | userName }}</p> <p>%fa:quote-left%{{ notification.note.user | userName }}</p>
<p class="note-preview">{{ getNoteSummary(notification.note) }}</p> <p class="note-preview">{{ getNoteSummary(notification.note) }}</p>
@ -25,14 +25,21 @@
</template> </template>
<template v-if="notification.type == 'follow'"> <template v-if="notification.type == 'follow'">
<img class="avatar" :src="`${notification.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
<p>%fa:user-plus%{{ notification.user | userName }}</p> <p>%fa:user-plus%{{ notification.user | userName }}</p>
</div> </div>
</template> </template>
<template v-if="notification.type == 'followRequest'">
<mk-avatar class="avatar" :user="notification.user"/>
<div class="text">
<p>%fa:user-clock%{{ notification.user | userName }}</p>
</div>
</template>
<template v-if="notification.type == 'reply'"> <template v-if="notification.type == 'reply'">
<img class="avatar" :src="`${notification.note.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
<p>%fa:reply%{{ notification.note.user | userName }}</p> <p>%fa:reply%{{ notification.note.user | userName }}</p>
<p class="note-preview">{{ getNoteSummary(notification.note) }}</p> <p class="note-preview">{{ getNoteSummary(notification.note) }}</p>
@ -40,7 +47,7 @@
</template> </template>
<template v-if="notification.type == 'mention'"> <template v-if="notification.type == 'mention'">
<img class="avatar" :src="`${notification.note.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.note.user"/>
<div class="text"> <div class="text">
<p>%fa:at%{{ notification.note.user | userName }}</p> <p>%fa:at%{{ notification.note.user | userName }}</p>
<p class="note-preview">{{ getNoteSummary(notification.note) }}</p> <p class="note-preview">{{ getNoteSummary(notification.note) }}</p>
@ -48,7 +55,7 @@
</template> </template>
<template v-if="notification.type == 'poll_vote'"> <template v-if="notification.type == 'poll_vote'">
<img class="avatar" :src="`${notification.user.avatarUrl}?thumbnail&size=64`" alt="avatar"/> <mk-avatar class="avatar" :user="notification.user"/>
<div class="text"> <div class="text">
<p>%fa:chart-pie%{{ notification.user | userName }}</p> <p>%fa:chart-pie%{{ notification.user | userName }}</p>
<p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note) }}%fa:quote-right%</p> <p class="note-ref">%fa:quote-left%{{ getNoteSummary(notification.note) }}%fa:quote-right%</p>
@ -83,16 +90,14 @@ export default Vue.extend({
display block display block
clear both clear both
img > .avatar
display block display block
float left float left
min-width 36px width 36px
min-height 36px height 36px
max-width 36px
max-height 36px
border-radius 6px border-radius 6px
.text > .text
float right float right
width calc(100% - 36px) width calc(100% - 36px)
padding-left 8px padding-left 8px
@ -120,6 +125,10 @@ export default Vue.extend({
.text p i .text p i
color #53c7ce color #53c7ce
&.followRequest
.text p i
color #888
&.reply, &.mention &.reply, &.mention
.text p i .text p i
color #fff color #fff

View File

@ -40,6 +40,17 @@
</div> </div>
</div> </div>
<div class="notification followRequest" v-if="notification.type == 'followRequest'">
<mk-avatar class="avatar" :user="notification.user"/>
<div>
<header>
%fa:user-clock%
<router-link :to="notification.user | userPage">{{ notification.user | userName }}</router-link>
<mk-time :time="notification.createdAt"/>
</header>
</div>
</div>
<div class="notification poll_vote" v-if="notification.type == 'poll_vote'"> <div class="notification poll_vote" v-if="notification.type == 'poll_vote'">
<mk-avatar class="avatar" :user="notification.user"/> <mk-avatar class="avatar" :user="notification.user"/>
<div> <div>
@ -156,6 +167,10 @@ root(isDark)
> div > header i > div > header i
color #53c7ce color #53c7ce
&.followRequest
> div > header i
color #888
.mk-notification[data-darkmode] .mk-notification[data-darkmode]
root(true) root(true)

View File

@ -448,6 +448,16 @@ const endpoints: Endpoint[] = [
}, },
kind: 'following-write' kind: 'following-write'
}, },
{
name: 'following/request/accept',
withCredential: true,
kind: 'following-write'
},
{
name: 'following/request/reject',
withCredential: true,
kind: 'following-write'
},
{ {
name: 'following/stalk', name: 'following/stalk',
withCredential: true, withCredential: true,

View File

@ -0,0 +1,26 @@
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import acceptFollowRequest from '../../../../../services/user/accept-follow-request';
import User from '../../../../../models/user';
/**
* Accept a follow request
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'followerId' parameter
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
if (followerIdErr) return rej('invalid followerId param');
// Fetch follower
const follower = await User.findOne({
_id: followerId
});
if (follower === null) {
return rej('follower not found');
}
await acceptFollowRequest(user, follower);
// Send response
res();
});

View File

@ -0,0 +1,26 @@
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import rejectFollowRequest from '../../../../../services/user/reject-follow-request';
import User from '../../../../../models/user';
/**
* Reject a follow request
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'followerId' parameter
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
if (followerIdErr) return rej('invalid followerId param');
// Fetch follower
const follower = await User.findOne({
_id: followerId
});
if (follower === null) {
return rej('follower not found');
}
await rejectFollowRequest(user, follower);
// Send response
res();
});