summaryrefslogtreecommitdiff
path: root/src/message/handlers/delete
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-08-27 06:10:29 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-08-27 06:10:29 +0200
commit8712c3a19c279d664ce75e8e90d6dde1bda56cb4 (patch)
tree93c95548126eea048cd8962345b720b883d391c1 /src/message/handlers/delete
parent7b131e35fdea1a68aaf9230d157bafb200557ef8 (diff)
parentf839449d5505b5352bd0da931b980a7a0305234f (diff)
Implement storage of synchronized entities in terms of events, not state.
Conversations, users, messages, and all other "synchronized" entities now have an in-memory implementation of their lifecycle, rather than a database-backed one. These operations take a history, apply one lifecycle change to that history, and emit a new history. Storage is then implemented by applying the events in this new history to the database. The storage methods in repo types, which process these events by emitting SQL statements, make necessary assumptions that the events being passed to them are coherent with the data already in storage. For example, the code to handle a conversation's delete event is allowed to assume that the database already contains a row for that conversation, inserted in response to a prior conversation creation event. Data retrieval is not modified in this commit, and probably never will be without a more thorough storage rewrite. The whole intention of the data modelling approach I've been using is that a single row per entity represents its entire history, in turn so that the data in the database should be legible to people approaching it using normal SQL tools. Developed as an aesthetic response to increasing unease with the lack of an ORM versus the boring-ness of our actual queries. Merges event-based-storage into main.
Diffstat (limited to 'src/message/handlers/delete')
-rw-r--r--src/message/handlers/delete/mod.rs7
-rw-r--r--src/message/handlers/delete/test.rs18
2 files changed, 12 insertions, 13 deletions
diff --git a/src/message/handlers/delete/mod.rs b/src/message/handlers/delete/mod.rs
index 606f502..3e9a212 100644
--- a/src/message/handlers/delete/mod.rs
+++ b/src/message/handlers/delete/mod.rs
@@ -51,10 +51,9 @@ impl IntoResponse for Error {
DeleteError::MessageNotFound(_) | DeleteError::Deleted(_) => {
NotFound(error).into_response()
}
- DeleteError::UserNotFound(_)
- | DeleteError::UserDeleted(_)
- | DeleteError::Database(_)
- | DeleteError::Name(_) => Internal::from(error).into_response(),
+ DeleteError::Database(_) | DeleteError::Name(_) => {
+ Internal::from(error).into_response()
+ }
}
}
}
diff --git a/src/message/handlers/delete/test.rs b/src/message/handlers/delete/test.rs
index d0e1794..05d9344 100644
--- a/src/message/handlers/delete/test.rs
+++ b/src/message/handlers/delete/test.rs
@@ -70,23 +70,23 @@ pub async fn delete_deleted() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let sender = fixtures::user::create(&app, &fixtures::now()).await;
+ let sender = fixtures::identity::create(&app, &fixtures::now()).await;
let conversation = fixtures::conversation::create(&app, &fixtures::now()).await;
- let message = fixtures::message::send(&app, &conversation, &sender, &fixtures::now()).await;
+ let message =
+ fixtures::message::send(&app, &conversation, &sender.login, &fixtures::now()).await;
app.messages()
- .delete(&sender, &message.id, &fixtures::now())
+ .delete(&sender.login, &message.id, &fixtures::now())
.await
.expect("deleting a recently-sent message succeeds");
// Send the request
- let deleter = fixtures::identity::create(&app, &fixtures::now()).await;
let super::Error(error) = super::handler(
State(app.clone()),
Path(message.id.clone()),
fixtures::now(),
- deleter,
+ sender,
)
.await
.expect_err("deleting a deleted message fails");
@@ -101,9 +101,10 @@ pub async fn delete_expired() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let sender = fixtures::user::create(&app, &fixtures::ancient()).await;
+ let sender = fixtures::identity::create(&app, &fixtures::ancient()).await;
let conversation = fixtures::conversation::create(&app, &fixtures::ancient()).await;
- let message = fixtures::message::send(&app, &conversation, &sender, &fixtures::ancient()).await;
+ let message =
+ fixtures::message::send(&app, &conversation, &sender.login, &fixtures::ancient()).await;
app.messages()
.expire(&fixtures::now())
@@ -112,12 +113,11 @@ pub async fn delete_expired() {
// Send the request
- let deleter = fixtures::identity::create(&app, &fixtures::now()).await;
let super::Error(error) = super::handler(
State(app.clone()),
Path(message.id.clone()),
fixtures::now(),
- deleter,
+ sender,
)
.await
.expect_err("deleting an expired message fails");