arj03 / ssb-browser-demo

A secure scuttlebutt client interface running in the browser
Other
58 stars 11 forks source link

Make blob display independent of being connected to a peer #76

Closed KyleMaas closed 3 years ago

KyleMaas commented 3 years ago

Markdown display of blobs is currently tied to needing to be connected to a peer (see https://github.com/arj03/ssb-browser-demo/issues/72#issuecomment-762553625 ). I've worked around this with #75, but this also means that blobs can't be displayed at all if you're offline or if you're not currently connected to a peer with data (such as if you're connected to a room, and all other room-peer connections are offline). It would be nicer if we had a way to try to display blobs if we already have them in cache.

KyleMaas commented 3 years ago

So, it looks like part of the problem is that localGetHelper() is not asynchronous. And, indeed, it probably cannot be made to be due to the localGet API not being asynchronous. It looks like it might be appropriate to have localGetHelper() return an error when not connected (instead of just crashing), which would theoretically be passed back up. That way, we could still attempt to load Markdown containing blobs if not connected. They just wouldn't display unless they were either in the cache or we are currently connected to a peer. Does that make sense as a way to do that?

arj03 commented 3 years ago

It should work without a network connection: https://github.com/arj03/ssb-browser-core/blob/4e1178bc8736602488fa1940ea0ee08a2c1c4384/simple-blobs.js#L348. I didn't change that for a while. Maybe it would be good if httpGet would use use the connected stuff.

KyleMaas commented 3 years ago

The problem comes in from here:

https://github.com/arj03/ssb-browser-core/blob/4e1178bc8736602488fa1940ea0ee08a2c1c4384/simple-blobs.js#L352

If it stats the file and the size is zero (which is what happens when the file hasn't been written - see https://github.com/random-access-storage/random-access-file/issues/25 ), it calls remoteURL(), which if it isn't connected, returns an empty string. This causes httpGet() to crash. What I'm proposing is that rather than letting it crash, we have localGetHelper() return an error.

arj03 commented 3 years ago

Hmm, there is a pretty annoying problem where the profile index needs to load before we can actually start showing profile pictures. This is unrelated to the network. Need to do something else for a while, but will get back to that one.