diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-15 16:43:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-16 16:41:36 +0200 |
commit | 65b21c961c69c4a63c7c0c34be3d6d034a1176c7 (patch) | |
tree | 35ec4a16c90a1de99b2865fbabb368b683ca6c87 /client/src/app/shared | |
parent | b44164bb567fe7c9f65f1ac2908d44990a8ccc8e (diff) | |
download | PeerTube-65b21c961c69c4a63c7c0c34be3d6d034a1176c7.tar.gz PeerTube-65b21c961c69c4a63c7c0c34be3d6d034a1176c7.tar.zst PeerTube-65b21c961c69c4a63c7c0c34be3d6d034a1176c7.zip |
Add ability to mute a user/instance by server in client
Diffstat (limited to 'client/src/app/shared')
5 files changed, 185 insertions, 24 deletions
diff --git a/client/src/app/shared/account/account.model.ts b/client/src/app/shared/account/account.model.ts index 0aba9428a..c5cd2051c 100644 --- a/client/src/app/shared/account/account.model.ts +++ b/client/src/app/shared/account/account.model.ts | |||
@@ -5,8 +5,10 @@ export class Account extends Actor implements ServerAccount { | |||
5 | displayName: string | 5 | displayName: string |
6 | description: string | 6 | description: string |
7 | nameWithHost: string | 7 | nameWithHost: string |
8 | muted: boolean | 8 | mutedByUser: boolean |
9 | mutedServer: boolean | 9 | mutedByInstance: boolean |
10 | mutedServerByUser: boolean | ||
11 | mutedServerByInstance: boolean | ||
10 | 12 | ||
11 | userId?: number | 13 | userId?: number |
12 | 14 | ||
@@ -18,7 +20,9 @@ export class Account extends Actor implements ServerAccount { | |||
18 | this.userId = hash.userId | 20 | this.userId = hash.userId |
19 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) | 21 | this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) |
20 | 22 | ||
21 | this.muted = false | 23 | this.mutedByUser = false |
22 | this.mutedServer = false | 24 | this.mutedByInstance = false |
25 | this.mutedServerByUser = false | ||
26 | this.mutedServerByInstance = false | ||
23 | } | 27 | } |
24 | } | 28 | } |
diff --git a/client/src/app/shared/blocklist/account-block.model.ts b/client/src/app/shared/blocklist/account-block.model.ts index 336680f65..e7b433d88 100644 --- a/client/src/app/shared/blocklist/account-block.model.ts +++ b/client/src/app/shared/blocklist/account-block.model.ts | |||
@@ -11,4 +11,4 @@ export class AccountBlock implements AccountBlockServer { | |||
11 | this.blockedAccount = new Account(block.blockedAccount) | 11 | this.blockedAccount = new Account(block.blockedAccount) |
12 | this.createdAt = block.createdAt | 12 | this.createdAt = block.createdAt |
13 | } | 13 | } |
14 | } \ No newline at end of file | 14 | } |
diff --git a/client/src/app/shared/blocklist/blocklist.service.ts b/client/src/app/shared/blocklist/blocklist.service.ts index d9c318258..c1f7312f0 100644 --- a/client/src/app/shared/blocklist/blocklist.service.ts +++ b/client/src/app/shared/blocklist/blocklist.service.ts | |||
@@ -11,6 +11,7 @@ import { AccountBlock } from '@app/shared/blocklist/account-block.model' | |||
11 | @Injectable() | 11 | @Injectable() |
12 | export class BlocklistService { | 12 | export class BlocklistService { |
13 | static BASE_USER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/users/me/blocklist' | 13 | static BASE_USER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/users/me/blocklist' |
14 | static BASE_SERVER_BLOCKLIST_URL = environment.apiUrl + '/api/v1/server/blocklist' | ||
14 | 15 | ||
15 | constructor ( | 16 | constructor ( |
16 | private authHttp: HttpClient, | 17 | private authHttp: HttpClient, |
@@ -73,6 +74,61 @@ export class BlocklistService { | |||
73 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 74 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
74 | } | 75 | } |
75 | 76 | ||
77 | /*********************** Instance -> Account blocklist ***********************/ | ||
78 | |||
79 | getInstanceAccountBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
80 | let params = new HttpParams() | ||
81 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
82 | |||
83 | return this.authHttp.get<ResultList<AccountBlock>>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', { params }) | ||
84 | .pipe( | ||
85 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
86 | map(res => this.restExtractor.applyToResultListData(res, this.formatAccountBlock.bind(this))), | ||
87 | catchError(err => this.restExtractor.handleError(err)) | ||
88 | ) | ||
89 | } | ||
90 | |||
91 | blockAccountByInstance (account: Account) { | ||
92 | const body = { accountName: account.nameWithHost } | ||
93 | |||
94 | return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts', body) | ||
95 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
96 | } | ||
97 | |||
98 | unblockAccountByInstance (account: Account) { | ||
99 | const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/accounts/' + account.nameWithHost | ||
100 | |||
101 | return this.authHttp.delete(path) | ||
102 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
103 | } | ||
104 | |||
105 | /*********************** Instance -> Server blocklist ***********************/ | ||
106 | |||
107 | getInstanceServerBlocklist (pagination: RestPagination, sort: SortMeta) { | ||
108 | let params = new HttpParams() | ||
109 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
110 | |||
111 | return this.authHttp.get<ResultList<ServerBlock>>(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', { params }) | ||
112 | .pipe( | ||
113 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | ||
114 | catchError(err => this.restExtractor.handleError(err)) | ||
115 | ) | ||
116 | } | ||
117 | |||
118 | blockServerByInstance (host: string) { | ||
119 | const body = { host } | ||
120 | |||
121 | return this.authHttp.post(BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers', body) | ||
122 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
123 | } | ||
124 | |||
125 | unblockServerByInstance (host: string) { | ||
126 | const path = BlocklistService.BASE_SERVER_BLOCKLIST_URL + '/servers/' + host | ||
127 | |||
128 | return this.authHttp.delete(path) | ||
129 | .pipe(catchError(err => this.restExtractor.handleError(err))) | ||
130 | } | ||
131 | |||
76 | private formatAccountBlock (accountBlock: AccountBlockServer) { | 132 | private formatAccountBlock (accountBlock: AccountBlockServer) { |
77 | return new AccountBlock(accountBlock) | 133 | return new AccountBlock(accountBlock) |
78 | } | 134 | } |
diff --git a/client/src/app/shared/blocklist/index.ts b/client/src/app/shared/blocklist/index.ts index 8cf6a55f7..5886ca07e 100644 --- a/client/src/app/shared/blocklist/index.ts +++ b/client/src/app/shared/blocklist/index.ts | |||
@@ -1,2 +1,2 @@ | |||
1 | export * from './blocklist.service' | 1 | export * from './blocklist.service' |
2 | export * from './account-block.model' \ No newline at end of file | 2 | export * from './account-block.model' |
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 | } |