Skip to content

Conversation

@SessionHero01
Copy link
Collaborator

@SessionHero01 SessionHero01 commented Nov 11, 2025

This PR adds a LoginStateRepository to manage user credentials: all access to keys will go through here. It also handles migration and persistent.

We now have LoggedInState to encapsulate all the keys the user will use to do all sort of stuff, including pro related operations.

All calls to prefs.getLocalNumber(), prefs.watchLocalNumber() and so on are replaced to call to the repository instead.

Also added a flowWithLoggedInState() to help with the common case where we need to be logged in before a flow can be created.



init {
var initialState = sharedPrefs.getString("state", null)?.let { serializedState ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could extract those strings since they are re-used to avoid making mistakes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private val currentPoller: StateFlow<Poller?> = channelFlow {
prefers.watchLocalNumber()
loginStateRepository
.loggedInState
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use your new flowWithLoggedInState here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately no, the use case here is too specific. It needs to be able to explicitly cancel the poller, while with flowWithLoggedInState it only emits "nothing" which can't be use to drive an action.

// we want to preload the data as soon as the user is logged in
scope.launch {
textSecurePreferences.watchLocalNumber()
loginStateRepository.loggedInState
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use flowWithLoggedInState?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit awkward to use that in here, as flowWithLoggedInState is used to limit the creation of a flow, but in here it's actually a coroutine so i don't think it's worth doing it here.

Copy link
Collaborator

@ThomasSession ThomasSession left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@SessionHero01 SessionHero01 merged commit 6391667 into dev Nov 11, 2025
4 checks passed
@SessionHero01 SessionHero01 deleted the integrate-pro-master-key branch November 11, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants