cleanup: trim trailing whitespace (#11136)
* cleanup: trim trailing whitespace * update(`.editorconfig`) --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
@@ -39,12 +39,12 @@ export class PollService {
|
||||
@bindThis
|
||||
public async vote(user: User, note: Note, choice: number) {
|
||||
const poll = await this.pollsRepository.findOneBy({ noteId: note.id });
|
||||
|
||||
|
||||
if (poll == null) throw new Error('poll not found');
|
||||
|
||||
|
||||
// Check whether is valid choice
|
||||
if (poll.choices[choice] == null) throw new Error('invalid choice param');
|
||||
|
||||
|
||||
// Check blocking
|
||||
if (note.userId !== user.id) {
|
||||
const blocked = await this.userBlockingService.checkBlocked(note.userId, user.id);
|
||||
@@ -52,13 +52,13 @@ export class PollService {
|
||||
throw new Error('blocked');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if already voted
|
||||
const exist = await this.pollVotesRepository.findBy({
|
||||
noteId: note.id,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
|
||||
if (poll.multiple) {
|
||||
if (exist.some(x => x.choice === choice)) {
|
||||
throw new Error('already voted');
|
||||
@@ -66,7 +66,7 @@ export class PollService {
|
||||
} else if (exist.length !== 0) {
|
||||
throw new Error('already voted');
|
||||
}
|
||||
|
||||
|
||||
// Create vote
|
||||
await this.pollVotesRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
@@ -75,11 +75,11 @@ export class PollService {
|
||||
userId: user.id,
|
||||
choice: choice,
|
||||
});
|
||||
|
||||
|
||||
// Increment votes count
|
||||
const index = choice + 1; // In SQL, array index is 1 based
|
||||
await this.pollsRepository.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE "noteId" = '${poll.noteId}'`);
|
||||
|
||||
|
||||
this.globalEventService.publishNoteStream(note.id, 'pollVoted', {
|
||||
choice: choice,
|
||||
userId: user.id,
|
||||
@@ -90,10 +90,10 @@ export class PollService {
|
||||
public async deliverQuestionUpdate(noteId: Note['id']) {
|
||||
const note = await this.notesRepository.findOneBy({ id: noteId });
|
||||
if (note == null) throw new Error('note not found');
|
||||
|
||||
|
||||
const user = await this.usersRepository.findOneBy({ id: note.userId });
|
||||
if (user == null) throw new Error('note not found');
|
||||
|
||||
|
||||
if (this.userEntityService.isLocalUser(user)) {
|
||||
const content = this.apRendererService.addContext(this.apRendererService.renderUpdate(await this.apRendererService.renderNote(note, false), user));
|
||||
this.apDeliverManagerService.deliverToFollowers(user, content);
|
||||
|
Reference in New Issue
Block a user