styleUrls: ['./remote-subscribe.component.scss']
})
export class RemoteSubscribeComponent extends FormReactive implements OnInit {
- @Input() account: string
+ @Input() uri: string
@Input() interact = false
@Input() showHelp = false
}
onValidKey () {
- this.onValueChanged()
+ this.check()
if (!this.form.valid) return
this.formValidated()
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))
}
}