Skip to content

Fetch posts on login, purge on logout#24

Merged
AngeloStavrow merged 6 commits intomainfrom
fetch-posts-on-login
Aug 27, 2020
Merged

Fetch posts on login, purge on logout#24
AngeloStavrow merged 6 commits intomainfrom
fetch-posts-on-login

Conversation

@AngeloStavrow
Copy link
Collaborator

@AngeloStavrow AngeloStavrow commented Aug 25, 2020

Closes #13.

⚠️ This PR is dependent on work done in #22. ⚠️

This PR adds an API call (and result handler) to the WriteFreelyModel to fetch user posts from the server, and calls it on login. The handler matches posts that are in a collection to the fetched collections (hence its dependency) and then adds them to the PostStore, which updates the PostListView.

A purge() method is also added to the PostStore, to purge the fetch posts when the user logs out.

@AngeloStavrow AngeloStavrow added this to the 1.0.0-beta milestone Aug 25, 2020
@AngeloStavrow AngeloStavrow requested a review from thebaer August 25, 2020 19:17
@AngeloStavrow AngeloStavrow self-assigned this Aug 25, 2020
@thebaer
Copy link
Member

thebaer commented Aug 27, 2020

I probably should've mentioned this in #22, but there's actually an experimental, undocumented API feature (originally deployed for the v2.0 Android app) that saves on API calls upon login. When you call the /api/auth/login endpoint, you can supply an additional parameter: ?verbose=1 to retrieve all user collections and posts along with the user data (valid parameters here, and backend logic here).

We should of course support reloading collections + posts separately (once logged in), but during login, I think we should include the verbose=1 parameter in order to save on network calls (particularly on mobile).

Given that information, does this PR need to be changed, or can we still use it as-is for features like #32?

@AngeloStavrow
Copy link
Collaborator Author

That's a good parameter to have!

Because any calls to the WriteFreely/Write.as API are being handled by the Swift package, rather than this client app, I think it makes more sense to implement this as is for now, and open an issue in the package repo to add something like a loginAndFetchContent() method in WFClient. When that's implemented, we can use it here. What do you think?

Once that's implemented in the package, we can add the behaviour to the client. You mention that it's "experimental", @thebaer — is there anything that might need to be guarded against in production?

@thebaer
Copy link
Member

thebaer commented Aug 27, 2020

That sounds like a good plan!

As for being "experimental," I mostly mention that for the audience, to note we can change this particular interface at any time without notice. But otherwise it's ready and safe to use in production -- we just need to pick which parameter/value we want to make "official" (again, my suggestion: verbose=1).

Copy link
Member

@thebaer thebaer left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

On login, the user's Posts should be retrieved from the server

2 participants