summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-02 00:51:20 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-02 00:51:20 +0900
commita26c19cbd2f3e9efbe9155895cd01e803e8c7b59 (patch)
tree017a9fdc1756b28b47647b6a8334906f01bde36f
parentwip (diff)
downloadsharkey-a26c19cbd2f3e9efbe9155895cd01e803e8c7b59.tar.gz
sharkey-a26c19cbd2f3e9efbe9155895cd01e803e8c7b59.tar.bz2
sharkey-a26c19cbd2f3e9efbe9155895cd01e803e8c7b59.zip
wip
-rw-r--r--src/client/app/desktop/views/components/settings.profile.vue11
-rw-r--r--src/models/follow-request.ts37
-rw-r--r--src/server/api/endpoints.ts10
-rw-r--r--src/server/api/endpoints/following/requests/cancel.ts26
-rw-r--r--src/server/api/endpoints/following/requests/list.ts14
5 files changed, 97 insertions, 1 deletions
diff --git a/src/client/app/desktop/views/components/settings.profile.vue b/src/client/app/desktop/views/components/settings.profile.vue
index 9932cbf7db..0b3a25f389 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 @@
</label>
<button class="ui primary" @click="save">%i18n:@save%</button>
<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.isCat" @change="onChangeIsCat" text="%i18n:@is-cat%"/>
</section>
@@ -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 0de4b8e3af..0cdb8b4f47 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<IFollowRequest>('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<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);
+});
diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts
index ad51a249bf..e9392d236b 100644
--- a/src/server/api/endpoints.ts
+++ b/src/server/api/endpoints.ts
@@ -459,6 +459,16 @@ const endpoints: Endpoint[] = [
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,
limit: {
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 0000000000..417422e06b
--- /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 0000000000..e8364335d1
--- /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))));
+});