on master help sign in
Merge pull request #145 from ilyakooo0/develop
2733d30iko
denis/src/Data/Limits.hs+4−1
@@ -29,4 +29,7 @@ listLimit :: Int
29listLimit = 100
29listLimit = 100
30
30
31globalTextLimit :: Int
31globalTextLimit :: Int
32−globalTextLimit = 50000
32+globalTextLimit = 50000
33+
34+groupChatSizeLimit :: Int
35+groupChatSizeLimit = 256
denis/src/Server/API/Messages.hs+7−2
@@ -4,7 +4,8 @@
4 OverloadedLabels,
4 OverloadedLabels,
5 OverloadedStrings ,
5 OverloadedStrings ,
6 TypeApplications ,
6 TypeApplications ,
7− TypeOperators #-}
7+ TypeOperators,
8+ RecordWildCards #-}
8
9
9module Server.API.Messages (
10module Server.API.Messages (
10 MessagesApi,
11 MessagesApi,
@@ -24,6 +25,9 @@ import Server.Query.Dialog
24import Data.Text.Validator
25import Data.Text.Validator
25import Control.Monad
26import Control.Monad
26import Server.Error
27import Server.Error
28+import qualified Data.Map as M
29+import Squeal.PostgreSQL.Schema
30+import Data.Limits
27
31
28type GetAllChatsDescription = Description "Gets chats starting from/ending with the given message id."
32type GetAllChatsDescription = Description "Gets chats starting from/ending with the given message id."
29type GetGroupChatDescription = Description "Gets information about a given group chat."
33type GetGroupChatDescription = Description "Gets information about a given group chat."
@@ -94,8 +98,9 @@ sendMessageApi uId mes = do
94 runQerror $ sendMessage uId mes
98 runQerror $ sendMessage uId mes
95
99
96createGroupChatApi :: UserId -> GroupChatCreation -> App GroupChatId
100createGroupChatApi :: UserId -> GroupChatCreation -> App GroupChatId
97−createGroupChatApi uId group = do
101+createGroupChatApi uId group@GroupChatCreation{..} = do
98 unless (validateText group) $ throwError lengthExceeded
102 unless (validateText group) $ throwError lengthExceeded
103+ unless ((M.size $ getJsonb groupChatCreationUsers) < groupChatSizeLimit) $ throwError amountExceeded
99 runQerror $ createGroupChat uId group
104 runQerror $ createGroupChat uId group
100
105
101leaveChatAPI :: UserId -> GroupChatId -> App NoContent
106leaveChatAPI :: UserId -> GroupChatId -> App NoContent