diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 3ced4dafe..2a8cfebb5 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -167,6 +167,7 @@ common: local: "ローカル" hybrid: "ソーシャル" global: "グローバル" + mentions: "あなた宛て" notifications: "通知" list: "リスト" swap-left: "左に移動" @@ -913,6 +914,7 @@ desktop/views/components/timeline.vue: local: "ローカル" hybrid: "ソーシャル" global: "グローバル" + mentions: "あなた宛て" list: "リスト" desktop/views/components/ui.header.vue: @@ -1314,6 +1316,7 @@ mobile/views/pages/home.vue: local: "ローカル" hybrid: "ソーシャル" global: "グローバル" + mentions: "あなた宛て" mobile/views/pages/tag.vue: no-posts-found: "ハッシュタグ「{}」が付けられた投稿は見つかりませんでした。" diff --git a/src/client/app/desktop/views/components/timeline.core.vue b/src/client/app/desktop/views/components/timeline.core.vue index 25fd5d36a..b6b5cca81 100644 --- a/src/client/app/desktop/views/components/timeline.core.vue +++ b/src/client/app/desktop/views/components/timeline.core.vue @@ -48,6 +48,7 @@ export default Vue.extend({ case 'local': return (this as any).os.streams.localTimelineStream; case 'hybrid': return (this as any).os.streams.hybridTimelineStream; case 'global': return (this as any).os.streams.globalTimelineStream; + case 'mentions': return (this as any).os.stream; } }, @@ -57,6 +58,7 @@ export default Vue.extend({ case 'local': return 'notes/local-timeline'; case 'hybrid': return 'notes/hybrid-timeline'; case 'global': return 'notes/global-timeline'; + case 'mentions': return 'notes/mentions'; } }, @@ -69,7 +71,7 @@ export default Vue.extend({ this.connection = this.stream.getConnection(); this.connectionId = this.stream.use(); - this.connection.on('note', this.onNote); + this.connection.on(this.src == 'mentions' ? 'mention' : 'note', this.onNote); if (this.src == 'home') { this.connection.on('follow', this.onChangeFollowing); this.connection.on('unfollow', this.onChangeFollowing); @@ -81,7 +83,7 @@ export default Vue.extend({ }, beforeDestroy() { - this.connection.off('note', this.onNote); + this.connection.off(this.src == 'mentions' ? 'mention' : 'note', this.onNote); if (this.src == 'home') { this.connection.off('follow', this.onChangeFollowing); this.connection.off('unfollow', this.onChangeFollowing); diff --git a/src/client/app/desktop/views/components/timeline.vue b/src/client/app/desktop/views/components/timeline.vue index 8d72016f2..3e51d1288 100644 --- a/src/client/app/desktop/views/components/timeline.vue +++ b/src/client/app/desktop/views/components/timeline.vue @@ -5,6 +5,7 @@ %fa:R comments% %i18n:@local% %fa:share-alt% %i18n:@hybrid% %fa:globe% %i18n:@global% + %fa:at% %i18n:@mentions% %fa:list% {{ list.title }} @@ -12,6 +13,7 @@ + diff --git a/src/client/app/mobile/views/pages/home.timeline.vue b/src/client/app/mobile/views/pages/home.timeline.vue index 416b006cd..d4fcea1f9 100644 --- a/src/client/app/mobile/views/pages/home.timeline.vue +++ b/src/client/app/mobile/views/pages/home.timeline.vue @@ -47,6 +47,7 @@ export default Vue.extend({ case 'local': return (this as any).os.streams.localTimelineStream; case 'hybrid': return (this as any).os.streams.hybridTimelineStream; case 'global': return (this as any).os.streams.globalTimelineStream; + case 'mentions': return (this as any).os.stream; } }, @@ -56,6 +57,7 @@ export default Vue.extend({ case 'local': return 'notes/local-timeline'; case 'hybrid': return 'notes/hybrid-timeline'; case 'global': return 'notes/global-timeline'; + case 'mentions': return 'notes/mentions'; } }, @@ -68,7 +70,7 @@ export default Vue.extend({ this.connection = this.stream.getConnection(); this.connectionId = this.stream.use(); - this.connection.on('note', this.onNote); + this.connection.on(this.src == 'mentions' ? 'mention' : 'note', this.onNote); if (this.src == 'home') { this.connection.on('follow', this.onChangeFollowing); this.connection.on('unfollow', this.onChangeFollowing); @@ -78,7 +80,7 @@ export default Vue.extend({ }, beforeDestroy() { - this.connection.off('note', this.onNote); + this.connection.off(this.src == 'mentions' ? 'mention' : 'note', this.onNote); if (this.src == 'home') { this.connection.off('follow', this.onChangeFollowing); this.connection.off('unfollow', this.onChangeFollowing); diff --git a/src/client/app/mobile/views/pages/home.vue b/src/client/app/mobile/views/pages/home.vue index 333ca1a7a..3150bb02b 100644 --- a/src/client/app/mobile/views/pages/home.vue +++ b/src/client/app/mobile/views/pages/home.vue @@ -6,6 +6,7 @@ %fa:R comments%%i18n:@local% %fa:share-alt%%i18n:@hybrid% %fa:globe%%i18n:@global% + %fa:at%%i18n:@mentions% %fa:list%{{ list.title }} @@ -27,6 +28,7 @@ %fa:R comments% %i18n:@local% %fa:share-alt% %i18n:@hybrid% %fa:globe% %i18n:@global% + %fa:at% %i18n:@mentions% @@ -39,6 +41,7 @@ + diff --git a/src/models/note.ts b/src/models/note.ts index 6530d0b32..62b1b3ecb 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -17,6 +17,8 @@ import Following from './following'; const Note = db.get('notes'); Note.createIndex('uri', { sparse: true, unique: true }); Note.createIndex('userId'); +Note.createIndex('mentions'); +Note.createIndex('visibleUserIds'); Note.createIndex('tagsLower'); Note.createIndex('_files.contentType'); Note.createIndex({ diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index a7fb14d8a..3b2e262e4 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -3,6 +3,7 @@ import Note from '../../../../models/note'; import { getFriendIds } from '../../common/get-friends'; import { pack } from '../../../../models/note'; import { ILocalUser } from '../../../../models/user'; +import getParams from '../../get-params'; export const meta = { desc: { @@ -10,42 +11,48 @@ export const meta = { 'en-US': 'Get mentions of myself.' }, - requireCredential: true + requireCredential: true, + + params: { + following: $.bool.optional.note({ + default: false + }), + + limit: $.num.optional.range(1, 100).note({ + default: 10 + }), + + sinceId: $.type(ID).optional.note({ + }), + + untilId: $.type(ID).optional.note({ + }), + } }; export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { - // Get 'following' parameter - const [following = false, followingError] = - $.bool.optional.get(params.following); - if (followingError) return rej('invalid following param'); - - // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); - if (limitErr) return rej('invalid limit param'); - - // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); - if (sinceIdErr) return rej('invalid sinceId param'); - - // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); - if (untilIdErr) return rej('invalid untilId param'); + const [ps, psErr] = getParams(meta, params); + if (psErr) throw psErr; // Check if both of sinceId and untilId is specified - if (sinceId && untilId) { + if (ps.sinceId && ps.untilId) { return rej('cannot set sinceId and untilId'); } // Construct query const query = { - mentions: user._id + $or: [{ + mentions: user._id + }, { + visibleUserIds: user._id + }] } as any; const sort = { _id: -1 }; - if (following) { + if (ps.following) { const followingIds = await getFriendIds(user._id); query.userId = { @@ -53,26 +60,24 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = }; } - if (sinceId) { + if (ps.sinceId) { sort._id = 1; query._id = { - $gt: sinceId + $gt: ps.sinceId }; - } else if (untilId) { + } else if (ps.untilId) { query._id = { - $lt: untilId + $lt: ps.untilId }; } // Issue query const mentions = await Note .find(query, { - limit: limit, + limit: ps.limit, sort: sort }); // Serialize - res(await Promise.all(mentions.map(async mention => - await pack(mention, user) - ))); + res(await Promise.all(mentions.map(mention => pack(mention, user)))); }); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 771e9cade..aa65cfe0c 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -138,6 +138,10 @@ export default async (user: IUser, data: Option, silent = false) => new Promise< const mentionedUsers = await extractMentionedUsers(tokens); + if (data.reply && !user._id.equals(data.reply.userId) && !mentionedUsers.some(u => u._id.equals(data.reply.userId))) { + mentionedUsers.push(await User.findOne({ _id: data.reply.userId })); + } + const note = await insertNote(user, data, tags, mentionedUsers); res(note);