@@ -935,7 +935,7 @@ publishPost uId pc = commitedTransactionallyUpdate $ do
935935 pId' <- manipulateParams createPostRowQ (uId, postCreationTags pc) >>= firstRow
936936 case pId' of
937937 (Just (Only pId)) -> do
938− traversePrepared_ createPostElementRowsQ $ elementsToRows pId (postCreationBody pc)
938+ traversePrepared_ createPostElementRowsQ $ elementsToRows pId (map stripPostElement $ postCreationBody pc)
939939 return pId
940940 _ -> lift $ S.throwError S.err404
941941
@@ -1006,7 +1006,6 @@ deleteNamedChannel uId cId = do
10061006 _ <- commitedTransactionallyUpdate $ manipulateParams deleteNamedChannelQ (Only cId)
10071007 return ()
10081008
1009−-- Returns n most popular
10101009getTags :: Limit -> StaticPQ [String]
10111010getTags lim = map fromOnly <$> (runQuery (getNpopularTagsQ lim) >>= getRows)
10121011
@@ -1044,33 +1043,37 @@ getMessagesInGroupChat selfId gId mId lim dir = do
10441043 return . catMaybes . map restoreMessage $ resp
10451044
10461045sendMessage :: UserId -> MessageCreation -> StaticPQ MessageId
1047−sendMessage selfId (MessageCreation (Just gId) uId@Nothing body) = do
1046+sendMessage selfId (MessageCreation (Just gId) uId@Nothing (Jsonb body)) = do
10481047 _ <- getGroupChatForUser selfId gId
1049− (Only mId) <- manipulateParams createMessageQ (selfId, Just gId, uId, body)
1048+ (Only mId) <- manipulateParams createMessageQ (selfId, Just gId, uId, Jsonb $ stripPostElement body)
10501049 >>= firstRow >>= fromMaybe500
10511050 return mId
1052−sendMessage selfId (MessageCreation gId@Nothing (Just uId) body) = do
1051+sendMessage selfId (MessageCreation gId@Nothing (Just uId) (Jsonb body)) = do
10531052 verifyUsers [uId]
1054− (Only mId) <- manipulateParams createMessageQ (selfId, gId, Just uId, body)
1053+ (Only mId) <- manipulateParams createMessageQ (selfId, gId, Just uId, Jsonb $ stripPostElement body)
10551054 >>= firstRow >>= fromMaybe500
10561055 return mId
10571056sendMessage _ _ = lift $ S.throwError S.err400
10581057
10591058createGroupChat :: UserId -> GroupChatCreation -> StaticPQ GroupChatId
1060−createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = commitedTransactionallyUpdate $ do
1061− let chatUsers' = M.insert uId maxChatPermissions chatUsers
1062− (Only chatId) <- manipulateParams createGroupChatQ (GroupChatCreation (Jsonb chatUsers') name)
1063− >>= firstRow >>= fromMaybe500
1064− _ <- manipulateParams createPhantomMessageQ (Only chatId)
1065− return chatId
1059+createGroupChat uId (GroupChatCreation (Jsonb chatUsers) name) = do
1060+ verifyUsers . M.keys $ chatUsers
1061+ commitedTransactionallyUpdate $ do
1062+ let chatUsers' = M.insert uId maxChatPermissions chatUsers
1063+ (Only chatId) <- manipulateParams createGroupChatQ (GroupChatCreation (Jsonb chatUsers') name)
1064+ >>= firstRow >>= fromMaybe500
1065+ _ <- manipulateParams createPhantomMessageQ (Only chatId)
1066+ return chatId
10661067
10671068updateGroupChat :: UserId -> GroupChat -> StaticPQ ()
1068−updateGroupChat uId (GroupChat gId (Jsonb perms) name) = commitedTransactionallyUpdate $ do
1069− (GroupChat _ (Jsonb perms') _) <- getGroupChatForUser uId gId
1070− let userPerm = fromMaybe minChatPermissions $ M.lookup uId perms'
1071− unless (isAdmin userPerm) $ lift $ S.throwError $ S.err401
1072− let newPerms = M.insert uId userPerm perms
1073− void $ manipulateParams updateGroupChatQ (GroupChat gId (Jsonb newPerms) name)
1069+updateGroupChat uId (GroupChat gId (Jsonb perms) name) = do
1070+ verifyUsers . M.keys $ perms
1071+ commitedTransactionallyUpdate $ do
1072+ (GroupChat _ (Jsonb perms') _) <- getGroupChatForUser uId gId
1073+ let userPerm = fromMaybe minChatPermissions $ M.lookup uId perms'
1074+ unless (isAdmin userPerm) $ lift $ S.throwError $ S.err401
1075+ let newPerms = M.insert uId userPerm perms
1076+ void $ manipulateParams updateGroupChatQ (GroupChat gId (Jsonb newPerms) name)
10741077
10751078leaveGroupChat :: UserId -> GroupChatId -> StaticPQ ()
10761079leaveGroupChat uId gId = commitedTransactionallyUpdate $ do