diff --git a/source/Network/Xmpp/IM/Message.hs b/source/Network/Xmpp/IM/Message.hs index f6fdc3a..b141eea 100644 --- a/source/Network/Xmpp/IM/Message.hs +++ b/source/Network/Xmpp/IM/Message.hs @@ -3,14 +3,14 @@ module Network.Xmpp.IM.Message where +import Data.Default +import Data.Function +import Data.List import Data.Text (Text) import Data.XML.Pickle import Data.XML.Types import Network.Xmpp.Marshal import Network.Xmpp.Types -import Data.List -import Data.Function - data MessageBody = MessageBody { bodyLang :: Maybe LangTag , bodyContent :: Text @@ -36,6 +36,9 @@ instantMessage = InstantMessage { imThread = Nothing , imBody = [] } +instance Default InstantMessage where + def = instantMessage + -- | Get the IM specific parts of a message. Returns 'Nothing' when the received -- payload is not valid IM data. getIM :: Message -> Maybe InstantMessage diff --git a/source/Network/Xmpp/IM/Presence.hs b/source/Network/Xmpp/IM/Presence.hs index d5d3750..0f0ba03 100644 --- a/source/Network/Xmpp/IM/Presence.hs +++ b/source/Network/Xmpp/IM/Presence.hs @@ -4,10 +4,11 @@ module Network.Xmpp.IM.Presence where -import Data.Text (Text) -import Data.XML.Pickle -import Data.XML.Types -import Network.Xmpp.Types +import Data.Default +import Data.Text (Text) +import Data.XML.Pickle +import Data.XML.Types +import Network.Xmpp.Types data ShowStatus = StatusAway | StatusChat @@ -38,7 +39,11 @@ imPresence = IMP { showStatus = Nothing , priority = Nothing } +instance Default IMPresence where + def = imPresence +-- | Try to extract RFC6121 IM presence information from presence stanza +-- Returns Nothing when the data is malformed, (Just IMPresence) otherwise getIMPresence :: Presence -> Maybe IMPresence getIMPresence pres = case unpickle xpIMPresence (presencePayload pres) of Left _ -> Nothing