From f37fb38640a31c4b8865a5562628197ff21f3cce Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 03:17:14 +0900 Subject: wip --- src/web/app/ch/router.js | 32 +++++++ src/web/app/ch/script.js | 18 ++++ src/web/app/ch/style.styl | 4 + src/web/app/ch/tags/channel.tag | 204 ++++++++++++++++++++++++++++++++++++++++ src/web/app/ch/tags/index.js | 2 + src/web/app/ch/tags/index.tag | 24 +++++ 6 files changed, 284 insertions(+) create mode 100644 src/web/app/ch/router.js create mode 100644 src/web/app/ch/script.js create mode 100644 src/web/app/ch/style.styl create mode 100644 src/web/app/ch/tags/channel.tag create mode 100644 src/web/app/ch/tags/index.js create mode 100644 src/web/app/ch/tags/index.tag (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/router.js b/src/web/app/ch/router.js new file mode 100644 index 0000000000..424158f403 --- /dev/null +++ b/src/web/app/ch/router.js @@ -0,0 +1,32 @@ +import * as riot from 'riot'; +const route = require('page'); +let page = null; + +export default me => { + route('/', index); + route('/:channel', channel); + route('*', notFound); + + function index() { + mount(document.createElement('mk-index')); + } + + function channel(ctx) { + const el = document.createElement('mk-channel'); + el.setAttribute('id', ctx.params.channel); + mount(el); + } + + function notFound() { + mount(document.createElement('mk-not-found')); + } + + // EXEC + route(); +}; + +function mount(content) { + if (page) page.unmount(); + const body = document.getElementById('app'); + page = riot.mount(body.appendChild(content))[0]; +} diff --git a/src/web/app/ch/script.js b/src/web/app/ch/script.js new file mode 100644 index 0000000000..760d405c52 --- /dev/null +++ b/src/web/app/ch/script.js @@ -0,0 +1,18 @@ +/** + * Channels + */ + +// Style +import './style.styl'; + +require('./tags'); +import init from '../init'; +import route from './router'; + +/** + * init + */ +init(me => { + // Start routing + route(me); +}); diff --git a/src/web/app/ch/style.styl b/src/web/app/ch/style.styl new file mode 100644 index 0000000000..2fc3ac3fca --- /dev/null +++ b/src/web/app/ch/style.styl @@ -0,0 +1,4 @@ +@import "../base" + +html + background #efefef diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag new file mode 100644 index 0000000000..b16844b8bc --- /dev/null +++ b/src/web/app/ch/tags/channel.tag @@ -0,0 +1,204 @@ + +
+

{ channel.title }

+ + + +
+ +
+

参加するにはログインまたは新規登録してください

+
+
+
+ Misskey ver { version } (葵 aoi) +
+
+ + +
+ + +
+ { post.index }: + { post.user.name } + + ID:{ post.user.username } +
+
+ >>{ post.reply_to.index } + { post.text } +
+ + { + +
+
+ + +
+ + +

>>{ reply.index } ({ reply.user.name }): [x]

+ + +
+ +
    +
  1. { name }
  2. +
+ + +
diff --git a/src/web/app/ch/tags/index.js b/src/web/app/ch/tags/index.js new file mode 100644 index 0000000000..1e99ccd43e --- /dev/null +++ b/src/web/app/ch/tags/index.js @@ -0,0 +1,2 @@ +require('./index.tag'); +require('./channel.tag'); diff --git a/src/web/app/ch/tags/index.tag b/src/web/app/ch/tags/index.tag new file mode 100644 index 0000000000..1c0a037c2d --- /dev/null +++ b/src/web/app/ch/tags/index.tag @@ -0,0 +1,24 @@ + + + + + -- cgit v1.2.3-freya From 3c4719a0b119c78108edeff2ecf7965f1c517237 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 03:31:36 +0900 Subject: wip --- src/web/app/ch/tags/channel.tag | 2 +- src/web/app/mobile/router.js | 5 ++ src/web/app/mobile/tags/drive.tag | 6 +- src/web/app/mobile/tags/index.js | 1 + src/web/app/mobile/tags/page/selectdrive.tag | 83 ++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/web/app/mobile/tags/page/selectdrive.tag (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index b16844b8bc..d43113a554 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -11,7 +11,7 @@
- Misskey ver { version } (葵 aoi) + Misskey ver { version } (葵 aoi)
+ + -- cgit v1.2.3-freya From 20707d6fd9ce2dea1342ad38156c32fcec82217a Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 03:41:34 +0900 Subject: wip --- locales/en.yml | 3 +++ locales/ja.yml | 3 +++ src/web/app/ch/tags/channel.tag | 24 +++++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/web/app/ch') diff --git a/locales/en.yml b/locales/en.yml index 643649b46c..afb6d2f2fb 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -360,6 +360,9 @@ desktop: mobile: tags: + mk-selectdrive-page: + select-file: "Select file(s)" + mk-drive-file-viewer: download: "Download" rename: "Rename" diff --git a/locales/ja.yml b/locales/ja.yml index 9fd7d94f0b..03975556b5 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -360,6 +360,9 @@ desktop: mobile: tags: + mk-selectdrive-page: + select-file: "ファイルを選択" + mk-drive-file-viewer: download: "ダウンロード" rename: "名前を変更" diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index d43113a554..e8537e3f0a 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -1,9 +1,13 @@

{ channel.title }

- - - +

読み込み中

+
+

> + + + +

@@ -33,6 +37,7 @@ this.id = this.opts.id; this.fetching = true; + this.postsFetching = true; this.channel = null; this.posts = null; this.connection = new ChannelStream(this.id); @@ -60,6 +65,7 @@ channel_id: this.id }).then(posts => { this.update({ + postsFetching: false, posts: posts }); }); @@ -84,6 +90,7 @@
{ post.index }: { post.user.name } + ID:{ post.user.username }
@@ -114,6 +121,17 @@ > mk-time margin-right 0.5em + &:first-of-type + display none + + @media (max-width 600px) + > mk-time + &:first-of-type + display initial + + &:last-of-type + display none + > div padding 0 0 1em 2em -- cgit v1.2.3-freya From 0cffc1cac0140a420c64e039487c32237c581d5e Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 03:42:50 +0900 Subject: wip --- src/web/app/ch/tags/channel.tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index e8537e3f0a..43a1f851f8 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -3,7 +3,7 @@

{ channel.title }

読み込み中

-

> +

まだ投稿がありません

-- 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/web/app/ch') 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 @@ - + +
+ -- cgit v1.2.3-freya From 86901b68b84bb68167c6a3d8cd043e63ba66bed2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 16:42:15 +0900 Subject: いい感じに MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/app/ch/tags/channel.tag | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 602b80bc11..fdc9ab4cef 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -182,12 +182,13 @@

>>{ reply.index } ({ reply.user.name }): [x]

- +
+
  1. { name }
@@ -202,6 +203,19 @@ this.mixin('api'); this.channel = this.opts.channel; + this.files = null; + + this.on('mount', () => { + this.refs.uploader.on('uploaded', file => { + this.update({ + files: [file] + }); + }); + }); + + this.upload = file => { + this.refs.uploader.upload(file); + }; this.clearReply = () => { this.update({ @@ -217,7 +231,7 @@ this.refs.text.value = ''; }; - this.post = e => { + this.post = () => { this.update({ wait: true }); @@ -250,5 +264,17 @@ }; window.open(CONFIG.url + '/selectdrive?multiple=true', '_blank'); }; + + this.onkeydown = e => { + if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey)) this.post(); + }; + + this.onpaste = e => { + e.clipboardData.items.forEach(item => { + if (item.kind == 'file') { + this.upload(item.getAsFile()); + } + }); + };
-- cgit v1.2.3-freya From b65e038686913812a1e6ddf7e1288337c6fe5fe7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 16:48:00 +0900 Subject: Better progress bar --- src/web/app/ch/tags/channel.tag | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index fdc9ab4cef..c6921e1a5c 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -51,10 +51,18 @@ Progress.start(); + const fetched = false; + + // チャンネル概要読み込み this.api('channels/show', { channel_id: this.id }).then(channel => { - Progress.done(); + if (fetched) { + Progress.done(); + } else { + Progress.set(0.5); + fetched = true; + } this.update({ fetching: false, @@ -64,9 +72,17 @@ document.title = channel.title + ' | Misskey' }); + // 投稿読み込み this.api('channels/posts', { channel_id: this.id }).then(posts => { + if (fetched) { + Progress.done(); + } else { + Progress.set(0.5); + fetched = true; + } + this.update({ postsFetching: false, posts: posts -- cgit v1.2.3-freya From e221d410e056ea348c994efb9d0a7f3b9addd2eb Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 17:09:24 +0900 Subject: Fix bug --- src/web/app/ch/tags/channel.tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index c6921e1a5c..67b012cb5c 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -51,7 +51,7 @@ Progress.start(); - const fetched = false; + let fetched = false; // チャンネル概要読み込み this.api('channels/show', { -- cgit v1.2.3-freya From 5e2053ca869cbfe18a2e552f228e8138b6a95f61 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 17:20:54 +0900 Subject: :v: --- src/web/app/ch/tags/channel.tag | 54 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'src/web/app/ch') diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 67b012cb5c..ad254c98e5 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -3,12 +3,20 @@

{ channel.title }

-

読み込み中

-
-

まだ投稿がありません

- - - + + + +
+

読み込み中

+
+

まだ投稿がありません

+ + + +

@@ -29,6 +37,14 @@ > h1 font-size 1.5em color #f00 + + > .share + > * + margin-right 4px + + > .body + margin 8px 0 0 0 + + + + + + + + + + + -- cgit v1.2.3-freya From d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 1 Nov 2017 19:33:08 +0900 Subject: Implement Channel Watching --- src/api/endpoints.ts | 8 +++++ src/api/endpoints/channels/create.ts | 11 ++++++- src/api/endpoints/channels/unwatch.ts | 60 +++++++++++++++++++++++++++++++++++ src/api/endpoints/channels/watch.ts | 58 +++++++++++++++++++++++++++++++++ src/api/endpoints/posts/create.ts | 43 +++++++++++++++---------- src/api/endpoints/posts/timeline.ts | 37 +++++++++++++++------ src/api/models/channel-watching.ts | 3 ++ src/api/serializers/channel.ts | 22 +++++++++++++ src/web/app/ch/tags/channel.tag | 27 ++++++++++++++++ 9 files changed, 243 insertions(+), 26 deletions(-) create mode 100644 src/api/endpoints/channels/unwatch.ts create mode 100644 src/api/endpoints/channels/watch.ts create mode 100644 src/api/models/channel-watching.ts (limited to 'src/web/app/ch') diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index c4dacad857..afefce39e5 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -490,6 +490,14 @@ const endpoints: Endpoint[] = [ { name: 'channels/posts' }, + { + name: 'channels/watch', + withCredential: true + }, + { + name: 'channels/unwatch', + withCredential: true + }, { name: 'channels' }, diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts index e0c0e0192a..a8d7c29dc1 100644 --- a/src/api/endpoints/channels/create.ts +++ b/src/api/endpoints/channels/create.ts @@ -3,6 +3,7 @@ */ import $ from 'cafy'; import Channel from '../../models/channel'; +import Watching from '../../models/channel-watching'; import serialize from '../../serializers/channel'; /** @@ -22,9 +23,17 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { created_at: new Date(), user_id: user._id, title: title, - index: 0 + index: 0, + watching_count: 1 }); // Response res(await serialize(channel)); + + // Create Watching + await Watching.insert({ + created_at: new Date(), + user_id: user._id, + channel_id: channel._id + }); }); diff --git a/src/api/endpoints/channels/unwatch.ts b/src/api/endpoints/channels/unwatch.ts new file mode 100644 index 0000000000..19d3be118a --- /dev/null +++ b/src/api/endpoints/channels/unwatch.ts @@ -0,0 +1,60 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Channel from '../../models/channel'; +import Watching from '../../models/channel-watching'; + +/** + * Unwatch a channel + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'channel_id' parameter + const [channelId, channelIdErr] = $(params.channel_id).id().$; + if (channelIdErr) return rej('invalid channel_id param'); + + //#region Fetch channel + const channel = await Channel.findOne({ + _id: channelId + }); + + if (channel === null) { + return rej('channel not found'); + } + //#endregion + + //#region Check whether not watching + const exist = await Watching.findOne({ + user_id: user._id, + channel_id: channel._id, + deleted_at: { $exists: false } + }); + + if (exist === null) { + return rej('already not watching'); + } + //#endregion + + // Delete watching + await Watching.update({ + _id: exist._id + }, { + $set: { + deleted_at: new Date() + } + }); + + // Send response + res(); + + // Decrement watching count + Channel.update(channel._id, { + $inc: { + watching_count: -1 + } + }); +}); diff --git a/src/api/endpoints/channels/watch.ts b/src/api/endpoints/channels/watch.ts new file mode 100644 index 0000000000..030e0dd411 --- /dev/null +++ b/src/api/endpoints/channels/watch.ts @@ -0,0 +1,58 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Channel from '../../models/channel'; +import Watching from '../../models/channel-watching'; + +/** + * Watch a channel + * + * @param {any} params + * @param {any} user + * @return {Promise} + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'channel_id' parameter + const [channelId, channelIdErr] = $(params.channel_id).id().$; + if (channelIdErr) return rej('invalid channel_id param'); + + //#region Fetch channel + const channel = await Channel.findOne({ + _id: channelId + }); + + if (channel === null) { + return rej('channel not found'); + } + //#endregion + + //#region Check whether already watching + const exist = await Watching.findOne({ + user_id: user._id, + channel_id: channel._id, + deleted_at: { $exists: false } + }); + + if (exist !== null) { + return rej('already watching'); + } + //#endregion + + // Create Watching + await Watching.insert({ + created_at: new Date(), + user_id: user._id, + channel_id: channel._id + }); + + // Send response + res(); + + // Increment watching count + Channel.update(channel._id, { + $inc: { + watching_count: 1 + } + }); +}); diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index b3fbdf6fa2..2326f7baf1 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -10,6 +10,7 @@ import { default as Channel, IChannel } from '../../models/channel'; import Following from '../../models/following'; import DriveFile from '../../models/drive-file'; import Watching from '../../models/post-watching'; +import ChannelWatching from '../../models/channel-watching'; import serialize from '../../serializers/post'; import notify from '../../common/notify'; import watch from '../../common/watch-post'; @@ -249,26 +250,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { } } - // TODO + // タイムラインへの投稿 if (!channel) { // Publish event to myself's stream event(user._id, 'post', postObj); - } - if (channel) { - // Increment channel index(posts count) - Channel.update({ _id: channel._id }, { - $inc: { - index: 1 - } - }); - - // Publish event to channel - publishChannelStream(channel._id, 'post', postObj); - } - - // TODO - if (!channel) { // Fetch all followers const followers = await Following .find({ @@ -285,6 +271,31 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { event(following.follower_id, 'post', postObj)); } + // チャンネルへの投稿 + if (channel) { + // Increment channel index(posts count) + Channel.update({ _id: channel._id }, { + $inc: { + index: 1 + } + }); + + // Publish event to channel + publishChannelStream(channel._id, 'post', postObj); + + // Get channel watchers + const watches = await ChannelWatching.find({ + channel_id: channel._id, + // 削除されたドキュメントは除く + deleted_at: { $exists: false } + }); + + // チャンネルの視聴者(のタイムライン)に配信 + watches.forEach(w => { + event(w.user_id, 'post', postObj); + }); + } + // Increment my posts count User.update({ _id: user._id }, { $inc: { diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index fe096442b4..aa5aff5ba5 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -3,6 +3,7 @@ */ import $ from 'cafy'; import Post from '../../models/post'; +import ChannelWatching from '../../models/channel-watching'; import getFriends from '../../common/get-friends'; import serialize from '../../serializers/post'; @@ -32,26 +33,43 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { return rej('cannot set since_id and max_id'); } - // ID list of the user $self and other users who the user follows + // ID list of the user itself and other users who the user follows const followingIds = await getFriends(user._id); - // Construct query + // Watchしているチャンネルを取得 + const watches = await ChannelWatching.find({ + user_id: user._id, + // 削除されたドキュメントは除く + deleted_at: { $exists: false } + }); + + //#region Construct query const sort = { _id: -1 }; + const query = { - user_id: { - $in: followingIds - }, - // TODO $or: [{ + // フォローしている人のタイムラインへの投稿 + user_id: { + $in: followingIds + }, + // 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る + $or: [{ + channel_id: { + $exists: false + } + }, { + channel_id: null + }] + }, { + // Watchしているチャンネルへの投稿 channel_id: { - $exists: false + $in: watches.map(w => w.channel_id) } - }, { - channel_id: null }] } as any; + if (sinceId) { sort._id = 1; query._id = { @@ -62,6 +80,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { $lt: maxId }; } + //#endregion // Issue query const timeline = await Post diff --git a/src/api/models/channel-watching.ts b/src/api/models/channel-watching.ts new file mode 100644 index 0000000000..6184ae408d --- /dev/null +++ b/src/api/models/channel-watching.ts @@ -0,0 +1,3 @@ +import db from '../../db/mongodb'; + +export default db.get('channel_watching') as any; // fuck type definition diff --git a/src/api/serializers/channel.ts b/src/api/serializers/channel.ts index d4e16d6be3..3cba39aa16 100644 --- a/src/api/serializers/channel.ts +++ b/src/api/serializers/channel.ts @@ -5,6 +5,7 @@ import * as mongo from 'mongodb'; import deepcopy = require('deepcopy'); import { IUser } from '../models/user'; import { default as Channel, IChannel } from '../models/channel'; +import Watching from '../models/channel-watching'; /** * Serialize a channel @@ -40,5 +41,26 @@ export default ( // Remove needless properties delete _channel.user_id; + // Me + const meId: mongo.ObjectID = me + ? mongo.ObjectID.prototype.isPrototypeOf(me) + ? me as mongo.ObjectID + : typeof me === 'string' + ? new mongo.ObjectID(me) + : (me as IUser)._id + : null; + + if (me) { + //#region Watchしているかどうか + const watch = await Watching.findOne({ + user_id: meId, + channel_id: _channel.id, + deleted_at: { $exists: false } + }); + + _channel.is_watching = watch !== null; + //#endregion + } + resolve(_channel); }); diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index ad254c98e5..57cedf10d4 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -4,6 +4,11 @@

{ channel.title }

+
+

このチャンネルをウォッチしています ウォッチ解除

+

このチャンネルをウォッチする

+
+