summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-05-13 23:03:56 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-05-13 23:03:56 -0400
commitad4ac3e10d2a3e5569c1b36f87d6a5f78a9cf863 (patch)
treeceb0b6dcff5b0d530d6effa261a1314a9651731a
parent48b4e4ebc4558cf6790c0a9043c46f16b0cbc285 (diff)
Make creation time an intrinsic fact about channels, the way it is for events.
To make unread handling of empty channels coherent (and to make it possible to mark an empty channel as having been read), they need to be associated with a specific point in time. This change exposes their creation time in the snapshot - it was already part of the event view, though the client doesn't know that yet.
-rw-r--r--docs/api/boot.md10
-rw-r--r--src/channel/event.rs4
-rw-r--r--src/channel/history.rs2
-rw-r--r--src/channel/repo.rs10
-rw-r--r--src/channel/snapshot.rs4
5 files changed, 15 insertions, 15 deletions
diff --git a/docs/api/boot.md b/docs/api/boot.md
index 46b972f..2b9cf00 100644
--- a/docs/api/boot.md
+++ b/docs/api/boot.md
@@ -51,6 +51,7 @@ This endpoint will respond with a status of
],
"channels": [
{
+ "at": "2025-04-14T23:58:11.421901Z",
"name": "nonsense and such",
"id": "C1234abcd"
}
@@ -94,10 +95,11 @@ Each element of the `users` array describes a distinct user, and will include th
Each element of the `channels` array describes a distinct channel, and will include the following fields:
-| Field | Type | Description |
-|:-------|:-------|:----------------------------------------------------------------------------------------------------------------------------------------------|
-| `name` | string | The name for the channel. |
-| `id` | string | A unique identifier for the channel. This can be used to associate the channel with other events, or to make API calls targeting the channel. |
+| Field | Type | Description |
+|:-------|:----------|:----------------------------------------------------------------------------------------------------------------------------------------------|
+| `at` | timestamp | The moment the channel was created. |
+| `name` | string | The name for the channel. |
+| `id` | string | A unique identifier for the channel. This can be used to associate the channel with other events, or to make API calls targeting the channel. |
Each element of the `messages` array describes a distinct message, and will include the following fields:
diff --git a/src/channel/event.rs b/src/channel/event.rs
index f3dca3e..a5739f9 100644
--- a/src/channel/event.rs
+++ b/src/channel/event.rs
@@ -14,7 +14,7 @@ pub enum Event {
impl Sequenced for Event {
fn instant(&self) -> Instant {
match self {
- Self::Created(event) => event.instant,
+ Self::Created(event) => event.channel.created,
Self::Deleted(event) => event.instant,
}
}
@@ -23,8 +23,6 @@ impl Sequenced for Event {
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub struct Created {
#[serde(flatten)]
- pub instant: Instant,
- #[serde(flatten)]
pub channel: Channel,
}
diff --git a/src/channel/history.rs b/src/channel/history.rs
index 4af46ce..faf6a0e 100644
--- a/src/channel/history.rs
+++ b/src/channel/history.rs
@@ -9,7 +9,6 @@ use crate::event::{Instant, Sequence};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct History {
pub channel: Channel,
- pub created: Instant,
pub deleted: Option<Instant>,
}
@@ -50,7 +49,6 @@ impl History {
fn created(&self) -> Event {
Created {
- instant: self.created,
channel: self.channel.clone(),
}
.into()
diff --git a/src/channel/repo.rs b/src/channel/repo.rs
index 91f245b..812a259 100644
--- a/src/channel/repo.rs
+++ b/src/channel/repo.rs
@@ -57,11 +57,11 @@ impl Channels<'_> {
let channel = History {
channel: Channel {
+ created,
id,
name: name.clone(),
deleted_at: None,
},
- created,
deleted: None,
};
@@ -91,11 +91,11 @@ impl Channels<'_> {
.map(|row| {
Ok::<_, name::Error>(History {
channel: Channel {
+ created: Instant::new(row.created_at, row.created_sequence),
id: row.id,
name: Name::optional(row.display_name, row.canonical_name)?.unwrap_or_default(),
deleted_at: row.deleted_at,
},
- created: Instant::new(row.created_at, row.created_sequence),
deleted: Instant::optional(row.deleted_at, row.deleted_sequence),
})
})
@@ -129,11 +129,11 @@ impl Channels<'_> {
.map(|row| {
Ok::<_, name::Error>(History {
channel: Channel {
+ created: Instant::new(row.created_at, row.created_sequence),
id: row.id,
name: Name::optional(row.display_name, row.canonical_name)?.unwrap_or_default(),
deleted_at: row.deleted_at,
},
- created: Instant::new(row.created_at, row.created_sequence),
deleted: Instant::optional(row.deleted_at, row.deleted_sequence),
})
})
@@ -168,11 +168,11 @@ impl Channels<'_> {
.map(|row| {
Ok::<_, name::Error>(History {
channel: Channel {
+ created: Instant::new(row.created_at, row.created_sequence),
id: row.id,
name: Name::optional(row.display_name, row.canonical_name)?.unwrap_or_default(),
deleted_at: row.deleted_at,
},
- created: Instant::new(row.created_at, row.created_sequence),
deleted: Instant::optional(row.deleted_at, row.deleted_sequence),
})
})
@@ -299,11 +299,11 @@ impl Channels<'_> {
.map(|row| {
Ok::<_, name::Error>(History {
channel: Channel {
+ created: Instant::new(row.created_at, row.created_sequence),
id: row.id,
name: Name::optional(row.display_name, row.canonical_name)?.unwrap_or_default(),
deleted_at: row.deleted_at,
},
- created: Instant::new(row.created_at, row.created_sequence),
deleted: Instant::optional(row.deleted_at, row.deleted_sequence),
})
})
diff --git a/src/channel/snapshot.rs b/src/channel/snapshot.rs
index 046ac38..96801b8 100644
--- a/src/channel/snapshot.rs
+++ b/src/channel/snapshot.rs
@@ -2,10 +2,12 @@ use super::{
Id,
event::{Created, Event},
};
-use crate::{clock::DateTime, name::Name};
+use crate::{clock::DateTime, event::Instant, name::Name};
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub struct Channel {
+ #[serde(flatten)]
+ pub created: Instant,
pub id: Id,
pub name: Name,
#[serde(skip_serializing_if = "Option::is_none")]