wip
This commit is contained in:
parent
a26c19cbd2
commit
56fa24e401
10 changed files with 67 additions and 75 deletions
|
@ -50,7 +50,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="notification.type == 'followRequest'">
|
<template v-if="notification.type == 'reciveFollowRequest'">
|
||||||
<mk-avatar class="avatar" :user="notification.user"/>
|
<mk-avatar class="avatar" :user="notification.user"/>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<p>%fa:user-clock%
|
<p>%fa:user-clock%
|
||||||
|
@ -268,7 +268,7 @@ root(isDark)
|
||||||
.text p i
|
.text p i
|
||||||
color #53c7ce
|
color #53c7ce
|
||||||
|
|
||||||
&.followRequest
|
&.reciveFollowRequest
|
||||||
.text p i
|
.text p i
|
||||||
color #888
|
color #888
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<button class="mk-follow-button"
|
<button class="mk-follow-button"
|
||||||
:class="{ wait: wait, following: user.isFollowing, unfollow: user.isFollowing }"
|
:class="{ wait: wait, following: u.isFollowing }"
|
||||||
@click="onClick"
|
@click="onClick"
|
||||||
:disabled="wait"
|
:disabled="wait"
|
||||||
>
|
>
|
||||||
<template v-if="!wait">
|
<template v-if="!wait">
|
||||||
<template v-if="user.hasPendingFollowRequestFromYou">%fa:hourglass-half% %i18n:@request-pending%</template>
|
<template v-if="u.hasPendingFollowRequestFromYou">%fa:hourglass-half% %i18n:@request-pending%</template>
|
||||||
<template v-else-if="user.isFollowing">%fa:minus% %i18n:@unfollow%</template>
|
<template v-else-if="u.isFollowing">%fa:minus% %i18n:@unfollow%</template>
|
||||||
<template v-else-if="!user.isFollowing && user.isLocked">%fa:plus% %i18n:@follow-request%</template>
|
<template v-else-if="!u.isFollowing && u.isLocked">%fa:plus% %i18n:@follow-request%</template>
|
||||||
<template v-else-if="!user.isFollowing && !user.isLocked">%fa:plus% %i18n:@follow%</template>
|
<template v-else-if="!u.isFollowing && !u.isLocked">%fa:plus% %i18n:@follow%</template>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>%fa:spinner .pulse .fw%</template>
|
<template v-else>%fa:spinner .pulse .fw%</template>
|
||||||
</button>
|
</button>
|
||||||
|
@ -25,6 +25,7 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
u: this.user,
|
||||||
wait: false,
|
wait: false,
|
||||||
connection: null,
|
connection: null,
|
||||||
connectionId: null
|
connectionId: null
|
||||||
|
@ -45,51 +46,44 @@ export default Vue.extend({
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
onFollow(user) {
|
onFollow(user) {
|
||||||
if (user.id == this.user.id) {
|
if (user.id == this.u.id) {
|
||||||
this.user.isFollowing = user.isFollowing;
|
this.u.isFollowing = user.isFollowing;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnfollow(user) {
|
onUnfollow(user) {
|
||||||
if (user.id == this.user.id) {
|
if (user.id == this.u.id) {
|
||||||
this.user.isFollowing = user.isFollowing;
|
this.u.isFollowing = user.isFollowing;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onClick() {
|
async onClick() {
|
||||||
this.wait = true;
|
this.wait = true;
|
||||||
if (this.user.isFollowing) {
|
|
||||||
(this as any).api('following/delete', {
|
try {
|
||||||
userId: this.user.id
|
if (this.u.isFollowing) {
|
||||||
}).then(() => {
|
this.u = await (this as any).api('following/delete', {
|
||||||
this.user.isFollowing = false;
|
userId: this.u.id
|
||||||
}).catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
}).then(() => {
|
|
||||||
this.wait = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (this.user.isLocked && this.user.hasPendingFollowRequestFromYou) {
|
|
||||||
(this as any).api('following/requests/cancel', {
|
|
||||||
userId: this.user.id
|
|
||||||
}).then(() => {
|
|
||||||
this.user.hasPendingFollowRequestFromYou = false;
|
|
||||||
}).catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
}).then(() => {
|
|
||||||
this.wait = false;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
(this as any).api('following/create', {
|
if (this.u.isLocked && this.u.hasPendingFollowRequestFromYou) {
|
||||||
userId: this.user.id
|
this.u = await (this as any).api('following/requests/cancel', {
|
||||||
}).then(() => {
|
userId: this.u.id
|
||||||
this.user.isFollowing = true;
|
});
|
||||||
}).catch(err => {
|
} else if (this.u.isLocked) {
|
||||||
console.error(err);
|
this.u = await (this as any).api('following/create', {
|
||||||
}).then(() => {
|
userId: this.u.id
|
||||||
this.wait = false;
|
});
|
||||||
});
|
} else {
|
||||||
|
this.u = await (this as any).api('following/create', {
|
||||||
|
userId: this.user.id
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
this.wait = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +101,8 @@ export default Vue.extend({
|
||||||
margin 0
|
margin 0
|
||||||
line-height 36px
|
line-height 36px
|
||||||
font-size 14px
|
font-size 14px
|
||||||
|
color $theme-color
|
||||||
|
background transparent
|
||||||
outline none
|
outline none
|
||||||
border solid 1px $theme-color
|
border solid 1px $theme-color
|
||||||
border-radius 36px
|
border-radius 36px
|
||||||
|
@ -114,9 +110,9 @@ export default Vue.extend({
|
||||||
*
|
*
|
||||||
pointer-events none
|
pointer-events none
|
||||||
|
|
||||||
&.follow
|
&.following
|
||||||
color $theme-color
|
color $theme-color-foreground
|
||||||
background transparent
|
background $theme-color
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
background rgba($theme-color, 0.1)
|
background rgba($theme-color, 0.1)
|
||||||
|
@ -124,10 +120,6 @@ export default Vue.extend({
|
||||||
&:active
|
&:active
|
||||||
background rgba($theme-color, 0.2)
|
background rgba($theme-color, 0.2)
|
||||||
|
|
||||||
&.unfollow
|
|
||||||
color $theme-color-foreground
|
|
||||||
background $theme-color
|
|
||||||
|
|
||||||
&.wait
|
&.wait
|
||||||
cursor wait !important
|
cursor wait !important
|
||||||
opacity 0.7
|
opacity 0.7
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="notification.type == 'followRequest'">
|
<template v-if="notification.type == 'reciveFollowRequest'">
|
||||||
<mk-avatar class="avatar" :user="notification.user"/>
|
<mk-avatar class="avatar" :user="notification.user"/>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<p>%fa:user-clock%{{ notification.user | userName }}</p>
|
<p>%fa:user-clock%{{ notification.user | userName }}</p>
|
||||||
|
@ -125,7 +125,7 @@ export default Vue.extend({
|
||||||
.text p i
|
.text p i
|
||||||
color #53c7ce
|
color #53c7ce
|
||||||
|
|
||||||
&.followRequest
|
&.reciveFollowRequest
|
||||||
.text p i
|
.text p i
|
||||||
color #888
|
color #888
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="notification followRequest" v-if="notification.type == 'followRequest'">
|
<div class="notification followRequest" v-if="notification.type == 'reciveFollowRequest'">
|
||||||
<mk-avatar class="avatar" :user="notification.user"/>
|
<mk-avatar class="avatar" :user="notification.user"/>
|
||||||
<div>
|
<div>
|
||||||
<header>
|
<header>
|
||||||
|
@ -167,7 +167,7 @@ root(isDark)
|
||||||
> div > header i
|
> div > header i
|
||||||
color #53c7ce
|
color #53c7ce
|
||||||
|
|
||||||
&.followRequest
|
&.reciveFollowRequest
|
||||||
> div > header i
|
> div > header i
|
||||||
color #888
|
color #888
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Module dependencies
|
* Module dependencies
|
||||||
*/
|
*/
|
||||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||||
import User from '../../../../models/user';
|
import User, { pack } from '../../../../models/user';
|
||||||
import Following from '../../../../models/following';
|
import Following from '../../../../models/following';
|
||||||
import create from '../../../../services/following/create';
|
import create from '../../../../services/following/create';
|
||||||
|
|
||||||
|
@ -49,5 +49,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
create(follower, followee);
|
create(follower, followee);
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
res();
|
res(await pack(followee, user));
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Module dependencies
|
* Module dependencies
|
||||||
*/
|
*/
|
||||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||||
import User from '../../../../models/user';
|
import User, { pack } from '../../../../models/user';
|
||||||
import Following from '../../../../models/following';
|
import Following from '../../../../models/following';
|
||||||
import deleteFollowing from '../../../../services/following/delete';
|
import deleteFollowing from '../../../../services/following/delete';
|
||||||
|
|
||||||
|
@ -49,5 +49,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
deleteFollowing(follower, followee);
|
deleteFollowing(follower, followee);
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
res();
|
res(await pack(followee, user));
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,9 +6,9 @@ import User from '../../../../../models/user';
|
||||||
* Accept a follow request
|
* Accept a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'followerId' parameter
|
// Get 'userId' parameter
|
||||||
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
|
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followerIdErr) return rej('invalid followerId param');
|
if (followerIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Fetch follower
|
// Fetch follower
|
||||||
const follower = await User.findOne({
|
const follower = await User.findOne({
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||||
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
||||||
import User from '../../../../../models/user';
|
import User, { pack } from '../../../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel a follow request
|
* Cancel a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'followerId' parameter
|
// Get 'userId' parameter
|
||||||
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
|
const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followerIdErr) return rej('invalid followerId param');
|
if (followeeIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Fetch follower
|
// Fetch followee
|
||||||
const follower = await User.findOne({
|
const followee = await User.findOne({
|
||||||
_id: followerId
|
_id: followeeId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (follower === null) {
|
if (followee === null) {
|
||||||
return rej('follower not found');
|
return rej('followee not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
await cancelFollowRequest(user, follower);
|
await cancelFollowRequest(followee, user);
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
res();
|
res(await pack(followee._id, user));
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,9 +6,9 @@ import User from '../../../../../models/user';
|
||||||
* Reject a follow request
|
* Reject a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'followerId' parameter
|
// Get 'userId' parameter
|
||||||
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
|
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followerIdErr) return rej('invalid followerId param');
|
if (followerIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Fetch follower
|
// Fetch follower
|
||||||
const follower = await User.findOne({
|
const follower = await User.findOne({
|
||||||
|
|
|
@ -33,10 +33,10 @@ export default async function(follower: IUser, followee: IUser) {
|
||||||
|
|
||||||
// Publish reciveRequest event
|
// Publish reciveRequest event
|
||||||
if (isLocalUser(followee)) {
|
if (isLocalUser(followee)) {
|
||||||
packUser(follower, followee).then(packed => event(followee._id, 'reciveRequest', packed)),
|
packUser(follower, followee).then(packed => event(followee._id, 'reciveFollowRequest', packed)),
|
||||||
|
|
||||||
// 通知を作成
|
// 通知を作成
|
||||||
notify(followee._id, follower._id, 'reciveRequest');
|
notify(followee._id, follower._id, 'reciveFollowRequest');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||||
|
|
Loading…
Reference in a new issue