summaryrefslogtreecommitdiff
path: root/src/message/app.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-05 20:32:02 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-05 22:47:12 -0400
commit1fb26ad31d385ddc628e1b73d6a8764981ca6885 (patch)
treeda226cfc7e054ce93bf37da943a395dee226baa6 /src/message/app.rs
parent8edd5625ad5dde0ef1637d5c89e9901b3ee65d73 (diff)
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.
Diffstat (limited to 'src/message/app.rs')
-rw-r--r--src/message/app.rs27
1 files changed, 27 insertions, 0 deletions
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<Sequence>,
+ ) -> Result<Vec<Message>, 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?;