module Matterhorn.State.ChannelList
( updateSidebar
, updateWindowTitle
, toggleChannelListVisibility
, showChannelInSidebar
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick.Main ( getVtyHandle, invalidateCache, invalidateCacheEntry )
import qualified Data.HashMap.Strict as HM
import qualified Data.Sequence as Seq
import Data.Time.Clock ( getCurrentTime )
import Data.Maybe ( fromJust )
import qualified Graphics.Vty as Vty
import Lens.Micro.Platform
import Network.Mattermost.Types
import Network.Mattermost.Lenses
import qualified Network.Mattermost.Endpoints as MM
import {-# SOURCE #-} Matterhorn.State.Messages ( fetchVisibleIfNeeded )
import Matterhorn.Types
import Matterhorn.State.Async
import qualified Matterhorn.Zipper as Z
updateSidebar :: Maybe TeamId -> MH ()
Maybe TeamId
mTid = do
case Maybe TeamId
mTid of
Maybe TeamId
Nothing -> do
HashMap TeamId TeamState
ts <- Getting
(HashMap TeamId TeamState) ChatState (HashMap TeamId TeamState)
-> MH (HashMap TeamId TeamState)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting
(HashMap TeamId TeamState) ChatState (HashMap TeamId TeamState)
Lens' ChatState (HashMap TeamId TeamState)
csTeams
[TeamId] -> (TeamId -> MH ()) -> MH ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (HashMap TeamId TeamState -> [TeamId]
forall k v. HashMap k v -> [k]
HM.keys HashMap TeamId TeamState
ts) TeamId -> MH ()
updateTeamSidebar
Just TeamId
tId -> do
TeamId -> MH ()
updateTeamSidebar TeamId
tId
(TeamId -> MH ()) -> MH ()
withCurrentTeam ((TeamId -> MH ()) -> MH ()) -> (TeamId -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \TeamId
tId -> do
Zipper ChannelListGroup ChannelListEntry
z <- Getting
(Zipper ChannelListGroup ChannelListEntry)
ChatState
(Zipper ChannelListGroup ChannelListEntry)
-> MH (Zipper ChannelListGroup ChannelListEntry)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState)
-> ChatState
-> Const (Zipper ChannelListGroup ChannelListEntry) ChatState)
-> ((Zipper ChannelListGroup ChannelListEntry
-> Const
(Zipper ChannelListGroup ChannelListEntry)
(Zipper ChannelListGroup ChannelListEntry))
-> TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState)
-> Getting
(Zipper ChannelListGroup ChannelListEntry)
ChatState
(Zipper ChannelListGroup ChannelListEntry)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Zipper ChannelListGroup ChannelListEntry
-> Const
(Zipper ChannelListGroup ChannelListEntry)
(Zipper ChannelListGroup ChannelListEntry))
-> TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState
Lens' TeamState (Zipper ChannelListGroup ChannelListEntry)
tsFocus)
UserId
myId <- (ChatState -> UserId) -> MH UserId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ChatState -> UserId
myUserId
[UserId] -> MH ()
scheduleUserStatusFetches ([UserId] -> MH ()) -> [UserId] -> MH ()
forall a b. (a -> b) -> a -> b
$ UserId
myId UserId -> [UserId] -> [UserId]
forall a. a -> [a] -> [a]
: Zipper ChannelListGroup ChannelListEntry -> [UserId]
userIdsFromZipper Zipper ChannelListGroup ChannelListEntry
z
MH ()
updateWindowTitle
MH ()
refreshTeamZipper
updateWindowTitle :: MH ()
updateWindowTitle :: MH ()
updateWindowTitle = do
HashMap TeamId TeamState
ts <- Getting
(HashMap TeamId TeamState) ChatState (HashMap TeamId TeamState)
-> MH (HashMap TeamId TeamState)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting
(HashMap TeamId TeamState) ChatState (HashMap TeamId TeamState)
Lens' ChatState (HashMap TeamId TeamState)
csTeams
[Int]
unreadCounts <- [TeamId] -> (TeamId -> MH Int) -> MH [Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (HashMap TeamId TeamState -> [TeamId]
forall k v. HashMap k v -> [k]
HM.keys HashMap TeamId TeamState
ts) ((TeamId -> MH Int) -> MH [Int]) -> (TeamId -> MH Int) -> MH [Int]
forall a b. (a -> b) -> a -> b
$ \TeamId
tId -> do
Zipper ChannelListGroup ChannelListEntry
z <- Getting
(Zipper ChannelListGroup ChannelListEntry)
ChatState
(Zipper ChannelListGroup ChannelListEntry)
-> MH (Zipper ChannelListGroup ChannelListEntry)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState)
-> ChatState
-> Const (Zipper ChannelListGroup ChannelListEntry) ChatState)
-> ((Zipper ChannelListGroup ChannelListEntry
-> Const
(Zipper ChannelListGroup ChannelListEntry)
(Zipper ChannelListGroup ChannelListEntry))
-> TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState)
-> Getting
(Zipper ChannelListGroup ChannelListEntry)
ChatState
(Zipper ChannelListGroup ChannelListEntry)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Zipper ChannelListGroup ChannelListEntry
-> Const
(Zipper ChannelListGroup ChannelListEntry)
(Zipper ChannelListGroup ChannelListEntry))
-> TeamState
-> Const (Zipper ChannelListGroup ChannelListEntry) TeamState
Lens' TeamState (Zipper ChannelListGroup ChannelListEntry)
tsFocus)
Int -> MH Int
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> MH Int) -> Int -> MH Int
forall a b. (a -> b) -> a -> b
$ [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (ChannelListGroup -> Int
channelListGroupUnread (ChannelListGroup -> Int)
-> ((ChannelListGroup, [ChannelListEntry]) -> ChannelListGroup)
-> (ChannelListGroup, [ChannelListEntry])
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChannelListGroup, [ChannelListEntry]) -> ChannelListGroup
forall a b. (a, b) -> a
fst) ((ChannelListGroup, [ChannelListEntry]) -> Int)
-> [(ChannelListGroup, [ChannelListEntry])] -> [Int]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Zipper ChannelListGroup ChannelListEntry
-> [(ChannelListGroup, [ChannelListEntry])]
forall a b. Zipper a b -> [(a, [b])]
Z.toList Zipper ChannelListGroup ChannelListEntry
z
let title :: String
title = String
"matterhorn" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> if Int
unread Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 then String
"(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
unread String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")" else String
""
unread :: Int
unread = [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
unreadCounts
Vty
vty <- EventM Name ChatState Vty -> MH Vty
forall a. EventM Name ChatState a -> MH a
mh EventM Name ChatState Vty
forall n s. EventM n s Vty
getVtyHandle
IO () -> MH ()
forall a. IO a -> MH a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ Vty -> String -> IO ()
Vty.setWindowTitle Vty
vty String
title
updateTeamSidebar :: TeamId -> MH ()
TeamId
tId = do
EventM Name ChatState () -> MH ()
forall a. EventM Name ChatState a -> MH a
mh (EventM Name ChatState () -> MH ())
-> EventM Name ChatState () -> MH ()
forall a b. (a -> b) -> a -> b
$ Name -> EventM Name ChatState ()
forall n s. Ord n => n -> EventM n s ()
invalidateCacheEntry (Name -> EventM Name ChatState ())
-> Name -> EventM Name ChatState ()
forall a b. (a -> b) -> a -> b
$ TeamId -> Name
ChannelSidebar TeamId
tId
Maybe ClientConfig
cconfig <- Getting (Maybe ClientConfig) ChatState (Maybe ClientConfig)
-> MH (Maybe ClientConfig)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting (Maybe ClientConfig) ChatState (Maybe ClientConfig)
Lens' ChatState (Maybe ClientConfig)
csClientConfig
Maybe ChannelId
oldCid <- Getting (Maybe ChannelId) ChatState (Maybe ChannelId)
-> MH (Maybe ChannelId)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState (Maybe ChannelId)
csCurrentChannelId TeamId
tId)
ClientChannels
cs <- Getting ClientChannels ChatState ClientChannels
-> MH ClientChannels
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting ClientChannels ChatState ClientChannels
Lens' ChatState ClientChannels
csChannels
ChannelListSorting
sorting <- Getting ChannelListSorting ChatState ChannelListSorting
-> MH ChannelListSorting
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const ChannelListSorting TeamState)
-> ChatState -> Const ChannelListSorting ChatState)
-> ((ChannelListSorting
-> Const ChannelListSorting ChannelListSorting)
-> TeamState -> Const ChannelListSorting TeamState)
-> Getting ChannelListSorting ChatState ChannelListSorting
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChannelListSorting -> Const ChannelListSorting ChannelListSorting)
-> TeamState -> Const ChannelListSorting TeamState
Lens' TeamState ChannelListSorting
tsChannelListSorting)
Users
us <- MH Users
getUsers
UserPreferences
prefs <- Getting UserPreferences ChatState UserPreferences
-> MH UserPreferences
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const UserPreferences ChatResources)
-> ChatState -> Const UserPreferences ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const UserPreferences ChatResources)
-> ChatState -> Const UserPreferences ChatState)
-> ((UserPreferences -> Const UserPreferences UserPreferences)
-> ChatResources -> Const UserPreferences ChatResources)
-> Getting UserPreferences ChatState UserPreferences
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(UserPreferences -> Const UserPreferences UserPreferences)
-> ChatResources -> Const UserPreferences ChatResources
Lens' ChatResources UserPreferences
crUserPreferences)
HashMap TeamId (Set ChannelListGroupLabel)
hidden <- Getting
(HashMap TeamId (Set ChannelListGroupLabel))
ChatState
(HashMap TeamId (Set ChannelListGroupLabel))
-> MH (HashMap TeamId (Set ChannelListGroupLabel))
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting
(HashMap TeamId (Set ChannelListGroupLabel))
ChatState
(HashMap TeamId (Set ChannelListGroupLabel))
Lens' ChatState (HashMap TeamId (Set ChannelListGroupLabel))
csHiddenChannelGroups
UTCTime
now <- IO UTCTime -> MH UTCTime
forall a. IO a -> MH a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
Config
config <- Getting Config ChatState Config -> MH Config
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState)
-> ((Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources)
-> Getting Config ChatState Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources
Lens' ChatResources Config
crConfiguration)
let zl :: [(ChannelListGroup, [ChannelListEntry])]
zl = ChannelListSorting
-> UTCTime
-> Config
-> TeamId
-> Maybe ClientConfig
-> UserPreferences
-> HashMap TeamId (Set ChannelListGroupLabel)
-> ClientChannels
-> Users
-> [(ChannelListGroup, [ChannelListEntry])]
mkChannelZipperList ChannelListSorting
sorting UTCTime
now Config
config TeamId
tId Maybe ClientConfig
cconfig UserPreferences
prefs HashMap TeamId (Set ChannelListGroupLabel)
hidden ClientChannels
cs Users
us
compareEntries :: Maybe ChannelListEntry -> ChannelListEntry -> Bool
compareEntries Maybe ChannelListEntry
mOld ChannelListEntry
new = (ChannelListEntry -> ChannelId
channelListEntryChannelId (ChannelListEntry -> ChannelId)
-> Maybe ChannelListEntry -> Maybe ChannelId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ChannelListEntry
mOld) Maybe ChannelId -> Maybe ChannelId -> Bool
forall a. Eq a => a -> a -> Bool
== ChannelId -> Maybe ChannelId
forall a. a -> Maybe a
Just (ChannelListEntry -> ChannelId
channelListEntryChannelId ChannelListEntry
new)
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Zipper ChannelListGroup ChannelListEntry
-> Identity (Zipper ChannelListGroup ChannelListEntry))
-> TeamState -> Identity TeamState)
-> (Zipper ChannelListGroup ChannelListEntry
-> Identity (Zipper ChannelListGroup ChannelListEntry))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Zipper ChannelListGroup ChannelListEntry
-> Identity (Zipper ChannelListGroup ChannelListEntry))
-> TeamState -> Identity TeamState
Lens' TeamState (Zipper ChannelListGroup ChannelListEntry)
tsFocus ((Zipper ChannelListGroup ChannelListEntry
-> Identity (Zipper ChannelListGroup ChannelListEntry))
-> ChatState -> Identity ChatState)
-> (Zipper ChannelListGroup ChannelListEntry
-> Zipper ChannelListGroup ChannelListEntry)
-> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (Maybe ChannelListEntry -> ChannelListEntry -> Bool)
-> [(ChannelListGroup, [ChannelListEntry])]
-> Zipper ChannelListGroup ChannelListEntry
-> Zipper ChannelListGroup ChannelListEntry
forall b a.
Eq b =>
(Maybe b -> b -> Bool) -> [(a, [b])] -> Zipper a b -> Zipper a b
Z.updateListBy Maybe ChannelListEntry -> ChannelListEntry -> Bool
compareEntries [(ChannelListGroup, [ChannelListEntry])]
zl
Maybe ChannelId
newCid <- Getting (Maybe ChannelId) ChatState (Maybe ChannelId)
-> MH (Maybe ChannelId)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState (Maybe ChannelId)
csCurrentChannelId TeamId
tId)
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe ChannelId
newCid Maybe ChannelId -> Maybe ChannelId -> Bool
forall a. Eq a => a -> a -> Bool
/= Maybe ChannelId
oldCid) (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
TeamId -> MH ()
fetchVisibleIfNeeded TeamId
tId
toggleChannelListVisibility :: MH ()
toggleChannelListVisibility :: MH ()
toggleChannelListVisibility = do
EventM Name ChatState () -> MH ()
forall a. EventM Name ChatState a -> MH a
mh EventM Name ChatState ()
forall n s. Ord n => EventM n s ()
invalidateCache
(ChatResources -> Identity ChatResources)
-> ChatState -> Identity ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Identity ChatResources)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool)
-> ChatResources -> Identity ChatResources)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Identity Config)
-> ChatResources -> Identity ChatResources
Lens' ChatResources Config
crConfiguration((Config -> Identity Config)
-> ChatResources -> Identity ChatResources)
-> ((Bool -> Identity Bool) -> Config -> Identity Config)
-> (Bool -> Identity Bool)
-> ChatResources
-> Identity ChatResources
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool) -> Config -> Identity Config
Lens' Config Bool
configShowChannelListL ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> (Bool -> Bool) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not
showChannelInSidebar :: ChannelId -> Bool -> MH ()
ChannelId
cId Bool
setPending = do
Maybe ClientChannel
mChan <- Getting (First ClientChannel) ChatState ClientChannel
-> MH (Maybe ClientChannel)
forall s (m :: * -> *) a.
MonadState s m =>
Getting (First a) s a -> m (Maybe a)
preuse (Getting (First ClientChannel) ChatState ClientChannel
-> MH (Maybe ClientChannel))
-> Getting (First ClientChannel) ChatState ClientChannel
-> MH (Maybe ClientChannel)
forall a b. (a -> b) -> a -> b
$ ChannelId -> Traversal' ChatState ClientChannel
csChannel ChannelId
cId
User
me <- (ChatState -> User) -> MH User
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ChatState -> User
myUser
UserPreferences
prefs <- Getting UserPreferences ChatState UserPreferences
-> MH UserPreferences
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const UserPreferences ChatResources)
-> ChatState -> Const UserPreferences ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const UserPreferences ChatResources)
-> ChatState -> Const UserPreferences ChatState)
-> ((UserPreferences -> Const UserPreferences UserPreferences)
-> ChatResources -> Const UserPreferences ChatResources)
-> Getting UserPreferences ChatState UserPreferences
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(UserPreferences -> Const UserPreferences UserPreferences)
-> ChatResources -> Const UserPreferences ChatResources
Lens' ChatResources UserPreferences
crUserPreferences)
Session
session <- MH Session
getSession
case Maybe ClientChannel
mChan of
Maybe ClientChannel
Nothing ->
() -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just ClientChannel
ch -> do
UTCTime
now <- IO UTCTime -> MH UTCTime
forall a. IO a -> MH a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
ChannelId -> Traversal' ChatState ClientChannel
csChannel(ChannelId
cId)((ClientChannel -> Identity ClientChannel)
-> ChatState -> Identity ChatState)
-> ((Maybe UTCTime -> Identity (Maybe UTCTime))
-> ClientChannel -> Identity ClientChannel)
-> (Maybe UTCTime -> Identity (Maybe UTCTime))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChannelInfo -> Identity ChannelInfo)
-> ClientChannel -> Identity ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Identity ChannelInfo)
-> ClientChannel -> Identity ClientChannel)
-> ((Maybe UTCTime -> Identity (Maybe UTCTime))
-> ChannelInfo -> Identity ChannelInfo)
-> (Maybe UTCTime -> Identity (Maybe UTCTime))
-> ClientChannel
-> Identity ClientChannel
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe UTCTime -> Identity (Maybe UTCTime))
-> ChannelInfo -> Identity ChannelInfo
Lens' ChannelInfo (Maybe UTCTime)
cdSidebarShowOverride ((Maybe UTCTime -> Identity (Maybe UTCTime))
-> ChatState -> Identity ChatState)
-> Maybe UTCTime -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= UTCTime -> Maybe UTCTime
forall a. a -> Maybe a
Just UTCTime
now
Maybe TeamId -> MH ()
updateSidebar (ClientChannel
chClientChannel
-> Getting (Maybe TeamId) ClientChannel (Maybe TeamId)
-> Maybe TeamId
forall s a. s -> Getting a s a -> a
^.(ChannelInfo -> Const (Maybe TeamId) ChannelInfo)
-> ClientChannel -> Const (Maybe TeamId) ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Const (Maybe TeamId) ChannelInfo)
-> ClientChannel -> Const (Maybe TeamId) ClientChannel)
-> ((Maybe TeamId -> Const (Maybe TeamId) (Maybe TeamId))
-> ChannelInfo -> Const (Maybe TeamId) ChannelInfo)
-> Getting (Maybe TeamId) ClientChannel (Maybe TeamId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe TeamId -> Const (Maybe TeamId) (Maybe TeamId))
-> ChannelInfo -> Const (Maybe TeamId) ChannelInfo
Lens' ChannelInfo (Maybe TeamId)
cdTeamId)
case ClientChannel
chClientChannel -> Getting Type ClientChannel Type -> Type
forall s a. s -> Getting a s a -> a
^.(ChannelInfo -> Const Type ChannelInfo)
-> ClientChannel -> Const Type ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Const Type ChannelInfo)
-> ClientChannel -> Const Type ClientChannel)
-> ((Type -> Const Type Type)
-> ChannelInfo -> Const Type ChannelInfo)
-> Getting Type ClientChannel Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Type -> Const Type Type) -> ChannelInfo -> Const Type ChannelInfo
Lens' ChannelInfo Type
cdType of
Type
Direct -> do
let uId :: UserId
uId = Maybe UserId -> UserId
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe UserId -> UserId) -> Maybe UserId -> UserId
forall a b. (a -> b) -> a -> b
$ ClientChannel
chClientChannel
-> Getting (Maybe UserId) ClientChannel (Maybe UserId)
-> Maybe UserId
forall s a. s -> Getting a s a -> a
^.(ChannelInfo -> Const (Maybe UserId) ChannelInfo)
-> ClientChannel -> Const (Maybe UserId) ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Const (Maybe UserId) ChannelInfo)
-> ClientChannel -> Const (Maybe UserId) ClientChannel)
-> ((Maybe UserId -> Const (Maybe UserId) (Maybe UserId))
-> ChannelInfo -> Const (Maybe UserId) ChannelInfo)
-> Getting (Maybe UserId) ClientChannel (Maybe UserId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe UserId -> Const (Maybe UserId) (Maybe UserId))
-> ChannelInfo -> Const (Maybe UserId) ChannelInfo
Lens' ChannelInfo (Maybe UserId)
cdDMUserId
case UserPreferences -> UserId -> Maybe Bool
dmChannelShowPreference UserPreferences
prefs UserId
uId of
Just Bool
False -> do
let pref :: Preference
pref = UserId -> UserId -> Bool -> Preference
showDirectChannelPref (User
meUser -> Getting UserId User UserId -> UserId
forall s a. s -> Getting a s a -> a
^.Getting UserId User UserId
Lens' User UserId
userIdL) UserId
uId Bool
True
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
setPending (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
(TeamId -> MH ()) -> MH ()
withCurrentTeam ((TeamId -> MH ()) -> MH ()) -> (TeamId -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \TeamId
tId ->
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> TeamState -> Identity TeamState)
-> (Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> TeamState -> Identity TeamState
Lens' TeamState (Maybe PendingChannelChange)
tsPendingChannelChange ((Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> ChatState -> Identity ChatState)
-> Maybe PendingChannelChange -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.=
PendingChannelChange -> Maybe PendingChannelChange
forall a. a -> Maybe a
Just (TeamId -> ChannelId -> Maybe (MH ()) -> PendingChannelChange
ChangeByChannelId TeamId
tId (ClientChannel
chClientChannel
-> Getting ChannelId ClientChannel ChannelId -> ChannelId
forall s a. s -> Getting a s a -> a
^.(ChannelInfo -> Const ChannelId ChannelInfo)
-> ClientChannel -> Const ChannelId ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Const ChannelId ChannelInfo)
-> ClientChannel -> Const ChannelId ClientChannel)
-> ((ChannelId -> Const ChannelId ChannelId)
-> ChannelInfo -> Const ChannelId ChannelInfo)
-> Getting ChannelId ClientChannel ChannelId
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChannelId -> Const ChannelId ChannelId)
-> ChannelInfo -> Const ChannelId ChannelInfo
Lens' ChannelInfo ChannelId
cdChannelId) Maybe (MH ())
forall a. Maybe a
Nothing)
AsyncPriority -> IO (Maybe (MH ())) -> MH ()
doAsyncWith AsyncPriority
Preempt (IO (Maybe (MH ())) -> MH ()) -> IO (Maybe (MH ())) -> MH ()
forall a b. (a -> b) -> a -> b
$ do
UserParam -> Seq Preference -> Session -> IO ()
MM.mmSaveUsersPreferences UserParam
UserMe (Preference -> Seq Preference
forall a. a -> Seq a
Seq.singleton Preference
pref) Session
session
Maybe (MH ()) -> IO (Maybe (MH ()))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (MH ())
forall a. Maybe a
Nothing
Maybe Bool
_ -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Type
Group ->
case UserPreferences -> ChannelId -> Maybe Bool
groupChannelShowPreference UserPreferences
prefs ChannelId
cId of
Just Bool
False -> do
let pref :: Preference
pref = ChannelId -> UserId -> Preference
showGroupChannelPref ChannelId
cId (User
meUser -> Getting UserId User UserId -> UserId
forall s a. s -> Getting a s a -> a
^.Getting UserId User UserId
Lens' User UserId
userIdL)
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
setPending (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
(TeamId -> MH ()) -> MH ()
withCurrentTeam ((TeamId -> MH ()) -> MH ()) -> (TeamId -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \TeamId
tId ->
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> TeamState -> Identity TeamState)
-> (Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> TeamState -> Identity TeamState
Lens' TeamState (Maybe PendingChannelChange)
tsPendingChannelChange ((Maybe PendingChannelChange
-> Identity (Maybe PendingChannelChange))
-> ChatState -> Identity ChatState)
-> Maybe PendingChannelChange -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.=
PendingChannelChange -> Maybe PendingChannelChange
forall a. a -> Maybe a
Just (TeamId -> ChannelId -> Maybe (MH ()) -> PendingChannelChange
ChangeByChannelId TeamId
tId (ClientChannel
chClientChannel
-> Getting ChannelId ClientChannel ChannelId -> ChannelId
forall s a. s -> Getting a s a -> a
^.(ChannelInfo -> Const ChannelId ChannelInfo)
-> ClientChannel -> Const ChannelId ClientChannel
Lens' ClientChannel ChannelInfo
ccInfo((ChannelInfo -> Const ChannelId ChannelInfo)
-> ClientChannel -> Const ChannelId ClientChannel)
-> ((ChannelId -> Const ChannelId ChannelId)
-> ChannelInfo -> Const ChannelId ChannelInfo)
-> Getting ChannelId ClientChannel ChannelId
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChannelId -> Const ChannelId ChannelId)
-> ChannelInfo -> Const ChannelId ChannelInfo
Lens' ChannelInfo ChannelId
cdChannelId) Maybe (MH ())
forall a. Maybe a
Nothing)
AsyncPriority -> IO (Maybe (MH ())) -> MH ()
doAsyncWith AsyncPriority
Preempt (IO (Maybe (MH ())) -> MH ()) -> IO (Maybe (MH ())) -> MH ()
forall a b. (a -> b) -> a -> b
$ do
UserParam -> Seq Preference -> Session -> IO ()
MM.mmSaveUsersPreferences UserParam
UserMe (Preference -> Seq Preference
forall a. a -> Seq a
Seq.singleton Preference
pref) Session
session
Maybe (MH ()) -> IO (Maybe (MH ()))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (MH ())
forall a. Maybe a
Nothing
Maybe Bool
_ -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Type
_ -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()