Add ability to mute user when banning them

Implements https://github.com/Chocobozzz/PeerTube/issues/1803
This commit is contained in:
Poslovitch 2021-12-21 12:23:36 +00:00 committed by Chocobozzz
parent 0ff01f837b
commit 5a8de57d57
2 changed files with 31 additions and 2 deletions

View File

@ -21,6 +21,13 @@
A banned user will no longer be able to login.
</div>
<div class="form-group">
<my-peertube-checkbox
inputName="banMute" formControlName="mute"
i18n-labelText labelText="Mute this account"
></my-peertube-checkbox>
</div>
<div class="form-group inputs">
<input
type="button" role="button" i18n-value value="Cancel" class="peertube-button grey-button"

View File

@ -5,7 +5,9 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { User } from '@shared/models'
import { USER_BAN_REASON_VALIDATOR } from '../form-validators/user-validators'
import { Account } from '../shared-main'
import { UserAdminService } from '../shared-users'
import { BlocklistService } from './blocklist.service'
@Component({
selector: 'my-user-ban-modal',
@ -24,14 +26,16 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
protected formValidatorService: FormValidatorService,
private modalService: NgbModal,
private notifier: Notifier,
private userAdminService: UserAdminService
private userAdminService: UserAdminService,
private blocklistService: BlocklistService
) {
super()
}
ngOnInit () {
this.buildForm({
reason: USER_BAN_REASON_VALIDATOR
reason: USER_BAN_REASON_VALIDATOR,
mute: null
})
}
@ -50,6 +54,7 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
banUser () {
const reason = this.form.value['reason'] || undefined
const mute = this.form.value['mute']
this.userAdminService.banUsers(this.usersToBan, reason)
.subscribe({
@ -61,6 +66,23 @@ export class UserBanModalComponent extends FormReactive implements OnInit {
this.notifier.success(message)
this.userBanned.emit(this.usersToBan)
if (mute) {
const users = Array.isArray(this.usersToBan) ? this.usersToBan : [ this.usersToBan ]
users.forEach(user => {
const account = new Account(user.account)
this.blocklistService.blockAccountByInstance(account)
.subscribe({
next: () => {
this.notifier.success($localize`Account ${user.username} muted by the instance.`)
account.mutedByInstance = true
},
error: err => this.notifier.error(err.message)
})
})
}
this.hide()
},