diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 19:14:22 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 19:14:22 -0400 |
| commit | 4563f221bf61123b15f9608bb14e8f46db05e4f6 (patch) | |
| tree | 58a5ee7e0e14b918a332d4536dec06d4ad8367e8 /src/channel/repo.rs | |
| parent | 588a14848d4ac45f31ee8646555e1e21cca5595d (diff) | |
Remove the notion of "channel members."
This came out of a conversation with Kit. Their position, loosely, was that seeing scrollback when you look at a channel is useful, and since message delivery isn't meaningfully tied to membership (or at least doesn't have to be), what the hell is membership even doing? (I may have added that last part.)
My take, on top of that, is that membership increases the amount of concepts we're committed to. We don't need that commitment yet.
Diffstat (limited to 'src/channel/repo.rs')
| -rw-r--r-- | src/channel/repo.rs | 76 |
1 files changed, 4 insertions, 72 deletions
diff --git a/src/channel/repo.rs b/src/channel/repo.rs index a255305..a04cac5 100644 --- a/src/channel/repo.rs +++ b/src/channel/repo.rs @@ -2,8 +2,8 @@ use std::fmt; use sqlx::{sqlite::Sqlite, SqliteConnection, Transaction}; +use crate::error::BoxedError; use crate::id::Id as BaseId; -use crate::{error::BoxedError, login::repo::logins::Id as LoginId}; pub trait Provider { fn channels(&mut self) -> Channels; @@ -25,65 +25,25 @@ pub struct Channel { impl<'c> Channels<'c> { /// Create a new channel. - pub async fn create(&mut self, name: &str) -> Result<Channel, BoxedError> { + pub async fn create(&mut self, name: &str) -> Result<(), BoxedError> { let id = Id::generate(); - let channel = sqlx::query_as!( - Channel, + sqlx::query!( r#" insert into channel (id, name) values ($1, $2) - returning id as "id: Id", name "#, id, name, ) - .fetch_one(&mut *self.0) - .await?; - - Ok(channel) - } - - /// Enrol a login in a channel. - pub async fn join(&mut self, channel: &Id, login: &LoginId) -> Result<(), BoxedError> { - sqlx::query!( - r#" - insert - into channel_member (channel, login) - values ($1, $2) - "#, - channel, - login, - ) .execute(&mut *self.0) .await?; Ok(()) } - pub async fn joined(&mut self, login: &LoginId) -> Result<Vec<Channel>, BoxedError> { - let channels = sqlx::query_as!( - Channel, - r#" - select - channel.id as "id: Id", - channel.name - from channel - join channel_member - on (channel.id = channel_member.channel) - where channel_member.login = $1 - order by channel.name - "#, - login, - ) - .fetch_all(&mut *self.0) - .await?; - - Ok(channels) - } - - pub async fn unjoined(&mut self, login: &LoginId) -> Result<Vec<Channel>, BoxedError> { + pub async fn all(&mut self) -> Result<Vec<Channel>, BoxedError> { let channels = sqlx::query_as!( Channel, r#" @@ -91,42 +51,14 @@ impl<'c> Channels<'c> { channel.id as "id: Id", channel.name from channel - except - select - channel.id as "id: Id", - channel.name - from channel - join channel_member - on (channel.id = channel_member.channel) - where channel_member.login = $1 order by channel.name "#, - login, ) .fetch_all(&mut *self.0) .await?; Ok(channels) } - - /// Unenrol a login from a channel. - pub async fn leave(&mut self, channel: &Id, login: &LoginId) -> Result<(), BoxedError> { - sqlx::query_scalar!( - r#" - delete - from channel_member - where channel = $1 - and login = $2 - returning 1 as "deleted: bool" - "#, - channel, - login, - ) - .fetch_one(&mut *self.0) - .await?; - - Ok(()) - } } /// Stable identifier for a [Channel]. Prefixed with `C`. |
