From c05251525b4849660f0a1ee50a23b941eb4cd99f Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 15 Aug 2018 21:52:04 +0300 Subject: [PATCH] Complete functions for channels --- src/Database/Channel.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Database/Channel.hs b/src/Database/Channel.hs index 9011863..b1dbfe9 100644 --- a/src/Database/Channel.hs +++ b/src/Database/Channel.hs @@ -51,10 +51,10 @@ booksChannels bookId = fromRels <$> query q attachChannel :: (MonadMask m, MonadIO m, MonadSelda m) => Username -> BookID -> Text -> m () attachChannel username bookId channel = do - -- XXX: test what happens if channel doesn't exist - [Channel{identifier}] <- fromRels <$> query channelQ - whenM (null <$> query (attachQ identifier)) $ - void $ insertGen bookChannels [BookChannel identifier bookId] + mCh <- fromRels <$> query channelQ + forM_ mCh $ \Channel{identifier} -> + whenM (null <$> query (attachQ identifier)) $ + void $ insertGen bookChannels [BookChannel identifier bookId] where attachQ channelId = do (channelId' :*: bookId') <- select (gen bookChannels)