TryQuiet / quiet

A private, p2p alternative to Slack and Discord built on Tor & IPFS
https://www.tryquiet.org
GNU General Public License v3.0
1.98k stars 87 forks source link

QSS: Load channels, messages, certificates into OrbitDB during LAUNCH_COMMUNITY #2407

Open leblowl opened 7 months ago

leblowl commented 7 months ago

Add functions in the storage service to support this and call these functions from launchCommunity.

On the backend launchCommunity connects to the storage service and downloads the JSON object from /invite. Once the object has been retrieved, it can then use data from the invite property to connect to peers via p2p. We can also store the data in the invite property (psk, ownerOrbitDbIdentity, peerList) in the Community model when creating the community. Then we can load the CommunityMetadata into OrbitDB. See https://github.com/TryQuiet/quiet/pull/2190 for how to do this. Then we can load the Certificates. Then we can load Channels. Then we can load the Messages. Loading the messages depends on having the channel DBs created, which is async, so perhaps we can wait on the CHANNEL_REPLICATED/CREATED event before loading messages.

And I think that should be it. I think the ‘replicated’ event fires when loading into OrbitDB, so all other event-based actions should work as if we had connected to a peer and downloaded this data.

We will need to add functions in communityMetadata.store, certificates.store, etc. for loading entries into the OrbitDB databases.

EmiM commented 6 months ago

Not directly connected but rather pre-work: https://github.com/TryQuiet/quiet/pull/2493 Reason: we use similar or identical methods across all our stores so I introduced simple abstractions. This structure will ensure that we will implement all necessary functionalities in our stores. Next step would be to add something like loadData to abstract base class.