package Ġdev . base io . slack clone . uid ashboard . compose Ċ Ċ import Ġandroidx . lifecycle . Saved State Handle Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġdagger . h ilt . android . lifecycle . H ilt ViewModel Ċ import Ġdev . base io . slack clone . chat core . data . Ui Layer Channels Ċ import Ġdev . base io . slack clone . domain . map pers . Ui Model Mapper Ċ import Ġdev . base io . slack clone . domain . model . channel . Domain Layer Channels Ċ import Ġdev . base io . slack clone . domain . use cases . channels . UseCase Create Channels Ċ import Ġdev . base io . slack clone . domain . use cases . channels . UseCase Fetch Users Ċ import Ġdev . base io . slack clone . domain . use cases . channels . UseCase Get Channel Ċ import Ġdev . base io . slack clone . navigator . Compose Navigator Ċ import Ġdev . base io . slack clone . navigator . Navigation Keys Ċ import Ġkotlinx . coroutines . flow .* Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ Ċ @ H ilt ViewModel Ċ class ĠDashboard VM Ġ@ Inject Ġconstructor ( ĊĠ Ġprivate Ġval Ġsaved State Handle : ĠSaved State Handle , ĊĠ Ġprivate Ġval Ġcompose Navigator : ĠCompose Navigator , ĊĠ Ġprivate Ġval Ġuse Case Get Channel : ĠUse Case Get Channel , ĊĠ Ġprivate Ġval Ġuse Case Fetch Users : ĠUse Case Fetch Users , ĊĠ Ġprivate Ġval Ġuse Case Save Channel : ĠUse Case Create Channels , ĊĠ Ġprivate Ġval Ġchannel Mapper : ĠUi Model Mapper < Domain Layer Channels . Slack Channel , ĠUi Layer Channels . Slack Channel > Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠ Ġval Ġselected Chat Channel Ġ= ĠMutable State Flow < Ui Layer Channels . Slack Channel ? >( null ) ĊĠ Ġval Ġis Chat View Closed Ġ= ĠMutable State Flow ( true ) ĊĊĠ Ġinit Ġ{ ĊĠĠĠ Ġobserve Channel Created () ĊĠĠĠ Ġpreload Users () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġobserve Channel Created () Ġ{ ĊĠĠĠ Ġcompose Navigator . observe Result < String >( ĊĠĠĠĠĠ ĠNavigation Keys . navigate Channel , ĊĠĠĠ Ġ). onStart Ġ{ ĊĠĠĠĠĠ Ġval Ġmessage Ġ= Ġsaved State Handle . get < String >( Navigation Keys . navigate Channel ) ĊĠĠĠĠĠ Ġmessage ?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġemit ( it ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}. map Ġ{ ĊĠĠĠĠĠ Ġuse Case Get Channel . perform ( it ) ĊĠĠĠ Ġ}. on Each Ġ{ Ġslack Channel Ġ-> ĊĠĠĠĠĠ Ġnavigate Chat Thread For Channel ( slack Channel ) ĊĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. launch In ( viewModel Scope ) ĊĊĠĠĠ Ġselected Chat Channel . on Each Ġ{ ĊĠĠĠĠĠ Ġsaved State Handle . set ( Navigation Keys . navigate Channel , Ġit ?. uuid ) ĊĠĠĠ Ġ}. launch In ( viewModel Scope ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġnavigate Chat Thread For Channel ( slack Channel : ĠDomain Layer Channels . Slack Channel ?) Ġ{ ĊĠĠĠ Ġslack Channel ?. let Ġ{ ĊĠĠĠĠĠ Ġselected Chat Channel . value Ġ= Ġchannel Mapper . map To Presentation ( it ) ĊĠĠĠĠĠ Ġis Chat View Closed . value Ġ= Ġfalse ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġpreload Users () Ġ{ ĊĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠ Ġval Ġusers Ġ= Ġuse Case Fetch Users . perform ( 1 0 ) ĊĠĠĠĠĠ Ġuse Case Save Channel . perform ( users ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ Ċ }