@@ -379,15 +379,26 @@ createMessageQ :: Manipulation
379createMessageQ = insertRow #messages
379createMessageQ = insertRow #messages
381 Default `as` #messageStorageId :*
381 Default `as` #messageStorageId :*
382− Set (param @1) `as` #messageStorageAuthorId :*
382+ Set (notNull $ param @1) `as` #messageStorageAuthorId :*
383 Set (param @2) `as` #messageStorageDestinationGroupId :*
383 Set (param @2) `as` #messageStorageDestinationGroupId :*
384 Set (param @3) `as` #messageStorageDestinationUserId :*
384 Set (param @3) `as` #messageStorageDestinationUserId :*
385− Set (param @4) `as` #messageStorageBody :*
385+ Set (notNull $ param @4) `as` #messageStorageBody :*
386 Set currentTimestamp `as` #messageStorageTime
386 Set currentTimestamp `as` #messageStorageTime
388 OnConflictDoRaise
388 OnConflictDoRaise
389 (Returning $ #messageStorageId `as` #fromOnly)
389 (Returning $ #messageStorageId `as` #fromOnly)
391+createPhantomMessageQ :: Manipulation Schema (TuplePG (Only GroupChatId)) '[]
392+createPhantomMessageQ = insertRow_ #messages
394+ Default `as` #messageStorageId :*
395+ Set null_ `as` #messageStorageAuthorId :*
396+ Set (notNull $ param @1) `as` #messageStorageDestinationGroupId :*
397+ Set null_ `as` #messageStorageDestinationUserId :*
398+ Set null_ `as` #messageStorageBody :*
399+ Set currentTimestamp `as` #messageStorageTime
391createGroupChatQ :: Manipulation Schema (TuplePG GroupChatCreation) (RowPG (Only GroupChatId))
402createGroupChatQ :: Manipulation Schema (TuplePG GroupChatCreation) (RowPG (Only GroupChatId))
392createGroupChatQ = insertRow #groupChats
403createGroupChatQ = insertRow #groupChats
@@ -463,7 +474,7 @@ getChatsQ lim dir = select (
463 (ifThenElse
474 (ifThenElse
464 (#messageStorageAuthorId .== param @1)
475 (#messageStorageAuthorId .== param @1)
465 #messageStorageDestinationUserId
476 #messageStorageDestinationUserId
466− (notNull #messageStorageAuthorId)) `as` #messageUserId) $
477+ #messageStorageAuthorId) `as` #messageUserId) $
467 from (table #messages) &
478 from (table #messages) &
468 where_ (isNotNull #messageStorageDestinationUserId .&&
479 where_ (isNotNull #messageStorageDestinationUserId .&&
469 (#messageStorageAuthorId .== param @1 .||
480 (#messageStorageAuthorId .== param @1 .||
@@ -974,12 +985,11 @@ sendMessage selfId (MessageCreation gId@Nothing (Just uId) body) = do
974sendMessage _ _ = lift $ S.throwError S.err400
985sendMessage _ _ = lift $ S.throwError S.err400
976createGroupChat :: UserId -> GroupChatCreation -> StaticPQ GroupChatId
987createGroupChat :: UserId -> GroupChatCreation -> StaticPQ GroupChatId
977−createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = do
988+createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = commitedTransactionallyUpdate $ do
978 let chatUsers' = M.insert uId maxChatPermissions chatUsers
989 let chatUsers' = M.insert uId maxChatPermissions chatUsers
979 (Only chatId) <- manipulateParams createGroupChatQ (GroupChatCreation (Jsonb chatUsers') name)
990 (Only chatId) <- manipulateParams createGroupChatQ (GroupChatCreation (Jsonb chatUsers') name)
980 >>= firstRow >>= fromMaybe500
991 >>= firstRow >>= fromMaybe500
981− -- TODO: Do somehting with this
992+ _ <- manipulateParams createPhantomMessageQ (Only chatId)
982− _ <- sendMessage uId $ MessageCreation (Just chatId) Nothing (Jsonb $ Markdown "henlo")
983 return chatId
993 return chatId
985updateGroupChat :: UserId -> GroupChat -> StaticPQ ()
995updateGroupChat :: UserId -> GroupChat -> StaticPQ ()