Can register an account with the bot to manage variables and stuff in
private room, and then separately "link" it with a password, which
makes it available to anything using the bot API (aka web app). Can
also unlink and unregister. Check command no longer validates
password. It just checks and reports your account status.
Instead of automatically creating a user account entry for any user
executing a command, we use an Account enum which covers both
registered and "transient" unregistered users. If a user registers,
the context has the actual user instance available, with state and
everything. If a user is unregistered, then the account is considered
transient for the request, with only the username available.
- Adds a user_state table, currently only with active_room.
- A user must have an account to take advantage of state.
- Now, all users will get an 'account' even if they don't explicitly register.
- Bonus: converts user queries to compile-time checked macros.
To support these automatically created "accounts," the accounts table
now also has an account_status column, indicating if the user is
registered or not (or pending activation--future use).
The User model has been updated with extra properties from the state,
and the user is now carrried in the Context during command execution.
A user is ensured to be created before executing the command.
- Processing events multiple times when re-joining rooms.
- Always thinking we've not processed an event/constraint
violations (arguments were reversed in record_event).
- Not handling errors when fetchin users in a room, and instead
just suppressing them. Now, we handle errors!
- Also update dependencies (attempt to fix ID too big bug, but no
fix).
- Adds migrations for the necessary tables.
- Implements the user variables database functions.
- Adds sqlx metadata for 'offline' use so we can build without a database.
Adds new db tree for simple global state values (which also lays
foundation for other stuff), and stores device ID in that tree after
first login. The ID is then reused on subsequent runs of the
application.
This is simpler than storing device ID in config file.
Fixes#9.
Add get/insert functions for RoomInfo in the rooms db.
Move 'bot joins room' code to single method, so we can also record a
RoomInfo struct into the database.
Adds a new function `should_process` to rooms impl that determines if
calling could should proceed with processing an event ID. Event IDs
are recorded (along with room ID) as a key pointing to the
system-local timestamp of when the event was received. If the key was
not originally present, we instruct calling code to process the event.
Events are also asychronously recorded by timestamp using a sled event
watcher that listens to inserts in the main tree (described above).
This secondary tree will allow easy cleanup of old events in the
future.
The database API for user variables has changed somewhat again, this
time closer to the proper vision. There are now two separate sled
Trees in the Variables struct, one for user-defined variables, and one
for counts. Keys have been changed to be username-first, then room ID.
The signatures of the functions now also use a strongly-typed struct,
UserAndRoom.
As part of this, the Context object now once again avoids allocating
new strings.
Other random changes included here:
- Remove tempfile crate in favor of sled temporary db config.
- Add bincode crate in anticipation of future (de)serializing.
This is a bit of a large commit that adds basic database migration
support. It also alters the way user variables are stored in a way
requiring manual migration of existing data. The first automated
migration adds variable count in a new place.