1
0
forked from mirror/misskey

APからには不要な処理を削除

This commit is contained in:
mei23 2019-01-21 05:41:52 +09:00
parent a8265d1e49
commit 8b5d8af9b0

View File

@ -1,11 +1,6 @@
import Vote from '../../../models/poll-vote'; import Vote from '../../../models/poll-vote';
import Note, { INote } from '../../../models/note'; import Note, { INote } from '../../../models/note';
import Watching from '../../../models/note-watching'; import { IUser } from '../../../models/user';
import watch from '../../../services/note/watch';
import { publishNoteStream } from '../../../stream';
import notify from '../../../notify';
import createNote from '../../../services/note/create';
import { isLocalUser, IUser } from '../../../models/user';
export default (user: IUser, note: INote, choice: number) => new Promise(async (res, rej) => { export default (user: IUser, note: INote, choice: number) => new Promise(async (res, rej) => {
if (!note.poll.choices.some(x => x.id == choice)) return rej('invalid choice param'); if (!note.poll.choices.some(x => x.id == choice)) return rej('invalid choice param');
@ -38,50 +33,4 @@ export default (user: IUser, note: INote, choice: number) => new Promise(async (
await Note.update({ _id: note._id }, { await Note.update({ _id: note._id }, {
$inc: inc $inc: inc
}); });
publishNoteStream(note._id, 'pollVoted', {
choice: choice,
userId: user._id.toHexString()
});
// Notify
notify(note.userId, user._id, 'poll_vote', {
noteId: note._id,
choice: choice
});
// Fetch watchers
Watching
.find({
noteId: note._id,
userId: { $ne: user._id },
// 削除されたドキュメントは除く
deletedAt: { $exists: false }
}, {
fields: {
userId: true
}
})
.then(watchers => {
for (const watcher of watchers) {
notify(watcher.userId, user._id, 'poll_vote', {
noteId: note._id,
choice: choice
});
}
});
// ローカルユーザーが投票した場合この投稿をWatchする
if (isLocalUser(user) && user.settings.autoWatch !== false) {
watch(user._id, note);
}
// ローカルからリモートへの投票の場合リプライ送信
if (isLocalUser(user) && note._user.host != null) {
createNote(user, {
createdAt: new Date(),
text: choice.toString(),
reply: note,
});
}
}); });