project-robius / robrix

A Matrix chat client written in pure Rust using the Makepad UI toolkit and the Robius app dev framework
MIT License
67 stars 11 forks source link

Persistent app data on disk storage #112

Open kevinaboos opened 3 weeks ago

kevinaboos commented 3 weeks ago

Currently Robrix does not save any app state to persistent storage. Thus, all data displayed by Robrix must be re-fetched from scratch every time the app is started. Obviously this is not suitable for a real usable app that would be installed on actual user devices.

In the Moxin app, I used the directories crate to store persistent application data to (and read it back from) the canonical directories for app data, cached data, preferences/settings/config data, etc. See the PR here: https://github.com/moxin-org/moxin/pull/96

The ability to save and restore Matrix SDK state is required for properly handling login tokens (sessions), E2EE tokens

Unknowns

One complication is that the Matrix SDK itself wants to implicitly handle saving and restoring its internal state (e.g., timeline content, etc). So we don't necessarily have full direct control over all states that are persisted to storage.

I'm not sure what internal states that the Matrix SDK Client manages (and other session data) are capable of being saved/restored to disk. Furthermore, I'm not sure which Matrix SDK APIs should be used to actually trigger the saving or restoring action. Things are a bit opaque and not well documented.

Examples

Thankfully, the Matrix SDK does provide one example of how to persist internal session data. https://github.com/matrix-org/matrix-rust-sdk/blob/main/examples/persist_session/src/main.rs

This should provide a good baseline for where to start on implementing app data persistence.