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

Rich Text #23

Open
KB1RD opened this issue Jul 1, 2020 · 0 comments
Open

Rich Text #23

KB1RD opened this issue Jul 1, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request medium priority

Comments

@KB1RD
Copy link
Owner

KB1RD commented Jul 1, 2020

Rich text refers to having inline embedded content (such as mentions), block embedded content (such as images), and marks in the text (such as bold or italic). This could actually happen really soon. Like in a few days if I really wanted to go quickly. Why?

TL;DR: Since the algorithm is data-agnostic, I can push anything through. I did a bit of future-proofing in the event representation, so all I really need to do is stop being lazy.

Here's an example event:

{
  "type": "net.kb1rd.anchorlogoot0.ins",
  "sender": "@kb1rd:kb1rd.net",
  "content": {
    "a": {
      "v": 0,
      "o": []
    },
    "d": [
      "Hello"
    ],
    "c": 0
  }
}

(For reference, the a contains the anchors, which are undefined in this case, so it anchors to DocStart and DocEnd. d corresponds to the data. c corresponds to the Lamport clock)

If you look closely, you'll notice something odd: The data is actually an array of strings. Why? Well, because you can't embed an object in a string. This is future-proofing to allow individual characters to be efficiently mixed with objects. If one wishes to embed one or more objects in the string, they could add an array of objects to the current data array. On the receiving end, each element in the data array would be merged end-to-end. It's easier to see an example:

{
  "type": "net.kb1rd.anchorlogoot0.ins",
  "sender": "@kb1rd:kb1rd.net",
  "content": {
    "a": {
      "v": 0,
      "o": []
    },
    "d": [
      "Hi ",
      [ { "type": "net.kb1rd.image-block", "url": "mxc://myimage" } ]
    ],
    "c": 0
  }
}

I could just as easily make that an array of characters, but the JSON representation would be less efficient. You may be wondering why I need the array brackets around the object. The reason for this is because it lets the clients know that each element of that array is an atom and cannot be broken. It is still algorithmically correct to distinguish between a string that is a single atom and a string that is a set of atoms. So, if you wanted to send a single-atom string (though most clients would likely discard it), you could set "d": ["each letter is an atom", ["this is an atom"] ].

@KB1RD KB1RD added enhancement New feature or request medium priority labels Jul 1, 2020
@KB1RD KB1RD self-assigned this Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium priority
Projects
None yet
Development

No branches or pull requests

1 participant