]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/user-subscription/remote-subscribe.component.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / user-subscription / remote-subscribe.component.ts
index 7a81108cde0e36e2b22ebcb3980180e7ec06a6a0..63e7cd5d95390555cf6a970db56f6b78f56bf816 100644 (file)
@@ -11,7 +11,7 @@ import {
   styleUrls: ['./remote-subscribe.component.scss']
 })
 export class RemoteSubscribeComponent extends FormReactive implements OnInit {
-  @Input() account: string
+  @Input() uri: string
   @Input() interact = false
   @Input() showHelp = false
 
@@ -29,7 +29,7 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
   }
 
   onValidKey () {
-    this.onValueChanged()
+    this.check()
     if (!this.form.valid) return
 
     this.formValidated()
@@ -37,7 +37,25 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
 
   formValidated () {
     const address = this.form.value['text']
-    const [ , hostname ] = address.split('@')
-    window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`)
+    const [ username, hostname ] = address.split('@')
+
+    fetch(`https://${hostname}/.well-known/webfinger?resource=acct:${username}@${hostname}`)
+      .then(response => response.json())
+      .then(data => new Promise((resolve, reject) => {
+        console.log(data)
+
+        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)))
+          }
+        }
+        reject()
+      }))
+      .then(window.open)
+      .catch(err => console.error(err))
   }
 }