quotient-im / libQuotient

A Qt library to write cross-platform clients for Matrix
https://quotient-im.github.io/libQuotient/
GNU Lesser General Public License v2.1
135 stars 56 forks source link

Batteries-included Account / Connection management #781

Open TobiasFella opened 3 months ago

TobiasFella commented 3 months ago

Problem

Currently, handling connections in libquotient-based clients is complicated.

To log in a client, the flow is roughly:

To load an existing connection:

(I'm skipping over SSO login and account registration here. From libQuotient's perspective, account registration doesn't really exist; the relevant API here is the same as for login. For SSO login, SsoSession exists)

There are some further complications here, e.g., that a client might want to wait until after the initial sync / load from cache before showing the connection (or switching away from a loading screen) to make the UX nicer.

With sliding sync, OIDC login, and my work on making libquotient work offline (#777), this would not get simpler.

Overall, there are too many things that are hard to understand, making the developer expierence not amazing.

There's also the - somewhat failed - attempt to improve this by providing the account loading functionality in Quotient::AccountRegistry.

Goals

Proposal

vkrause commented 3 months ago

As a user of libquotient in a an app that isn't primarily a Matrix (chat) client, having the library handle more of this out of the box would indeed be much appreciated :)

KitsuneRal commented 3 months ago

Wow, this is comprehensive :) I wasn't particularly happy with this part of the library for a long time, and my ideas overlap with a lot of this. A few considerations below:

I'm not sure if Connection should still be a base class and provide a protected interface; I see NeoChat using it quite successfully, but we should probably give a bit more thought to what (else) Connection should provide for derived classes.

KitsuneRal commented 3 months ago

Looking once again at it, I wonder if it would make more sense to have login functions in Homeserver, rather than AccountRegistry. We could even make Homeserver a base class so that client authors could add their own fancy login methods.

TobiasFella commented 3 months ago

Not sure if we should allow skipping the account registry though.

Sure, that's not something I want to push for anyway

I wonder if it would make more sense to have login functions in Homeserver, rather than AccountRegistry

That would also make sense from an API perspective. I've put it in AccountRegistry for my proposal since then we automatically have the accountregistry object that is needed during creation of the connection