From aff688d9bf7f55a6f91a9b50f2dd6809f13683a1 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Thu, 14 Dec 2017 13:31:17 +0900
Subject: :v:
---
src/api/endpoints/posts/create.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'src/api/endpoints/posts/create.ts')
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index ae4959dae4..7270efaf71 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -222,7 +222,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const postObj = await serialize(post);
// Reponse
- res(postObj);
+ res({
+ created_post: postObj
+ });
//#region Post processes
--
cgit v1.2.3-freya
From 11e05a3a3298ea072f24ece0ad7a5c8c00bb1b23 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 05:41:21 +0900
Subject: wip
---
src/api/endpoints/posts/create.ts | 6 ++-
tools/migration/node.2017-12-22.hiseikika.js | 67 ++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 tools/migration/node.2017-12-22.hiseikika.js
(limited to 'src/api/endpoints/posts/create.ts')
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 7270efaf71..9d791538fe 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -215,7 +215,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
poll: poll,
text: text,
user_id: user._id,
- app_id: app ? app._id : null
+ app_id: app ? app._id : null,
+
+ // 以下非正規化データ
+ _reply: reply ? { user_id: reply.user_id } : undefined,
+ _repost: repost ? { user_id: repost.user_id } : undefined,
});
// Serialize
diff --git a/tools/migration/node.2017-12-22.hiseikika.js b/tools/migration/node.2017-12-22.hiseikika.js
new file mode 100644
index 0000000000..ff8294c8d1
--- /dev/null
+++ b/tools/migration/node.2017-12-22.hiseikika.js
@@ -0,0 +1,67 @@
+// for Node.js interpret
+
+const { default: Post } = require('../../built/api/models/post')
+const { default: zip } = require('@prezzemolo/zip')
+
+const migrate = async (post) => {
+ const x = {};
+ if (post.reply_id != null) {
+ const reply = await Post.findOne({
+ _id: post.reply_id
+ });
+ x['_reply.user_id'] = reply.user_id;
+ }
+ if (post.repost_id != null) {
+ const repost = await Post.findOne({
+ _id: post.repost_id
+ });
+ x['_repost.user_id'] = repost.user_id;
+ }
+ if (post.reply_id != null || post.repost_id != null) {
+ const result = await Post.update(post._id, {
+ $set: x,
+ });
+ return result.ok === 1;
+ } else {
+ return true;
+ }
+}
+
+async function main() {
+ const query = {
+ $or: [{
+ reply_id: {
+ $exists: true,
+ $ne: null
+ }
+ }, {
+ repost_id: {
+ $exists: true,
+ $ne: null
+ }
+ }]
+ }
+
+ const count = await Post.count(query);
+
+ const dop = Number.parseInt(process.argv[2]) || 5
+ const idop = ((count - (count % dop)) / dop) + 1
+
+ return zip(
+ 1,
+ async (time) => {
+ console.log(`${time} / ${idop}`)
+ const doc = await Post.find(query, {
+ limit: dop, skip: time * dop
+ })
+ return Promise.all(doc.map(migrate))
+ },
+ idop
+ ).then(a => {
+ const rv = []
+ a.forEach(e => rv.push(...e))
+ return rv
+ })
+}
+
+main().then(console.dir).catch(console.error)
--
cgit v1.2.3-freya
From f93bc3a8ec7eae63330193bc87c5b1437bf874ed Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 22 Dec 2017 07:43:56 +0900
Subject: wip
---
src/api/common/notify.ts | 2 +-
src/api/endpoints/posts/create.ts | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
(limited to 'src/api/endpoints/posts/create.ts')
diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts
index f06622f912..2b79416a30 100644
--- a/src/api/common/notify.ts
+++ b/src/api/common/notify.ts
@@ -39,7 +39,7 @@ export default (
deleted_at: { $exists: false }
});
const mutedUserIds = mute.map(m => m.mutee_id.toString());
- if (mutedUserIds.indexOf(notifier.toHexString()) != -1) {
+ if (mutedUserIds.indexOf(notifier.toString()) != -1) {
return;
}
//#endregion
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 9d791538fe..a1d05c67c6 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -8,6 +8,7 @@ import { default as Post, IPost, isValidText } from '../../models/post';
import { default as User, IUser } from '../../models/user';
import { default as Channel, IChannel } from '../../models/channel';
import Following from '../../models/following';
+import Mute from '../../models/mute';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
import ChannelWatching from '../../models/channel-watching';
@@ -240,7 +241,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const mentions = [];
- function addMention(mentionee, reason) {
+ async function addMention(mentionee, reason) {
// Reject if already added
if (mentions.some(x => x.equals(mentionee))) return;
@@ -249,8 +250,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// Publish event
if (!user._id.equals(mentionee)) {
- event(mentionee, reason, postObj);
- pushSw(mentionee, reason, postObj);
+ const mentioneeMutes = await Mute.find({
+ muter_id: mentionee,
+ deleted_at: { $exists: false }
+ });
+ const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString());
+ if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
+ event(mentionee, reason, postObj);
+ pushSw(mentionee, reason, postObj);
+ }
}
}
--
cgit v1.2.3-freya
From 718060dc855e09f270b8e19c089ed3c3743665e0 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Fri, 2 Feb 2018 08:21:30 +0900
Subject: wip
---
src/api/common/add-file-to-drive.ts | 4 ++--
src/api/common/notify.ts | 6 +++---
src/api/endpoints/app/create.ts | 4 ++--
src/api/endpoints/app/show.ts | 4 ++--
src/api/endpoints/auth/session/show.ts | 4 ++--
src/api/endpoints/auth/session/userkey.ts | 4 ++--
src/api/endpoints/channels.ts | 4 ++--
src/api/endpoints/channels/create.ts | 4 ++--
src/api/endpoints/channels/posts.ts | 4 ++--
src/api/endpoints/channels/show.ts | 4 ++--
src/api/endpoints/drive/files.ts | 4 ++--
src/api/endpoints/drive/files/create.ts | 4 ++--
src/api/endpoints/drive/files/find.ts | 4 ++--
src/api/endpoints/drive/files/show.ts | 4 ++--
src/api/endpoints/drive/files/update.ts | 4 ++--
src/api/endpoints/drive/files/upload_from_url.ts | 4 ++--
src/api/endpoints/drive/folders.ts | 4 ++--
src/api/endpoints/drive/folders/create.ts | 4 ++--
src/api/endpoints/drive/folders/find.ts | 4 ++--
src/api/endpoints/drive/folders/show.ts | 4 ++--
src/api/endpoints/drive/folders/update.ts | 4 ++--
src/api/endpoints/drive/stream.ts | 4 ++--
src/api/endpoints/i.ts | 4 ++--
src/api/endpoints/i/authorized_apps.ts | 4 ++--
src/api/endpoints/i/favorites.ts | 4 ++--
src/api/endpoints/i/notifications.ts | 4 ++--
src/api/endpoints/i/pin.ts | 4 ++--
src/api/endpoints/i/signin_history.ts | 4 ++--
src/api/endpoints/i/update.ts | 4 ++--
src/api/endpoints/messaging/history.ts | 4 ++--
src/api/endpoints/messaging/messages.ts | 4 ++--
src/api/endpoints/messaging/messages/create.ts | 4 ++--
src/api/endpoints/mute/list.ts | 4 ++--
src/api/endpoints/my/apps.ts | 4 ++--
src/api/endpoints/posts.ts | 4 ++--
src/api/endpoints/posts/context.ts | 4 ++--
src/api/endpoints/posts/create.ts | 4 ++--
src/api/endpoints/posts/mentions.ts | 4 ++--
src/api/endpoints/posts/polls/recommendation.ts | 4 ++--
src/api/endpoints/posts/reactions.ts | 4 ++--
src/api/endpoints/posts/replies.ts | 4 ++--
src/api/endpoints/posts/reposts.ts | 4 ++--
src/api/endpoints/posts/search.ts | 4 ++--
src/api/endpoints/posts/show.ts | 4 ++--
src/api/endpoints/posts/timeline.ts | 4 ++--
src/api/endpoints/posts/trend.ts | 4 ++--
src/api/endpoints/users.ts | 4 ++--
src/api/endpoints/users/followers.ts | 4 ++--
src/api/endpoints/users/following.ts | 4 ++--
src/api/endpoints/users/get_frequently_replied_users.ts | 4 ++--
src/api/endpoints/users/posts.ts | 4 ++--
src/api/endpoints/users/recommendation.ts | 4 ++--
src/api/endpoints/users/search.ts | 4 ++--
src/api/endpoints/users/search_by_username.ts | 4 ++--
src/api/endpoints/users/show.ts | 4 ++--
src/api/models/drive-file.ts | 10 ++++++++--
src/api/models/drive-folder.ts | 2 ++
src/api/models/messaging-message.ts | 5 +++++
src/api/private/signin.ts | 4 ++--
src/api/private/signup.ts | 4 ++--
src/api/service/twitter.ts | 4 ++--
61 files changed, 132 insertions(+), 119 deletions(-)
(limited to 'src/api/endpoints/posts/create.ts')
diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts
index 23cbc44e61..1ee455c092 100644
--- a/src/api/common/add-file-to-drive.ts
+++ b/src/api/common/add-file-to-drive.ts
@@ -12,7 +12,7 @@ import prominence = require('prominence');
import DriveFile, { getGridFSBucket } from '../models/drive-file';
import DriveFolder from '../models/drive-folder';
-import serialize from '../serializers/drive-file';
+import { pack } from '../models/drive-file';
import event, { publishDriveStream } from '../event';
import config from '../../conf';
@@ -282,7 +282,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
log(`drive file has been created ${file._id}`);
resolve(file);
- serialize(file).then(serializedFile => {
+ pack(file).then(serializedFile => {
// Publish drive_file_created event
event(user._id, 'drive_file_created', serializedFile);
publishDriveStream(user._id, 'file_created', serializedFile);
diff --git a/src/api/common/notify.ts b/src/api/common/notify.ts
index 2b79416a30..ae5669b84c 100644
--- a/src/api/common/notify.ts
+++ b/src/api/common/notify.ts
@@ -2,7 +2,7 @@ import * as mongo from 'mongodb';
import Notification from '../models/notification';
import Mute from '../models/mute';
import event from '../event';
-import serialize from '../serializers/notification';
+import { pack } from '../models/notification';
export default (
notifiee: mongo.ObjectID,
@@ -27,7 +27,7 @@ export default (
// Publish notification event
event(notifiee, 'notification',
- await serialize(notification));
+ await pack(notification));
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
setTimeout(async () => {
@@ -44,7 +44,7 @@ export default (
}
//#endregion
- event(notifiee, 'unread_notification', await serialize(notification));
+ event(notifiee, 'unread_notification', await pack(notification));
}
}, 3000);
});
diff --git a/src/api/endpoints/app/create.ts b/src/api/endpoints/app/create.ts
index ca684de02d..320163ebd9 100644
--- a/src/api/endpoints/app/create.ts
+++ b/src/api/endpoints/app/create.ts
@@ -5,7 +5,7 @@ import rndstr from 'rndstr';
import $ from 'cafy';
import App from '../../models/app';
import { isValidNameId } from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* @swagger
@@ -106,5 +106,5 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
- res(await serialize(app));
+ res(await pack(app));
});
diff --git a/src/api/endpoints/app/show.ts b/src/api/endpoints/app/show.ts
index 054aab8596..a3ef24717d 100644
--- a/src/api/endpoints/app/show.ts
+++ b/src/api/endpoints/app/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* @swagger
@@ -67,7 +67,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
}
// Send response
- res(await serialize(app, user, {
+ res(await pack(app, user, {
includeSecret: isSecure && app.user_id.equals(user._id)
}));
});
diff --git a/src/api/endpoints/auth/session/show.ts b/src/api/endpoints/auth/session/show.ts
index ede8a67634..1fe3b873fe 100644
--- a/src/api/endpoints/auth/session/show.ts
+++ b/src/api/endpoints/auth/session/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AuthSess from '../../../models/auth-session';
-import serialize from '../../../serializers/auth-session';
+import { pack } from '../../../models/auth-session';
/**
* @swagger
@@ -67,5 +67,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Response
- res(await serialize(session, user));
+ res(await pack(session, user));
});
diff --git a/src/api/endpoints/auth/session/userkey.ts b/src/api/endpoints/auth/session/userkey.ts
index afd3250b04..fc989bf8c2 100644
--- a/src/api/endpoints/auth/session/userkey.ts
+++ b/src/api/endpoints/auth/session/userkey.ts
@@ -5,7 +5,7 @@ import $ from 'cafy';
import App from '../../../models/app';
import AuthSess from '../../../models/auth-session';
import AccessToken from '../../../models/access-token';
-import serialize from '../../../serializers/user';
+import { pack } from '../../../models/user';
/**
* @swagger
@@ -102,7 +102,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
// Response
res({
access_token: accessToken.token,
- user: await serialize(session.user_id, null, {
+ user: await pack(session.user_id, null, {
detail: true
})
});
diff --git a/src/api/endpoints/channels.ts b/src/api/endpoints/channels.ts
index 14817d9bd8..92dcee83db 100644
--- a/src/api/endpoints/channels.ts
+++ b/src/api/endpoints/channels.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Channel from '../models/channel';
-import serialize from '../serializers/channel';
+import { pack } from '../models/channel';
/**
* Get all channels
@@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(channels.map(async channel =>
- await serialize(channel, me))));
+ await pack(channel, me))));
});
diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts
index a8d7c29dc1..695b4515b3 100644
--- a/src/api/endpoints/channels/create.ts
+++ b/src/api/endpoints/channels/create.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Channel from '../../models/channel';
import Watching from '../../models/channel-watching';
-import serialize from '../../serializers/channel';
+import { pack } from '../../models/channel';
/**
* Create a channel
@@ -28,7 +28,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Response
- res(await serialize(channel));
+ res(await pack(channel));
// Create Watching
await Watching.insert({
diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts
index 9c2d607edb..3feee51f76 100644
--- a/src/api/endpoints/channels/posts.ts
+++ b/src/api/endpoints/channels/posts.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a posts of a channel
@@ -74,6 +74,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
- await serialize(post, user)
+ await pack(post, user)
)));
});
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
index 8861e54594..89c48379a4 100644
--- a/src/api/endpoints/channels/show.ts
+++ b/src/api/endpoints/channels/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { default as Channel, IChannel } from '../../models/channel';
-import serialize from '../../serializers/channel';
+import { pack } from '../../models/channel';
/**
* Show a channel
@@ -27,5 +27,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(channel, user));
+ res(await pack(channel, user));
});
diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts
index 3d5f81339a..3bd80e7282 100644
--- a/src/api/endpoints/drive/files.ts
+++ b/src/api/endpoints/drive/files.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
-import serialize from '../../serializers/drive-file';
+import { pack } from '../../models/drive-file';
/**
* Get drive files
@@ -69,6 +69,6 @@ module.exports = async (params, user, app) => {
});
// Serialize
- const _files = await Promise.all(files.map(file => serialize(file)));
+ const _files = await Promise.all(files.map(file => pack(file)));
return _files;
};
diff --git a/src/api/endpoints/drive/files/create.ts b/src/api/endpoints/drive/files/create.ts
index 437348a1ef..6fa76d7e95 100644
--- a/src/api/endpoints/drive/files/create.ts
+++ b/src/api/endpoints/drive/files/create.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
/**
@@ -43,7 +43,7 @@ module.exports = async (file, params, user): Promise => {
const driveFile = await create(user, file.path, name, null, folderId);
// Serialize
- return serialize(driveFile);
+ return pack(driveFile);
} catch (e) {
console.error(e);
diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts
index a1cdf1643e..571aba81f4 100644
--- a/src/api/endpoints/drive/files/find.ts
+++ b/src/api/endpoints/drive/files/find.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
/**
* Find a file(s)
@@ -31,5 +31,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
- await serialize(file))));
+ await pack(file))));
});
diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts
index 3c7cf774f9..00f69f1415 100644
--- a/src/api/endpoints/drive/files/show.ts
+++ b/src/api/endpoints/drive/files/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
/**
* Show a file
@@ -29,7 +29,7 @@ module.exports = async (params, user) => {
}
// Serialize
- const _file = await serialize(file, {
+ const _file = await pack(file, {
detail: true
});
diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts
index f39a420d6e..9ef8215b1a 100644
--- a/src/api/endpoints/drive/files/update.ts
+++ b/src/api/endpoints/drive/files/update.ts
@@ -5,7 +5,7 @@ import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import DriveFile from '../../../models/drive-file';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import { publishDriveStream } from '../../../event';
/**
@@ -67,7 +67,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const fileObj = await serialize(file);
+ const fileObj = await pack(file);
// Response
res(fileObj);
diff --git a/src/api/endpoints/drive/files/upload_from_url.ts b/src/api/endpoints/drive/files/upload_from_url.ts
index 519e0bdf65..f0398bfc5d 100644
--- a/src/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/api/endpoints/drive/files/upload_from_url.ts
@@ -4,7 +4,7 @@
import * as URL from 'url';
import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file';
-import serialize from '../../../serializers/drive-file';
+import { pack } from '../../../models/drive-file';
import create from '../../../common/add-file-to-drive';
import * as debug from 'debug';
import * as tmp from 'tmp';
@@ -63,5 +63,5 @@ module.exports = async (params, user): Promise => {
if (e) log(e.stack);
});
- return serialize(driveFile);
+ return pack(driveFile);
};
diff --git a/src/api/endpoints/drive/folders.ts b/src/api/endpoints/drive/folders.ts
index 7944e2c6a6..e650fb74aa 100644
--- a/src/api/endpoints/drive/folders.ts
+++ b/src/api/endpoints/drive/folders.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../models/drive-folder';
-import serialize from '../../serializers/drive-folder';
+import { pack } from '../../models/drive-folder';
/**
* Get drive folders
@@ -63,5 +63,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(folders.map(async folder =>
- await serialize(folder))));
+ await pack(folder))));
});
diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts
index be847b2153..1953c09ee0 100644
--- a/src/api/endpoints/drive/folders/create.ts
+++ b/src/api/endpoints/drive/folders/create.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const folderObj = await serialize(folder);
+ const folderObj = await pack(folder);
// Response
res(folderObj);
diff --git a/src/api/endpoints/drive/folders/find.ts b/src/api/endpoints/drive/folders/find.ts
index a5eb8e015d..caad45d740 100644
--- a/src/api/endpoints/drive/folders/find.ts
+++ b/src/api/endpoints/drive/folders/find.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
/**
* Find a folder(s)
@@ -30,5 +30,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(folders.map(folder => serialize(folder))));
+ res(await Promise.all(folders.map(folder => pack(folder))));
});
diff --git a/src/api/endpoints/drive/folders/show.ts b/src/api/endpoints/drive/folders/show.ts
index 9b1c04ca3c..fd3061ca54 100644
--- a/src/api/endpoints/drive/folders/show.ts
+++ b/src/api/endpoints/drive/folders/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
/**
* Show a folder
@@ -29,7 +29,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(folder, {
+ res(await pack(folder, {
detail: true
}));
});
diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts
index ff673402ab..8f50a9d009 100644
--- a/src/api/endpoints/drive/folders/update.ts
+++ b/src/api/endpoints/drive/folders/update.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder';
-import serialize from '../../../serializers/drive-folder';
+import { pack } from '../../../models/drive-folder';
import { publishDriveStream } from '../../../event';
/**
@@ -91,7 +91,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const folderObj = await serialize(folder);
+ const folderObj = await pack(folder);
// Response
res(folderObj);
diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts
index 5b0eb0a0d8..3527d70500 100644
--- a/src/api/endpoints/drive/stream.ts
+++ b/src/api/endpoints/drive/stream.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import DriveFile from '../../models/drive-file';
-import serialize from '../../serializers/drive-file';
+import { pack } from '../../models/drive-file';
/**
* Get drive stream
@@ -64,5 +64,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(files.map(async file =>
- await serialize(file))));
+ await pack(file))));
});
diff --git a/src/api/endpoints/i.ts b/src/api/endpoints/i.ts
index ae75f11d54..1b6c1e58de 100644
--- a/src/api/endpoints/i.ts
+++ b/src/api/endpoints/i.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
/**
* Show myself
@@ -15,7 +15,7 @@ import serialize from '../serializers/user';
*/
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
// Serialize
- res(await serialize(user, user, {
+ res(await pack(user, user, {
detail: true,
includeSecrets: isSecure
}));
diff --git a/src/api/endpoints/i/authorized_apps.ts b/src/api/endpoints/i/authorized_apps.ts
index 807ca5b1e7..40ce7a68c8 100644
--- a/src/api/endpoints/i/authorized_apps.ts
+++ b/src/api/endpoints/i/authorized_apps.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import AccessToken from '../../models/access-token';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* Get authorized apps of my account
@@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(tokens.map(async token =>
- await serialize(token.app_id))));
+ await pack(token.app_id))));
});
diff --git a/src/api/endpoints/i/favorites.ts b/src/api/endpoints/i/favorites.ts
index a66eaa7546..eb464cf0f0 100644
--- a/src/api/endpoints/i/favorites.ts
+++ b/src/api/endpoints/i/favorites.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Favorite from '../../models/favorite';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get followers of a user
@@ -39,6 +39,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(favorites.map(async favorite =>
- await serialize(favorite.post)
+ await pack(favorite.post)
)));
});
diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts
index fb9be7f61b..688039a0dd 100644
--- a/src/api/endpoints/i/notifications.ts
+++ b/src/api/endpoints/i/notifications.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Notification from '../../models/notification';
import Mute from '../../models/mute';
-import serialize from '../../serializers/notification';
+import { pack } from '../../models/notification';
import getFriends from '../../common/get-friends';
import read from '../../common/read-notification';
@@ -101,7 +101,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(notifications.map(async notification =>
- await serialize(notification))));
+ await pack(notification))));
// Mark as read all
if (notifications.length > 0 && markAsRead) {
diff --git a/src/api/endpoints/i/pin.ts b/src/api/endpoints/i/pin.ts
index a94950d22b..ff546fc2bd 100644
--- a/src/api/endpoints/i/pin.ts
+++ b/src/api/endpoints/i/pin.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Post from '../../models/post';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Pin post
@@ -35,7 +35,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const iObj = await serialize(user, user, {
+ const iObj = await pack(user, user, {
detail: true
});
diff --git a/src/api/endpoints/i/signin_history.ts b/src/api/endpoints/i/signin_history.ts
index e38bfa4d98..3ab59b694d 100644
--- a/src/api/endpoints/i/signin_history.ts
+++ b/src/api/endpoints/i/signin_history.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Signin from '../../models/signin';
-import serialize from '../../serializers/signin';
+import { pack } from '../../models/signin';
/**
* Get signin history of my account
@@ -58,5 +58,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async record =>
- await serialize(record))));
+ await pack(record))));
});
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index c484c51a96..a138832e54 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import event from '../../event';
import config from '../../../conf';
@@ -65,7 +65,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
});
// Serialize
- const iObj = await serialize(user, user, {
+ const iObj = await pack(user, user, {
detail: true,
includeSecrets: isSecure
});
diff --git a/src/api/endpoints/messaging/history.ts b/src/api/endpoints/messaging/history.ts
index f14740dff5..1683ca7a89 100644
--- a/src/api/endpoints/messaging/history.ts
+++ b/src/api/endpoints/messaging/history.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import History from '../../models/messaging-history';
import Mute from '../../models/mute';
-import serialize from '../../serializers/messaging-message';
+import { pack } from '../../models/messaging-message';
/**
* Show messaging history
@@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async h =>
- await serialize(h.message, user))));
+ await pack(h.message, user))));
});
diff --git a/src/api/endpoints/messaging/messages.ts b/src/api/endpoints/messaging/messages.ts
index 3d3c6950a1..67ba5e9d6d 100644
--- a/src/api/endpoints/messaging/messages.ts
+++ b/src/api/endpoints/messaging/messages.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Message from '../../models/messaging-message';
import User from '../../models/user';
-import serialize from '../../serializers/messaging-message';
+import { pack } from '../../models/messaging-message';
import read from '../../common/read-messaging-message';
/**
@@ -87,7 +87,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(messages.map(async message =>
- await serialize(message, user, {
+ await pack(message, user, {
populateRecipient: false
}))));
diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts
index 4e9d10197c..1b8a5f59e6 100644
--- a/src/api/endpoints/messaging/messages/create.ts
+++ b/src/api/endpoints/messaging/messages/create.ts
@@ -8,7 +8,7 @@ import History from '../../../models/messaging-history';
import User from '../../../models/user';
import Mute from '../../../models/mute';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/messaging-message';
+import { pack } from '../../../models/messaging-message';
import publishUserStream from '../../../event';
import { publishMessagingStream, publishMessagingIndexStream, pushSw } from '../../../event';
import config from '../../../../conf';
@@ -79,7 +79,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const messageObj = await serialize(message);
+ const messageObj = await pack(message);
// Reponse
res(messageObj);
diff --git a/src/api/endpoints/mute/list.ts b/src/api/endpoints/mute/list.ts
index 740e19f0bb..19e3b157e6 100644
--- a/src/api/endpoints/mute/list.ts
+++ b/src/api/endpoints/mute/list.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Mute from '../../models/mute';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(mutes.map(async m =>
- await serialize(m.mutee_id, me, { detail: true })));
+ await pack(m.mutee_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/my/apps.ts b/src/api/endpoints/my/apps.ts
index eb9c758768..fe583db86a 100644
--- a/src/api/endpoints/my/apps.ts
+++ b/src/api/endpoints/my/apps.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import App from '../../models/app';
-import serialize from '../../serializers/app';
+import { pack } from '../../models/app';
/**
* Get my apps
@@ -37,5 +37,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Reply
res(await Promise.all(apps.map(async app =>
- await serialize(app))));
+ await pack(app))));
});
diff --git a/src/api/endpoints/posts.ts b/src/api/endpoints/posts.ts
index db166cd67a..d10c6ab408 100644
--- a/src/api/endpoints/posts.ts
+++ b/src/api/endpoints/posts.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../models/post';
-import serialize from '../serializers/post';
+import { pack } from '../models/post';
/**
* Lists all posts
@@ -85,5 +85,5 @@ module.exports = (params) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(posts.map(async post => await serialize(post))));
+ res(await Promise.all(posts.map(async post => await pack(post))));
});
diff --git a/src/api/endpoints/posts/context.ts b/src/api/endpoints/posts/context.ts
index bad59a6bee..3051e7af17 100644
--- a/src/api/endpoints/posts/context.ts
+++ b/src/api/endpoints/posts/context.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a context of a post
@@ -60,5 +60,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(context.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index a1d05c67c6..0fa52221f9 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -12,7 +12,7 @@ import Mute from '../../models/mute';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
import ChannelWatching from '../../models/channel-watching';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
import notify from '../../common/notify';
import watch from '../../common/watch-post';
import event, { pushSw, publishChannelStream } from '../../event';
@@ -224,7 +224,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
});
// Serialize
- const postObj = await serialize(post);
+ const postObj = await pack(post);
// Reponse
res({
diff --git a/src/api/endpoints/posts/mentions.ts b/src/api/endpoints/posts/mentions.ts
index 3bb4ec3fa0..7127db0ad1 100644
--- a/src/api/endpoints/posts/mentions.ts
+++ b/src/api/endpoints/posts/mentions.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get mentions of myself
@@ -73,6 +73,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(mentions.map(async mention =>
- await serialize(mention, user)
+ await pack(mention, user)
)));
});
diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts
index 9c92d6cac4..5ccb754496 100644
--- a/src/api/endpoints/posts/polls/recommendation.ts
+++ b/src/api/endpoints/posts/polls/recommendation.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Vote from '../../../models/poll-vote';
import Post from '../../../models/post';
-import serialize from '../../../serializers/post';
+import { pack } from '../../../models/post';
/**
* Get recommended polls
@@ -56,5 +56,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, user, { detail: true }))));
+ await pack(post, user, { detail: true }))));
});
diff --git a/src/api/endpoints/posts/reactions.ts b/src/api/endpoints/posts/reactions.ts
index eab5d9b258..f60334df8a 100644
--- a/src/api/endpoints/posts/reactions.ts
+++ b/src/api/endpoints/posts/reactions.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import Reaction from '../../models/post-reaction';
-import serialize from '../../serializers/post-reaction';
+import { pack } from '../../models/post-reaction';
/**
* Show reactions of a post
@@ -54,5 +54,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reactions.map(async reaction =>
- await serialize(reaction, user))));
+ await pack(reaction, user))));
});
diff --git a/src/api/endpoints/posts/replies.ts b/src/api/endpoints/posts/replies.ts
index 3fd6a46769..1442b8a4c5 100644
--- a/src/api/endpoints/posts/replies.ts
+++ b/src/api/endpoints/posts/replies.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a replies of a post
@@ -50,5 +50,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(replies.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/reposts.ts b/src/api/endpoints/posts/reposts.ts
index bcc6163a11..0fbb0687b9 100644
--- a/src/api/endpoints/posts/reposts.ts
+++ b/src/api/endpoints/posts/reposts.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a reposts of a post
@@ -70,5 +70,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(reposts.map(async post =>
- await serialize(post, user))));
+ await pack(post, user))));
});
diff --git a/src/api/endpoints/posts/search.ts b/src/api/endpoints/posts/search.ts
index 31c9a8d3c8..6e26f55390 100644
--- a/src/api/endpoints/posts/search.ts
+++ b/src/api/endpoints/posts/search.ts
@@ -7,7 +7,7 @@ import Post from '../../models/post';
import User from '../../models/user';
import Mute from '../../models/mute';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Search a post
@@ -351,5 +351,5 @@ async function search(
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, me))));
+ await pack(post, me))));
}
diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts
index 5bfe4f6605..c312449710 100644
--- a/src/api/endpoints/posts/show.ts
+++ b/src/api/endpoints/posts/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Show a post
@@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await serialize(post, user, {
+ res(await pack(post, user, {
detail: true
}));
});
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index da7ffd0c14..c41cfdb8bd 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -7,7 +7,7 @@ import Post from '../../models/post';
import Mute from '../../models/mute';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get timeline of myself
@@ -128,5 +128,5 @@ module.exports = async (params, user, app) => {
});
// Serialize
- return await Promise.all(timeline.map(post => serialize(post, user)));
+ return await Promise.all(timeline.map(post => pack(post, user)));
};
diff --git a/src/api/endpoints/posts/trend.ts b/src/api/endpoints/posts/trend.ts
index 64a195dff1..b2b1d327a8 100644
--- a/src/api/endpoints/posts/trend.ts
+++ b/src/api/endpoints/posts/trend.ts
@@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import Post from '../../models/post';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get trend posts
@@ -76,5 +76,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async post =>
- await serialize(post, user, { detail: true }))));
+ await pack(post, user, { detail: true }))));
});
diff --git a/src/api/endpoints/users.ts b/src/api/endpoints/users.ts
index f3c9b66a5e..ba33b1aeb7 100644
--- a/src/api/endpoints/users.ts
+++ b/src/api/endpoints/users.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
/**
* Lists all users
@@ -55,5 +55,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me))));
+ await pack(user, me))));
});
diff --git a/src/api/endpoints/users/followers.ts b/src/api/endpoints/users/followers.ts
index 4905323ba5..b0fb83c683 100644
--- a/src/api/endpoints/users/followers.ts
+++ b/src/api/endpoints/users/followers.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
- await serialize(f.follower_id, me, { detail: true })));
+ await pack(f.follower_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/users/following.ts b/src/api/endpoints/users/following.ts
index dc2ff49bbe..8e88431e92 100644
--- a/src/api/endpoints/users/following.ts
+++ b/src/api/endpoints/users/following.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../models/user';
import Following from '../../models/following';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
const users = await Promise.all(following.map(async f =>
- await serialize(f.followee_id, me, { detail: true })));
+ await pack(f.followee_id, me, { detail: true })));
// Response
res({
diff --git a/src/api/endpoints/users/get_frequently_replied_users.ts b/src/api/endpoints/users/get_frequently_replied_users.ts
index a8add623d4..3cbc761322 100644
--- a/src/api/endpoints/users/get_frequently_replied_users.ts
+++ b/src/api/endpoints/users/get_frequently_replied_users.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter
@@ -91,7 +91,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Make replies object (includes weights)
const repliesObj = await Promise.all(topRepliedUsers.map(async (user) => ({
- user: await serialize(user, me, { detail: true }),
+ user: await pack(user, me, { detail: true }),
weight: repliedUsers[user] / peak
})));
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts
index 0d8384a43d..1f3db3cf79 100644
--- a/src/api/endpoints/users/posts.ts
+++ b/src/api/endpoints/users/posts.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Post from '../../models/post';
import User from '../../models/user';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get posts of a user
@@ -124,6 +124,6 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(posts.map(async (post) =>
- await serialize(post, me)
+ await pack(post, me)
)));
});
diff --git a/src/api/endpoints/users/recommendation.ts b/src/api/endpoints/users/recommendation.ts
index 731d68a7b1..b80fd63ce7 100644
--- a/src/api/endpoints/users/recommendation.ts
+++ b/src/api/endpoints/users/recommendation.ts
@@ -4,7 +4,7 @@
const ms = require('ms');
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import getFriends from '../../common/get-friends';
/**
@@ -44,5 +44,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
diff --git a/src/api/endpoints/users/search.ts b/src/api/endpoints/users/search.ts
index 73a5db47e2..213038403b 100644
--- a/src/api/endpoints/users/search.ts
+++ b/src/api/endpoints/users/search.ts
@@ -4,7 +4,7 @@
import * as mongo from 'mongodb';
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
import config from '../../../conf';
const escapeRegexp = require('escape-regexp');
@@ -94,6 +94,6 @@ async function byElasticsearch(res, rej, me, query, offset, max) {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
}
diff --git a/src/api/endpoints/users/search_by_username.ts b/src/api/endpoints/users/search_by_username.ts
index 7f2f42f0a6..63e206b1f2 100644
--- a/src/api/endpoints/users/search_by_username.ts
+++ b/src/api/endpoints/users/search_by_username.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Search a user by username
@@ -35,5 +35,5 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(users.map(async user =>
- await serialize(user, me, { detail: true }))));
+ await pack(user, me, { detail: true }))));
});
diff --git a/src/api/endpoints/users/show.ts b/src/api/endpoints/users/show.ts
index 8e74b0fe3f..a51cb619d4 100644
--- a/src/api/endpoints/users/show.ts
+++ b/src/api/endpoints/users/show.ts
@@ -3,7 +3,7 @@
*/
import $ from 'cafy';
import User from '../../models/user';
-import serialize from '../../serializers/user';
+import { pack } from '../../models/user';
/**
* Show a user
@@ -41,7 +41,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
}
// Send response
- res(await serialize(user, me, {
+ res(await pack(user, me, {
detail: true
}));
});
diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts
index 6a8db3ad42..9b9df1dac6 100644
--- a/src/api/models/drive-file.ts
+++ b/src/api/models/drive-file.ts
@@ -20,8 +20,14 @@ export { getGridFSBucket };
export type IDriveFile = {
_id: mongodb.ObjectID;
- created_at: Date;
- user_id: mongodb.ObjectID;
+ uploadDate: Date;
+ md5: string;
+ filename: string;
+ metadata: {
+ properties: any;
+ user_id: mongodb.ObjectID;
+ folder_id: mongodb.ObjectID;
+ }
};
export function validateFileName(name: string): boolean {
diff --git a/src/api/models/drive-folder.ts b/src/api/models/drive-folder.ts
index 48b26c2bd6..54b45049b9 100644
--- a/src/api/models/drive-folder.ts
+++ b/src/api/models/drive-folder.ts
@@ -9,7 +9,9 @@ export default DriveFolder;
export type IDriveFolder = {
_id: mongo.ObjectID;
created_at: Date;
+ name: string;
user_id: mongo.ObjectID;
+ parent_id: mongo.ObjectID;
};
export function isValidFolderName(name: string): boolean {
diff --git a/src/api/models/messaging-message.ts b/src/api/models/messaging-message.ts
index ffdda1db21..90cf1cd71c 100644
--- a/src/api/models/messaging-message.ts
+++ b/src/api/models/messaging-message.ts
@@ -10,6 +10,11 @@ export default MessagingMessage;
export interface IMessagingMessage {
_id: mongo.ObjectID;
+ created_at: Date;
+ text: string;
+ user_id: mongo.ObjectID;
+ recipient_id: mongo.ObjectID;
+ is_read: boolean;
}
export function isValidText(text: string): boolean {
diff --git a/src/api/private/signin.ts b/src/api/private/signin.ts
index a26c8f6c5a..ab6e93562c 100644
--- a/src/api/private/signin.ts
+++ b/src/api/private/signin.ts
@@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy';
import { default as User, IUser } from '../models/user';
import Signin from '../models/signin';
-import serialize from '../serializers/signin';
+import { pack } from '../models/signin';
import event from '../event';
import signin from '../common/signin';
import config from '../../conf';
@@ -85,5 +85,5 @@ export default async (req: express.Request, res: express.Response) => {
});
// Publish signin event
- event(user._id, 'signin', await serialize(record));
+ event(user._id, 'signin', await pack(record));
};
diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts
index 466c6a489f..105fe319a5 100644
--- a/src/api/private/signup.ts
+++ b/src/api/private/signup.ts
@@ -4,7 +4,7 @@ import * as bcrypt from 'bcryptjs';
import recaptcha = require('recaptcha-promise');
import { default as User, IUser } from '../models/user';
import { validateUsername, validatePassword } from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
import generateUserToken from '../common/generate-native-user-token';
import config from '../../conf';
@@ -142,7 +142,7 @@ export default async (req: express.Request, res: express.Response) => {
});
// Response
- res.send(await serialize(account));
+ res.send(await pack(account));
// Create search index
if (config.elasticsearch.enable) {
diff --git a/src/api/service/twitter.ts b/src/api/service/twitter.ts
index 0e75ee0bdb..ca4f8abcca 100644
--- a/src/api/service/twitter.ts
+++ b/src/api/service/twitter.ts
@@ -6,7 +6,7 @@ import * as uuid from 'uuid';
import autwh from 'autwh';
import redis from '../../db/redis';
import User from '../models/user';
-import serialize from '../serializers/user';
+import { pack } from '../models/user';
import event from '../event';
import config from '../../conf';
import signin from '../common/signin';
@@ -50,7 +50,7 @@ module.exports = (app: express.Application) => {
res.send(`Twitterの連携を解除しました :v:`);
// Publish i updated event
- event(user._id, 'i_updated', await serialize(user, user, {
+ event(user._id, 'i_updated', await pack(user, user, {
detail: true,
includeSecrets: true
}));
--
cgit v1.2.3-freya
From 3ae824c3542b0e232b9847ae702956e631acb276 Mon Sep 17 00:00:00 2001
From: syuilo
Date: Mon, 26 Feb 2018 00:39:05 +0900
Subject: :v:
---
src/api/endpoints/posts/create.ts | 24 ++++++++-
.../app/desktop/views/components/post-detail.vue | 29 +++++++++++
.../app/desktop/views/components/posts.post.vue | 35 +++++++++++--
src/web/app/desktop/views/components/timeline.vue | 14 ++++-
src/web/app/desktop/views/pages/search.vue | 55 ++++++++++++++------
.../app/mobile/views/components/post-detail.vue | 25 +++++++++
src/web/app/mobile/views/components/posts.post.vue | 30 +++++++++--
src/web/app/mobile/views/pages/search.vue | 59 +++++++++++++++-------
8 files changed, 227 insertions(+), 44 deletions(-)
(limited to 'src/api/endpoints/posts/create.ts')
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 0fa52221f9..075e1ac9f0 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -31,6 +31,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text');
+ // Get 'tags' parameter
+ const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
+ if (tagsErr) return rej('invalid tags');
+
// Get 'media_ids' parameter
const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
if (mediaIdsErr) return rej('invalid media_ids');
@@ -205,6 +209,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
}
+ let tokens = null;
+ if (text) {
+ // Analyze
+ tokens = parse(text);
+
+ // Extract hashtags
+ const hashtags = tokens
+ .filter(t => t.type == 'hashtag')
+ .map(t => t.hashtag);
+
+ hashtags.forEach(tag => {
+ if (tags.indexOf(tag) == -1) {
+ tags.push(tag);
+ }
+ });
+ }
+
// 投稿を作成
const post = await Post.insert({
created_at: new Date(),
@@ -215,6 +236,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
repost_id: repost ? repost._id : undefined,
poll: poll,
text: text,
+ tags: tags,
user_id: user._id,
app_id: app ? app._id : null,
@@ -423,8 +445,6 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
// If has text content
if (text) {
- // Analyze
- const tokens = parse(text);
/*
// Extract a hashtags
const hashtags = tokens
diff --git a/src/web/app/desktop/views/components/post-detail.vue b/src/web/app/desktop/views/components/post-detail.vue
index c453867dfb..1e31752fe7 100644
--- a/src/web/app/desktop/views/components/post-detail.vue
+++ b/src/web/app/desktop/views/components/post-detail.vue
@@ -44,6 +44,9 @@
+
+ {{ tag }}
+
%fa:reply%
+
+ {{ tag }}
+
RP:
@@ -342,9 +345,9 @@ export default Vue.extend({
display block
float left
margin 0 16px 10px 0
- position -webkit-sticky
- position sticky
- top 74px
+ //position -webkit-sticky
+ //position sticky
+ //top 74px
> .avatar
display block
@@ -428,6 +431,32 @@ export default Vue.extend({
font-style oblique
color #a0bf46
+ > .tags
+ > *
+ margin 0 8px 0 0
+ padding 0 8px 0 16px
+ font-size 90%
+ color #8d969e
+ background #edf0f3
+ border-radius 4px
+
+ &:before
+ content ""
+ display block
+ position absolute
+ top 0
+ bottom 0
+ left 4px
+ width 8px
+ height 8px
+ margin auto 0
+ background #fff
+ border-radius 100%
+
+ &:hover
+ text-decoration none
+ background #e2e7ec
+
> .mk-poll
font-size 80%
diff --git a/src/web/app/desktop/views/components/timeline.vue b/src/web/app/desktop/views/components/timeline.vue
index eef62104eb..0d16d60df9 100644
--- a/src/web/app/desktop/views/components/timeline.vue
+++ b/src/web/app/desktop/views/components/timeline.vue
@@ -24,6 +24,7 @@ export default Vue.extend({
return {
fetching: true,
moreFetching: false,
+ existMore: false,
posts: [],
connection: null,
connectionId: null,
@@ -62,8 +63,13 @@ export default Vue.extend({
this.fetching = true;
(this as any).api('posts/timeline', {
+ limit: 11,
until_date: this.date ? this.date.getTime() : undefined
}).then(posts => {
+ if (posts.length == 11) {
+ posts.pop();
+ this.existMore = true;
+ }
this.posts = posts;
this.fetching = false;
this.$emit('loaded');
@@ -71,11 +77,17 @@ export default Vue.extend({
});
},
more() {
- if (this.moreFetching || this.fetching || this.posts.length == 0) return;
+ if (this.moreFetching || this.fetching || this.posts.length == 0 || !this.existMore) return;
this.moreFetching = true;
(this as any).api('posts/timeline', {
+ limit: 11,
until_id: this.posts[this.posts.length - 1].id
}).then(posts => {
+ if (posts.length == 11) {
+ posts.pop();
+ } else {
+ this.existMore = false;
+ }
this.posts = this.posts.concat(posts);
this.moreFetching = false;
});
diff --git a/src/web/app/desktop/views/pages/search.vue b/src/web/app/desktop/views/pages/search.vue
index b8e8db2e79..afd37c8cee 100644
--- a/src/web/app/desktop/views/pages/search.vue
+++ b/src/web/app/desktop/views/pages/search.vue
@@ -1,13 +1,13 @@
- %fa:search%「{{ query }}」に関する投稿は見つかりませんでした。
-
+ %fa:search%「{{ q }}」に関する投稿は見つかりませんでした。
+
%fa:search%
%fa:spinner .pulse .fw%
@@ -21,33 +21,34 @@ import Vue from 'vue';
import Progress from '../../../common/scripts/loading';
import parse from '../../../common/scripts/parse-search-query';
-const limit = 30;
+const limit = 20;
export default Vue.extend({
- props: ['query'],
data() {
return {
fetching: true,
moreFetching: false,
+ existMore: false,
offset: 0,
posts: []
};
},
+ watch: {
+ $route: 'fetch'
+ },
computed: {
empty(): boolean {
return this.posts.length == 0;
+ },
+ q(): string {
+ return this.$route.query.q;
}
},
mounted() {
- Progress.start();
-
document.addEventListener('keydown', this.onDocumentKeydown);
window.addEventListener('scroll', this.onScroll);
- (this as any).api('posts/search', parse(this.query)).then(posts => {
- this.posts = posts;
- this.fetching = false;
- });
+ this.fetch();
},
beforeDestroy() {
document.removeEventListener('keydown', this.onDocumentKeydown);
@@ -61,16 +62,38 @@ export default Vue.extend({
}
}
},
+ fetch() {
+ this.fetching = true;
+ Progress.start();
+
+ (this as any).api('posts/search', Object.assign({
+ limit: limit + 1,
+ offset: this.offset
+ }, parse(this.q))).then(posts => {
+ if (posts.length == limit + 1) {
+ posts.pop();
+ this.existMore = true;
+ }
+ this.posts = posts;
+ this.fetching = false;
+ Progress.done();
+ });
+ },
more() {
- if (this.moreFetching || this.fetching || this.posts.length == 0) return;
+ if (this.moreFetching || this.fetching || this.posts.length == 0 || !this.existMore) return;
this.offset += limit;
this.moreFetching = true;
- return (this as any).api('posts/search', Object.assign({}, parse(this.query), {
- limit: limit,
+ return (this as any).api('posts/search', Object.assign({
+ limit: limit + 1,
offset: this.offset
- })).then(posts => {
- this.moreFetching = false;
+ }, parse(this.q))).then(posts => {
+ if (posts.length == limit + 1) {
+ posts.pop();
+ } else {
+ this.existMore = false;
+ }
this.posts = this.posts.concat(posts);
+ this.moreFetching = false;
});
},
onScroll() {
diff --git a/src/web/app/mobile/views/components/post-detail.vue b/src/web/app/mobile/views/components/post-detail.vue
index 05138607ff..a83744ec4d 100644
--- a/src/web/app/mobile/views/components/post-detail.vue
+++ b/src/web/app/mobile/views/components/post-detail.vue
@@ -39,6 +39,9 @@
+
+ {{ tag }}
+
@@ -346,10 +349,7 @@ export default Vue.extend({
font-size 1.1em
color #717171
- > .dummy
- display none
-
- mk-url-preview
+ .mk-url-preview
margin-top 8px
> .channel
@@ -364,6 +364,28 @@ export default Vue.extend({
font-style oblique
color #a0bf46
+ > .tags
+ > *
+ margin 0 8px 0 0
+ padding 0 8px 0 16px
+ font-size 90%
+ color #8d969e
+ background #edf0f3
+ border-radius 4px
+
+ &:before
+ content ""
+ display block
+ position absolute
+ top 0
+ bottom 0
+ left 4px
+ width 8px
+ height 8px
+ margin auto 0
+ background #fff
+ border-radius 100%
+
[data-is-me]:after
content "you"
padding 0 4px
diff --git a/src/web/app/mobile/views/pages/search.vue b/src/web/app/mobile/views/pages/search.vue
index b6e114a82b..cbab504e3c 100644
--- a/src/web/app/mobile/views/pages/search.vue
+++ b/src/web/app/mobile/views/pages/search.vue
@@ -1,10 +1,10 @@
- %fa:search% {{ query }}
+ %fa:search% {{ q }}
- {{ '%i18n:mobile.tags.mk-search-posts.empty%'.replace('{}', query) }}
-