From 1fb26ad31d385ddc628e1b73d6a8764981ca6885 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sat, 5 Oct 2024 20:32:02 -0400 Subject: Use `/api/boot` to bootstrap the client. The client now takes an initial snapshot from the response to `/api/boot`, then picks up the event stream at the immediately-successive event to the moment the snapshot was taken. This commit removes the following unused endpoints: * `/api/channels` (GET) * `/api/channels/:channel/messages` (GET) The information therein is now part of the boot response. We can always add 'em back, but I wanted to clear the deck for designing something more capable, for dealing with client needs. --- src/message/app.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/message') diff --git a/src/message/app.rs b/src/message/app.rs index 385c92e..1e50a65 100644 --- a/src/message/app.rs +++ b/src/message/app.rs @@ -44,6 +44,33 @@ impl<'a> Messages<'a> { Ok(message.as_sent()) } + pub async fn in_channel( + &self, + channel: &channel::Id, + resume_point: Option, + ) -> Result, DeleteError> { + let mut tx = self.db.begin().await?; + let channel = tx + .channels() + .by_id(channel) + .await + .not_found(|| DeleteError::ChannelNotFound(channel.clone()))?; + let messages = tx.messages().in_channel(&channel, resume_point).await?; + tx.commit().await?; + + let messages = messages + .into_iter() + .filter_map(|message| { + message + .events() + .filter(Sequence::up_to(resume_point)) + .collect() + }) + .collect(); + + Ok(messages) + } + pub async fn delete(&self, message: &Id, deleted_at: &DateTime) -> Result<(), DeleteError> { let mut tx = self.db.begin().await?; let deleted = tx.sequence().next(deleted_at).await?; -- cgit v1.2.3