• Feathercrown@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    I’ve read the discussion on this, IDs are specific to each instance so you’d have to fetch from the instance then translate the ID to your instance’s own version. It’s in progress but kind of stalled because of that for some reason.

    • wpuckering@lm.williampuckering.com
      link
      fedilink
      English
      arrow-up
      3
      ·
      edit-2
      1 year ago

      It’s actually easy, here’s an explanation for one simple way you could do it.

      On my instance, this post has the URL: https://lm.williampuckering.com/post/171615

      On the instance the post originated on, the URL is: https://lemmings.world/post/175809

      So on my instance, the post has the ID: 171615

      On the originating instance, the ID is: 175809

      In the database on my instance, this query will retrieve the post: select * from post where id = 171615

      Also in the database on my instance, this query will retrieve the post: select * from post where ap_id = 'https://lemmings.world/post/175809'

      Using the second query and finding the post by URL, I can see if the post is federated to my own instance or not. If so, I can look at the id field in the database and merely swap it out with the originating instance’s ID, and form the URL to access the post as it exists on my own instance. If the post isn’t federated on my own instance, then of course this won’t work. But that makes total sense, since you won’t be able to transform links for external instances to the corresponding entity on your own instance, because it doesn’t exist there.

      tl;dr - You can look up local entities by ID, and you can lookup remote entities by original URL. Then you just need to swap the ID in the URL to the ID (primary key in the table) in the database, if it exists, to convert a remote link to a local link. If a link can’t be converted, you can just leave it as-is.

      The capability needed to add this functionality is already there. Someone just needs to decide how to handle it on the frontend elegantly from a UI perspective, and decide how the backend will pass what’s required to the frontend to drive the functionality. But the plumbing is already there.