summaryrefslogtreecommitdiff
path: root/src/services/note/polls
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-04-13 01:43:22 +0900
committerGitHub <noreply@github.com>2019-04-13 01:43:22 +0900
commit987168b863c52d0548050ffbac569782bb9a8cef (patch)
treec9aa2243dcdcbd044688d201a51c601574bff259 /src/services/note/polls
parentFix bug (diff)
downloadmisskey-987168b863c52d0548050ffbac569782bb9a8cef.tar.gz
misskey-987168b863c52d0548050ffbac569782bb9a8cef.tar.bz2
misskey-987168b863c52d0548050ffbac569782bb9a8cef.zip
strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
Diffstat (limited to 'src/services/note/polls')
-rw-r--r--src/services/note/polls/update.ts11
-rw-r--r--src/services/note/polls/vote.ts16
2 files changed, 12 insertions, 15 deletions
diff --git a/src/services/note/polls/update.ts b/src/services/note/polls/update.ts
index beb35cc278..277ace204d 100644
--- a/src/services/note/polls/update.ts
+++ b/src/services/note/polls/update.ts
@@ -7,8 +7,10 @@ import { Note } from '../../../models/entities/note';
export async function deliverQuestionUpdate(noteId: Note['id']) {
const note = await Notes.findOne(noteId);
+ if (note == null) throw 'note not found';
const user = await Users.findOne(note.userId);
+ if (user == null) throw 'note not found';
const followers = await Followings.find({
followeeId: user.id
@@ -19,13 +21,8 @@ export async function deliverQuestionUpdate(noteId: Note['id']) {
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
if (Users.isLocalUser(user)) {
for (const following of followers) {
- const follower = {
- inbox: following.followerInbox,
- sharedInbox: following.followerSharedInbox
- };
-
- if (following.followerHost !== null) {
- const inbox = follower.sharedInbox || follower.inbox;
+ if (Followings.isRemoteFollower(following)) {
+ const inbox = following.followerSharedInbox || following.followerInbox;
if (!queue.includes(inbox)) queue.push(inbox);
}
}
diff --git a/src/services/note/polls/vote.ts b/src/services/note/polls/vote.ts
index 3051ff42d9..3bae617b4f 100644
--- a/src/services/note/polls/vote.ts
+++ b/src/services/note/polls/vote.ts
@@ -7,11 +7,13 @@ import { Not } from 'typeorm';
import { genId } from '../../../misc/gen-id';
import { createNotification } from '../../create-notification';
-export default (user: User, note: Note, choice: number) => new Promise(async (res, rej) => {
+export default async function(user: User, note: Note, choice: number) {
const poll = await Polls.findOne({ noteId: note.id });
+ if (poll == null) throw 'poll not found';
+
// Check whether is valid choice
- if (poll.choices[choice] == null) return rej('invalid choice param');
+ if (poll.choices[choice] == null) throw new Error('invalid choice param');
// if already voted
const exist = await PollVotes.find({
@@ -21,10 +23,10 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
if (poll.multiple) {
if (exist.some(x => x.choice === choice)) {
- return rej('already voted');
+ throw new Error('already voted');
}
} else if (exist.length !== 0) {
- return rej('already voted');
+ throw new Error('already voted');
}
// Create vote
@@ -36,8 +38,6 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
choice: choice
});
- res();
-
// Increment votes count
const index = choice + 1; // In SQL, array index is 1 based
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
@@ -70,7 +70,7 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
const profile = await UserProfiles.findOne({ userId: user.id });
// ローカルユーザーが投票した場合この投稿をWatchする
- if (Users.isLocalUser(user) && profile.autoWatch) {
+ if (Users.isLocalUser(user) && profile!.autoWatch) {
watch(user.id, note);
}
-});
+}