{-# OPTIONS_GHC -Wno-orphans #-} -- :/ {-| Module: SignalDBus.Types Description: Types used by this package Copyright: (c) Lia Lenckowski, 2022 License: AGPL Maintainer: lialenck@protonmail.com Stability: experimental Portability: GNU/Linux, MacOS This module contains types used by this package. Please import SignalDBus instead. -} module SignalDBus.Types ( SignalConn(..), Timestamp, Device(..), Group(..), ReceivedMessage(..), ) where import Data.Int (Int64) import DBus.Client (Client) import DBus.Internal.Types import Text.Read (readPrec) -- |Opaque connection object, aquired by 'SignalDBus.withConn' or -- 'SignalDBus.withConnNum' data SignalConn = SignalConn !ObjectPath !Client -- |Timestamp, represented as an ms-precision unix timestamp newtype Timestamp = Timestamp Int64 deriving (Show, Read, Eq, Ord) instance IsVariant Timestamp where toVariant (Timestamp ts) = toVariant ts fromVariant v = Timestamp <$> fromVariant v instance IsValue Timestamp where typeOf_ _ = TypeInt64 toValue (Timestamp ts) = toValue ts fromValue v = Timestamp <$> fromValue v -- |Opaque object representing a linked device newtype Device = Device Int64 deriving (Show, Read, Eq) instance IsVariant Device where toVariant (Device i) = toVariant i fromVariant v = Device <$> fromVariant v instance IsValue Device where typeOf_ _ = TypeInt64 toValue (Device i) = toValue i fromValue v = Device <$> fromValue v instance Read ObjectPath where -- :/ readPrec = ObjectPath <$> readPrec -- |Opaque Group object, aquired by 'SignalDBus.listGroups' or 'SignalDBus.getGroup' newtype Group = Group ObjectPath deriving (Show, Read, Eq, Ord) instance IsVariant Group where toVariant (Group i) = toVariant i fromVariant v = Group <$> fromVariant v instance IsValue Group where typeOf_ _ = TypeObjectPath toValue (Group i) = toValue i fromValue v = Group <$> fromValue v -- |Received message data ReceivedMessage = -- |Message sent by a linked device to someone else SyncMessage Timestamp -- ^ When this message was sent String -- ^ Message sender (TODO: always yourself?) (Maybe Group) -- ^ If sent in a group, corresponding group object String -- ^ Message text [String] -- ^ Paths to stored attachments -- |Read receipt sent by someone else in response to one of your messages | Receipt Timestamp -- ^ Which message was read String -- ^ Phone number of the receipt sender -- |Message sent to you by someone else | Message Timestamp -- ^ When this message was sent String -- ^ Message sender (Maybe Group) -- ^ If sent in a group, corresponding group object String -- ^ Message text [String] -- ^ Paths to stored attachments deriving (Show, Read, Eq, Ord)