From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- .../+about/about-instance/contact-admin-modal.component.ts | 3 +-- client/src/app/+accounts/accounts.component.ts | 3 +-- .../+my-video-channels/my-video-channel-create.component.ts | 7 +++---- client/src/app/+page-not-found/page-not-found.component.ts | 3 ++- client/src/app/+video-channels/video-channels.component.ts | 2 +- .../video-add-components/video-upload.component.ts | 3 +-- client/src/app/+videos/+video-watch/video-watch.component.ts | 11 +++++++++-- client/src/app/core/auth/auth.service.ts | 3 +-- client/src/app/core/rest/rest-extractor.service.ts | 3 +-- client/src/app/helpers/utils.ts | 2 +- .../app/shared/shared-main/auth/auth-interceptor.service.ts | 8 ++++---- client/src/standalone/videos/embed.ts | 2 +- 12 files changed, 26 insertions(+), 24 deletions(-) (limited to 'client') diff --git a/client/src/app/+about/about-instance/contact-admin-modal.component.ts b/client/src/app/+about/about-instance/contact-admin-modal.component.ts index a528faa20..37e9feacb 100644 --- a/client/src/app/+about/about-instance/contact-admin-modal.component.ts +++ b/client/src/app/+about/about-instance/contact-admin-modal.component.ts @@ -11,8 +11,7 @@ import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { InstanceService } from '@app/shared/shared-instance' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { HTMLServerConfig } from '@shared/models' +import { HTMLServerConfig, HttpStatusCode } from '@shared/models' type Prefill = { subject?: string diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index c69b04a01..5b59f3cd0 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -13,8 +13,7 @@ import { VideoService } from '@app/shared/shared-main' import { AccountReportComponent } from '@app/shared/shared-moderation' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { User, UserRight } from '@shared/models' +import { HttpStatusCode, User, UserRight } from '@shared/models' import { AccountSearchComponent } from './account-search/account-search.component' @Component({ diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts index b3265210f..433475f66 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts +++ b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts @@ -1,3 +1,5 @@ +import { of } from 'rxjs' +import { switchMap } from 'rxjs/operators' import { Component, OnInit } from '@angular/core' import { Router } from '@angular/router' import { AuthService, Notifier } from '@app/core' @@ -9,11 +11,8 @@ import { } from '@app/shared/form-validators/video-channel-validators' import { FormValidatorService } from '@app/shared/shared-forms' import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' -import { VideoChannelCreate } from '@shared/models' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode, VideoChannelCreate } from '@shared/models' import { MyVideoChannelEdit } from './my-video-channel-edit' -import { switchMap } from 'rxjs/operators' -import { of } from 'rxjs' @Component({ templateUrl: './my-video-channel-edit.component.html', diff --git a/client/src/app/+page-not-found/page-not-found.component.ts b/client/src/app/+page-not-found/page-not-found.component.ts index 639e5db78..10645a634 100644 --- a/client/src/app/+page-not-found/page-not-found.component.ts +++ b/client/src/app/+page-not-found/page-not-found.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit } from '@angular/core' import { Title } from '@angular/platform-browser' import { Router } from '@angular/router' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' + @Component({ selector: 'my-page-not-found', templateUrl: './page-not-found.component.html', diff --git a/client/src/app/+video-channels/video-channels.component.ts b/client/src/app/+video-channels/video-channels.component.ts index 3833d9c54..6479644f1 100644 --- a/client/src/app/+video-channels/video-channels.component.ts +++ b/client/src/app/+video-channels/video-channels.component.ts @@ -7,7 +7,7 @@ import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService } import { ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' import { SupportModalComponent } from '@app/shared/shared-support-modal' import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' @Component({ templateUrl: './video-channels.component.html', diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index 627de33c0..e9420fe62 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts @@ -7,8 +7,7 @@ import { genericUploadErrorHandler, scrollToTop } from '@app/helpers' import { FormValidatorService } from '@app/shared/shared-forms' import { BytesPipe, Video, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' import { LoadingBarService } from '@ngx-loading-bar/core' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { UploaderXFormData } from './uploaderx-form-data' import { VideoSend } from './video-send' diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index d078844c3..7460ae3fc 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -21,8 +21,15 @@ import { isXPercentInViewport, scrollToTop } from '@app/helpers' import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main' import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { HTMLServerConfig, PeerTubeProblemDocument, ServerErrorCode, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' +import { + HTMLServerConfig, + HttpStatusCode, + PeerTubeProblemDocument, + ServerErrorCode, + VideoCaption, + VideoPrivacy, + VideoState +} from '@shared/models' import { cleanupVideoWatch, getStoredTheater, getStoredVideoWatchHistory } from '../../../assets/player/peertube-player-local-storage' import { CustomizationOptions, diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index cdf13186b..60bd72c60 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -6,12 +6,11 @@ import { Injectable } from '@angular/core' import { Router } from '@angular/router' import { Notifier } from '@app/core/notification/notifier.service' import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index' -import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' +import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' import { environment } from '../../../environments/environment' import { RestExtractor } from '../rest/rest-extractor.service' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' interface UserLoginWithUsername extends UserLogin { access_token: string diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts index 08ab49512..2a926e68f 100644 --- a/client/src/app/core/rest/rest-extractor.service.ts +++ b/client/src/app/core/rest/rest-extractor.service.ts @@ -2,8 +2,7 @@ import { throwError as observableThrowError } from 'rxjs' import { Injectable } from '@angular/core' import { Router } from '@angular/router' import { dateToHuman } from '@app/helpers' -import { ResultList } from '@shared/models' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode, ResultList } from '@shared/models' @Injectable() export class RestExtractor { diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts index 94f6def26..edcaf50e0 100644 --- a/client/src/app/helpers/utils.ts +++ b/client/src/app/helpers/utils.ts @@ -3,7 +3,7 @@ import { SelectChannelItem } from 'src/types/select-options-item.model' import { DatePipe } from '@angular/common' import { HttpErrorResponse } from '@angular/common/http' import { Notifier } from '@app/core' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { environment } from '../../environments/environment' import { AuthService } from '../core/auth' diff --git a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts index 5bcad36d0..a75c8a25c 100644 --- a/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts +++ b/client/src/app/shared/shared-main/auth/auth-interceptor.service.ts @@ -1,11 +1,11 @@ import { Observable, of, throwError as observableThrowError } from 'rxjs' import { catchError, switchMap } from 'rxjs/operators' -import { HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpErrorResponse } from '@angular/common/http' +import { HTTP_INTERCEPTORS, HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http' import { Injectable, Injector } from '@angular/core' -import { AuthService } from '@app/core/auth/auth.service' import { Router } from '@angular/router' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { OAuth2ErrorCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models/server' +import { AuthService } from '@app/core/auth/auth.service' +import { HttpStatusCode } from '@shared/models' +import { OAuth2ErrorCode, PeerTubeProblemDocument } from '@shared/models/server' @Injectable() export class AuthInterceptor implements HttpInterceptor { diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index e59d8b940..97437ce45 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -1,9 +1,9 @@ import './embed.scss' import videojs from 'video.js' import { peertubeTranslate } from '../../../../shared/core-utils/i18n' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HTMLServerConfig, + HttpStatusCode, OAuth2ErrorCode, ResultList, UserRefreshToken, -- cgit v1.2.3 From 01af646261264befde7ce6ca5130fd07c0b23aa1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 13:38:26 +0200 Subject: Channel deletion consistency --- .../app/+my-library/+my-video-channels/my-video-channels.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts index 67b3ee496..b6a2f592d 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts +++ b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts @@ -45,9 +45,9 @@ export class MyVideoChannelsComponent { It will delete ${videoChannel.videosCount} videos uploaded in this channel, and you will not be able to create another channel with the same name (${videoChannel.name})!`, - $localize`Please type the display name of the video channel (${videoChannel.displayName}) to confirm`, + $localize`Please type the name of the video channel (${videoChannel.name}) to confirm`, - videoChannel.displayName, + videoChannel.name, $localize`Delete` ) -- cgit v1.2.3 From 7f28f2ddbaeecf451d501e99ded0408c14a33600 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 13:47:49 +0200 Subject: Warning when using capitalized letter in login --- client/src/app/+login/login.component.html | 4 ++++ client/src/app/+login/login.component.ts | 4 ++++ client/src/sass/application.scss | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/src/app/+login/login.component.html b/client/src/app/+login/login.component.html index 5f5b0f565..27793ff0c 100644 --- a/client/src/app/+login/login.component.html +++ b/client/src/app/+login/login.component.html @@ -28,6 +28,10 @@
{{ formErrors.username }}
+ +
+ ⚠️ Most email addresses do not include capital letters. +
diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts index d8ad49081..9731383af 100644 --- a/client/src/app/+login/login.component.ts +++ b/client/src/app/+login/login.component.ts @@ -141,6 +141,10 @@ The link will expire within 1 hour.` this.accordion = instanceAboutAccordion.accordion } + hasUsernameUppercase () { + return this.form.value['username'].match(/[A-Z]/) + } + private loadExternalAuthToken (username: string, token: string) { this.isAuthenticatedWithExternalAuth = true diff --git a/client/src/sass/application.scss b/client/src/sass/application.scss index 30d487b11..bd834db70 100644 --- a/client/src/sass/application.scss +++ b/client/src/sass/application.scss @@ -123,12 +123,16 @@ code { vertical-align: middle; } -.form-error { +.form-error, +.form-warning { display: block; - color: $red; margin-top: 5px; } +.form-error { + color: $red; +} + .input-error, my-input-toggle-hidden ::ng-deep input { border-color: $red !important; -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- client/src/app/+admin/admin.component.ts | 4 +- client/src/app/+admin/admin.module.ts | 3 +- .../followers-list/followers-list.component.html | 4 +- .../following-list/follow-modal.component.html | 42 +++++++++ .../following-list/follow-modal.component.scss | 3 + .../following-list/follow-modal.component.ts | 69 ++++++++++++++ .../following-list/following-list.component.html | 21 ++--- .../following-list/following-list.component.ts | 22 ++--- .../src/app/+admin/follows/following-list/index.ts | 1 + client/src/app/+admin/follows/follows.routes.ts | 4 +- .../form-validators/batch-domains-validators.ts | 60 ------------ .../app/shared/form-validators/host-validators.ts | 105 +++++++++++++++++++++ client/src/app/shared/form-validators/host.ts | 8 -- client/src/app/shared/form-validators/index.ts | 1 - .../shared-instance/instance-follow.service.ts | 13 ++- .../batch-domains-modal.component.html | 14 +-- .../batch-domains-modal.component.ts | 8 +- 17 files changed, 260 insertions(+), 122 deletions(-) create mode 100644 client/src/app/+admin/follows/following-list/follow-modal.component.html create mode 100644 client/src/app/+admin/follows/following-list/follow-modal.component.scss create mode 100644 client/src/app/+admin/follows/following-list/follow-modal.component.ts delete mode 100644 client/src/app/shared/form-validators/batch-domains-validators.ts create mode 100644 client/src/app/shared/form-validators/host-validators.ts delete mode 100644 client/src/app/shared/form-validators/host.ts (limited to 'client') diff --git a/client/src/app/+admin/admin.component.ts b/client/src/app/+admin/admin.component.ts index dd92ed2ca..4b6fab6ed 100644 --- a/client/src/app/+admin/admin.component.ts +++ b/client/src/app/+admin/admin.component.ts @@ -26,12 +26,12 @@ export class AdminComponent implements OnInit { label: $localize`Federation`, children: [ { - label: $localize`Instances you follow`, + label: $localize`Following`, routerLink: '/admin/follows/following-list', iconName: 'following' }, { - label: $localize`Instances following you`, + label: $localize`Followers`, routerLink: '/admin/follows/followers-list', iconName: 'follower' }, diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index a7fe20b07..1ea7b9784 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -25,7 +25,7 @@ import { EditVODTranscodingComponent } from './config' import { ConfigService } from './config/shared/config.service' -import { FollowersListComponent, FollowsComponent, VideoRedundanciesListComponent } from './follows' +import { FollowersListComponent, FollowModalComponent, FollowsComponent, VideoRedundanciesListComponent } from './follows' import { FollowingListComponent } from './follows/following-list/following-list.component' import { RedundancyCheckboxComponent } from './follows/shared/redundancy-checkbox.component' import { VideoRedundancyInformationComponent } from './follows/video-redundancies-list/video-redundancy-information.component' @@ -68,6 +68,7 @@ import { UserCreateComponent, UserListComponent, UserPasswordComponent, UsersCom FollowsComponent, FollowersListComponent, FollowingListComponent, + FollowModalComponent, RedundancyCheckboxComponent, VideoRedundanciesListComponent, VideoRedundancyInformationComponent, diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.html b/client/src/app/+admin/follows/followers-list/followers-list.component.html index c2e9a4df6..08459634d 100644 --- a/client/src/app/+admin/follows/followers-list/followers-list.component.html +++ b/client/src/app/+admin/follows/followers-list/followers-list.component.html @@ -1,6 +1,6 @@

- Instances following you + Followers of your instance

Actions - Follower handle + Follower State Score Created diff --git a/client/src/app/+admin/follows/following-list/follow-modal.component.html b/client/src/app/+admin/follows/following-list/follow-modal.component.html new file mode 100644 index 000000000..d0761b718 --- /dev/null +++ b/client/src/app/+admin/follows/following-list/follow-modal.component.html @@ -0,0 +1,42 @@ + + + + + + diff --git a/client/src/app/+admin/follows/following-list/follow-modal.component.scss b/client/src/app/+admin/follows/following-list/follow-modal.component.scss new file mode 100644 index 000000000..9621a566f --- /dev/null +++ b/client/src/app/+admin/follows/following-list/follow-modal.component.scss @@ -0,0 +1,3 @@ +textarea { + height: 200px; +} diff --git a/client/src/app/+admin/follows/following-list/follow-modal.component.ts b/client/src/app/+admin/follows/following-list/follow-modal.component.ts new file mode 100644 index 000000000..dc6909200 --- /dev/null +++ b/client/src/app/+admin/follows/following-list/follow-modal.component.ts @@ -0,0 +1,69 @@ +import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' +import { Notifier } from '@app/core' +import { splitAndGetNotEmpty, UNIQUE_HOSTS_OR_HANDLE_VALIDATOR } from '@app/shared/form-validators/host-validators' +import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' +import { InstanceFollowService } from '@app/shared/shared-instance' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' + +@Component({ + selector: 'my-follow-modal', + templateUrl: './follow-modal.component.html', + styleUrls: [ './follow-modal.component.scss' ] +}) +export class FollowModalComponent extends FormReactive implements OnInit { + @ViewChild('modal', { static: true }) modal: NgbModal + + @Output() newFollow = new EventEmitter() + + placeholder = 'example.com\nchocobozzz@example.com\nchocobozzz_channel@example.com' + + private openedModal: NgbModalRef + + constructor ( + protected formValidatorService: FormValidatorService, + private modalService: NgbModal, + private followService: InstanceFollowService, + private notifier: Notifier + ) { + super() + } + + ngOnInit () { + this.buildForm({ + hostsOrHandles: UNIQUE_HOSTS_OR_HANDLE_VALIDATOR + }) + } + + openModal () { + this.openedModal = this.modalService.open(this.modal, { centered: true }) + } + + hide () { + this.openedModal.close() + } + + submit () { + this.addFollowing() + + this.form.reset() + this.hide() + } + + httpEnabled () { + return window.location.protocol === 'https:' + } + + private async addFollowing () { + const hostsOrHandles = splitAndGetNotEmpty(this.form.value['hostsOrHandles']) + + this.followService.follow(hostsOrHandles).subscribe( + () => { + this.notifier.success($localize`Follow request(s) sent!`) + this.newFollow.emit() + }, + + err => this.notifier.error(err.message) + ) + } +} diff --git a/client/src/app/+admin/follows/following-list/following-list.component.html b/client/src/app/+admin/follows/following-list/following-list.component.html index e7c0c9088..75b0efca8 100644 --- a/client/src/app/+admin/follows/following-list/following-list.component.html +++ b/client/src/app/+admin/follows/following-list/following-list.component.html @@ -1,6 +1,6 @@

- Instances you follow + Your instance subscriptions

@@ -28,7 +28,7 @@ Action - Host + Following State Created Redundancy allowed @@ -41,8 +41,8 @@ - - {{ follow.following.host }} + + {{ follow.following.name + '@' + follow.following.host }} @@ -57,6 +57,7 @@ {{ follow.createdAt | date: 'short' }} @@ -75,10 +76,4 @@ - - -
- It seems that you are not on a HTTPS server. Your webserver needs to have TLS activated in order to follow servers. -
-
-
+ diff --git a/client/src/app/+admin/follows/following-list/following-list.component.ts b/client/src/app/+admin/follows/following-list/following-list.component.ts index b63fe08c0..ba62dfa23 100644 --- a/client/src/app/+admin/follows/following-list/following-list.component.ts +++ b/client/src/app/+admin/follows/following-list/following-list.component.ts @@ -4,13 +4,14 @@ import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' import { InstanceFollowService } from '@app/shared/shared-instance' import { BatchDomainsModalComponent } from '@app/shared/shared-moderation' import { ActorFollow } from '@shared/models' +import { FollowModalComponent } from './follow-modal.component' @Component({ templateUrl: './following-list.component.html', styleUrls: [ '../follows.component.scss', './following-list.component.scss' ] }) export class FollowingListComponent extends RestTable implements OnInit { - @ViewChild('batchDomainsModal') batchDomainsModal: BatchDomainsModalComponent + @ViewChild('followModal') followModal: FollowModalComponent following: ActorFollow[] = [] totalRecords = 0 @@ -33,23 +34,12 @@ export class FollowingListComponent extends RestTable implements OnInit { return 'FollowingListComponent' } - addDomainsToFollow () { - this.batchDomainsModal.openModal() + openFollowModal () { + this.followModal.openModal() } - httpEnabled () { - return window.location.protocol === 'https:' - } - - async addFollowing (hosts: string[]) { - this.followService.follow(hosts).subscribe( - () => { - this.notifier.success($localize`Follow request(s) sent!`) - this.reloadData() - }, - - err => this.notifier.error(err.message) - ) + isInstanceFollowing (follow: ActorFollow) { + return follow.following.name === 'peertube' } async removeFollowing (follow: ActorFollow) { diff --git a/client/src/app/+admin/follows/following-list/index.ts b/client/src/app/+admin/follows/following-list/index.ts index a70d46a7e..88be0ed4c 100644 --- a/client/src/app/+admin/follows/following-list/index.ts +++ b/client/src/app/+admin/follows/following-list/index.ts @@ -1 +1,2 @@ +export * from './follow-modal.component' export * from './following-list.component' diff --git a/client/src/app/+admin/follows/follows.routes.ts b/client/src/app/+admin/follows/follows.routes.ts index cd70daf77..3843b42b5 100644 --- a/client/src/app/+admin/follows/follows.routes.ts +++ b/client/src/app/+admin/follows/follows.routes.ts @@ -25,7 +25,7 @@ export const FollowsRoutes: Routes = [ component: FollowingListComponent, data: { meta: { - title: $localize`Following list` + title: $localize`Following` } } }, @@ -34,7 +34,7 @@ export const FollowsRoutes: Routes = [ component: FollowersListComponent, data: { meta: { - title: $localize`Followers list` + title: $localize`Followers` } } }, diff --git a/client/src/app/shared/form-validators/batch-domains-validators.ts b/client/src/app/shared/form-validators/batch-domains-validators.ts deleted file mode 100644 index 423d1337f..000000000 --- a/client/src/app/shared/form-validators/batch-domains-validators.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { AbstractControl, FormControl, ValidatorFn, Validators } from '@angular/forms' -import { BuildFormValidator } from './form-validator.model' -import { validateHost } from './host' - -export function getNotEmptyHosts (hosts: string) { - return hosts - .split('\n') - .filter((host: string) => host && host.length !== 0) // Eject empty hosts -} - -const validDomains: ValidatorFn = (control: FormControl) => { - if (!control.value) return null - - const newHostsErrors = [] - const hosts = getNotEmptyHosts(control.value) - - for (const host of hosts) { - if (validateHost(host) === false) { - newHostsErrors.push($localize`${host} is not valid`) - } - } - - /* Is not valid. */ - if (newHostsErrors.length !== 0) { - return { - 'validDomains': { - reason: 'invalid', - value: newHostsErrors.join('. ') + '.' - } - } - } - - /* Is valid. */ - return null -} - -const isHostsUnique: ValidatorFn = (control: AbstractControl) => { - if (!control.value) return null - - const hosts = getNotEmptyHosts(control.value) - - if (hosts.every((host: string) => hosts.indexOf(host) === hosts.lastIndexOf(host))) { - return null - } else { - return { - 'uniqueDomains': { - reason: 'invalid' - } - } - } -} - -export const DOMAINS_VALIDATOR: BuildFormValidator = { - VALIDATORS: [Validators.required, validDomains, isHostsUnique], - MESSAGES: { - 'required': $localize`Domain is required.`, - 'validDomains': $localize`Domains entered are invalid.`, - 'uniqueDomains': $localize`Domains entered contain duplicates.` - } -} diff --git a/client/src/app/shared/form-validators/host-validators.ts b/client/src/app/shared/form-validators/host-validators.ts new file mode 100644 index 000000000..d750113ef --- /dev/null +++ b/client/src/app/shared/form-validators/host-validators.ts @@ -0,0 +1,105 @@ +import { AbstractControl, ValidatorFn, Validators } from '@angular/forms' +import { BuildFormValidator } from './form-validator.model' + +function validateHost (value: string) { + // Thanks to http://stackoverflow.com/a/106223 + const HOST_REGEXP = new RegExp( + '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' + ) + + return HOST_REGEXP.test(value) +} + +function validateHandle (value: string) { + if (!value) return false + + return value.includes('@') +} + +const validHosts: ValidatorFn = (control: AbstractControl) => { + if (!control.value) return null + + const errors = [] + const hosts = splitAndGetNotEmpty(control.value) + + for (const host of hosts) { + if (validateHost(host) === false) { + errors.push($localize`${host} is not valid`) + } + } + + // valid + if (errors.length === 0) return null + + return { + 'validHosts': { + reason: 'invalid', + value: errors.join('. ') + '.' + } + } +} + +const validHostsOrHandles: ValidatorFn = (control: AbstractControl) => { + if (!control.value) return null + + const errors = [] + const lines = splitAndGetNotEmpty(control.value) + + for (const line of lines) { + if (validateHost(line) === false && validateHandle(line) === false) { + errors.push($localize`${line} is not valid`) + } + } + + // valid + if (errors.length === 0) return null + + return { + 'validHostsOrHandles': { + reason: 'invalid', + value: errors.join('. ') + '.' + } + } +} + +// --------------------------------------------------------------------------- + +export function splitAndGetNotEmpty (value: string) { + return value + .split('\n') + .filter(line => line && line.length !== 0) // Eject empty hosts +} + +export const unique: ValidatorFn = (control: AbstractControl) => { + if (!control.value) return null + + const hosts = splitAndGetNotEmpty(control.value) + + if (hosts.every((host: string) => hosts.indexOf(host) === hosts.lastIndexOf(host))) { + return null + } + + return { + 'unique': { + reason: 'invalid' + } + } +} + +export const UNIQUE_HOSTS_VALIDATOR: BuildFormValidator = { + VALIDATORS: [ Validators.required, validHosts, unique ], + MESSAGES: { + 'required': $localize`Domain is required.`, + 'validHosts': $localize`Hosts entered are invalid.`, + 'unique': $localize`Hosts entered contain duplicates.` + } +} + +export const UNIQUE_HOSTS_OR_HANDLE_VALIDATOR: BuildFormValidator = { + VALIDATORS: [ Validators.required, validHostsOrHandles, unique ], + MESSAGES: { + 'required': $localize`Domain is required.`, + 'validHostsOrHandles': $localize`Hosts or handles are invalid.`, + 'unique': $localize`Hosts or handles contain duplicates.` + } +} diff --git a/client/src/app/shared/form-validators/host.ts b/client/src/app/shared/form-validators/host.ts deleted file mode 100644 index c18a35f9b..000000000 --- a/client/src/app/shared/form-validators/host.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function validateHost (value: string) { - // Thanks to http://stackoverflow.com/a/106223 - const HOST_REGEXP = new RegExp( - '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' - ) - - return HOST_REGEXP.test(value) -} diff --git a/client/src/app/shared/form-validators/index.ts b/client/src/app/shared/form-validators/index.ts index f621f03a4..c14272a2a 100644 --- a/client/src/app/shared/form-validators/index.ts +++ b/client/src/app/shared/form-validators/index.ts @@ -1,5 +1,4 @@ export * from './form-validator.model' -export * from './host' // Don't re export const variables because webpack 4 cannot do tree shaking with them // export * from './abuse-validators' diff --git a/client/src/app/shared/shared-instance/instance-follow.service.ts b/client/src/app/shared/shared-instance/instance-follow.service.ts index e52660140..af44020cf 100644 --- a/client/src/app/shared/shared-instance/instance-follow.service.ts +++ b/client/src/app/shared/shared-instance/instance-follow.service.ts @@ -4,7 +4,7 @@ import { catchError, map } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { RestExtractor, RestPagination, RestService } from '@app/core' -import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models' +import { ActivityPubActorType, ActorFollow, FollowState, ResultList, ServerFollowCreate } from '@shared/models' import { environment } from '../../../environments/environment' @Injectable() @@ -64,9 +64,10 @@ export class InstanceFollowService { ) } - follow (notEmptyHosts: string[]) { - const body = { - hosts: notEmptyHosts + follow (hostsOrHandles: string[]) { + const body: ServerFollowCreate = { + handles: hostsOrHandles.filter(v => v.includes('@')), + hosts: hostsOrHandles.filter(v => !v.includes('@')) } return this.authHttp.post(InstanceFollowService.BASE_APPLICATION_URL + '/following', body) @@ -77,7 +78,9 @@ export class InstanceFollowService { } unfollow (follow: ActorFollow) { - return this.authHttp.delete(InstanceFollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host) + const handle = follow.following.name + '@' + follow.following.host + + return this.authHttp.delete(InstanceFollowService.BASE_APPLICATION_URL + '/following/' + handle) .pipe( map(this.restExtractor.extractDataBool), catchError(res => this.restExtractor.handleError(res)) diff --git a/client/src/app/shared/shared-moderation/batch-domains-modal.component.html b/client/src/app/shared/shared-moderation/batch-domains-modal.component.html index 6a3c65721..8306a96bc 100644 --- a/client/src/app/shared/shared-moderation/batch-domains-modal.component.html +++ b/client/src/app/shared/shared-moderation/batch-domains-modal.component.html @@ -1,6 +1,6 @@ @@ -11,15 +11,15 @@ -
- {{ formErrors.domains }} +
+ {{ formErrors.hosts }} -
- {{ form.controls['domains'].errors.validDomains.value }} +
+ {{ form.controls['hosts'].errors.validHosts.value }}
diff --git a/client/src/app/shared/shared-moderation/batch-domains-modal.component.ts b/client/src/app/shared/shared-moderation/batch-domains-modal.component.ts index 6edbb6023..20be728f6 100644 --- a/client/src/app/shared/shared-moderation/batch-domains-modal.component.ts +++ b/client/src/app/shared/shared-moderation/batch-domains-modal.component.ts @@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angu import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' -import { DOMAINS_VALIDATOR, getNotEmptyHosts } from '../form-validators/batch-domains-validators' +import { splitAndGetNotEmpty, UNIQUE_HOSTS_VALIDATOR } from '../form-validators/host-validators' @Component({ selector: 'my-batch-domains-modal', @@ -28,7 +28,7 @@ export class BatchDomainsModalComponent extends FormReactive implements OnInit { if (!this.action) this.action = $localize`Process domains` this.buildForm({ - domains: DOMAINS_VALIDATOR + hosts: UNIQUE_HOSTS_VALIDATOR }) } @@ -41,9 +41,7 @@ export class BatchDomainsModalComponent extends FormReactive implements OnInit { } submit () { - this.domains.emit( - getNotEmptyHosts(this.form.controls['domains'].value) - ) + this.domains.emit(splitAndGetNotEmpty(this.form.controls['hosts'].value)) this.form.reset() this.hide() } -- cgit v1.2.3 From c63830f15403ac4e750829f27d8bbbdc9a59282c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Jul 2021 13:58:35 +0200 Subject: Rename captions commands --- client/src/app/shared/form-validators/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'client') diff --git a/client/src/app/shared/form-validators/index.ts b/client/src/app/shared/form-validators/index.ts index c14272a2a..0b605719c 100644 --- a/client/src/app/shared/form-validators/index.ts +++ b/client/src/app/shared/form-validators/index.ts @@ -1,6 +1,6 @@ export * from './form-validator.model' -// Don't re export const variables because webpack 4 cannot do tree shaking with them +// Don't re export const variables because webpack cannot do tree shaking with them // export * from './abuse-validators' // export * from './batch-domains-validators' // export * from './custom-config-validators' -- cgit v1.2.3