forked from FoundKeyGang/FoundKey
[API] お気に入り状態は投稿情報に含めないように統一
This commit is contained in:
parent
06707705bf
commit
c107333f56
3 changed files with 99 additions and 71 deletions
|
@ -15,48 +15,47 @@ import { faCopy } from '@fortawesome/free-regular-svg-icons';
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
i18n: i18n('common/views/components/note-menu.vue'),
|
i18n: i18n('common/views/components/note-menu.vue'),
|
||||||
props: ['note', 'source'],
|
props: ['note', 'source'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
isFavorited: false
|
||||||
|
};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
items(): any[] {
|
items(): any[] {
|
||||||
return concat(intersperse([null], [
|
return [{
|
||||||
[
|
|
||||||
[{
|
|
||||||
icon: 'at',
|
icon: 'at',
|
||||||
text: this.$t('mention'),
|
text: this.$t('mention'),
|
||||||
action: this.mention
|
action: this.mention
|
||||||
}]
|
}, null, {
|
||||||
],
|
|
||||||
[
|
|
||||||
[{
|
|
||||||
icon: 'info-circle',
|
icon: 'info-circle',
|
||||||
text: this.$t('detail'),
|
text: this.$t('detail'),
|
||||||
action: this.detail
|
action: this.detail
|
||||||
}], [{
|
}, {
|
||||||
icon: faCopy,
|
icon: faCopy,
|
||||||
text: this.$t('copy-content'),
|
text: this.$t('copy-content'),
|
||||||
action: this.copyContent
|
action: this.copyContent
|
||||||
}], [{
|
}, {
|
||||||
icon: 'link',
|
icon: 'link',
|
||||||
text: this.$t('copy-link'),
|
text: this.$t('copy-link'),
|
||||||
action: this.copyLink
|
action: this.copyLink
|
||||||
}], this.note.uri ? [{
|
}, this.note.uri ? {
|
||||||
icon: 'external-link-square-alt',
|
icon: 'external-link-square-alt',
|
||||||
text: this.$t('remote'),
|
text: this.$t('remote'),
|
||||||
action: () => {
|
action: () => {
|
||||||
window.open(this.note.uri, '_blank');
|
window.open(this.note.uri, '_blank');
|
||||||
}
|
}
|
||||||
}] : []
|
} : undefined,
|
||||||
],
|
null,
|
||||||
[
|
this.isFavorited ? {
|
||||||
this.note.isFavorited ? [{
|
|
||||||
icon: 'star',
|
icon: 'star',
|
||||||
text: this.$t('unfavorite'),
|
text: this.$t('unfavorite'),
|
||||||
action: this.unfavorite
|
action: this.unfavorite
|
||||||
}] : [{
|
} : {
|
||||||
icon: 'star',
|
icon: 'star',
|
||||||
text: this.$t('favorite'),
|
text: this.$t('favorite'),
|
||||||
action: this.favorite
|
action: this.favorite
|
||||||
}], this.note.userId == this.$store.state.i.id ? [
|
},
|
||||||
(this.$store.state.i.pinnedNoteIds || []).includes(this.note.id) ? {
|
this.note.userId == this.$store.state.i.id ? (this.$store.state.i.pinnedNoteIds || []).includes(this.note.id) ? {
|
||||||
icon: 'thumbtack',
|
icon: 'thumbtack',
|
||||||
text: this.$t('unpin'),
|
text: this.$t('unpin'),
|
||||||
action: this.unpin
|
action: this.unpin
|
||||||
|
@ -64,19 +63,24 @@ export default Vue.extend({
|
||||||
icon: 'thumbtack',
|
icon: 'thumbtack',
|
||||||
text: this.$t('pin'),
|
text: this.$t('pin'),
|
||||||
action: this.pin
|
action: this.pin
|
||||||
}
|
} : undefined,
|
||||||
] : []
|
null,
|
||||||
], [
|
this.note.userId == this.$store.state.i.id || this.$store.state.i.isAdmin || this.$store.state.i.isModerator ? {
|
||||||
this.note.userId == this.$store.state.i.id || this.$store.state.i.isAdmin || this.$store.state.i.isModerator ? [{
|
|
||||||
icon: ['far', 'trash-alt'],
|
icon: ['far', 'trash-alt'],
|
||||||
text: this.$t('delete'),
|
text: this.$t('delete'),
|
||||||
action: this.del
|
action: this.del
|
||||||
}] : []
|
} : undefined].filter(x => x !== undefined)
|
||||||
]
|
|
||||||
].map(concat).filter(x => x.length > 0)));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.$root.api('notes/state', {
|
||||||
|
noteId: this.note.id
|
||||||
|
}).then(state => {
|
||||||
|
this.isFavorited = state.isFavorited;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
mention() {
|
mention() {
|
||||||
this.$post({ mention: this.note.user });
|
this.$post({ mention: this.note.user });
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { pack as packApp } from './app';
|
||||||
import PollVote from './poll-vote';
|
import PollVote from './poll-vote';
|
||||||
import Reaction from './note-reaction';
|
import Reaction from './note-reaction';
|
||||||
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
||||||
import Favorite from './favorite';
|
|
||||||
import Following from './following';
|
import Following from './following';
|
||||||
import Emoji from './emoji';
|
import Emoji from './emoji';
|
||||||
|
|
||||||
|
@ -346,19 +345,6 @@ export const pack = async (
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// isFavorited
|
|
||||||
_note.isFavorited = (async () => {
|
|
||||||
const favorite = await Favorite
|
|
||||||
.count({
|
|
||||||
userId: meId,
|
|
||||||
noteId: id
|
|
||||||
}, {
|
|
||||||
limit: 1
|
|
||||||
});
|
|
||||||
|
|
||||||
return favorite === 1;
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
38
src/server/api/endpoints/notes/state.ts
Normal file
38
src/server/api/endpoints/notes/state.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
|
import define from '../../define';
|
||||||
|
import Favorite from '../../../../models/favorite';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
stability: 'stable',
|
||||||
|
|
||||||
|
desc: {
|
||||||
|
'ja-JP': '指定した投稿の状態を取得します。',
|
||||||
|
'en-US': 'Get state of a note.'
|
||||||
|
},
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
|
||||||
|
params: {
|
||||||
|
noteId: {
|
||||||
|
validator: $.type(ID),
|
||||||
|
transform: transform,
|
||||||
|
desc: {
|
||||||
|
'ja-JP': '対象の投稿のID',
|
||||||
|
'en-US': 'Target note ID.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||||
|
const favorite = await Favorite.count({
|
||||||
|
userId: user._id,
|
||||||
|
noteId: ps.noteId
|
||||||
|
}, {
|
||||||
|
limit: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
res({
|
||||||
|
isFavorited: favorite !== 0
|
||||||
|
});
|
||||||
|
}));
|
Loading…
Reference in a new issue