packages feed

helic-0.6.1.0: lib/Helic/Data/Event.hs

-- |The data type 'Event' consists of a yank text and metadata identifying its source and time.
module Helic.Data.Event where

import qualified Chronos
import Polysemy.Chronos (ChronosTime)
import qualified Polysemy.Time as Time

import Helic.Data.AgentId (AgentId)
import Helic.Data.InstanceName (InstanceName)
import Exon (exon)

-- |The central data type representing a clipboard event.
data Event =
  Event {
    -- |The host from which the event originated.
    sender :: InstanceName,
    -- |The entity that caused the event.
    source :: AgentId,
    -- |Timestamp.
    time :: Chronos.Time,
    -- |Payload.
    content :: Text
  }
  deriving stock (Eq, Show)

json ''Event

-- |Construct an event for the current host and time.
now ::
  Members [ChronosTime, Reader InstanceName] r =>
  AgentId ->
  Text ->
  Sem r Event
now source content = do
  sender <- ask
  time <- Time.now
  pure Event {..}

describe :: Event -> Text
describe Event {..} =
  [exon|##{sender}:##{source}|]