From ceda2ca89661d1bd3889453997fe0868a8c31e9d Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 May 2018 14:39:46 +0900 Subject: Implement delete note --- src/server/api/endpoints/notes/delete.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/server/api/endpoints/notes/delete.ts (limited to 'src/server/api/endpoints/notes') diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts new file mode 100644 index 0000000000..9bbb1541d6 --- /dev/null +++ b/src/server/api/endpoints/notes/delete.ts @@ -0,0 +1,26 @@ +import $ from 'cafy'; import ID from '../../../../cafy-id'; +import Note from '../../../../models/note'; +import deleteNote from '../../../../services/note/delete'; + +/** + * Delete a note + */ +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'noteId' parameter + const [noteId, noteIdErr] = $.type(ID).get(params.noteId); + if (noteIdErr) return rej('invalid noteId param'); + + // Fetch note + const note = await Note.findOne({ + _id: noteId, + userId: user._id + }); + + if (note === null) { + return rej('note not found'); + } + + await deleteNote(user, note); + + res(); +}); -- cgit v1.2.3-freya From 3f9e5fffbe2418c906e567b4922fa3ac3571984c Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 May 2018 21:43:21 +0900 Subject: Fix bug --- src/server/api/endpoints/notes/local-timeline.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/server/api/endpoints/notes') diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index e7ebe5d960..64118e1f14 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -57,6 +57,9 @@ module.exports = async (params, user, app) => { $nin: mutedUserIds }, + // public only + visibility: 'public', + // local '_user.host': null } as any; -- cgit v1.2.3-freya From 43eb8bd99b09532b76de30b257bf02f47525fe69 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 May 2018 21:59:57 +0900 Subject: notes/local-timeline と notes/global-timeline のサインインを不要に MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints.ts | 2 -- src/server/api/endpoints/notes/global-timeline.ts | 28 ++++++++++++-------- src/server/api/endpoints/notes/local-timeline.ts | 31 +++++++++++++---------- 3 files changed, 34 insertions(+), 27 deletions(-) (limited to 'src/server/api/endpoints/notes') diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts index 908d9574a5..c1ac4777b6 100644 --- a/src/server/api/endpoints.ts +++ b/src/server/api/endpoints.ts @@ -515,7 +515,6 @@ const endpoints: Endpoint[] = [ }, { name: 'notes/local-timeline', - withCredential: true, limit: { duration: ms('10minutes'), max: 100 @@ -523,7 +522,6 @@ const endpoints: Endpoint[] = [ }, { name: 'notes/global-timeline', - withCredential: true, limit: { duration: ms('10minutes'), max: 100 diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts index d22a1763de..7cf06c3af1 100644 --- a/src/server/api/endpoints/notes/global-timeline.ts +++ b/src/server/api/endpoints/notes/global-timeline.ts @@ -9,7 +9,7 @@ import { pack } from '../../../../models/note'; /** * Get timeline of global */ -module.exports = async (params, user, app) => { +module.exports = async (params, user) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; @@ -36,9 +36,9 @@ module.exports = async (params, user, app) => { } // ミュートしているユーザーを取得 - const mutedUserIds = (await Mute.find({ + const mutedUserIds = user ? (await Mute.find({ muterId: user._id - })).map(m => m.muteeId); + })).map(m => m.muteeId) : null; //#region Construct query const sort = { @@ -46,17 +46,23 @@ module.exports = async (params, user, app) => { }; const query = { - // mute - userId: { + // public only + visibility: 'public' + } as any; + + if (mutedUserIds && mutedUserIds.length > 0) { + query.userId = { $nin: mutedUserIds - }, - '_reply.userId': { + }; + + query['_reply.userId'] = { $nin: mutedUserIds - }, - '_renote.userId': { + }; + + query['_renote.userId'] = { $nin: mutedUserIds - } - } as any; + }; + } if (sinceId) { sort._id = 1; diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index 64118e1f14..7d01de3d43 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -9,7 +9,7 @@ import { pack } from '../../../../models/note'; /** * Get timeline of local */ -module.exports = async (params, user, app) => { +module.exports = async (params, user) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; @@ -36,9 +36,9 @@ module.exports = async (params, user, app) => { } // ミュートしているユーザーを取得 - const mutedUserIds = (await Mute.find({ + const mutedUserIds = user ? (await Mute.find({ muterId: user._id - })).map(m => m.muteeId); + })).map(m => m.muteeId) : null; //#region Construct query const sort = { @@ -46,17 +46,6 @@ module.exports = async (params, user, app) => { }; const query = { - // mute - userId: { - $nin: mutedUserIds - }, - '_reply.userId': { - $nin: mutedUserIds - }, - '_renote.userId': { - $nin: mutedUserIds - }, - // public only visibility: 'public', @@ -64,6 +53,20 @@ module.exports = async (params, user, app) => { '_user.host': null } as any; + if (mutedUserIds && mutedUserIds.length > 0) { + query.userId = { + $nin: mutedUserIds + }; + + query['_reply.userId'] = { + $nin: mutedUserIds + }; + + query['_renote.userId'] = { + $nin: mutedUserIds + }; + } + if (sinceId) { sort._id = 1; query._id = { -- cgit v1.2.3-freya From bd1f3a2f0196214248e8a259f8aacfe3e8259c19 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 29 May 2018 00:36:52 +0900 Subject: #1579 --- src/models/note.ts | 1 + src/server/api/endpoints/notes/replies.ts | 26 +++----------------------- src/services/note/create.ts | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src/server/api/endpoints/notes') diff --git a/src/models/note.ts b/src/models/note.ts index 5d7bab3833..ad8c1565f0 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -77,6 +77,7 @@ export type INote = { host: string; inbox?: string; }; + _replyIds?: mongo.ObjectID[]; }; /** diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 11d221d8f7..7261d3dbf6 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -1,15 +1,8 @@ -/** - * Module dependencies - */ import $ from 'cafy'; import ID from '../../../../cafy-id'; import Note, { pack } from '../../../../models/note'; /** - * Show a replies of a note - * - * @param {any} params - * @param {any} user - * @return {Promise} + * GEt replies of a note */ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'noteId' parameter @@ -24,10 +17,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); - // Get 'sort' parameter - const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort); - if (sortError) return rej('invalid sort param'); - // Lookup note const note = await Note.findOne({ _id: noteId @@ -37,17 +26,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('note not found'); } - // Issue query - const replies = await Note - .find({ replyId: note._id }, { - limit: limit, - skip: offset, - sort: { - _id: sort == 'asc' ? 1 : -1 - } - }); + const ids = note._replyIds.slice(offset, offset + limit); // Serialize - res(await Promise.all(replies.map(async note => - await pack(note, user)))); + res(await Promise.all(ids.map(id => pack(id, user)))); }); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index b9ff1f679b..37d21fecad 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -172,6 +172,24 @@ export default async (user: IUser, data: { } }); + if (data.reply) { + Note.update({ _id: data.reply._id }, { + $push: { + _replyIds: note._id + } + }); + } + + const isQuote = data.renote && (data.text || data.poll || data.media); + + if (isQuote) { + Note.update({ _id: data.renote._id }, { + $push: { + _quoteIds: note._id + } + }); + } + // Serialize const noteObj = await pack(note); -- cgit v1.2.3-freya From 973b1e42ef41e842cecce2a11f6b8dd8b50f767b Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 29 May 2018 00:38:07 +0900 Subject: typo --- src/server/api/endpoints/notes/replies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/api/endpoints/notes') diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 7261d3dbf6..f407f3bd56 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import Note, { pack } from '../../../../models/note'; /** - * GEt replies of a note + * Get replies of a note */ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'noteId' parameter -- cgit v1.2.3-freya From a0a4ce4dd9d649839da7862e206f47d1c27de2c2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 29 May 2018 11:25:28 +0900 Subject: Fix bug --- src/server/api/endpoints/notes/replies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/api/endpoints/notes') diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index f407f3bd56..608027f6b1 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -26,7 +26,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('note not found'); } - const ids = note._replyIds.slice(offset, offset + limit); + const ids = (note._replyIds || []).slice(offset, offset + limit); // Serialize res(await Promise.all(ids.map(id => pack(id, user)))); -- cgit v1.2.3-freya From be9f836b21c3d7dc1b315fa305caf17f04c139c4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 7 Jun 2018 06:13:57 +0900 Subject: やった MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja.yml | 1 + .../app/desktop/views/pages/deck/deck.column.vue | 17 +++++++- .../app/desktop/views/pages/deck/deck.list-tl.vue | 15 +++++++ .../views/pages/deck/deck.notifications-column.vue | 17 +++++--- .../desktop/views/pages/deck/deck.tl-column.vue | 50 +++++++++++++++++++--- .../app/desktop/views/pages/deck/deck.tl.vue | 15 +++++++ src/client/app/desktop/views/pages/deck/deck.vue | 2 +- .../views/pages/deck/deck.widgets-column.vue | 11 ++++- src/client/app/store.ts | 11 +++++ src/server/api/endpoints/notes/global-timeline.ts | 8 ++++ src/server/api/endpoints/notes/local-timeline.ts | 8 ++++ src/server/api/endpoints/notes/timeline.ts | 10 +++++ .../api/endpoints/notes/user-list-timeline.ts | 10 +++++ 13 files changed, 159 insertions(+), 16 deletions(-) (limited to 'src/server/api/endpoints/notes') diff --git a/locales/ja.yml b/locales/ja.yml index 8e04d0988f..320da8e777 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -87,6 +87,7 @@ common: swap-right: "右に移動" remove: "カラムを削除" add-column: "カラムを追加" + rename: "名前を変更" common/views/components/connect-failed.vue: title: "サーバーに接続できません" diff --git a/src/client/app/desktop/views/pages/deck/deck.column.vue b/src/client/app/desktop/views/pages/deck/deck.column.vue index f71503d5c1..10005fa9b0 100644 --- a/src/client/app/desktop/views/pages/deck/deck.column.vue +++ b/src/client/app/desktop/views/pages/deck/deck.column.vue @@ -20,6 +20,10 @@ export default Vue.extend({ type: String, required: false }, + name: { + type: String, + required: false + }, menu: { type: Array, required: false @@ -75,6 +79,17 @@ export default Vue.extend({ showMenu() { const items = [{ + content: '%fa:pencil-alt% %i18n:common.deck.rename%', + onClick: () => { + (this as any).apis.input({ + title: '%i18n:common.deck.rename%', + default: this.name, + allowEmpty: false + }).then(name => { + this.$store.dispatch('settings/renameDeckColumn', { id: this.id, name }); + }); + } + }, null, { content: '%fa:arrow-left% %i18n:common.deck.swap-left%', onClick: () => { this.$store.dispatch('settings/swapLeftDeckColumn', this.id); @@ -84,7 +99,7 @@ export default Vue.extend({ onClick: () => { this.$store.dispatch('settings/swapRightDeckColumn', this.id); } - }, { + }, null, { content: '%fa:trash-alt R% %i18n:common.deck.remove%', onClick: () => { this.$store.dispatch('settings/removeDeckColumn', this.id); diff --git a/src/client/app/desktop/views/pages/deck/deck.list-tl.vue b/src/client/app/desktop/views/pages/deck/deck.list-tl.vue index 7b5e76ffec..ee4e89747b 100644 --- a/src/client/app/desktop/views/pages/deck/deck.list-tl.vue +++ b/src/client/app/desktop/views/pages/deck/deck.list-tl.vue @@ -18,6 +18,11 @@ export default Vue.extend({ list: { type: Object, required: true + }, + mediaOnly: { + type: Boolean, + required: false, + default: false } }, @@ -30,6 +35,12 @@ export default Vue.extend({ }; }, + watch: { + mediaOnly() { + this.fetch(); + } + }, + mounted() { if (this.connection) this.connection.close(); this.connection = new UserListStream((this as any).os, this.$store.state.i, this.list.id); @@ -52,6 +63,7 @@ export default Vue.extend({ (this as any).api('notes/user-list-timeline', { listId: this.list.id, limit: fetchLimit + 1, + mediaOnly: this.mediaOnly, includeMyRenotes: this.$store.state.settings.showMyRenotes, includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes }).then(notes => { @@ -72,6 +84,7 @@ export default Vue.extend({ listId: this.list.id, limit: fetchLimit + 1, untilId: (this.$refs.timeline as any).tail().id, + mediaOnly: this.mediaOnly, includeMyRenotes: this.$store.state.settings.showMyRenotes, includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes }); @@ -89,6 +102,8 @@ export default Vue.extend({ return promise; }, onNote(note) { + if (this.mediaOnly && note.media.length == 0) return; + // Prepend a note (this.$refs.timeline as any).prepend(note); }, diff --git a/src/client/app/desktop/views/pages/deck/deck.notifications-column.vue b/src/client/app/desktop/views/pages/deck/deck.notifications-column.vue index f57c52d2e1..e01f91c24d 100644 --- a/src/client/app/desktop/views/pages/deck/deck.notifications-column.vue +++ b/src/client/app/desktop/views/pages/deck/deck.notifications-column.vue @@ -1,7 +1,7 @@