From ffaec0b9712df9a5024c0883a154442f02b72a03 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 Aug 2017 23:47:43 +0900 Subject: #497 --- src/api/endpoints.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/api/endpoints.ts') diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index 5bbc480a8e..a658c9a42e 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -159,6 +159,10 @@ const endpoints: Endpoint[] = [ }, kind: 'account-write' }, + { + name: 'i/regenerate_token', + withCredential: true + }, { name: 'i/appdata/get', withCredential: true -- cgit v1.2.3-freya From 8f0e6a70cf22f1248b99bd3b300feed8b1b1efc8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 29 Aug 2017 00:20:47 +0900 Subject: #364 --- CHANGELOG.md | 1 + locales/en.yml | 9 ++++++++ locales/ja.yml | 9 ++++++++ src/api/endpoints.ts | 4 ++++ src/api/endpoints/i/change_password.ts | 42 ++++++++++++++++++++++++++++++++++ src/web/app/desktop/tags/settings.tag | 38 ++++++++++++++++++++++++++++-- 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/api/endpoints/i/change_password.ts (limited to 'src/api/endpoints.ts') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d18b1b7f6..4e49f9ca49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ChangeLog unlereased ---------- * New: トークンを再生成できるように (#497) +* New: パスワードを変更する機能 (#364) 2461 (2017/08/28) ----------------- diff --git a/locales/en.yml b/locales/en.yml index 950180278d..a24b8725ae 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -208,6 +208,12 @@ desktop: settings: "Settings" signout: "Sign out" + mk-password-setting: + reset: "Change your password" + enter-current-password: "Enter the current password" + enter-new-password: "Enter the new password" + changed: "Password updated successfully" + mk-post-form: post-placeholder: "What's happening?" reply-placeholder: "Reply to this post..." @@ -239,6 +245,9 @@ desktop: prev: "Previous post" next: "Next post" + mk-settings: + password: "Password" + mk-timeline-post: reposted-by: "Reposted by {}" reply: "Reply" diff --git a/locales/ja.yml b/locales/ja.yml index 2655eb4846..88e0b76d82 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -208,6 +208,12 @@ desktop: settings: "設定" signout: "サインアウト" + mk-password-setting: + reset: "パスワードを変更する" + enter-current-password: "現在のパスワードを入力してください" + enter-new-password: "新しいパスワードを入力してください" + changed: "パスワードを変更しました" + mk-post-form: post-placeholder: "いまどうしてる?" reply-placeholder: "この投稿への返信..." @@ -239,6 +245,9 @@ desktop: prev: "前の投稿" next: "次の投稿" + mk-settings: + password: "パスワード" + mk-timeline-post: reposted-by: "{}がRepost" reply: "返信" diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index a658c9a42e..c6661533e8 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -159,6 +159,10 @@ const endpoints: Endpoint[] = [ }, kind: 'account-write' }, + { + name: 'i/change_password', + withCredential: true + }, { name: 'i/regenerate_token', withCredential: true diff --git a/src/api/endpoints/i/change_password.ts b/src/api/endpoints/i/change_password.ts new file mode 100644 index 0000000000..faceded29d --- /dev/null +++ b/src/api/endpoints/i/change_password.ts @@ -0,0 +1,42 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import * as bcrypt from 'bcryptjs'; +import User from '../../models/user'; + +/** + * Change password + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = async (params, user) => new Promise(async (res, rej) => { + // Get 'current_password' parameter + const [currentPassword, currentPasswordErr] = $(params.current_password).string().$; + if (currentPasswordErr) return rej('invalid current_password param'); + + // Get 'new_password' parameter + const [newPassword, newPasswordErr] = $(params.new_password).string().$; + if (newPasswordErr) return rej('invalid new_password param'); + + // Compare password + const same = bcrypt.compareSync(currentPassword, user.password); + + if (!same) { + return rej('incorrect password'); + } + + // Generate hash of password + const salt = bcrypt.genSaltSync(8); + const hash = bcrypt.hashSync(newPassword, salt); + + await User.update(user._id, { + $set: { + password: hash + } + }); + + res(); +}); diff --git a/src/web/app/desktop/tags/settings.tag b/src/web/app/desktop/tags/settings.tag index 7fc6acb4a8..80a42d6652 100644 --- a/src/web/app/desktop/tags/settings.tag +++ b/src/web/app/desktop/tags/settings.tag @@ -7,7 +7,7 @@

アプリ

Twitter

ログイン履歴

-

パスワード

+

%i18n:desktop.tags.mk-settings.password%

API

@@ -58,6 +58,11 @@ +
+

%i18n:desktop.tags.mk-settings.password%

+ +
+

API

@@ -236,8 +241,37 @@ passwordDialog('%i18n:desktop.tags.mk-api-info.regenerate-token%', password => { this.api('i/regenerate_token', { password: password - }) + }); }); }; + + + + + + -- cgit v1.2.3-freya From e7415dd42bf656a24d70c49776ff7c84a1838f9e Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 30 Aug 2017 17:31:39 +0900 Subject: Implement #746 --- CHANGELOG.md | 4 + locales/en.yml | 4 + locales/ja.yml | 4 + src/api/endpoints.ts | 4 + src/api/endpoints/i/pin.ts | 44 ++++++++++ src/api/serializers/user.ts | 43 ++++++---- src/web/app/common/tags/index.js | 1 + src/web/app/common/tags/post-menu.tag | 134 +++++++++++++++++++++++++++++++ src/web/app/desktop/tags/post-detail.tag | 23 ++++-- src/web/app/desktop/tags/timeline.tag | 21 +++-- src/web/app/mobile/tags/page/post.tag | 14 +++- src/web/app/mobile/tags/post-detail.tag | 54 +++++++------ src/web/app/mobile/tags/timeline.tag | 23 ++++-- src/web/app/mobile/tags/user.tag | 4 + 14 files changed, 316 insertions(+), 61 deletions(-) create mode 100644 src/api/endpoints/i/pin.ts create mode 100644 src/web/app/common/tags/post-menu.tag (limited to 'src/api/endpoints.ts') diff --git a/CHANGELOG.md b/CHANGELOG.md index c64a8ea04d..2669bfee74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +unreleased +---------- +* New: 投稿のピン留め (#746) + 2508 (2017/08/30) ----------------- * New: モバイル版のユーザーページのアクティビティチャートを変更 diff --git a/locales/en.yml b/locales/en.yml index 29a6a764d3..15d278c370 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -77,6 +77,10 @@ common: show-result: "Show result" voted: "Voted" + mk-post-menu: + pin: "Pin" + pinned: "Pinned" + mk-reaction-picker: choose-reaction: "Pick your reaction" diff --git a/locales/ja.yml b/locales/ja.yml index 21a07640d0..7ed4262f1c 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -77,6 +77,10 @@ common: show-result: "結果を見る" voted: "投票済み" + mk-post-menu: + pin: "ピン留め" + pinned: "ピン留めしました" + mk-reaction-picker: choose-reaction: "リアクションを選択" diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index c6661533e8..e5be68c096 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -167,6 +167,10 @@ const endpoints: Endpoint[] = [ name: 'i/regenerate_token', withCredential: true }, + { + name: 'i/pin', + kind: 'account-write' + }, { name: 'i/appdata/get', withCredential: true diff --git a/src/api/endpoints/i/pin.ts b/src/api/endpoints/i/pin.ts new file mode 100644 index 0000000000..a94950d22b --- /dev/null +++ b/src/api/endpoints/i/pin.ts @@ -0,0 +1,44 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import User from '../../models/user'; +import Post from '../../models/post'; +import serialize from '../../serializers/user'; + +/** + * Pin post + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = async (params, user) => new Promise(async (res, rej) => { + // Get 'post_id' parameter + const [postId, postIdErr] = $(params.post_id).id().$; + if (postIdErr) return rej('invalid post_id param'); + + // Fetch pinee + const post = await Post.findOne({ + _id: postId, + user_id: user._id + }); + + if (post === null) { + return rej('post not found'); + } + + await User.update(user._id, { + $set: { + pinned_post_id: post._id + } + }); + + // Serialize + const iObj = await serialize(user, user, { + detail: true + }); + + // Send response + res(iObj); +}); diff --git a/src/api/serializers/user.ts b/src/api/serializers/user.ts index bdbc749589..c9189d9034 100644 --- a/src/api/serializers/user.ts +++ b/src/api/serializers/user.ts @@ -4,6 +4,7 @@ import * as mongo from 'mongodb'; import deepcopy = require('deepcopy'); import User from '../models/user'; +import serializePost from './post'; import Following from '../models/following'; import getFriends from '../common/get-friends'; import config from '../../conf'; @@ -116,24 +117,32 @@ export default ( _user.is_followed = follow2 !== null; } - if (me && !me.equals(_user.id) && opts.detail) { - const myFollowingIds = await getFriends(me); - - // Get following you know count - const followingYouKnowCount = await Following.count({ - followee_id: { $in: myFollowingIds }, - follower_id: _user.id, - deleted_at: { $exists: false } - }); - _user.following_you_know_count = followingYouKnowCount; + if (opts.detail) { + if (_user.pinned_post_id) { + _user.pinned_post = await serializePost(_user.pinned_post_id, me, { + detail: true + }); + } - // Get followers you know count - const followersYouKnowCount = await Following.count({ - followee_id: _user.id, - follower_id: { $in: myFollowingIds }, - deleted_at: { $exists: false } - }); - _user.followers_you_know_count = followersYouKnowCount; + if (me && !me.equals(_user.id)) { + const myFollowingIds = await getFriends(me); + + // Get following you know count + const followingYouKnowCount = await Following.count({ + followee_id: { $in: myFollowingIds }, + follower_id: _user.id, + deleted_at: { $exists: false } + }); + _user.following_you_know_count = followingYouKnowCount; + + // Get followers you know count + const followersYouKnowCount = await Following.count({ + followee_id: _user.id, + follower_id: { $in: myFollowingIds }, + deleted_at: { $exists: false } + }); + _user.followers_you_know_count = followersYouKnowCount; + } } resolve(_user); diff --git a/src/web/app/common/tags/index.js b/src/web/app/common/tags/index.js index dd6ba75d7a..6e6081da9b 100644 --- a/src/web/app/common/tags/index.js +++ b/src/web/app/common/tags/index.js @@ -28,3 +28,4 @@ require('./reaction-picker.tag'); require('./reactions-viewer.tag'); require('./reaction-icon.tag'); require('./weekly-activity-chart.tag'); +require('./post-menu.tag'); diff --git a/src/web/app/common/tags/post-menu.tag b/src/web/app/common/tags/post-menu.tag new file mode 100644 index 0000000000..33895212bc --- /dev/null +++ b/src/web/app/common/tags/post-menu.tag @@ -0,0 +1,134 @@ + +
+
+ +
+ + +
diff --git a/src/web/app/desktop/tags/post-detail.tag b/src/web/app/desktop/tags/post-detail.tag index 7a90dccf39..58343482d0 100644 --- a/src/web/app/desktop/tags/post-detail.tag +++ b/src/web/app/desktop/tags/post-detail.tag @@ -43,16 +43,18 @@
- - - + -
@@ -315,6 +317,13 @@ }); }; + this.menu = () => { + riot.mount(document.body.appendChild(document.createElement('mk-post-menu')), { + source: this.refs.menuButton, + post: this.p + }); + }; + this.loadContext = () => { this.contextFetching = true; diff --git a/src/web/app/desktop/tags/timeline.tag b/src/web/app/desktop/tags/timeline.tag index bce27cd7f3..cd7ac7d207 100644 --- a/src/web/app/desktop/tags/timeline.tag +++ b/src/web/app/desktop/tags/timeline.tag @@ -128,16 +128,16 @@
- - - - - - + -
-
+
@@ -64,19 +66,14 @@ :scope display block overflow hidden - margin 8px auto + margin 0 auto padding 0 - max-width 500px - width calc(100% - 16px) + width 100% text-align left background #fff border-radius 8px box-shadow 0 0 0 1px rgba(0, 0, 0, 0.2) - @media (min-width 500px) - margin 16px auto - width calc(100% - 32px) - > .fetching padding 64px 0 @@ -269,6 +266,7 @@ this.mixin('api'); + this.compact = this.opts.compact; this.post = this.opts.post; this.isRepost = this.post.repost != null; this.p = this.isRepost ? this.post.repost : this.post; @@ -299,14 +297,16 @@ } // Get replies - this.api('posts/replies', { - post_id: this.p.id, - limit: 8 - }).then(replies => { - this.update({ - replies: replies + if (!this.compact) { + this.api('posts/replies', { + post_id: this.p.id, + limit: 8 + }).then(replies => { + this.update({ + replies: replies + }); }); - }); + } }); this.reply = () => { @@ -332,6 +332,14 @@ }); }; + this.menu = () => { + riot.mount(document.body.appendChild(document.createElement('mk-post-menu')), { + source: this.refs.menuButton, + post: this.p, + compact: true + }); + }; + this.loadContext = () => { this.contextFetching = true; diff --git a/src/web/app/mobile/tags/timeline.tag b/src/web/app/mobile/tags/timeline.tag index 43470d197e..d8df8b2663 100644 --- a/src/web/app/mobile/tags/timeline.tag +++ b/src/web/app/mobile/tags/timeline.tag @@ -181,14 +181,17 @@
- - - +
@@ -558,6 +561,14 @@ compact: true }); }; + + this.menu = () => { + riot.mount(document.body.appendChild(document.createElement('mk-post-menu')), { + source: this.refs.menuButton, + post: this.p, + compact: true + }); + }; diff --git a/src/web/app/mobile/tags/user.tag b/src/web/app/mobile/tags/user.tag index d85e3b51fd..0fe4055cf0 100644 --- a/src/web/app/mobile/tags/user.tag +++ b/src/web/app/mobile/tags/user.tag @@ -215,6 +215,7 @@ +

%i18n:mobile.tags.mk-user-overview.recent-posts%

@@ -240,6 +241,9 @@ max-width 600px margin 0 auto + > mk-post-detail + margin 0 0 8px 0 + > section background #eee border-radius 8px -- cgit v1.2.3-freya From c6b0bf42a112f0d9afa8920d6497cc76205ecaf4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 6 Sep 2017 23:19:58 +0900 Subject: wip --- locales/en.yml | 12 ++++ locales/ja.yml | 12 ++++ src/api/endpoints.ts | 4 ++ src/api/endpoints/posts/categorize.ts | 52 +++++++++++++++++ src/tools/ai/categorizer.ts | 93 ------------------------------- src/tools/ai/predict-all-post-category.ts | 57 +++++++++++++++++++ src/tools/ai/predict-user-interst.ts | 45 +++++++++++++++ src/web/app/common/tags/post-menu.tag | 23 ++++++++ 8 files changed, 205 insertions(+), 93 deletions(-) create mode 100644 src/api/endpoints/posts/categorize.ts delete mode 100644 src/tools/ai/categorizer.ts create mode 100644 src/tools/ai/predict-all-post-category.ts create mode 100644 src/tools/ai/predict-user-interst.ts (limited to 'src/api/endpoints.ts') diff --git a/locales/en.yml b/locales/en.yml index d40896212b..3b87ea758d 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -22,6 +22,14 @@ common: confused: "Confused" pudding: "Pudding" + post_categories: + music: "Music" + game: "Video Game" + anime: "Anime" + it: "IT" + gadgets: "Gadgets" + photography: "Photography" + input-message-here: "Enter message here" send: "Send" delete: "Delete" @@ -80,6 +88,9 @@ common: mk-post-menu: pin: "Pin" pinned: "Pinned" + select: "Select category" + categorize: "Accept" + categorized: "Category reported. Thank you!" mk-reaction-picker: choose-reaction: "Pick your reaction" @@ -375,6 +386,7 @@ mobile: twitter-integration: "Twitter integration" signin-history: "Sign in history" api: "API" + link: "MisskeyLink" settings: "Settings" signout: "Sign out" diff --git a/locales/ja.yml b/locales/ja.yml index b8e5cff412..13d451b6d8 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -22,6 +22,14 @@ common: confused: "こまこまのこまり" pudding: "Pudding" + post_categories: + music: "音楽" + game: "ゲーム" + anime: "アニメ" + it: "IT" + gadgets: "ガジェット" + photography: "写真" + input-message-here: "ここにメッセージを入力" send: "送信" delete: "削除" @@ -80,6 +88,9 @@ common: mk-post-menu: pin: "ピン留め" pinned: "ピン留めしました" + select: "カテゴリを選択" + categorize: "決定" + categorized: "カテゴリを報告しました。これによりMisskeyが賢くなり、投稿の自動カテゴライズに役立てられます。ご協力ありがとうございました。" mk-reaction-picker: choose-reaction: "リアクションを選択" @@ -375,6 +386,7 @@ mobile: twitter-integration: "Twitter連携" signin-history: "ログイン履歴" api: "API" + link: "Misskeyリンク" settings: "設定" signout: "サインアウト" diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index e5be68c096..97b98895b8 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -394,6 +394,10 @@ const endpoints: Endpoint[] = [ name: 'posts/trend', withCredential: true }, + { + name: 'posts/categorize', + withCredential: true + }, { name: 'posts/reactions', withCredential: true diff --git a/src/api/endpoints/posts/categorize.ts b/src/api/endpoints/posts/categorize.ts new file mode 100644 index 0000000000..3530ba6bc4 --- /dev/null +++ b/src/api/endpoints/posts/categorize.ts @@ -0,0 +1,52 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Post from '../../models/post'; + +/** + * Categorize a post + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + if (!user.is_pro) { + return rej('This endpoint is available only from a Pro account'); + } + + // Get 'post_id' parameter + const [postId, postIdErr] = $(params.post_id).id().$; + if (postIdErr) return rej('invalid post_id param'); + + // Get categorizee + const post = await Post.findOne({ + _id: postId + }); + + if (post === null) { + return rej('post not found'); + } + + if (post.is_category_verified) { + return rej('This post already has the verified category'); + } + + // Get 'category' parameter + const [category, categoryErr] = $(params.category).string().or([ + 'music', 'game', 'anime', 'it', 'gadgets', 'photography' + ]).$; + if (categoryErr) return rej('invalid category param'); + + // Set category + Post.update({ _id: post._id }, { + $set: { + category: category, + is_category_verified: true + } + }); + + // Send response + res(); +}); diff --git a/src/tools/ai/categorizer.ts b/src/tools/ai/categorizer.ts deleted file mode 100644 index c13374161d..0000000000 --- a/src/tools/ai/categorizer.ts +++ /dev/null @@ -1,93 +0,0 @@ -import * as fs from 'fs'; - -const bayes = require('./naive-bayes.js'); -const MeCab = require('mecab-async'); -import * as msgpack from 'msgpack-lite'; - -import Post from '../../api/models/post'; -import config from '../../conf'; - -/** - * 投稿を学習したり与えられた投稿のカテゴリを予測します - */ -export default class Categorizer { - private classifier: any; - private categorizerDbFilePath: string; - private mecab: any; - - constructor() { - this.categorizerDbFilePath = `${__dirname}/../../../data/category`; - - this.mecab = new MeCab(); - if (config.categorizer.mecab_command) this.mecab.command = config.categorizer.mecab_command; - - // BIND ----------------------------------- - this.tokenizer = this.tokenizer.bind(this); - } - - private tokenizer(text: string) { - return this.mecab.wakachiSync(text); - } - - public async init() { - try { - const buffer = fs.readFileSync(this.categorizerDbFilePath); - const db = msgpack.decode(buffer); - - this.classifier = bayes.import(db); - this.classifier.tokenizer = this.tokenizer; - } catch (e) { - this.classifier = bayes({ - tokenizer: this.tokenizer - }); - - // 訓練データ - const verifiedPosts = await Post.find({ - is_category_verified: true - }); - - // 学習 - verifiedPosts.forEach(post => { - this.classifier.learn(post.text, post.category); - }); - - this.save(); - } - } - - public async learn(id, category) { - const post = await Post.findOne({ _id: id }); - - Post.update({ _id: id }, { - $set: { - category: category, - is_category_verified: true - } - }); - - this.classifier.learn(post.text, category); - - this.save(); - } - - public async categorize(id) { - const post = await Post.findOne({ _id: id }); - - const category = this.classifier.categorize(post.text); - - Post.update({ _id: id }, { - $set: { - category: category - } - }); - } - - public async test(text) { - return this.classifier.categorize(text); - } - - private save() { - const buffer = msgpack.encode(this.classifier.export()); - fs.writeFileSync(this.categorizerDbFilePath, buffer); - } -} diff --git a/src/tools/ai/predict-all-post-category.ts b/src/tools/ai/predict-all-post-category.ts new file mode 100644 index 0000000000..87e198b39b --- /dev/null +++ b/src/tools/ai/predict-all-post-category.ts @@ -0,0 +1,57 @@ +const bayes = require('./naive-bayes.js'); +const MeCab = require('mecab-async'); + +import Post from '../../api/models/post'; +import config from '../../conf'; + +const classifier = bayes({ + tokenizer: this.tokenizer +}); + +const mecab = new MeCab(); +if (config.categorizer.mecab_command) mecab.command = config.categorizer.mecab_command; + +// 訓練データ取得 +Post.find({ + is_category_verified: true +}, { + fields: { + _id: false, + text: true, + category: true + } +}).then(verifiedPosts => { + // 学習 + verifiedPosts.forEach(post => { + classifier.learn(post.text, post.category); + }); + + // 全ての(人間によって証明されていない)投稿を取得 + Post.find({ + text: { + $exists: true + }, + is_category_verified: { + $ne: true + } + }, { + sort: { + _id: -1 + }, + fields: { + _id: true, + text: true + } + }).then(posts => { + posts.forEach(post => { + console.log(`predicting... ${post._id}`); + const category = classifier.categorize(post.text); + + Post.update({ _id: post._id }, { + $set: { + category: category + } + }); + }); + }); +}); diff --git a/src/tools/ai/predict-user-interst.ts b/src/tools/ai/predict-user-interst.ts new file mode 100644 index 0000000000..99bdfa4206 --- /dev/null +++ b/src/tools/ai/predict-user-interst.ts @@ -0,0 +1,45 @@ +import Post from '../../api/models/post'; +import User from '../../api/models/user'; + +export async function predictOne(id) { + console.log(`predict interest of ${id} ...`); + + // TODO: repostなども含める + const recentPosts = await Post.find({ + user_id: id, + category: { + $exists: true + } + }, { + sort: { + _id: -1 + }, + limit: 1000, + fields: { + _id: false, + category: true + } + }); + + const categories = {}; + + recentPosts.forEach(post => { + if (categories[post.category]) { + categories[post.category]++; + } else { + categories[post.category] = 1; + } + }); +} + +export async function predictAll() { + const allUsers = await User.find({}, { + fields: { + _id: true + } + }); + + allUsers.forEach(user => { + predictOne(user._id); + }); +} diff --git a/src/web/app/common/tags/post-menu.tag b/src/web/app/common/tags/post-menu.tag index 33895212bc..be4468a214 100644 --- a/src/web/app/common/tags/post-menu.tag +++ b/src/web/app/common/tags/post-menu.tag @@ -2,6 +2,18 @@
+
+ + +
+ + diff --git a/src/web/app/mobile/tags/user.tag b/src/web/app/mobile/tags/user.tag index a323559218..f29f0a0c86 100644 --- a/src/web/app/mobile/tags/user.tag +++ b/src/web/app/mobile/tags/user.tag @@ -246,6 +246,12 @@
+
+

%i18n:mobile.tags.mk-user-overview.frequently-replied-users%

+
+ +
+

%i18n:mobile.tags.mk-user-overview.followers-you-know%

@@ -619,6 +625,58 @@ + +

%i18n:mobile.tags.mk-user-overview-frequently-replied-users.loading%

+
0 }> + + + +
+

%i18n:mobile.tags.mk-user-overview-frequently-replied-users.no-users%

+ + +
+

%i18n:mobile.tags.mk-user-overview-followers-you-know.loading%

0 }> -- cgit v1.2.3-freya From caa47cb38cfc3950539c78ca2e70f2c50e815d2c Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 30 Oct 2017 22:12:10 +0900 Subject: 未読の通知がある場合アイコンを表示するように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 + locales/en.yml | 1 + locales/ja.yml | 1 + src/api/common/read-notification.ts | 52 +++ src/api/endpoints.ts | 8 +- src/api/endpoints/i/notifications.ts | 14 +- .../endpoints/notifications/get_unread_count.ts | 23 ++ src/api/endpoints/notifications/mark_as_read.ts | 47 --- .../endpoints/notifications/mark_as_read_all.ts | 32 ++ src/api/models/notification.ts | 5 + src/api/stream/home.ts | 6 + src/web/app/desktop/tags/notifications.tag | 6 + src/web/app/mobile/tags/index.js | 2 - src/web/app/mobile/tags/notifications.tag | 6 + src/web/app/mobile/tags/page/notifications.tag | 14 + src/web/app/mobile/tags/ui-header.tag | 156 --------- src/web/app/mobile/tags/ui-nav.tag | 170 ---------- src/web/app/mobile/tags/ui.tag | 368 +++++++++++++++++++++ 18 files changed, 524 insertions(+), 391 deletions(-) create mode 100644 src/api/common/read-notification.ts create mode 100644 src/api/endpoints/notifications/get_unread_count.ts delete mode 100644 src/api/endpoints/notifications/mark_as_read.ts create mode 100644 src/api/endpoints/notifications/mark_as_read_all.ts delete mode 100644 src/web/app/mobile/tags/ui-header.tag delete mode 100644 src/web/app/mobile/tags/ui-nav.tag (limited to 'src/api/endpoints.ts') diff --git a/CHANGELOG.md b/CHANGELOG.md index ca41d016c1..bf5c1fcb2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +unreleased +---------- +* New: 未読の通知がある場合アイコンを表示するように + 2747 (2017/10/25) ----------------- * Fix: 非ログイン状態ですべてのページが致命的な問題を発生させる (#89) diff --git a/locales/en.yml b/locales/en.yml index 03d5306d3e..020813ddbb 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -389,6 +389,7 @@ mobile: mk-notifications-page: notifications: "Notifications" + read-all: "Are you sure you want to mark as read all your notifications?" mk-post-page: title: "Post" diff --git a/locales/ja.yml b/locales/ja.yml index b640f0f248..1b3058fe02 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -389,6 +389,7 @@ mobile: mk-notifications-page: notifications: "通知" + read-all: "すべての通知を既読にしますか?" mk-post-page: title: "投稿" diff --git a/src/api/common/read-notification.ts b/src/api/common/read-notification.ts new file mode 100644 index 0000000000..3009cc5d08 --- /dev/null +++ b/src/api/common/read-notification.ts @@ -0,0 +1,52 @@ +import * as mongo from 'mongodb'; +import { default as Notification, INotification } from '../models/notification'; +import publishUserStream from '../event'; + +/** + * Mark as read notification(s) + */ +export default ( + user: string | mongo.ObjectID, + message: string | string[] | INotification | INotification[] | mongo.ObjectID | mongo.ObjectID[] +) => new Promise(async (resolve, reject) => { + + const userId = mongo.ObjectID.prototype.isPrototypeOf(user) + ? user + : new mongo.ObjectID(user); + + const ids: mongo.ObjectID[] = Array.isArray(message) + ? mongo.ObjectID.prototype.isPrototypeOf(message[0]) + ? (message as mongo.ObjectID[]) + : typeof message[0] === 'string' + ? (message as string[]).map(m => new mongo.ObjectID(m)) + : (message as INotification[]).map(m => m._id) + : mongo.ObjectID.prototype.isPrototypeOf(message) + ? [(message as mongo.ObjectID)] + : typeof message === 'string' + ? [new mongo.ObjectID(message)] + : [(message as INotification)._id]; + + // Update documents + await Notification.update({ + _id: { $in: ids }, + is_read: false + }, { + $set: { + is_read: true + } + }, { + multi: true + }); + + // Calc count of my unread notifications + const count = await Notification + .count({ + notifiee_id: userId, + is_read: false + }); + + if (count == 0) { + // 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行 + publishUserStream(userId, 'read_all_notifications'); + } +}); diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index f05762340c..29a97bcb8a 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -196,17 +196,17 @@ const endpoints: Endpoint[] = [ kind: 'notification-read' }, { - name: 'notifications/delete', + name: 'notifications/get_unread_count', withCredential: true, - kind: 'notification-write' + kind: 'notification-read' }, { - name: 'notifications/delete_all', + name: 'notifications/delete', withCredential: true, kind: 'notification-write' }, { - name: 'notifications/mark_as_read', + name: 'notifications/delete_all', withCredential: true, kind: 'notification-write' }, diff --git a/src/api/endpoints/i/notifications.ts b/src/api/endpoints/i/notifications.ts index 5575fb7412..607e0768a4 100644 --- a/src/api/endpoints/i/notifications.ts +++ b/src/api/endpoints/i/notifications.ts @@ -5,6 +5,7 @@ import $ from 'cafy'; import Notification from '../../models/notification'; import serialize from '../../serializers/notification'; import getFriends from '../../common/get-friends'; +import read from '../../common/read-notification'; /** * Get notifications @@ -91,17 +92,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Mark as read all if (notifications.length > 0 && markAsRead) { - const ids = notifications - .filter(x => x.is_read == false) - .map(x => x._id); - - // Update documents - await Notification.update({ - _id: { $in: ids } - }, { - $set: { is_read: true } - }, { - multi: true - }); + read(user._id, notifications); } }); diff --git a/src/api/endpoints/notifications/get_unread_count.ts b/src/api/endpoints/notifications/get_unread_count.ts new file mode 100644 index 0000000000..9514e78713 --- /dev/null +++ b/src/api/endpoints/notifications/get_unread_count.ts @@ -0,0 +1,23 @@ +/** + * Module dependencies + */ +import Notification from '../../models/notification'; + +/** + * Get count of unread notifications + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + const count = await Notification + .count({ + notifiee_id: user._id, + is_read: false + }); + + res({ + count: count + }); +}); diff --git a/src/api/endpoints/notifications/mark_as_read.ts b/src/api/endpoints/notifications/mark_as_read.ts deleted file mode 100644 index 5cce33e850..0000000000 --- a/src/api/endpoints/notifications/mark_as_read.ts +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Notification from '../../models/notification'; -import serialize from '../../serializers/notification'; -import event from '../../event'; - -/** - * Mark as read a notification - * - * @param {any} params - * @param {any} user - * @return {Promise} - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - const [notificationId, notificationIdErr] = $(params.notification_id).id().$; - if (notificationIdErr) return rej('invalid notification_id param'); - - // Get notification - const notification = await Notification - .findOne({ - _id: notificationId, - i: user._id - }); - - if (notification === null) { - return rej('notification-not-found'); - } - - // Update - notification.is_read = true; - Notification.update({ _id: notification._id }, { - $set: { - is_read: true - } - }); - - // Response - res(); - - // Serialize - const notificationObj = await serialize(notification); - - // Publish read_notification event - event(user._id, 'read_notification', notificationObj); -}); diff --git a/src/api/endpoints/notifications/mark_as_read_all.ts b/src/api/endpoints/notifications/mark_as_read_all.ts new file mode 100644 index 0000000000..3550e344c4 --- /dev/null +++ b/src/api/endpoints/notifications/mark_as_read_all.ts @@ -0,0 +1,32 @@ +/** + * Module dependencies + */ +import Notification from '../../models/notification'; +import event from '../../event'; + +/** + * Mark as read all notifications + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + // Update documents + await Notification.update({ + notifiee_id: user._id, + is_read: false + }, { + $set: { + is_read: true + } + }, { + multi: true + }); + + // Response + res(); + + // 全ての通知を読みましたよというイベントを発行 + event(user._id, 'read_all_notifications'); +}); diff --git a/src/api/models/notification.ts b/src/api/models/notification.ts index 1c1f429a0d..1065e8baaa 100644 --- a/src/api/models/notification.ts +++ b/src/api/models/notification.ts @@ -1,3 +1,8 @@ +import * as mongo from 'mongodb'; import db from '../../db/mongodb'; export default db.get('notifications') as any; // fuck type definition + +export interface INotification { + _id: mongo.ObjectID; +} diff --git a/src/api/stream/home.ts b/src/api/stream/home.ts index d5fe01c261..7c8f3bfec8 100644 --- a/src/api/stream/home.ts +++ b/src/api/stream/home.ts @@ -4,6 +4,7 @@ import * as debug from 'debug'; import User from '../models/user'; import serializePost from '../serializers/post'; +import readNotification from '../common/read-notification'; const log = debug('misskey'); @@ -45,6 +46,11 @@ export default function homeStream(request: websocket.request, connection: webso }); break; + case 'read_notification': + if (!msg.id) return; + readNotification(user._id, msg.id); + break; + case 'capture': if (!msg.id) return; const postId = msg.id; diff --git a/src/web/app/desktop/tags/notifications.tag b/src/web/app/desktop/tags/notifications.tag index 1046358ce9..a4f66105a8 100644 --- a/src/web/app/desktop/tags/notifications.tag +++ b/src/web/app/desktop/tags/notifications.tag @@ -252,6 +252,12 @@ }); this.onNotification = notification => { + // TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない + this.stream.send({ + type: 'read_notification', + id: notification.id + }); + this.notifications.unshift(notification); this.update(); }; diff --git a/src/web/app/mobile/tags/index.js b/src/web/app/mobile/tags/index.js index c5aafd20ba..a79f4f7e7e 100644 --- a/src/web/app/mobile/tags/index.js +++ b/src/web/app/mobile/tags/index.js @@ -1,6 +1,4 @@ require('./ui.tag'); -require('./ui-header.tag'); -require('./ui-nav.tag'); require('./page/entrance.tag'); require('./page/entrance/signin.tag'); require('./page/entrance/signup.tag'); diff --git a/src/web/app/mobile/tags/notifications.tag b/src/web/app/mobile/tags/notifications.tag index 7370aa84d3..2e95990314 100644 --- a/src/web/app/mobile/tags/notifications.tag +++ b/src/web/app/mobile/tags/notifications.tag @@ -123,6 +123,12 @@ }); this.onNotification = notification => { + // TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない + this.stream.send({ + type: 'read_notification', + id: notification.id + }); + this.notifications.unshift(notification); this.update(); }; diff --git a/src/web/app/mobile/tags/page/notifications.tag b/src/web/app/mobile/tags/page/notifications.tag index 06a5be039f..743de04393 100644 --- a/src/web/app/mobile/tags/page/notifications.tag +++ b/src/web/app/mobile/tags/page/notifications.tag @@ -10,16 +10,30 @@ import ui from '../../scripts/ui-event'; import Progress from '../../../common/scripts/loading'; + this.mixin('api'); + this.on('mount', () => { document.title = 'Misskey | %i18n:mobile.tags.mk-notifications-page.notifications%'; ui.trigger('title', '%i18n:mobile.tags.mk-notifications-page.notifications%'); document.documentElement.style.background = '#313a42'; + ui.trigger('func', () => { + this.readAll(); + }, 'check'); + Progress.start(); this.refs.ui.refs.notifications.on('fetched', () => { Progress.done(); }); }); + + this.readAll = () => { + const ok = window.confirm('%i18n:mobile.tags.mk-notifications-page.read-all%'); + + if (!ok) return; + + this.api('notifications/mark_as_read_all'); + }; diff --git a/src/web/app/mobile/tags/ui-header.tag b/src/web/app/mobile/tags/ui-header.tag deleted file mode 100644 index 10b44b2153..0000000000 --- a/src/web/app/mobile/tags/ui-header.tag +++ /dev/null @@ -1,156 +0,0 @@ - - -
-
-
- - -

Misskey

- -
-
- - -
diff --git a/src/web/app/mobile/tags/ui-nav.tag b/src/web/app/mobile/tags/ui-nav.tag deleted file mode 100644 index 34235ba4f1..0000000000 --- a/src/web/app/mobile/tags/ui-nav.tag +++ /dev/null @@ -1,170 +0,0 @@ - -
- - - -
diff --git a/src/web/app/mobile/tags/ui.tag b/src/web/app/mobile/tags/ui.tag index 9d9cd4d74a..fb8cbcdbd2 100644 --- a/src/web/app/mobile/tags/ui.tag +++ b/src/web/app/mobile/tags/ui.tag @@ -30,9 +30,377 @@ }; this.onStreamNotification = notification => { + // TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない + this.stream.send({ + type: 'read_notification', + id: notification.id + }); + riot.mount(document.body.appendChild(document.createElement('mk-notify')), { notification: notification }); }; + + + +
+
+
+ + +

Misskey

+ +
+
+ + +
+ + +
+ + + +
-- cgit v1.2.3-freya From 5efb52b9f563ae7d6b5383d054a6c21fee676b68 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 31 Oct 2017 22:35:31 +0900 Subject: wip --- locales/en.yml | 2 +- locales/ja.yml | 2 +- src/api/endpoints.ts | 12 ++++++++++-- src/api/endpoints/bbs/threads/create.ts | 29 ----------------------------- src/api/endpoints/channels/create.ts | 29 +++++++++++++++++++++++++++++ src/web/app/desktop/router.js | 5 +++++ src/web/app/desktop/tags/pages/channels.tag | 8 +++----- src/web/app/desktop/tags/ui.tag | 8 ++++---- 8 files changed, 53 insertions(+), 42 deletions(-) delete mode 100644 src/api/endpoints/bbs/threads/create.ts create mode 100644 src/api/endpoints/channels/create.ts (limited to 'src/api/endpoints.ts') diff --git a/locales/en.yml b/locales/en.yml index da532fc78a..5c7a1165ba 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -241,7 +241,7 @@ desktop: mk-ui-header-nav: home: "Home" messaging: "Messages" - bbs: "BBS" + channels: "Channels" info: "News" mk-ui-header-search: diff --git a/locales/ja.yml b/locales/ja.yml index 1ae94652b5..dd76a2b900 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -241,7 +241,7 @@ desktop: mk-ui-header-nav: home: "ホーム" messaging: "メッセージ" - bbs: "掲示板" + channels: "チャンネル" info: "お知らせ" mk-ui-header-search: diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index 29a97bcb8a..26177b8775 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -474,8 +474,16 @@ const endpoints: Endpoint[] = [ name: 'messaging/messages/create', withCredential: true, kind: 'messaging-write' - } - + }, + { + name: 'channels/create', + withCredential: true, + limit: { + duration: ms('1hour'), + max: 3, + minInterval: ms('10seconds') + } + }, ]; export default endpoints; diff --git a/src/api/endpoints/bbs/threads/create.ts b/src/api/endpoints/bbs/threads/create.ts deleted file mode 100644 index d9b4d34a0c..0000000000 --- a/src/api/endpoints/bbs/threads/create.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Channel from '../../../models/channel'; -import serialize from '../../../serializers/channel'; - -/** - * Create a channel - * - * @param {any} params - * @param {any} user - * @return {Promise} - */ -module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'title' parameter - const [title, titleErr] = $(params.title).string().range(1, 100).$; - if (titleErr) return rej('invalid title param'); - - // Create a channel - const channel = await Channel.insert({ - created_at: new Date(), - user_id: user._id, - title: title - }); - - // Response - res(await serialize(channel)); -}); diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts new file mode 100644 index 0000000000..74b089dfc3 --- /dev/null +++ b/src/api/endpoints/channels/create.ts @@ -0,0 +1,29 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Channel from '../../models/channel'; +import serialize from '../../serializers/channel'; + +/** + * Create a channel + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = async (params, user) => new Promise(async (res, rej) => { + // Get 'title' parameter + const [title, titleErr] = $(params.title).string().range(1, 100).$; + if (titleErr) return rej('invalid title param'); + + // Create a channel + const channel = await Channel.insert({ + created_at: new Date(), + user_id: user._id, + title: title + }); + + // Response + res(await serialize(channel)); +}); diff --git a/src/web/app/desktop/router.js b/src/web/app/desktop/router.js index afa8a2dce3..51738f3afa 100644 --- a/src/web/app/desktop/router.js +++ b/src/web/app/desktop/router.js @@ -9,6 +9,7 @@ let page = null; export default me => { route('/', index); route('/i>mentions', mentions); + route('/channel', channels); route('/post::post', post); route('/search::query', search); route('/:user', user.bind(null, 'home')); @@ -54,6 +55,10 @@ export default me => { mount(el); } + function channels() { + mount(document.createElement('mk-channels-page')); + } + function notFound() { mount(document.createElement('mk-not-found')); } diff --git a/src/web/app/desktop/tags/pages/channels.tag b/src/web/app/desktop/tags/pages/channels.tag index 9e47e52d25..03fae3c8d1 100644 --- a/src/web/app/desktop/tags/pages/channels.tag +++ b/src/web/app/desktop/tags/pages/channels.tag @@ -1,8 +1,7 @@
-

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

- +
+ + diff --git a/src/web/app/desktop/tags/pages/channels.tag b/src/web/app/desktop/tags/pages/channels.tag index 03fae3c8d1..220f1ca50e 100644 --- a/src/web/app/desktop/tags/pages/channels.tag +++ b/src/web/app/desktop/tags/pages/channels.tag @@ -18,7 +18,7 @@ this.new = () => { const title = window.prompt('%i18n:desktop.tags.mk-channels-page.channel-title%'); - this.api('bbs/channels/create', { + this.api('channels/create', { title: title }).then(channel => { location.href = '/channel/' + channel.id; diff --git a/src/web/app/desktop/tags/pages/user.tag b/src/web/app/desktop/tags/pages/user.tag index 864fe22735..811ca5c0fd 100644 --- a/src/web/app/desktop/tags/pages/user.tag +++ b/src/web/app/desktop/tags/pages/user.tag @@ -16,7 +16,7 @@ this.refs.ui.refs.user.on('user-fetched', user => { Progress.set(0.5); - document.title = user.name + ' | Misskey' + document.title = user.name + ' | Misskey'; }); this.refs.ui.refs.user.on('loaded', () => { -- cgit v1.2.3-freya From 346c2959e058fa445ebb82e71eb37ef023ba6bd4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 00:10:30 +0900 Subject: wip --- src/api/endpoints.ts | 3 + src/api/endpoints/channels/posts.ts | 79 +++++++++++++++++++++ src/web/app/common/scripts/channel-stream.js | 14 ++++ src/web/app/desktop/tags/pages/channel.tag | 87 ++++++++++++++++++++++++ src/web/app/desktop/tags/pages/drive-chooser.tag | 44 ++++++++++++ 5 files changed, 227 insertions(+) create mode 100644 src/api/endpoints/channels/posts.ts create mode 100644 src/web/app/common/scripts/channel-stream.js create mode 100644 src/web/app/desktop/tags/pages/drive-chooser.tag (limited to 'src/api/endpoints.ts') diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index 45b83fc9e5..88c01d4e7f 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -487,6 +487,9 @@ const endpoints: Endpoint[] = [ { name: 'channels/show' }, + { + name: 'channels/posts' + }, ]; export default endpoints; diff --git a/src/api/endpoints/channels/posts.ts b/src/api/endpoints/channels/posts.ts new file mode 100644 index 0000000000..fa91fb93ee --- /dev/null +++ b/src/api/endpoints/channels/posts.ts @@ -0,0 +1,79 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import { default as Channel, IChannel } from '../../models/channel'; +import { default as Post, IPost } from '../../models/post'; +import serialize from '../../serializers/post'; + +/** + * Show a posts of a channel + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'limit' parameter + const [limit = 1000, limitErr] = $(params.limit).optional.number().range(1, 1000).$; + if (limitErr) return rej('invalid limit param'); + + // Get 'since_id' parameter + const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; + if (sinceIdErr) return rej('invalid since_id param'); + + // Get 'max_id' parameter + const [maxId, maxIdErr] = $(params.max_id).optional.id().$; + if (maxIdErr) return rej('invalid max_id param'); + + // Check if both of since_id and max_id is specified + if (sinceId && maxId) { + return rej('cannot set since_id and max_id'); + } + + // Get 'channel_id' parameter + const [channelId, channelIdErr] = $(params.channel_id).id().$; + if (channelIdErr) return rej('invalid channel_id param'); + + // Fetch channel + const channel: IChannel = await Channel.findOne({ + _id: channelId + }); + + if (channel === null) { + return rej('channel not found'); + } + + //#region Construct query + const sort = { + _id: -1 + }; + + const query = { + channel_id: channel._id + } as any; + + if (sinceId) { + sort._id = 1; + query._id = { + $gt: sinceId + }; + } else if (maxId) { + query._id = { + $lt: maxId + }; + } + //#endregion Construct query + + // Issue query + const posts = await Post + .find(query, { + limit: limit, + sort: sort + }); + + // Serialize + res(await Promise.all(posts.map(async (post) => + await serialize(post, user) + ))); +}); diff --git a/src/web/app/common/scripts/channel-stream.js b/src/web/app/common/scripts/channel-stream.js new file mode 100644 index 0000000000..38e7d91132 --- /dev/null +++ b/src/web/app/common/scripts/channel-stream.js @@ -0,0 +1,14 @@ +'use strict'; + +import Stream from './stream'; + +/** + * Channel stream connection + */ +class Connection extends Stream { + constructor() { + super('channel'); + } +} + +export default Connection; diff --git a/src/web/app/desktop/tags/pages/channel.tag b/src/web/app/desktop/tags/pages/channel.tag index 4fa172f99d..8a3034f40c 100644 --- a/src/web/app/desktop/tags/pages/channel.tag +++ b/src/web/app/desktop/tags/pages/channel.tag @@ -2,6 +2,8 @@

{ parent.channel.title }

+ +
+ + +
+ { post.user.name } +
+
+ { post.text } +
+ + +
+ + +

{ reply.user.name }への返信: (or キャンセル)

+ + + + + +
diff --git a/src/web/app/desktop/tags/pages/drive-chooser.tag b/src/web/app/desktop/tags/pages/drive-chooser.tag new file mode 100644 index 0000000000..49741ad40c --- /dev/null +++ b/src/web/app/desktop/tags/pages/drive-chooser.tag @@ -0,0 +1,44 @@ + + +
+ + + +
+ + + +
-- cgit v1.2.3-freya From 42be937fcb6f02037ff4024a2fb1cf463c50ce0c Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 04:11:56 +0900 Subject: wip --- src/api/endpoints.ts | 3 +++ src/api/endpoints/channels.ts | 59 +++++++++++++++++++++++++++++++++++++++++ src/web/app/ch/tags/channel.tag | 7 ++--- src/web/app/ch/tags/index.tag | 13 +++++++-- 4 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/api/endpoints/channels.ts (limited to 'src/api/endpoints.ts') diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index 88c01d4e7f..c4dacad857 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -490,6 +490,9 @@ const endpoints: Endpoint[] = [ { name: 'channels/posts' }, + { + name: 'channels' + }, ]; export default endpoints; diff --git a/src/api/endpoints/channels.ts b/src/api/endpoints/channels.ts new file mode 100644 index 0000000000..e10c943896 --- /dev/null +++ b/src/api/endpoints/channels.ts @@ -0,0 +1,59 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Channel from '../models/channel'; +import serialize from '../serializers/channel'; + +/** + * Get all channels + * + * @param {any} params + * @param {any} me + * @return {Promise} + */ +module.exports = (params, me) => new Promise(async (res, rej) => { + // Get 'limit' parameter + const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; + if (limitErr) return rej('invalid limit param'); + + // Get 'since_id' parameter + const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; + if (sinceIdErr) return rej('invalid since_id param'); + + // Get 'max_id' parameter + const [maxId, maxIdErr] = $(params.max_id).optional.id().$; + if (maxIdErr) return rej('invalid max_id param'); + + // Check if both of since_id and max_id is specified + if (sinceId && maxId) { + return rej('cannot set since_id and max_id'); + } + + // Construct query + const sort = { + _id: -1 + }; + const query = {} as any; + if (sinceId) { + sort._id = 1; + query._id = { + $gt: sinceId + }; + } else if (maxId) { + query._id = { + $lt: maxId + }; + } + + // Issue query + const channels = await Channel + .find(query, { + limit: limit, + sort: sort + }); + + // Serialize + res(await Promise.all(channels.map(async channel => + await serialize(channel, me)))); +}); diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 43a1f851f8..12a6b5a3b9 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -1,4 +1,6 @@ +
Misskey Channels
+

{ channel.title }

読み込み中

@@ -21,10 +23,9 @@ diff --git a/src/web/app/ch/tags/index.tag b/src/web/app/ch/tags/index.tag index 1c0a037c2d..a64ddb6ccd 100644 --- a/src/web/app/ch/tags/index.tag +++ b/src/web/app/ch/tags/index.tag @@ -1,5 +1,9 @@ - + +
+