balzack / databag

fast & lightweight self-hosted messenger
Apache License 2.0
869 stars 46 forks source link

Move to an sdk package #95

Open lil5 opened 5 months ago

lil5 commented 5 months ago

Instead of reimplementing common chat functionality on each client, create an sdk that is plugged into mobile and web apps.

This could handle;

The sdk should not contain any react. Instead async and callbacks should be used

const sdk = new DatabagSdk()

sdk.onLogin(()=>{})

const room = sdk.selectRoom()
const g = () => appview(room.renderConversation())
room.onUpdate(g)

This is just an example of functionality not structure.

With an sdk the react could move to a more passive role of displaying data when the sdk says so.

balzack commented 5 months ago

Yes, I agree. Along those lines, I can see it allowing for other clients to participate in the network while maintaining interoperability. Just because clients speak the same protocol or api, doesn't mean they work well together.

It would be nice if there was just one SDK, but mobile generally requires storage for offline viewing. Supporting both modes within a single SDK may be messy.

There are a few new features, maybe bundled as separate apps, that I would like to include in an SDK. Perhaps it's over designing, but it goes to my hopes that the databag backend can be more general than a message service.

Thank you for the suggestion!

lil5 commented 5 months ago

but mobile generally requires storage for offline viewing. Supporting both modes within a single SDK may be messy.

That would require an optional addOfflineSqliteStorage(db)

Interoperability with other sqlite libraries isn't necessary as a non react native library exists too. https://github.com/asnando/sqlite-storage

balzack commented 5 months ago

Thank you for this reference. I have a rough idea what the API should look like now, but am not yet sure how much the refactor effort will be.

I will likely start the SDK work in a month or two, after I complete several other commitments. Would you be willing to review the SDK API after I finish a draft?

lil5 commented 5 months ago

Definitely 👍

I'd suggest cut-pasting from frontend to sdk then altering from there, that way you never have a commit where everything is broken.

balzack commented 5 months ago

I need to move the typescript changes into a branch until I can fix it: https://github.com/balzack/databag/tree/typescript

Deploying the latest gives me: 'Uncaught ReferenceError: require is not defined'

I thought I had tested it, but I must have been using a stale build.

lil5 commented 5 months ago

I'll see if I can work on the docker development env, you seem to be using production builds instead of the local code.

I haven't yet got it working properly (on a Mac machine)

balzack commented 5 months ago

It might not be worth this effort. When I start the SDK refactor work, I will make sure to use typescript.