{-# Language TemplateHaskell #-}
module Client.Message
(
ClientMessage(..)
, msgNetwork
, msgBody
, msgTime
, MessageBody(..)
, _IrcBody
, _ErrorBody
, _NormalBody
, msgText
) where
import Control.Lens
import Data.Text (Text)
import Data.Time (ZonedTime)
import Irc.Message
data MessageBody
= IrcBody !IrcMsg
| ErrorBody {-# UNPACK #-} !Text
| NormalBody {-# UNPACK #-} !Text
makePrisms ''MessageBody
data ClientMessage = ClientMessage
{ _msgNetwork :: !Text
, _msgBody :: !MessageBody
, _msgTime :: !ZonedTime
}
makeLenses ''ClientMessage
-- | Compute a searchable text representation of the message
msgText :: MessageBody -> Text
msgText (IrcBody irc) = ircMsgText irc
msgText (ErrorBody txt) = txt
msgText (NormalBody txt) = txt