summaryrefslogtreecommitdiff
path: root/src/channel/repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/repo.rs')
-rw-r--r--src/channel/repo.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/channel/repo.rs b/src/channel/repo.rs
index bb39d6e..a255305 100644
--- a/src/channel/repo.rs
+++ b/src/channel/repo.rs
@@ -62,7 +62,7 @@ impl<'c> Channels<'c> {
Ok(())
}
- pub async fn for_login(&mut self, login: &LoginId) -> Result<Vec<Channel>, BoxedError> {
+ pub async fn joined(&mut self, login: &LoginId) -> Result<Vec<Channel>, BoxedError> {
let channels = sqlx::query_as!(
Channel,
r#"
@@ -83,6 +83,32 @@ impl<'c> Channels<'c> {
Ok(channels)
}
+ pub async fn unjoined(&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
+ 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!(