Commit Graph

50 Commits

Author SHA1 Message Date
projectmoon 5b3d174edc Separate registering and linking accounts.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
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.
2021-05-26 15:28:59 +00:00
projectmoon 495df13fe6 Do not automatically create accounts; use enum to show this instead.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
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.
2021-05-26 14:20:18 +00:00
projectmoon 5d002e5063 Add ability to store user active room, with skeleton accounts.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
- 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.
2021-05-25 22:29:01 +00:00
projectmoon 849a1b6a14 Remove most of Room DB API
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2021-05-24 22:25:20 +00:00
projectmoon 97be5d5ccb Add migration to remove room state management tables.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details
2021-05-24 22:10:41 +00:00
projectmoon 76214bc790 Add an account deletion command.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2021-05-22 23:12:17 +00:00
projectmoon 8c2a90e86b Tests for secure commands and user DB API.
continuous-integration/drone/pr Build was killed Details
continuous-integration/drone/push Build is failing Details
2021-05-22 22:48:47 +00:00
projectmoon ca34841d86 Functional user account registration.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details
2021-05-22 14:52:32 +00:00
projectmoon c1ec7366e4 Add user accounts, registration command, secure command valiation. 2021-05-22 14:01:16 +00:00
projectmoon 402f236ba7 Remove sled and all related crates from dependencies.
continuous-integration/drone/push Build is passing Details
2021-05-21 14:21:22 +00:00
projectmoon 059538b95d Remove remaining warnings. 2021-05-21 14:14:03 +00:00
projectmoon 4de273db4a Remove sled code; promote sql to top level 2021-05-21 14:05:25 +00:00
projectmoon 5630b4ed20 Add sled migration utility.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2021-05-20 15:30:44 +00:00
projectmoon a3b39ee42c Use ON CONFLICT and transactions where appropriate.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/pr Build is failing Details
2021-05-19 21:34:11 +00:00
projectmoon 7eee16961e Add tests for dbstate.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-19 21:16:39 +00:00
projectmoon 43d8f9574f Allow 'upserts' in insert_room_info. Add a few more room db tests. 2021-05-19 21:06:28 +00:00
projectmoon 1c4cd3d139 Add tests for rooms db API
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 22:15:03 +00:00
projectmoon d1c04b8817 Tests for all of the variables DB api.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 21:39:48 +00:00
projectmoon 5e899cd962 Return key not found error if value not found for user.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 15:37:20 +00:00
projectmoon 257f3a066c Some user variable tests.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 15:17:30 +00:00
projectmoon e539dcac1f Move migrations to sqlite directory. Remove in-memory temp db until refinery supports sqlx.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 14:50:49 +00:00
projectmoon 9f97a6cb43 Implement variable count; fix listing all variables returning values for all users.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 14:27:15 +00:00
projectmoon 66fb6e7cf8 Fix various issues with room events and related logic.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
- 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).
2021-05-16 22:24:27 +00:00
projectmoon 9798821b7b Implement room and dbstate for sqlite.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-16 14:29:57 +00:00
projectmoon cf9ce63892 Replace application-level database connectivity.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
- Some database methods not yet implemented.
 - Unit tests create temp files that are not cleaned up (but they should be).
2021-05-15 23:45:30 +00:00
projectmoon 6b6e59da2e Initial SQLx implementation (variables). not yet wired up to bot.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
- 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.
2021-05-15 15:27:40 +00:00
projectmoon 94be4d2578 Avoid key clone when deleting variables. Minor db code cleanup.
continuous-integration/drone/push Build is passing Details
2021-02-07 21:16:58 +00:00
projectmoon 14f8bc8b39 Reuse device ID generated by matrix SDK after first login.
continuous-integration/drone/push Build is passing Details
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.
2021-02-07 14:21:28 +00:00
projectmoon a65084e04a Unit test for updating room info data.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2020-11-29 21:33:46 +00:00
projectmoon 979dc8ea34 Clearer test name for clearing room info. 2020-11-29 21:29:35 +00:00
projectmoon 0b2246cbd5 Unit tests for inserting and loading room info from db. 2020-11-29 21:29:13 +00:00
projectmoon c8c38ac1d4 Avoid nested map when retrieving room info from db.
continuous-integration/drone/push Build is passing Details
2020-11-29 16:55:23 +00:00
projectmoon 224f8cd0f1 Functions for storing RoomInfo in db. Refactor bot joins room event.
continuous-integration/drone/push Build is passing Details
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.
2020-11-29 14:00:05 +00:00
projectmoon 0e04e67f6e Log debug instead of trace for timestamp index inserts.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2020-11-10 20:37:14 +00:00
projectmoon 551f21a49a Fix minor typo in rooms db code. 2020-11-10 20:22:26 +00:00
projectmoon 9ed2a81dd3 Record all users in room when joining.
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details
2020-11-10 20:18:00 +00:00
projectmoon fb24090952 Keep seen events in database, don't process already-seen events.
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.
2020-11-09 21:16:07 +00:00
projectmoon d7aaed9e00 Implement room clearing, log to info for member updates. 2020-11-08 21:47:01 +00:00
projectmoon b5c78bcee5 Remove userandroom struct from rooms db 2020-11-08 21:47:01 +00:00
projectmoon 51ba3e3f42 Record user join/leaves in rooms. Move event emitter to its own file. 2020-11-08 21:47:01 +00:00
projectmoon 8e2f34819e Half implemented room state management foundations. 2020-11-08 21:47:01 +00:00
projectmoon bf4ce24b79 Better public API for user variables, avoid allocations in Context.
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.
2020-11-03 20:31:29 +00:00
projectmoon 7e15379c58 Migrate existing delineators to delimiter 0xfe. 2020-11-01 19:08:54 +00:00
projectmoon 9f598541fb Remove variable_count keys missed in manual data migration. 2020-10-30 22:44:19 +00:00
projectmoon 5224357f8b Add migration 2: remove old data. 2020-10-30 21:53:22 +00:00
projectmoon 6b21b0aff8 Add string name to migrations 2020-10-30 21:53:22 +00:00
projectmoon 3cec676b2f Clean up migration to make it more readable 2020-10-30 21:53:22 +00:00
projectmoon a53ce85f38 Add db migration support, change variables schema.
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.
2020-10-30 21:53:22 +00:00
projectmoon 4d9ad42bdd De-asyncify database methods 2020-10-30 21:53:22 +00:00
projectmoon 5410c53513 Split database code into separate modules. 2020-10-30 21:53:22 +00:00