Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Handling multiple facets #22

Open
jdhitsolutions opened this issue Nov 18, 2024 · 4 comments
Open

Bug: Handling multiple facets #22

jdhitsolutions opened this issue Nov 18, 2024 · 4 comments
Assignees
Labels
bug Something isn't working pending feedback

Comments

@jdhitsolutions
Copy link
Owner

There is a bug when handling multiple facets in a post. I think the byte location shifts.

{
  "record": {
    "$type": "app.bsky.feed.post",
    "text": "I have an open discussion topic if you want to add your thoughts on supporting 2FA in the PSBluesky #PowerShell module.",
    "createdAt": "2024-11-18T18:02:15.8878051-05:00",
    "facets": [
      {
        "index": {
          "byteStart": 162,
          "byteEnd": 173
        },
        "features": [
          {
            "$type": "app.bsky.richtext.facet#tag",
            "tag": "PowerShell"
          }
        ]
      },
      {
        "index": {
          "byteStart": 15,
          "byteEnd": 31
        },
        "features": [
          {
            "$type": "app.bsky.richtext.facet#link",
            "uri": "https://github.com/jdhitsolutions/PSBluesky/discussions/21"
          }
        ]
      }
    ]
  },

The original string was: "I have an open [discussion topic](https://github.com/jdhitsolutions/PSBluesky/discussions/21) if you want to add your thoughts on supporting 2FA in the PSBluesky #PowerShell module."

@jdhitsolutions jdhitsolutions added the bug Something isn't working label Nov 18, 2024
@jdhitsolutions jdhitsolutions self-assigned this Nov 18, 2024
@ShaunLawrie
Copy link

The byte offsets for tags and mentions are being calculated first. After that the record.text is being modified here which makes the offsets calculated for tags/mentions against the original record.text version, not the revised one.
You can quickly fix that by handling the markdown style links first because that's the only one mutating the original text.

The approach works until the message contains unicode characters that take more than one byte btw. It's unlikely to happen when someone is sending a message from the terminal but it can.

I only noticed because I was doing this in reverse. I was taking posts from my timeline and trying to use the facets to render them as links in the terminal and they were all off-by-one when emoji were present in the record.text.
https://github.com/jdhitsolutions/PSBluesky/pull/24/files#diff-1994ad15cb20c326911f9a70a3308644bc32ba2986d778de258a9c630bf3f46dR74

@jdhitsolutions
Copy link
Owner Author

I haven't had a chance to work on this so I appreciate your suggestion. That makes the most sense.

@jdhitsolutions
Copy link
Owner Author

I think I have this fixed in v2.1.0.

@jdhitsolutions
Copy link
Owner Author

This change has been released. Keeping this open until I'm sure this has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending feedback
Projects
None yet
Development

No branches or pull requests

2 participants