From 2f0b77e8fd02a137047c8975a573626cd76310ff Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 9 Oct 2024 01:43:34 -0400 Subject: 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. --- src/boot/mod.rs | 63 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) (limited to 'src/boot/mod.rs') 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, pub channels: Vec, -} - -#[derive(serde::Serialize)] -pub struct Channel { - pub id: channel::Id, - pub name: String, pub messages: Vec, } - -impl Channel { - fn new( - channel: channel::Channel, - messages: impl IntoIterator, - ) -> 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 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, -} -- cgit v1.2.3