Browse Source

add Default instance for InstantMessage and IMPresence

master
Philipp Balzarek 13 years ago
parent
commit
dd442a4446
  1. 9
      source/Network/Xmpp/IM/Message.hs
  2. 13
      source/Network/Xmpp/IM/Presence.hs

9
source/Network/Xmpp/IM/Message.hs

@ -3,14 +3,14 @@
module Network.Xmpp.IM.Message where module Network.Xmpp.IM.Message where
import Data.Default
import Data.Function
import Data.List
import Data.Text (Text) import Data.Text (Text)
import Data.XML.Pickle import Data.XML.Pickle
import Data.XML.Types import Data.XML.Types
import Network.Xmpp.Marshal import Network.Xmpp.Marshal
import Network.Xmpp.Types import Network.Xmpp.Types
import Data.List
import Data.Function
data MessageBody = MessageBody { bodyLang :: Maybe LangTag data MessageBody = MessageBody { bodyLang :: Maybe LangTag
, bodyContent :: Text , bodyContent :: Text
@ -36,6 +36,9 @@ instantMessage = InstantMessage { imThread = Nothing
, imBody = [] , imBody = []
} }
instance Default InstantMessage where
def = instantMessage
-- | Get the IM specific parts of a message. Returns 'Nothing' when the received -- | Get the IM specific parts of a message. Returns 'Nothing' when the received
-- payload is not valid IM data. -- payload is not valid IM data.
getIM :: Message -> Maybe InstantMessage getIM :: Message -> Maybe InstantMessage

13
source/Network/Xmpp/IM/Presence.hs

@ -4,10 +4,11 @@
module Network.Xmpp.IM.Presence where module Network.Xmpp.IM.Presence where
import Data.Text (Text) import Data.Default
import Data.XML.Pickle import Data.Text (Text)
import Data.XML.Types import Data.XML.Pickle
import Network.Xmpp.Types import Data.XML.Types
import Network.Xmpp.Types
data ShowStatus = StatusAway data ShowStatus = StatusAway
| StatusChat | StatusChat
@ -38,7 +39,11 @@ imPresence = IMP { showStatus = Nothing
, priority = 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 :: Presence -> Maybe IMPresence
getIMPresence pres = case unpickle xpIMPresence (presencePayload pres) of getIMPresence pres = case unpickle xpIMPresence (presencePayload pres) of
Left _ -> Nothing Left _ -> Nothing

Loading…
Cancel
Save