summaryrefslogtreecommitdiff
path: root/src/channel
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel')
-rw-r--r--src/channel/app.rs13
-rw-r--r--src/channel/history.rs31
2 files changed, 27 insertions, 17 deletions
diff --git a/src/channel/app.rs b/src/channel/app.rs
index bb331ec..1b2cc48 100644
--- a/src/channel/app.rs
+++ b/src/channel/app.rs
@@ -33,7 +33,7 @@ impl<'a> Channels<'a> {
self.events
.broadcast(channel.events().map(Event::from).collect::<Vec<_>>());
- Ok(channel.snapshot())
+ Ok(channel.as_created())
}
pub async fn all(&self, resume_point: Option<Sequence>) -> Result<Vec<Channel>, InternalError> {
@@ -64,8 +64,7 @@ impl<'a> Channels<'a> {
.channels()
.by_id(channel)
.await
- .not_found(|| Error::NotFound(channel.clone()))?
- .snapshot();
+ .not_found(|| Error::NotFound(channel.clone()))?;
let messages = tx
.messages()
@@ -90,16 +89,14 @@ impl<'a> Channels<'a> {
.channels()
.by_id(channel)
.await
- .not_found(|| Error::NotFound(channel.clone()))?
- .snapshot();
+ .not_found(|| Error::NotFound(channel.clone()))?;
let mut events = Vec::new();
let messages = tx.messages().in_channel(&channel, None).await?;
for message in messages {
- let message = message.snapshot();
let deleted = tx.sequence().next(deleted_at).await?;
- let message = tx.messages().delete(&message.id, &deleted).await?;
+ let message = tx.messages().delete(message.id(), &deleted).await?;
events.extend(
message
.events()
@@ -109,7 +106,7 @@ impl<'a> Channels<'a> {
}
let deleted = tx.sequence().next(deleted_at).await?;
- let channel = tx.channels().delete(&channel.id, &deleted).await?;
+ let channel = tx.channels().delete(channel.id(), &deleted).await?;
events.extend(
channel
.events()
diff --git a/src/channel/history.rs b/src/channel/history.rs
index 3cc7d9d..bd45d8d 100644
--- a/src/channel/history.rs
+++ b/src/channel/history.rs
@@ -1,6 +1,6 @@
use super::{
event::{Created, Deleted, Event},
- Channel,
+ Channel, Id,
};
use crate::event::Instant;
@@ -11,7 +11,28 @@ pub struct History {
pub deleted: Option<Instant>,
}
+// State interface
impl History {
+ pub fn id(&self) -> &Id {
+ &self.channel.id
+ }
+
+ // Snapshot of this channel as it was when created. (Note to the future: it's
+ // okay if this returns a redacted or modified version of the channel. If we
+ // implement renames by redacting the original name, then this should return the
+ // renamed channel, not the original, even if that's not how it was "as
+ // created.")
+ pub fn as_created(&self) -> Channel {
+ self.channel.clone()
+ }
+}
+
+// Event factories
+impl History {
+ pub fn events(&self) -> impl Iterator<Item = Event> {
+ [self.created()].into_iter().chain(self.deleted())
+ }
+
fn created(&self) -> Event {
Event {
instant: self.created,
@@ -31,12 +52,4 @@ impl History {
.into(),
})
}
-
- pub fn events(&self) -> impl Iterator<Item = Event> {
- [self.created()].into_iter().chain(self.deleted())
- }
-
- pub fn snapshot(&self) -> Channel {
- self.channel.clone()
- }
}