From dc9fddf839df7959a83819eb7064f402db05f200 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 31 Oct 2017 21:42:11 +0900 Subject: [PATCH] RENAME: bbs -> channel --- locales/en.yml | 7 ++- locales/ja.yml | 7 ++- src/api/endpoints/bbs/threads/create.ts | 12 ++--- src/api/models/{bbs-thread.ts => channel.ts} | 4 +- src/api/serializers/bbs-thread.ts | 44 ------------------- src/api/serializers/channel.ts | 44 +++++++++++++++++++ src/web/app/desktop/tags/index.js | 2 +- .../tags/pages/{bbs.tag => channels.tag} | 12 ++--- 8 files changed, 65 insertions(+), 67 deletions(-) rename src/api/models/{bbs-thread.ts => channel.ts} (75%) delete mode 100644 src/api/serializers/bbs-thread.ts create mode 100644 src/api/serializers/channel.ts rename src/web/app/desktop/tags/pages/{bbs.tag => channels.tag} (64%) diff --git a/locales/en.yml b/locales/en.yml index f0204b52cb..da532fc78a 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -352,10 +352,9 @@ desktop: mk-repost-form-window: title: "Are you sure you want to repost this post?" - mk-bbs-page: - title: "Misskey BBS" - new: "Create new thread" - thread-title: "Thread title" + mk-channels-page: + new: "Create new channel" + channel-title: "Channel title" mobile: tags: diff --git a/locales/ja.yml b/locales/ja.yml index 65d92782f2..1ae94652b5 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -352,10 +352,9 @@ desktop: mk-repost-form-window: title: "この投稿をRepostしますか?" - mk-bbs-page: - title: "Misskey掲示板" - new: "スレッドを作成" - thread-title: "スレッドのタイトル" + mk-channels-page: + new: "チャンネルを作成" + channel-title: "チャンネルのタイトル" mobile: tags: diff --git a/src/api/endpoints/bbs/threads/create.ts b/src/api/endpoints/bbs/threads/create.ts index 71d61d8711..d9b4d34a0c 100644 --- a/src/api/endpoints/bbs/threads/create.ts +++ b/src/api/endpoints/bbs/threads/create.ts @@ -2,11 +2,11 @@ * Module dependencies */ import $ from 'cafy'; -import Thread from '../../../models/bbs-thread'; -import serialize from '../../../serializers/bbs-thread'; +import Channel from '../../../models/channel'; +import serialize from '../../../serializers/channel'; /** - * Create a thread + * Create a channel * * @param {any} params * @param {any} user @@ -17,13 +17,13 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { const [title, titleErr] = $(params.title).string().range(1, 100).$; if (titleErr) return rej('invalid title param'); - // Create a thread - const thread = await Thread.insert({ + // Create a channel + const channel = await Channel.insert({ created_at: new Date(), user_id: user._id, title: title }); // Response - res(await serialize(thread)); + res(await serialize(channel)); }); diff --git a/src/api/models/bbs-thread.ts b/src/api/models/channel.ts similarity index 75% rename from src/api/models/bbs-thread.ts rename to src/api/models/channel.ts index a92157c6f4..79edb71367 100644 --- a/src/api/models/bbs-thread.ts +++ b/src/api/models/channel.ts @@ -1,11 +1,11 @@ import * as mongo from 'mongodb'; import db from '../../db/mongodb'; -const collection = db.get('bbs_threads'); +const collection = db.get('channels'); export default collection as any; // fuck type definition -export type IBbsThread = { +export type IChannel = { _id: mongo.ObjectID; created_at: Date; title: string; diff --git a/src/api/serializers/bbs-thread.ts b/src/api/serializers/bbs-thread.ts deleted file mode 100644 index d9e41a8468..0000000000 --- a/src/api/serializers/bbs-thread.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Module dependencies - */ -import * as mongo from 'mongodb'; -import deepcopy = require('deepcopy'); -import { IUser } from '../models/user'; -import { default as Thread, IBbsThread } from '../models/bbs-thread'; - -/** - * Serialize a thread - * - * @param thread target - * @param me? serializee - * @return response - */ -export default ( - thread: string | mongo.ObjectID | IBbsThread, - me?: string | mongo.ObjectID | IUser -) => new Promise(async (resolve, reject) => { - - let _thread: any; - - // Populate the thread if 'thread' is ID - if (mongo.ObjectID.prototype.isPrototypeOf(thread)) { - _thread = await Thread.findOne({ - _id: thread - }); - } else if (typeof thread === 'string') { - _thread = await Thread.findOne({ - _id: new mongo.ObjectID(thread) - }); - } else { - _thread = deepcopy(thread); - } - - // Rename _id to id - _thread.id = _thread._id; - delete _thread._id; - - // Remove needless properties - delete _thread.user_id; - - resolve(_thread); -}); diff --git a/src/api/serializers/channel.ts b/src/api/serializers/channel.ts new file mode 100644 index 0000000000..d4e16d6be3 --- /dev/null +++ b/src/api/serializers/channel.ts @@ -0,0 +1,44 @@ +/** + * Module dependencies + */ +import * as mongo from 'mongodb'; +import deepcopy = require('deepcopy'); +import { IUser } from '../models/user'; +import { default as Channel, IChannel } from '../models/channel'; + +/** + * Serialize a channel + * + * @param channel target + * @param me? serializee + * @return response + */ +export default ( + channel: string | mongo.ObjectID | IChannel, + me?: string | mongo.ObjectID | IUser +) => new Promise(async (resolve, reject) => { + + let _channel: any; + + // Populate the channel if 'channel' is ID + if (mongo.ObjectID.prototype.isPrototypeOf(channel)) { + _channel = await Channel.findOne({ + _id: channel + }); + } else if (typeof channel === 'string') { + _channel = await Channel.findOne({ + _id: new mongo.ObjectID(channel) + }); + } else { + _channel = deepcopy(channel); + } + + // Rename _id to id + _channel.id = _channel._id; + delete _channel._id; + + // Remove needless properties + delete _channel.user_id; + + resolve(_channel); +}); diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.js index fa7161ddfa..6d49006526 100644 --- a/src/web/app/desktop/tags/index.js +++ b/src/web/app/desktop/tags/index.js @@ -61,7 +61,7 @@ require('./pages/user.tag'); require('./pages/post.tag'); require('./pages/search.tag'); require('./pages/not-found.tag'); -require('./pages/bbs.tag'); +require('./pages/channels.tag'); require('./autocomplete-suggestion.tag'); require('./progress-dialog.tag'); require('./user-preview.tag'); diff --git a/src/web/app/desktop/tags/pages/bbs.tag b/src/web/app/desktop/tags/pages/channels.tag similarity index 64% rename from src/web/app/desktop/tags/pages/bbs.tag rename to src/web/app/desktop/tags/pages/channels.tag index cb58af1934..9e47e52d25 100644 --- a/src/web/app/desktop/tags/pages/bbs.tag +++ b/src/web/app/desktop/tags/pages/channels.tag @@ -1,4 +1,4 @@ - +

%i18n:desktop.tags.mk-bbs-page.title%

@@ -18,13 +18,13 @@ }); this.new = () => { - const title = window.prompt('%i18n:desktop.tags.mk-bbs-page.thread-title%'); + const title = window.prompt('%i18n:desktop.tags.mk-bbs-page.channel-title%'); - this.api('bbs/threads/create', { + this.api('bbs/channels/create', { title: title - }).then(thread => { - location.href = '/bbs/' + thread.id; + }).then(channel => { + location.href = '/bbs/' + channel.id; }); }; - +