Try to fix remote mastodon interactions
authorChocobozzz <me@florianbigard.com>
Fri, 7 Jun 2019 08:56:59 +0000 (10:56 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 7 Jun 2019 08:57:33 +0000 (10:57 +0200)
client/src/app/shared/user-subscription/remote-subscribe.component.ts
client/src/app/shared/user-subscription/subscribe-button.component.html
client/src/app/shared/user-subscription/subscribe-button.component.ts
client/src/app/videos/+video-watch/comment/video-comment-add.component.html
client/src/app/videos/+video-watch/comment/video-comment-add.component.ts
server/controllers/static.ts

index ba2a45df136897c9dbe95e9dad32be4437cdd643..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
 
@@ -42,19 +42,20 @@ export class RemoteSubscribeComponent extends FormReactive implements OnInit {
     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) =>
-            link && typeof link.template === 'string' && link.rel === 'http://ostatus.org/schema/1.0/subscribe')
+          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}', `acct:${this.account}`))
+            resolve(link.template.replace('{uri}', encodeURIComponent(this.uri)))
           }
         }
         reject()
       }))
       .then(window.open)
-      .catch(() => window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`))
+      .catch(err => console.error(err))
   }
 }
index dbf6a34f08fd67c8b00e1c37eece6b230d4fddb1..d32647b4288292a685bfd635261062454a633b20 100644 (file)
@@ -41,7 +41,7 @@
       </button>
 
       <button class="dropdown-item" i18n>Subscribe with a Mastodon account:</button>
-      <my-remote-subscribe showHelp="true" account="{{ uriAccount }}"></my-remote-subscribe>
+      <my-remote-subscribe showHelp="true" [uri]="channelUri"></my-remote-subscribe>
 
       <div class="dropdown-divider"></div>
 
@@ -50,4 +50,4 @@
 
     </div>
   </div>
-</div>
\ No newline at end of file
+</div>
index ef470ee44cbaf62bb5303fc24cd6db123522fd4f..25515f6ea31cd6367673c3720ad739edefb34323 100644 (file)
@@ -28,19 +28,19 @@ export class SubscribeButtonComponent implements OnInit {
     private videoService: VideoService
   ) { }
 
-  get uri () {
+  get channelHandle () {
     return this.videoChannel.name + '@' + this.videoChannel.host
   }
 
-  get uriAccount () {
-    return this.videoChannel.ownerAccount.name + '@' + this.videoChannel.host
+  get channelUri () {
+    return this.videoChannel.url
   }
 
   ngOnInit () {
     if (this.isUserLoggedIn()) {
-      this.userSubscriptionService.doesSubscriptionExist(this.uri)
+      this.userSubscriptionService.doesSubscriptionExist(this.channelHandle)
         .subscribe(
-          res => this.subscribed = res[this.uri],
+          res => this.subscribed = res[this.channelHandle],
 
           err => this.notifier.error(err.message)
         )
@@ -56,7 +56,7 @@ export class SubscribeButtonComponent implements OnInit {
   }
 
   localSubscribe () {
-    this.userSubscriptionService.addSubscription(this.uri)
+    this.userSubscriptionService.addSubscription(this.channelHandle)
       .subscribe(
         () => {
           this.subscribed = true
@@ -78,7 +78,7 @@ export class SubscribeButtonComponent implements OnInit {
   }
 
   localUnsubscribe () {
-    this.userSubscriptionService.deleteSubscription(this.uri)
+    this.userSubscriptionService.deleteSubscription(this.channelHandle)
         .subscribe(
           () => {
             this.subscribed = false
index d8a7a78c4b0a9dfb7dc6a100041a0e9405e114e5..916f5d0ff478df10d227ebfb57e5200c6f8ff43b 100644 (file)
@@ -41,7 +41,7 @@
     <span i18n>
       If you have an account on Mastodon or Pleroma, you can open it directly in their interface:
     </span>
-    <my-remote-subscribe [interact]="true" [account]="getUrl()"></my-remote-subscribe>
+    <my-remote-subscribe [interact]="true" [uri]="getUri()"></my-remote-subscribe>
   </div>
   <div class="modal-footer inputs">
     <span i18n class="action-button action-button-cancel" role="button" (click)="hideVisitorModal()">
index fd85c28f2cb77c1af01ed456fa3ac8149b3e7eee..ac1d02d940dfafc20dcc9f6b08267b2c52348384 100644 (file)
@@ -8,7 +8,6 @@ import { User } from '../../../shared/users'
 import { Video } from '../../../shared/video/video.model'
 import { VideoComment } from './video-comment.model'
 import { VideoCommentService } from './video-comment.service'
-import { I18n } from '@ngx-translate/i18n-polyfill'
 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
 import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service'
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
@@ -40,8 +39,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
     private videoCommentService: VideoCommentService,
     private authService: AuthService,
     private modalService: NgbModal,
-    private router: Router,
-    private i18n: I18n
+    private router: Router
   ) {
     super()
   }
@@ -124,7 +122,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
     return this.form.value['text']
   }
 
-  getUrl () {
+  getUri () {
     return window.location.href
   }
 
index 05019fcc2139b9c7f9706b8b7e74652aa3e71d9b..73951be2d4b3ff0cc9a1283f276365a31754d827 100644 (file)
@@ -156,6 +156,19 @@ staticRouter.use('/.well-known/change-password',
   }
 )
 
+staticRouter.use('/.well-known/host-meta',
+  (_, res: express.Response) => {
+    res.type('application/xml');
+
+    const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
+      '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
+      `  <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
+      '</XRD>'
+
+    res.send(xml).end()
+  }
+)
+
 // ---------------------------------------------------------------------------
 
 export {