aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts')
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.ts137
1 files changed, 119 insertions, 18 deletions
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
index 2f4a55f37..908f0b8e0 100644
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
+++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
@@ -26,7 +26,7 @@ export class UserModerationDropdownComponent implements OnChanges {
26 @Output() userChanged = new EventEmitter() 26 @Output() userChanged = new EventEmitter()
27 @Output() userDeleted = new EventEmitter() 27 @Output() userDeleted = new EventEmitter()
28 28
29 userActions: DropdownAction<User>[] = [] 29 userActions: DropdownAction<{ user: User, account: Account }>[] = []
30 30
31 constructor ( 31 constructor (
32 private authService: AuthService, 32 private authService: AuthService,
@@ -106,7 +106,7 @@ export class UserModerationDropdownComponent implements OnChanges {
106 this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) 106 this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost })
107 ) 107 )
108 108
109 this.account.muted = true 109 this.account.mutedByUser = true
110 this.userChanged.emit() 110 this.userChanged.emit()
111 }, 111 },
112 112
@@ -123,7 +123,7 @@ export class UserModerationDropdownComponent implements OnChanges {
123 this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) 123 this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost })
124 ) 124 )
125 125
126 this.account.muted = false 126 this.account.mutedByUser = false
127 this.userChanged.emit() 127 this.userChanged.emit()
128 }, 128 },
129 129
@@ -140,7 +140,7 @@ export class UserModerationDropdownComponent implements OnChanges {
140 this.i18n('Instance {{host}} muted.', { host }) 140 this.i18n('Instance {{host}} muted.', { host })
141 ) 141 )
142 142
143 this.account.mutedServer = true 143 this.account.mutedServerByUser = true
144 this.userChanged.emit() 144 this.userChanged.emit()
145 }, 145 },
146 146
@@ -157,7 +157,75 @@ export class UserModerationDropdownComponent implements OnChanges {
157 this.i18n('Instance {{host}} unmuted.', { host }) 157 this.i18n('Instance {{host}} unmuted.', { host })
158 ) 158 )
159 159
160 this.account.mutedServer = false 160 this.account.mutedServerByUser = false
161 this.userChanged.emit()
162 },
163
164 err => this.notificationsService.error(this.i18n('Error'), err.message)
165 )
166 }
167
168 blockAccountByInstance (account: Account) {
169 this.blocklistService.blockAccountByInstance(account)
170 .subscribe(
171 () => {
172 this.notificationsService.success(
173 this.i18n('Success'),
174 this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })
175 )
176
177 this.account.mutedByInstance = true
178 this.userChanged.emit()
179 },
180
181 err => this.notificationsService.error(this.i18n('Error'), err.message)
182 )
183 }
184
185 unblockAccountByInstance (account: Account) {
186 this.blocklistService.unblockAccountByInstance(account)
187 .subscribe(
188 () => {
189 this.notificationsService.success(
190 this.i18n('Success'),
191 this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost })
192 )
193
194 this.account.mutedByInstance = false
195 this.userChanged.emit()
196 },
197
198 err => this.notificationsService.error(this.i18n('Error'), err.message)
199 )
200 }
201
202 blockServerByInstance (host: string) {
203 this.blocklistService.blockServerByInstance(host)
204 .subscribe(
205 () => {
206 this.notificationsService.success(
207 this.i18n('Success'),
208 this.i18n('Instance {{host}} muted by the instance.', { host })
209 )
210
211 this.account.mutedServerByInstance = true
212 this.userChanged.emit()
213 },
214
215 err => this.notificationsService.error(this.i18n('Error'), err.message)
216 )
217 }
218
219 unblockServerByInstance (host: string) {
220 this.blocklistService.unblockServerByInstance(host)
221 .subscribe(
222 () => {
223 this.notificationsService.success(
224 this.i18n('Success'),
225 this.i18n('Instance {{host}} unmuted by the instance.', { host })
226 )
227
228 this.account.mutedServerByInstance = false
161 this.userChanged.emit() 229 this.userChanged.emit()
162 }, 230 },
163 231
@@ -189,41 +257,74 @@ export class UserModerationDropdownComponent implements OnChanges {
189 }, 257 },
190 { 258 {
191 label: this.i18n('Ban'), 259 label: this.i18n('Ban'),
192 handler: ({ user }) => this.openBanUserModal(user), 260 handler: ({ user }: { user: User }) => this.openBanUserModal(user),
193 isDisplayed: ({ user }) => !user.muted 261 isDisplayed: ({ user }: { user: User }) => !user.blocked
194 }, 262 },
195 { 263 {
196 label: this.i18n('Unban'), 264 label: this.i18n('Unban'),
197 handler: ({ user }) => this.unbanUser(user), 265 handler: ({ user }: { user: User }) => this.unbanUser(user),
198 isDisplayed: ({ user }) => user.muted 266 isDisplayed: ({ user }: { user: User }) => user.blocked
199 } 267 }
200 ]) 268 ])
201 } 269 }
202 270
203 // User actions on accounts/servers 271 // Actions on accounts/servers
204 if (this.account) { 272 if (this.account) {
273 // User actions
205 this.userActions = this.userActions.concat([ 274 this.userActions = this.userActions.concat([
206 { 275 {
207 label: this.i18n('Mute this account'), 276 label: this.i18n('Mute this account'),
208 isDisplayed: ({ account }) => account.muted === false, 277 isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === false,
209 handler: ({ account }) => this.blockAccountByUser(account) 278 handler: ({ account }: { account: Account }) => this.blockAccountByUser(account)
210 }, 279 },
211 { 280 {
212 label: this.i18n('Unmute this account'), 281 label: this.i18n('Unmute this account'),
213 isDisplayed: ({ account }) => account.muted === true, 282 isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === true,
214 handler: ({ account }) => this.unblockAccountByUser(account) 283 handler: ({ account }: { account: Account }) => this.unblockAccountByUser(account)
215 }, 284 },
216 { 285 {
217 label: this.i18n('Mute the instance'), 286 label: this.i18n('Mute the instance'),
218 isDisplayed: ({ account }) => !account.userId && account.mutedServer === false, 287 isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false,
219 handler: ({ account }) => this.blockServerByUser(account.host) 288 handler: ({ account }: { account: Account }) => this.blockServerByUser(account.host)
220 }, 289 },
221 { 290 {
222 label: this.i18n('Unmute the instance'), 291 label: this.i18n('Unmute the instance'),
223 isDisplayed: ({ account }) => !account.userId && account.mutedServer === true, 292 isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true,
224 handler: ({ account }) => this.unblockServerByUser(account.host) 293 handler: ({ account }: { account: Account }) => this.unblockServerByUser(account.host)
225 } 294 }
226 ]) 295 ])
296
297 // Instance actions
298 if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
299 this.userActions = this.userActions.concat([
300 {
301 label: this.i18n('Mute this account by your instance'),
302 isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === false,
303 handler: ({ account }: { account: Account }) => this.blockAccountByInstance(account)
304 },
305 {
306 label: this.i18n('Unmute this account by your instance'),
307 isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === true,
308 handler: ({ account }: { account: Account }) => this.unblockAccountByInstance(account)
309 }
310 ])
311 }
312
313 // Instance actions
314 if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
315 this.userActions = this.userActions.concat([
316 {
317 label: this.i18n('Mute the instance by your instance'),
318 isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false,
319 handler: ({ account }: { account: Account }) => this.blockServerByInstance(account.host)
320 },
321 {
322 label: this.i18n('Unmute the instance by your instance'),
323 isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true,
324 handler: ({ account }: { account: Account }) => this.unblockServerByInstance(account.host)
325 }
326 ])
327 }
227 } 328 }
228 } 329 }
229 } 330 }