The idea is to reduce number of separate files and imports for them to
make it easier on compiler. Unfortunately so far the gains are not as
big as we hoped but this change can be a base towards reducing direct
dependency on typeModels to that we can avoid recompiling them.
Because of that we try to avoid importing them directly and
theoretically we could reduce it even more.
Upon logging in and also when reconnecting, if it is detected that the stored offline data is out of sync with the servers (i.e. We haven't connected for > 45 days, meaning we would most likely have missed some entity events), then we just delete the stored offline data. Directly refreshing the offline cache is not taken care of with this commit, and we may or may not decide to do that in the future
The database key is stored and encrypted alongside the user's stored credentials
we depend on our own fork of Signal's fork of better-sqlite3 which replaces sqlite3 with sqlcipher. Our fork was necessary in order to obtain the newest version of better-sqlite-3. This fork also has a modification that makes it not try to resolve the nativeBindingPath into an absolute path, because otherwise it was not possible to make it load the native module from within the bundled app
In Desktop, we don't know what kind of storage to use until the use is logging in, so we want to delay initialisation until then by using a proxy storage implementation. The loginfacade may not use the cache in this case.
For each group we record the last batch we processed so that we can
download events since that batch and update the cache. Unfortunately
we would only write those ids when some events are processed. In case
there are no events we would not download any batches on next login.
This fixes plugs the issue with this case by preemptively writing last
id if none could be loaded. Next time we will download batches starting
with that id.
The time when the entityEvents were downloaded last time was used
incorrectly. Because of how it was written and read it would always be
the same number, and we would never detect OutOfSync.
Now we moved it completely to the cache, and we rely on cache to keep
track of it. We do not write incorrect value before fetching the
events during initialization anymore.
It was written recursively due to having been originally written with promise chains, which made it difficult to understand/test/debug
The implementation of "loading in the direction of an existing range" was also incorrect. It would only extend in one direction.
We fixed this and added a test case