--------------------------------------------------------------------------------
-- Networks
--------------------------------------------------------------------------------

behNetworks :: AcidState ChatCoreState
            -> ChatUserName
            -> Event ChatCoreNetwork
            -> Event ClientCommand
            -> Reactive (Behavior (I.IxSet ChatNetwork))
behNetworks acid uName eNewNetwork eClientCmd =
    accum I.empty eDoAddNetwork
  where
    initNet netSt = chatNetwork uName netSt acid
                    $ filterE (isForNetwork (netSt ^. netStName)) eClientCmd
    eDoAddNetwork = I.insert <$> execute (initNet <$> eNewNetwork)

-- | True if the given client command should be handled by the given network.
behNetworks :: AcidState ChatCoreState
            -> ChatUserName
            -> Event ChatCoreNetwork
            -> Event ClientCommand
            -> Reactive (Behavior (I.IxSet ChatNetwork))
behNetworks acid uName eNewNetwork eClientCmd =
    accum I.empty eDoAddNetwork
  where
    initNet netSt = chatNetwork uName netSt acid
                    $ filterE (isForNetwork (netSt ^. netStName)) eClientCmd
    eDoAddNetwork = I.insert <$> execute (initNet <$> eNewNetwork)

-- | True if the given client command should be handled by the given network.
behNetworks acid uName eNewNetwork eClientCmd =
    accum I.empty eDoAddNetwork
  where
    initNet netSt = chatNetwork uName netSt acid
                    $ filterE (isForNetwork (netSt ^. netStName)) eClientCmd
    eDoAddNetwork = I.insert <$> execute (initNet <$> eNewNetwork)

-- | True if the given client command should be handled by the given network.