From d43c6b1ffc5e6c895f9e9f9de6625f17a9755c20 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Jan 2021 14:13:23 +0100 Subject: Implement remote interaction --- .../app/shared/form-validators/user-validators.ts | 11 +++++++ .../remote-subscribe.component.html | 6 ++-- .../remote-subscribe.component.ts | 37 +++++++++++++--------- .../subscribe-button.component.html | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/form-validators/user-validators.ts b/client/src/app/shared/form-validators/user-validators.ts index a27290035..3f462ca3b 100644 --- a/client/src/app/shared/form-validators/user-validators.ts +++ b/client/src/app/shared/form-validators/user-validators.ts @@ -39,6 +39,17 @@ export const USER_EMAIL_VALIDATOR: BuildFormValidator = { } } +export const USER_HANDLE_VALIDATOR: BuildFormValidator = { + VALIDATORS: [ + Validators.required, + Validators.pattern(/@.+/) + ], + MESSAGES: { + 'required': $localize`Handle is required.`, + 'pattern': $localize`Handle must be valid (chocobozzz@example.com).` + } +} + export const USER_EXISTING_PASSWORD_VALIDATOR: BuildFormValidator = { VALIDATORS: [ Validators.required diff --git a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.html b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.html index acfec0a8e..a00c3d1c7 100644 --- a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.html +++ b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.html @@ -15,8 +15,7 @@ - You can subscribe to the channel via any ActivityPub-capable fediverse instance.

- For instance with Mastodon or Pleroma you can type the channel URL in the search box and subscribe there. + You can subscribe to the channel via any ActivityPub-capable fediverse instance (PeerTube, Mastodon or Pleroma for example).
@@ -24,8 +23,7 @@ - You can interact with this via any ActivityPub-capable fediverse instance.

- For instance with Mastodon or Pleroma you can type the current URL in the search box and interact with it there. + You can interact with this via any ActivityPub-capable fediverse instance (PeerTube, Mastodon or Pleroma for example).
diff --git a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts index b46c91bf8..666199523 100644 --- a/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts +++ b/client/src/app/shared/shared-user-subscription/remote-subscribe.component.ts @@ -1,6 +1,7 @@ import { Component, Input, OnInit } from '@angular/core' +import { Notifier } from '@app/core' import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' -import { USER_EMAIL_VALIDATOR } from '../form-validators/user-validators' +import { USER_HANDLE_VALIDATOR } from '../form-validators/user-validators' @Component({ selector: 'my-remote-subscribe', @@ -13,14 +14,15 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit { @Input() showHelp = false constructor ( - protected formValidatorService: FormValidatorService + protected formValidatorService: FormValidatorService, + private notifier: Notifier ) { super() } ngOnInit () { this.buildForm({ - text: USER_EMAIL_VALIDATOR + text: USER_HANDLE_VALIDATOR }) } @@ -35,22 +37,27 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit { const address = this.form.value['text'] const [ username, hostname ] = address.split('@') + const protocol = window.location.protocol + // Should not have CORS error because https://tools.ietf.org/html/rfc7033#section-5 - fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) + fetch(`${protocol}//${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`) .then(response => response.json()) - .then(data => new Promise((resolve, reject) => { - if (data && Array.isArray(data.links)) { - const link: { template: string } = data.links.find((link: any) => { - return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe' - }) - - if (link && link.template.includes('{uri}')) { - resolve(link.template.replace('{uri}', encodeURIComponent(this.uri))) - } + .then(data => new Promise((res, rej) => { + if (!data || Array.isArray(data.links) === false) return rej() + + const link: { template: string } = data.links.find((link: any) => { + return link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe' + }) + + if (link && link.template.includes('{uri}')) { + res(link.template.replace('{uri}', encodeURIComponent(this.uri))) } - reject() })) .then(window.open) - .catch(err => console.error(err)) + .catch(err => { + console.error(err) + + this.notifier.error($localize`Cannot fetch information of this remote account`) + }) } } diff --git a/client/src/app/shared/shared-user-subscription/subscribe-button.component.html b/client/src/app/shared/shared-user-subscription/subscribe-button.component.html index 607a7e113..75cfc918b 100644 --- a/client/src/app/shared/shared-user-subscription/subscribe-button.component.html +++ b/client/src/app/shared/shared-user-subscription/subscribe-button.component.html @@ -59,7 +59,7 @@ -- cgit v1.2.3