forked from FoundKeyGang/FoundKey
wip
This commit is contained in:
parent
f14571dc42
commit
a26c19cbd2
5 changed files with 97 additions and 1 deletions
|
@ -23,7 +23,11 @@
|
||||||
</label>
|
</label>
|
||||||
<button class="ui primary" @click="save">%i18n:@save%</button>
|
<button class="ui primary" @click="save">%i18n:@save%</button>
|
||||||
<section>
|
<section>
|
||||||
<h2>その他</h2>
|
<h2>%i18n:@locked-account%</h2>
|
||||||
|
<mk-switch v-model="$store.state.i.isLocked" @change="onChangeIsLocked" text="%i18n:@is-locked%"/>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>%i18n:@other%</h2>
|
||||||
<mk-switch v-model="$store.state.i.isBot" @change="onChangeIsBot" text="%i18n:@is-bot%"/>
|
<mk-switch v-model="$store.state.i.isBot" @change="onChangeIsBot" text="%i18n:@is-bot%"/>
|
||||||
<mk-switch v-model="$store.state.i.isCat" @change="onChangeIsCat" text="%i18n:@is-cat%"/>
|
<mk-switch v-model="$store.state.i.isCat" @change="onChangeIsCat" text="%i18n:@is-cat%"/>
|
||||||
</section>
|
</section>
|
||||||
|
@ -62,6 +66,11 @@ export default Vue.extend({
|
||||||
(this as any).apis.notify('プロフィールを更新しました');
|
(this as any).apis.notify('プロフィールを更新しました');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onChangeIsLocked() {
|
||||||
|
(this as any).api('i/update', {
|
||||||
|
isLocked: this.$store.state.i.isLocked
|
||||||
|
});
|
||||||
|
},
|
||||||
onChangeIsBot() {
|
onChangeIsBot() {
|
||||||
(this as any).api('i/update', {
|
(this as any).api('i/update', {
|
||||||
isBot: this.$store.state.i.isBot
|
isBot: this.$store.state.i.isBot
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
|
import * as deepcopy from 'deepcopy';
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
|
import { pack as packUser } from './user';
|
||||||
|
|
||||||
const FollowRequest = db.get<IFollowRequest>('followRequests');
|
const FollowRequest = db.get<IFollowRequest>('followRequests');
|
||||||
FollowRequest.createIndex(['followerId', 'followeeId'], { unique: true });
|
FollowRequest.createIndex(['followerId', 'followeeId'], { unique: true });
|
||||||
|
@ -48,3 +50,38 @@ export async function deleteFollowRequest(followRequest: string | mongo.ObjectID
|
||||||
_id: f._id
|
_id: f._id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pack a request for API response
|
||||||
|
*/
|
||||||
|
export const pack = (
|
||||||
|
request: any,
|
||||||
|
me?: any
|
||||||
|
) => new Promise<any>(async (resolve, reject) => {
|
||||||
|
let _request: any;
|
||||||
|
|
||||||
|
// Populate the request if 'request' is ID
|
||||||
|
if (mongo.ObjectID.prototype.isPrototypeOf(request)) {
|
||||||
|
_request = await FollowRequest.findOne({
|
||||||
|
_id: request
|
||||||
|
});
|
||||||
|
} else if (typeof request === 'string') {
|
||||||
|
_request = await FollowRequest.findOne({
|
||||||
|
_id: new mongo.ObjectID(request)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_request = deepcopy(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename _id to id
|
||||||
|
_request.id = _request._id;
|
||||||
|
delete _request._id;
|
||||||
|
|
||||||
|
// Populate follower
|
||||||
|
_request.followerId = await packUser(_request.followerId, me);
|
||||||
|
|
||||||
|
// Populate followee
|
||||||
|
_request.followeeId = await packUser(_request.followeeId, me);
|
||||||
|
|
||||||
|
resolve(_request);
|
||||||
|
});
|
||||||
|
|
|
@ -458,6 +458,16 @@ const endpoints: Endpoint[] = [
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
kind: 'following-write'
|
kind: 'following-write'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'following/requests/cancel',
|
||||||
|
withCredential: true,
|
||||||
|
kind: 'following-write'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'following/requests/list',
|
||||||
|
withCredential: true,
|
||||||
|
kind: 'following-read'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'following/stalk',
|
name: 'following/stalk',
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
|
|
26
src/server/api/endpoints/following/requests/cancel.ts
Normal file
26
src/server/api/endpoints/following/requests/cancel.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||||
|
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
||||||
|
import User from '../../../../../models/user';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel 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 cancelFollowRequest(user, follower);
|
||||||
|
|
||||||
|
// Send response
|
||||||
|
res();
|
||||||
|
});
|
14
src/server/api/endpoints/following/requests/list.ts
Normal file
14
src/server/api/endpoints/following/requests/list.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||||
|
import FollowRequest, { pack } from '../../../../../models/follow-request';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all pending received follow requests
|
||||||
|
*/
|
||||||
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
const reqs = await FollowRequest.find({
|
||||||
|
followeeId: user._id
|
||||||
|
});
|
||||||
|
|
||||||
|
// Send response
|
||||||
|
res(await Promise.all(reqs.map(req => pack(req))));
|
||||||
|
});
|
Loading…
Reference in a new issue