packages feed

mattermost-api 40900.1.0 → 50200.0.0

raw patch · 11 files changed

+105/−94 lines, 11 files

Files

CHANGELOG.md view
@@ -1,4 +1,22 @@ +50200.0.0+=========++API changes:+ * Expose new type, TeammateNameDisplayMode, as the type of the+   clientConfigTeammateNameDisplay field+ * Removed various fields from TeamSettings and ClientConfig that seem+   to have been removed in 4.9+ * Remove `parent_id` fields from Post and PendingPost since they are+   unused and thus confusing+ * Added basic parsing support for websocket events new in 5.2 (fixes #408)+ * ClientConfig: removed EnableUserCreation field that is removed in 5.0+ * Removed `extra_update_at` channel data field++Bug fixes:+ * Fixed examples and tests to use the UserText type instead of+   Data.Text (thanks Carlos D <m@cdagostino.io>)+ 40900.1.0 ========= 
examples/Config.hs view
@@ -1,12 +1,13 @@ module Config where  import Data.Text+import Network.Mattermost.Types ( UserText )  data Config   = Config   { configUsername :: Text   , configHostname :: Text-  , configTeam     :: Text+  , configTeam     :: UserText   , configPort     :: Int   , configPassword :: Text   }
examples/GetPosts.hs view
@@ -32,7 +32,7 @@  data Options   = Options-  { optChannel :: T.Text+  { optChannel :: UserText   , optVerbose :: Bool   , optOffset  :: Int   , optLimit   :: Int@@ -41,7 +41,7 @@  defaultOptions :: Options defaultOptions = Options-  { optChannel = "town-square"+  { optChannel = UserText "town-square"   , optVerbose = False   , optOffset  = 0   , optLimit   = 10@@ -52,7 +52,7 @@ options =   [ Option "c" ["channel"]       (ReqArg-        (\arg opt -> return opt { optChannel = T.pack arg })+        (\arg opt -> return opt { optChannel = UserText . T.pack $ arg })         "CHANNEL")       "Channel to fetch posts from"   , Option "v" ["verbose"]@@ -139,5 +139,5 @@                pPrint p             let message = printf "%s: %s"                                  (userUsername user)-                                 (postMessage p)+                                 (unsafeUserText . postMessage $ p)             putStrLn message
examples/LocalConfig.hs view
@@ -1,7 +1,9 @@+{-# LANGUAGE OverloadedStrings #-} module LocalConfig where import           Config import           System.Process ( readProcess ) import qualified Data.Text as T+import           Network.Mattermost.Types ( UserText (..) )  getConfig :: IO Config getConfig = do@@ -9,9 +11,9 @@   let cmd = words "pass ldap"   pass <- takeWhile (/='\n') <$> readProcess (head cmd) (tail cmd) ""   return $ Config-         { configUsername = T.pack "USERNAME"-         , configHostname = T.pack "mattermost.example.com"-         , configTeam     = T.pack "TEAMNAME"+         { configUsername = "USERNAME"+         , configHostname = "mattermost.example.com"+         , configTeam     = UserText "TEAMNAME"          , configPort     = 443 -- currently we only support HTTPS          , configPassword = T.pack pass          }
examples/MakePost.hs view
@@ -30,14 +30,14 @@  data Options   = Options-  { optChannel :: T.Text+  { optChannel :: UserText   , optVerbose :: Bool   , optMessage :: T.Text   } deriving (Read, Show)  defaultOptions :: Options defaultOptions = Options-  { optChannel = "town-square"+  { optChannel = UserText "town-square"   , optVerbose = False   , optMessage = ""   }@@ -46,7 +46,7 @@ options =   [ Option "c" ["channel"]       (ReqArg-        (\arg opt -> return opt { optChannel = T.pack arg })+        (\arg opt -> return opt { optChannel = UserText . T.pack $ arg })         "CHANNEL")       "Channel to fetch posts from"   , Option "v" ["verbose"]
mattermost-api.cabal view
@@ -1,5 +1,5 @@ name:                mattermost-api-version:             40900.1.0+version:             50200.0.0 synopsis:            Client API for Mattermost chat system description:         Client API for Mattermost chat system license:             BSD3
src/Network/Mattermost/Types.hs view
@@ -436,7 +436,6 @@   , channelPurpose       :: UserText   , channelLastPostAt    :: ServerTime   , channelTotalMsgCount :: Int-  , channelExtraUpdateAt :: ServerTime   , channelCreatorId     :: Maybe UserId   } deriving (Read, Show, Eq, Ord) @@ -457,7 +456,6 @@     channelPurpose         <- v .: "purpose"     channelLastPostAt      <- timeFromServer <$> v .: "last_post_at"     channelTotalMsgCount   <- v .: "total_msg_count"-    channelExtraUpdateAt   <- timeFromServer <$> v .: "extra_update_at"     channelCreatorId       <- maybeFail (v .: "creator_id")     return Channel { .. } @@ -794,7 +792,6 @@   , postEditAt        :: ServerTime   , postUserId        :: Maybe UserId   , postCreateAt      :: ServerTime-  , postParentId      :: Maybe PostId   , postChannelId     :: ChannelId   , postHasReactions  :: Bool   } deriving (Read, Show, Eq)@@ -818,7 +815,6 @@     postEditAt        <- timeFromServer <$> v .: "edit_at"     postUserId        <- maybeFail (v .: "user_id")     postCreateAt      <- timeFromServer <$> v .: "create_at"-    postParentId      <- maybeFail (v .: "parent_id")     postChannelId     <- v .: "channel_id"     postHasReactions  <- v .:? "has_reactions" .!= False     return Post { .. }@@ -838,7 +834,6 @@     , "update_at"       .= timeToServer postUpdateAt     , "user_id"         .= postUserId     , "create_at"       .= timeToServer postCreateAt-    , "parent_id"       .= postParentId     , "channel_id"      .= postChannelId     , "has_reactions"   .= postHasReactions     ]@@ -851,7 +846,6 @@   , pendingPostMessage   :: Text   , pendingPostId        :: PendingPostId   , pendingPostUserId    :: UserId-  , pendingPostParentId  :: Maybe PostId   , pendingPostRootId    :: Maybe PostId   } deriving (Read, Show, Eq) @@ -864,7 +858,6 @@     , "pending_post_id" .= pendingPostId        post     , "user_id"         .= pendingPostUserId    post     , "root_id"         .= pendingPostRootId    post-    , "parent_id"       .= pendingPostParentId  post     ]  newtype PendingPostId = PPI { unPPI :: Id }@@ -892,7 +885,6 @@     , pendingPostMessage   = msg     , pendingPostUserId    = userid     , pendingPostRootId    = Nothing-    , pendingPostParentId  = Nothing     }  data FileInfo
src/Network/Mattermost/Types/Config.hs view
@@ -163,6 +163,31 @@     ] ++     [ "PasswordResetSalt" A..= x | Just x <- [emailSettingsPasswordresetsalt] ] +data TeammateNameDisplayMode =+    TMUsername+    | TMNicknameOrFullname+    | TMFullname+    | TMUnknown T.Text+    deriving (Eq, Show, Read)++teammateDisplayModeFromText :: Text -> TeammateNameDisplayMode+teammateDisplayModeFromText t =+    case t of+        "username"           -> TMUsername+        "nickname_full_name" -> TMNicknameOrFullname+        "full_name"          -> TMFullname+        _                    -> TMUnknown t++instance A.FromJSON TeammateNameDisplayMode where+    parseJSON = A.withText "TeammateNameDisplayMode"+        (return . teammateDisplayModeFromText)++instance A.ToJSON TeammateNameDisplayMode where+    toJSON TMUsername           = "username"+    toJSON TMNicknameOrFullname = "nickname_full_name"+    toJSON TMFullname           = "full_name"+    toJSON (TMUnknown t)        = A.toJSON t+ data ClientConfig = ClientConfig   { clientConfigVersion :: T.Text   , clientConfigBuildNumber :: T.Text@@ -173,34 +198,21 @@    , clientConfigSiteURL :: T.Text   , clientConfigSiteName :: T.Text-  , clientConfigEnableTeamCreation :: T.Text-  , clientConfigEnableUserCreation :: T.Text   , clientConfigEnableOpenServer :: T.Text   , clientConfigRestrictDirectMessage :: T.Text-  , clientConfigRestrictTeamInvite :: T.Text-  , clientConfigRestrictPublicChannelCreation :: T.Text-  , clientConfigRestrictPrivateChannelCreation :: T.Text-  , clientConfigRestrictPublicChannelManagement :: T.Text-  , clientConfigRestrictPrivateChannelManagement :: T.Text-  , clientConfigRestrictPublicChannelDeletion :: T.Text-  , clientConfigRestrictPrivateChannelDeletion :: T.Text-  , clientConfigRestrictPrivateChannelManageMembers :: T.Text-  , clientConfigTeammateNameDisplay :: T.Text+  , clientConfigTeammateNameDisplay :: TeammateNameDisplayMode    , clientConfigEnableOAuthServiceProvider :: T.Text   , clientConfigGoogleDeveloperKey :: T.Text   , clientConfigEnableIncomingWebhooks :: T.Text   , clientConfigEnableOutgoingWebhooks :: T.Text   , clientConfigEnableCommands :: T.Text-  , clientConfigEnableOnlyAdminIntegrations :: T.Text   , clientConfigEnablePostUsernameOverride :: T.Text   , clientConfigEnablePostIconOverride :: T.Text   , clientConfigEnableLinkPreviews :: T.Text   , clientConfigEnableTesting :: T.Text   , clientConfigEnableDeveloper :: T.Text   , clientConfigEnableDiagnostics :: T.Text-  , clientConfigRestrictPostDelete :: T.Text-  , clientConfigAllowEditPost :: T.Text   , clientConfigPostEditTimeLimit :: T.Text    , clientConfigSendEmailNotifications :: T.Text@@ -237,15 +249,12 @@    , clientConfigEnableCustomEmoji :: T.Text   , clientConfigEnableEmojiPicker :: T.Text-  , clientConfigRestrictCustomEmojiCreation :: T.Text   , clientConfigMaxFileSize :: T.Text    , clientConfigAppDownloadLink :: T.Text   , clientConfigAndroidAppDownloadLink :: T.Text   , clientConfigIosAppDownloadLink :: T.Text -  , clientConfigEnableWebrtc :: T.Text-   , clientConfigMaxNotificationsPerChannel :: T.Text   , clientConfigTimeBetweenUserTypingUpdatesMilliseconds :: T.Text   , clientConfigEnableUserTypingMessages :: T.Text@@ -267,18 +276,8 @@      clientConfigSiteURL <- o A..: "SiteURL"     clientConfigSiteName <- o A..: "SiteName"-    clientConfigEnableTeamCreation <- o A..: "EnableTeamCreation"-    clientConfigEnableUserCreation <- o A..: "EnableUserCreation"     clientConfigEnableOpenServer <- o A..: "EnableOpenServer"     clientConfigRestrictDirectMessage <- o A..: "RestrictDirectMessage"-    clientConfigRestrictTeamInvite <- o A..: "RestrictTeamInvite"-    clientConfigRestrictPublicChannelCreation <- o A..: "RestrictPublicChannelCreation"-    clientConfigRestrictPrivateChannelCreation <- o A..: "RestrictPrivateChannelCreation"-    clientConfigRestrictPublicChannelManagement <- o A..: "RestrictPublicChannelManagement"-    clientConfigRestrictPrivateChannelManagement <- o A..: "RestrictPrivateChannelManagement"-    clientConfigRestrictPublicChannelDeletion <- o A..: "RestrictPublicChannelDeletion"-    clientConfigRestrictPrivateChannelDeletion <- o A..: "RestrictPrivateChannelDeletion"-    clientConfigRestrictPrivateChannelManageMembers <- o A..: "RestrictPrivateChannelManageMembers"     clientConfigTeammateNameDisplay <- o A..: "TeammateNameDisplay"      clientConfigEnableOAuthServiceProvider <- o A..: "EnableOAuthServiceProvider"@@ -286,15 +285,12 @@     clientConfigEnableIncomingWebhooks <- o A..: "EnableIncomingWebhooks"     clientConfigEnableOutgoingWebhooks <- o A..: "EnableOutgoingWebhooks"     clientConfigEnableCommands <- o A..: "EnableCommands"-    clientConfigEnableOnlyAdminIntegrations <- o A..: "EnableOnlyAdminIntegrations"     clientConfigEnablePostUsernameOverride <- o A..: "EnablePostUsernameOverride"     clientConfigEnablePostIconOverride <- o A..: "EnablePostIconOverride"     clientConfigEnableLinkPreviews <- o A..: "EnableLinkPreviews"     clientConfigEnableTesting <- o A..: "EnableTesting"     clientConfigEnableDeveloper <- o A..: "EnableDeveloper"     clientConfigEnableDiagnostics <- o A..: "EnableDiagnostics"-    clientConfigRestrictPostDelete <- o A..: "RestrictPostDelete"-    clientConfigAllowEditPost <- o A..: "AllowEditPost"     clientConfigPostEditTimeLimit <- o A..: "PostEditTimeLimit"      clientConfigSendEmailNotifications <- o A..: "SendEmailNotifications"@@ -331,15 +327,12 @@      clientConfigEnableCustomEmoji <- o A..: "EnableCustomEmoji"     clientConfigEnableEmojiPicker <- o A..: "EnableEmojiPicker"-    clientConfigRestrictCustomEmojiCreation <- o A..: "RestrictCustomEmojiCreation"     clientConfigMaxFileSize <- o A..: "MaxFileSize"      clientConfigAppDownloadLink <- o A..: "AppDownloadLink"     clientConfigAndroidAppDownloadLink <- o A..: "AndroidAppDownloadLink"     clientConfigIosAppDownloadLink <- o A..: "IosAppDownloadLink" -    clientConfigEnableWebrtc <- o A..: "EnableWebrtc"-     clientConfigMaxNotificationsPerChannel <- o A..: "MaxNotificationsPerChannel"     clientConfigTimeBetweenUserTypingUpdatesMilliseconds <- o A..: "TimeBetweenUserTypingUpdatesMilliseconds"     clientConfigEnableUserTypingMessages <- o A..: "EnableUserTypingMessages"@@ -361,7 +354,6 @@   , teamSettingsRestrictprivatechanneldeletion :: Text   , teamSettingsMaxchannelsperteam :: Int   , teamSettingsRestrictteaminvite :: Text-  , teamSettingsEnableteamcreation :: Bool   , teamSettingsSitename :: Text   , teamSettingsRestrictpublicchannelmanagement :: Text   , teamSettingsMaxnotificationsperchannel :: Int@@ -385,7 +377,6 @@     teamSettingsRestrictprivatechanneldeletion <- v A..: "RestrictPrivateChannelDeletion"     teamSettingsMaxchannelsperteam <- v A..: "MaxChannelsPerTeam"     teamSettingsRestrictteaminvite <- v A..: "RestrictTeamInvite"-    teamSettingsEnableteamcreation <- v A..: "EnableTeamCreation"     teamSettingsSitename <- v A..: "SiteName"     teamSettingsRestrictpublicchannelmanagement <- v A..: "RestrictPublicChannelManagement"     teamSettingsMaxnotificationsperchannel <- v A..: "MaxNotificationsPerChannel"@@ -409,7 +400,6 @@     , "RestrictPrivateChannelDeletion" A..= teamSettingsRestrictprivatechanneldeletion     , "MaxChannelsPerTeam" A..= teamSettingsMaxchannelsperteam     , "RestrictTeamInvite" A..= teamSettingsRestrictteaminvite-    , "EnableTeamCreation" A..= teamSettingsEnableteamcreation     , "SiteName" A..= teamSettingsSitename     , "RestrictPublicChannelManagement" A..= teamSettingsRestrictpublicchannelmanagement     , "MaxNotificationsPerChannel" A..= teamSettingsMaxnotificationsperchannel
src/Network/Mattermost/WebSocket/Types.hs view
@@ -66,6 +66,9 @@   | WMChannelUpdated   | WMEmojiAdded   | WMUserRoleUpdated+  | WMPluginStatusesChanged+  | WMPluginEnabled+  | WMPluginDisabled   deriving (Read, Show, Eq, Ord)  instance FromJSON WebsocketEventType where@@ -99,38 +102,44 @@     "channel_updated"    -> return WMChannelUpdated     "emoji_added"        -> return WMEmojiAdded     "user_role_updated"  -> return WMUserRoleUpdated+    "plugin_statuses_changed" -> return WMPluginStatusesChanged+    "plugin_enabled"     -> return WMPluginEnabled+    "plugin_disabled"    -> return WMPluginDisabled     _                    -> fail ("Unknown websocket message: " ++ show s)  instance ToJSON WebsocketEventType where-  toJSON WMTyping            = "typing"-  toJSON WMPosted            = "posted"-  toJSON WMPostEdited        = "post_edited"-  toJSON WMPostDeleted       = "post_deleted"-  toJSON WMChannelDeleted    = "channel_deleted"-  toJSON WMDirectAdded       = "direct_added"-  toJSON WMNewUser           = "new_user"-  toJSON WMLeaveTeam         = "leave_team"-  toJSON WMUserAdded         = "user_added"-  toJSON WMUserUpdated       = "user_updated"-  toJSON WMUserRemoved       = "user_removed"-  toJSON WMPreferenceChanged = "preferences_changed"-  toJSON WMPreferenceDeleted = "preferences_deleted"-  toJSON WMEphemeralMessage  = "ephemeral_message"-  toJSON WMStatusChange      = "status_change"-  toJSON WMHello             = "hello"-  toJSON WMUpdateTeam        = "update_team"-  toJSON WMTeamDeleted       = "delete_team"-  toJSON WMReactionAdded     = "reaction_added"-  toJSON WMReactionRemoved   = "reaction_removed"-  toJSON WMChannelCreated    = "channel_created"-  toJSON WMGroupAdded        = "group_added"-  toJSON WMAddedToTeam       = "added_to_team"-  toJSON WMWebRTC            = "webrtc"+  toJSON WMTyping                  = "typing"+  toJSON WMPosted                  = "posted"+  toJSON WMPostEdited              = "post_edited"+  toJSON WMPostDeleted             = "post_deleted"+  toJSON WMChannelDeleted          = "channel_deleted"+  toJSON WMDirectAdded             = "direct_added"+  toJSON WMNewUser                 = "new_user"+  toJSON WMLeaveTeam               = "leave_team"+  toJSON WMUserAdded               = "user_added"+  toJSON WMUserUpdated             = "user_updated"+  toJSON WMUserRemoved             = "user_removed"+  toJSON WMPreferenceChanged       = "preferences_changed"+  toJSON WMPreferenceDeleted       = "preferences_deleted"+  toJSON WMEphemeralMessage        = "ephemeral_message"+  toJSON WMStatusChange            = "status_change"+  toJSON WMHello                   = "hello"+  toJSON WMUpdateTeam              = "update_team"+  toJSON WMTeamDeleted             = "delete_team"+  toJSON WMReactionAdded           = "reaction_added"+  toJSON WMReactionRemoved         = "reaction_removed"+  toJSON WMChannelCreated          = "channel_created"+  toJSON WMGroupAdded              = "group_added"+  toJSON WMAddedToTeam             = "added_to_team"+  toJSON WMWebRTC                  = "webrtc"   toJSON WMAuthenticationChallenge = "authentication_challenge"   toJSON WMChannelViewed           = "channel_viewed"   toJSON WMChannelUpdated          = "channel_updated"   toJSON WMEmojiAdded              = "emoji_added"-  toJSON WMUserRoleUpdated   = "user_role_updated"+  toJSON WMUserRoleUpdated         = "user_role_updated"+  toJSON WMPluginStatusesChanged   = "plugin_statuses_changed"+  toJSON WMPluginEnabled           = "plugin_enabled"+  toJSON WMPluginDisabled          = "plugin_disabled"  -- 
test/Main.hs view
@@ -12,7 +12,6 @@  import           Data.Monoid ((<>)) import qualified Data.Sequence as Seq-import qualified Data.Text as T (Text)  import           Test.Tasty @@ -58,8 +57,8 @@   , minChannelTeamId      = tId   } -testMinChannelName :: T.Text-testMinChannelName = "test-channel"+testMinChannelName :: UserText+testMinChannelName = UserText "test-channel"   testTeamsCreate :: TeamsCreate@@ -117,8 +116,8 @@   -- Load channels so we can get the IDs of joined channels   chans <- getChannels testTeam -  let townSquare = findChannel chans "Town Square"-      offTopic   = findChannel chans "Off-Topic"+  let townSquare = findChannel chans (UserText "Town Square")+      offTopic   = findChannel chans (UserText "Off-Topic")    print_ "Getting Config"   config <- getConfig@@ -131,7 +130,7 @@   saveConfig newConfig    expectWSEvent "admin joined town square"-    (isPost adminUser townSquare "testadmin has joined the channel.")+    (isPost adminUser townSquare (UserText "testadmin has joined the channel."))    expectWSEvent "admin joined test team"     (isAddedToTeam adminUser testTeam)@@ -146,10 +145,10 @@     (isNewUserEvent testUser)    expectWSEvent "test user joined town square"-    (isPost testUser townSquare "test-user has joined the channel.")+    (isPost testUser townSquare (UserText "test-user has joined the channel."))    expectWSEvent "test user joined off-topic"-    (isPost testUser offTopic "test-user has joined the channel.")+    (isPost testUser offTopic (UserText "test-user has joined the channel."))    expectWSDone @@ -188,7 +187,7 @@          expectWSEvent "hello" (hasWSEventType WMHello)         expectWSEvent "test user joins test channel"-          (isPost testUser chan "test-user has joined the channel.")+          (isPost testUser chan (UserText "test-user has joined the channel."))         expectWSEvent "new channel event" (isChannelCreatedEvent chan)         expectWSDone @@ -247,7 +246,7 @@         expectWSEvent "hello" (hasWSEventType WMHello)         expectWSEvent "join channel" (isUserJoin testUser chan)         expectWSEvent "join post"-          (isPost testUser chan "test-user has joined the channel.")+          (isPost testUser chan (UserText "test-user has joined the channel."))         expectWSEvent "view channel" isViewedChannel         expectWSDone @@ -268,7 +267,7 @@         expectWSEvent "hello" (hasWSEventType WMHello)          expectWSEvent "channel deletion post"-            (isPost testUser toDelete "test-user has archived the channel.")+            (isPost testUser toDelete (UserText "test-user has archived the channel."))          expectWSEvent "channel delete event"             (isChannelDeleteEvent toDelete)
test/Tests/Util.hs view
@@ -258,7 +258,7 @@        -- ^ The user who posted        -> Channel        -- ^ The channel to which the new post was added-       -> T.Text+       -> UserText        -- ^ The content of the new post        -> WebsocketEvent        -> Bool@@ -314,7 +314,7 @@   print_ $ "Team created: " <> (T.unpack $ teamsCreateName tc)   return team -findChannel :: Channels -> T.Text -> Channel+findChannel :: Channels -> UserText -> Channel findChannel chans name =     let result = Seq.viewl (Seq.filter nameMatches chans)         nameMatches c = name `elem` [ channelName c