aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-moderation/user-ban-modal.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-moderation/user-ban-modal.component.ts')
-rw-r--r--client/src/app/shared/shared-moderation/user-ban-modal.component.ts41
1 files changed, 21 insertions, 20 deletions
diff --git a/client/src/app/shared/shared-moderation/user-ban-modal.component.ts b/client/src/app/shared/shared-moderation/user-ban-modal.component.ts
index b3f03990f..9edfac388 100644
--- a/client/src/app/shared/shared-moderation/user-ban-modal.component.ts
+++ b/client/src/app/shared/shared-moderation/user-ban-modal.component.ts
@@ -1,3 +1,4 @@
1import { forkJoin } from 'rxjs'
1import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' 2import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2import { Notifier } from '@app/core' 3import { Notifier } from '@app/core'
3import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' 4import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
@@ -42,9 +43,6 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
42 openModal (user: User | User[]) { 43 openModal (user: User | User[]) {
43 this.usersToBan = user 44 this.usersToBan = user
44 this.openedModal = this.modalService.open(this.modal, { centered: true }) 45 this.openedModal = this.modalService.open(this.modal, { centered: true })
45
46 const isSingleUser = !(Array.isArray(this.usersToBan) && this.usersToBan.length > 1)
47 this.modalMessage = isSingleUser ? $localize`Ban this user` : $localize`Ban these users`
48 } 46 }
49 47
50 hide () { 48 hide () {
@@ -56,7 +54,13 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
56 const reason = this.form.value['reason'] || undefined 54 const reason = this.form.value['reason'] || undefined
57 const mute = this.form.value['mute'] 55 const mute = this.form.value['mute']
58 56
59 this.userAdminService.banUsers(this.usersToBan, reason) 57 const observables = [
58 this.userAdminService.banUsers(this.usersToBan, reason)
59 ]
60
61 if (mute) observables.push(this.muteAccounts())
62
63 forkJoin(observables)
60 .subscribe({ 64 .subscribe({
61 next: () => { 65 next: () => {
62 const message = Array.isArray(this.usersToBan) 66 const message = Array.isArray(this.usersToBan)
@@ -67,22 +71,6 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
67 71
68 this.userBanned.emit(this.usersToBan) 72 this.userBanned.emit(this.usersToBan)
69 73
70 if (mute) {
71 const users = Array.isArray(this.usersToBan) ? this.usersToBan : [ this.usersToBan ]
72 users.forEach(user => {
73 const account = new Account(user.account)
74 this.blocklistService.blockAccountByInstance(account)
75 .subscribe({
76 next: () => {
77 this.notifier.success($localize`Account ${user.username} muted by the instance.`)
78 account.mutedByInstance = true
79 },
80
81 error: err => this.notifier.error(err.message)
82 })
83 })
84 }
85
86 this.hide() 74 this.hide()
87 }, 75 },
88 76
@@ -90,4 +78,17 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
90 }) 78 })
91 } 79 }
92 80
81 getModalTitle () {
82 if (Array.isArray(this.usersToBan)) return $localize`Ban ${this.usersToBan.length} users`
83
84 return $localize`Ban "${this.usersToBan.username}"`
85 }
86
87 private muteAccounts () {
88 const accounts = Array.isArray(this.usersToBan)
89 ? this.usersToBan.map(u => new Account(u.account))
90 : new Account(this.usersToBan.account)
91
92 return this.blocklistService.blockAccountByInstance(accounts)
93 }
93} 94}