module Network.Xmpp.Stanza where
import Data.XML.Types
import Network.Xmpp.Types
import Network.Xmpp.Lens
presenceSubscribe :: Jid -> Presence
presenceSubscribe to' = presence { presenceTo = Just to'
, presenceType = Subscribe
}
presenceSubscribed :: Jid -> Presence
presenceSubscribed to' = presence { presenceTo = Just to'
, presenceType = Subscribed
}
presenceUnsubscribe :: Jid -> Presence
presenceUnsubscribe to' = presence { presenceTo = Just to'
, presenceType = Unsubscribe
}
presenceUnsubscribed :: Jid -> Presence
presenceUnsubscribed to' = presence { presenceTo = Just to'
, presenceType = Unsubscribed
}
presenceOnline :: Presence
presenceOnline = presence
presenceOffline :: Presence
presenceOffline = presence {presenceType = Unavailable}
answerMessage :: Message -> [Element] -> Maybe Message
answerMessage Message{messageFrom = Just frm, ..} payload' =
Just Message{ messageFrom = Nothing
, messageID = Nothing
, messageTo = Just frm
, messagePayload = payload'
, ..
}
answerMessage _ _ = Nothing
presTo :: Presence -> Jid -> Presence
presTo pres to' = pres{presenceTo = Just to'}
mkStanzaError :: StanzaErrorCondition
-> StanzaError
mkStanzaError condition = StanzaError (associatedErrorType condition)
condition Nothing Nothing
iqError :: StanzaErrorCondition -> IQRequest -> IQError
iqError condition (IQRequest iqid from' _to lang' _tp _bd) =
IQError iqid Nothing from' lang' (mkStanzaError condition) Nothing
iqResult :: Maybe Element -> IQRequest -> IQResult
iqResult pl iqr = IQResult
{ iqResultID = iqRequestID iqr
, iqResultFrom = Nothing
, iqResultTo = view from iqr
, iqResultLangTag = view lang iqr
, iqResultPayload = pl
}
associatedErrorType :: StanzaErrorCondition -> StanzaErrorType
associatedErrorType BadRequest = Modify
associatedErrorType Conflict = Cancel
associatedErrorType FeatureNotImplemented = Cancel
associatedErrorType Forbidden = Auth
associatedErrorType Gone{} = Cancel
associatedErrorType InternalServerError = Cancel
associatedErrorType ItemNotFound = Cancel
associatedErrorType JidMalformed = Modify
associatedErrorType NotAcceptable = Modify
associatedErrorType NotAllowed = Cancel
associatedErrorType NotAuthorized = Auth
associatedErrorType PolicyViolation = Modify
associatedErrorType RecipientUnavailable = Wait
associatedErrorType Redirect{} = Modify
associatedErrorType RegistrationRequired = Auth
associatedErrorType RemoteServerNotFound = Cancel
associatedErrorType RemoteServerTimeout = Wait
associatedErrorType ResourceConstraint = Wait
associatedErrorType ServiceUnavailable = Cancel
associatedErrorType SubscriptionRequired = Auth
associatedErrorType UndefinedCondition = Cancel
associatedErrorType UnexpectedRequest = Modify