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 @@ @@ -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 @@ -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

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

@ -4,10 +4,11 @@ @@ -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 @@ -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

Loading…
Cancel
Save