diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-09 01:43:34 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-09 11:45:31 -0400 |
| commit | 2f0b77e8fd02a137047c8975a573626cd76310ff (patch) | |
| tree | 481d82e99cf8aad8fe256d8186ae72bcee23bf9f /src/boot/mod.rs | |
| parent | ba96974bdebd6d4ec345907d49944b5ee644ed47 (diff) | |
Return a flat message list on boot, not nested lists by channel.
This is a bit easier to compute, and sets us up nicely for pulling message boot out of the `/api/boot` response entirely.
Diffstat (limited to 'src/boot/mod.rs')
| -rw-r--r-- | src/boot/mod.rs | 63 |
1 files changed, 1 insertions, 62 deletions
diff --git a/src/boot/mod.rs b/src/boot/mod.rs index 1f94106..ed4764a 100644 --- a/src/boot/mod.rs +++ b/src/boot/mod.rs @@ -1,12 +1,7 @@ pub mod app; mod routes; -use crate::{ - channel, - event::{Instant, Sequence}, - login::{self, Login}, - message, -}; +use crate::{channel::Channel, event::Sequence, login::Login, message::Message}; pub use self::routes::router; @@ -15,61 +10,5 @@ pub struct Snapshot { pub resume_point: Sequence, pub logins: Vec<Login>, pub channels: Vec<Channel>, -} - -#[derive(serde::Serialize)] -pub struct Channel { - pub id: channel::Id, - pub name: String, pub messages: Vec<Message>, } - -impl Channel { - fn new( - channel: channel::Channel, - messages: impl IntoIterator<Item = message::Message>, - ) -> Self { - // The declarations are like this to guarantee that we aren't omitting any important fields from the corresponding types. - let channel::Channel { id, name } = channel; - - Self { - id, - name, - messages: messages.into_iter().map(Message::from).collect(), - } - } -} - -#[derive(serde::Serialize)] -pub struct Message { - #[serde(flatten)] - pub sent: Instant, - pub sender: login::Id, - pub id: message::Id, - pub body: String, -} - -impl From<message::Message> for Message { - fn from(message: message::Message) -> Self { - let message::Message { - sent, - channel: _, - sender, - id, - body, - } = message; - - Self { - sent, - sender, - id, - body, - } - } -} - -#[derive(serde::Serialize)] -pub struct Body { - id: message::Id, - body: String, -} |
