diff --git a/src/client/app/desktop/views/components/settings.profile.vue b/src/client/app/desktop/views/components/settings.profile.vue index 9932cbf7d..0b3a25f38 100644 --- a/src/client/app/desktop/views/components/settings.profile.vue +++ b/src/client/app/desktop/views/components/settings.profile.vue @@ -23,7 +23,11 @@
-

その他

+

%i18n:@locked-account%

+ +
+
+

%i18n:@other%

@@ -62,6 +66,11 @@ export default Vue.extend({ (this as any).apis.notify('プロフィールを更新しました'); }); }, + onChangeIsLocked() { + (this as any).api('i/update', { + isLocked: this.$store.state.i.isLocked + }); + }, onChangeIsBot() { (this as any).api('i/update', { isBot: this.$store.state.i.isBot diff --git a/src/models/follow-request.ts b/src/models/follow-request.ts index 0de4b8e3a..0cdb8b4f4 100644 --- a/src/models/follow-request.ts +++ b/src/models/follow-request.ts @@ -1,5 +1,7 @@ import * as mongo from 'mongodb'; +import * as deepcopy from 'deepcopy'; import db from '../db/mongodb'; +import { pack as packUser } from './user'; const FollowRequest = db.get('followRequests'); FollowRequest.createIndex(['followerId', 'followeeId'], { unique: true }); @@ -48,3 +50,38 @@ export async function deleteFollowRequest(followRequest: string | mongo.ObjectID _id: f._id }); } + +/** + * Pack a request for API response + */ +export const pack = ( + request: any, + me?: any +) => new Promise(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); +}); diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts index ad51a249b..e9392d236 100644 --- a/src/server/api/endpoints.ts +++ b/src/server/api/endpoints.ts @@ -458,6 +458,16 @@ const endpoints: Endpoint[] = [ withCredential: true, kind: 'following-write' }, + { + name: 'following/requests/cancel', + withCredential: true, + kind: 'following-write' + }, + { + name: 'following/requests/list', + withCredential: true, + kind: 'following-read' + }, { name: 'following/stalk', withCredential: true, diff --git a/src/server/api/endpoints/following/requests/cancel.ts b/src/server/api/endpoints/following/requests/cancel.ts new file mode 100644 index 000000000..417422e06 --- /dev/null +++ b/src/server/api/endpoints/following/requests/cancel.ts @@ -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(); +}); diff --git a/src/server/api/endpoints/following/requests/list.ts b/src/server/api/endpoints/following/requests/list.ts new file mode 100644 index 000000000..e8364335d --- /dev/null +++ b/src/server/api/endpoints/following/requests/list.ts @@ -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)))); +});