@@ -379,15 +379,26 @@ createMessageQ :: Manipulation
379379createMessageQ = insertRow #messages
380380 (
381381 Default `as` #messageStorageId :*
382− Set (param @1) `as` #messageStorageAuthorId :*
382+ Set (notNull $ param @1) `as` #messageStorageAuthorId :*
383383 Set (param @2) `as` #messageStorageDestinationGroupId :*
384384 Set (param @3) `as` #messageStorageDestinationUserId :*
385− Set (param @4) `as` #messageStorageBody :*
385+ Set (notNull $ param @4) `as` #messageStorageBody :*
386386 Set currentTimestamp `as` #messageStorageTime
387387 )
388388 OnConflictDoRaise
389389 (Returning $ #messageStorageId `as` #fromOnly)
390390
391+createPhantomMessageQ :: Manipulation Schema (TuplePG (Only GroupChatId)) '[]
392+createPhantomMessageQ = insertRow_ #messages
393+ (
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
400+ )
401+
391402createGroupChatQ :: Manipulation Schema (TuplePG GroupChatCreation) (RowPG (Only GroupChatId))
392403createGroupChatQ = insertRow #groupChats
393404 (
@@ -463,7 +474,7 @@ getChatsQ lim dir = select (
463474 (ifThenElse
464475 (#messageStorageAuthorId .== param @1)
465476 #messageStorageDestinationUserId
466− (notNull #messageStorageAuthorId)) `as` #messageUserId) $
477+ #messageStorageAuthorId) `as` #messageUserId) $
467478 from (table #messages) &
468479 where_ (isNotNull #messageStorageDestinationUserId .&&
469480 (#messageStorageAuthorId .== param @1 .||
@@ -974,12 +985,11 @@ sendMessage selfId (MessageCreation gId@Nothing (Just uId) body) = do
974985sendMessage _ _ = lift $ S.throwError S.err400
975986
976987createGroupChat :: UserId -> GroupChatCreation -> StaticPQ GroupChatId
977−createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = do
988+createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = commitedTransactionallyUpdate $ do
978989 let chatUsers' = M.insert uId maxChatPermissions chatUsers
979990 (Only chatId) <- manipulateParams createGroupChatQ (GroupChatCreation (Jsonb chatUsers') name)
980991 >>= firstRow >>= fromMaybe500
981− -- TODO: Do somehting with this
982− _ <- sendMessage uId $ MessageCreation (Just chatId) Nothing (Jsonb $ Markdown "henlo")
992+ _ <- manipulateParams createPhantomMessageQ (Only chatId)
983993 return chatId
984994
985995updateGroupChat :: UserId -> GroupChat -> StaticPQ ()