-
public final class ChannelListViewModel extends ViewModel
ViewModel class for ChannelListView. Responsible for keeping the channels list up to date. Can be bound to the view using ChannelListViewModel.bindView function.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classChannelListViewModel.StateDescribed the state of the list of channels.
public final classChannelListViewModel.PaginationStateDescribes the pagination state.
public classChannelListViewModel.ActionDescribes the available actions that can be taken.
public classChannelListViewModel.ErrorEventDescribes the actions that were taken.
public classChannelListViewModel.Companion
-
Field Summary
Fields Modifier and Type Field Description private final LiveData<ChannelListViewModel.State>stateprivate final LiveData<Map<String, TypingEvent>>typingEventsprivate final LiveData<Map<String, DraftMessage>>draftMessagesprivate final LiveData<ChannelListViewModel.PaginationState>paginationStateprivate final LiveData<Event<ChannelListViewModel.ErrorEvent>>errorEvents
-
Constructor Summary
Constructors Constructor Description ChannelListViewModel(FilterObject filter, QuerySorter<Channel> sort, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, Flow<GlobalState> globalState)Creates a view model that queries channels by an explicit filter and sort. ChannelListViewModel(String predefinedFilterName, Map<String, Object> filterValues, Map<String, Object> sortValues, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, Flow<GlobalState> globalState)Creates a view model that queries channels using a predefined filter resolved by the server. ChannelListViewModel(FilterObject filter, QuerySorter<Channel> sort, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, GlobalState globalState)ViewModel class for ChannelListView.
-
Method Summary
Modifier and Type Method Description final LiveData<ChannelListViewModel.State>getState()Represents the current state containing channel list information. final LiveData<Map<String, TypingEvent>>getTypingEvents()Updates about currently typing users in active channels. final LiveData<Map<String, DraftMessage>>getDraftMessages()Draft messages for channels. final LiveData<ChannelListViewModel.PaginationState>getPaginationState()Represents the current pagination state by containing information about the loading state and if we have reached the end of all available channels. final LiveData<Event<ChannelListViewModel.ErrorEvent>>getErrorEvents()Emits error events. final UnitonAction(ChannelListViewModel.Action action)Checks against available actions and creates side-effects accordingly. final UnitleaveChannel(Channel channel)Removes the current user from the channel. final UnitdeleteChannel(Channel channel)Deletes a channel. final UnithideChannel(Channel channel)Hides the given channel. final UnitmarkAllRead()Marks all of the channels as read. final UnitsetFilters(FilterObject filterObject)Allows us to change the filter based on our requirements. -
-
Constructor Detail
-
ChannelListViewModel
ChannelListViewModel(FilterObject filter, QuerySorter<Channel> sort, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, Flow<GlobalState> globalState)
Creates a view model that queries channels by an explicit filter and sort.- Parameters:
filter- Filter for querying channels.sort- Defines the ordering of the channels.
-
ChannelListViewModel
ChannelListViewModel(String predefinedFilterName, Map<String, Object> filterValues, Map<String, Object> sortValues, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, Flow<GlobalState> globalState)
Creates a view model that queries channels using a predefined filter resolved by the server.- Parameters:
predefinedFilterName- The name of the predefined filter registered on the backend.filterValues- Optional values interpolated into the predefined filter template.sortValues- Optional values interpolated into the predefined sort template.
-
ChannelListViewModel
ChannelListViewModel(FilterObject filter, QuerySorter<Channel> sort, Integer limit, Integer messageLimit, Integer memberLimit, Boolean isDraftMessagesEnabled, ChatEventHandlerFactory chatEventHandlerFactory, ChatClient chatClient, GlobalState globalState)
ViewModel class for ChannelListView.- Parameters:
globalState- The current GlobalState.
-
-
Method Detail
-
getState
final LiveData<ChannelListViewModel.State> getState()
Represents the current state containing channel list information.
-
getTypingEvents
final LiveData<Map<String, TypingEvent>> getTypingEvents()
Updates about currently typing users in active channels.
-
getDraftMessages
final LiveData<Map<String, DraftMessage>> getDraftMessages()
Draft messages for channels.
-
getPaginationState
final LiveData<ChannelListViewModel.PaginationState> getPaginationState()
Represents the current pagination state by containing information about the loading state and if we have reached the end of all available channels.
-
getErrorEvents
final LiveData<Event<ChannelListViewModel.ErrorEvent>> getErrorEvents()
Emits error events.
-
onAction
final Unit onAction(ChannelListViewModel.Action action)
Checks against available actions and creates side-effects accordingly.
- Parameters:
action- The action to process.
-
leaveChannel
final Unit leaveChannel(Channel channel)
Removes the current user from the channel.
- Parameters:
channel- The channel that the current user will leave.
-
deleteChannel
final Unit deleteChannel(Channel channel)
Deletes a channel.
- Parameters:
channel- Channel to be deleted.
-
hideChannel
final Unit hideChannel(Channel channel)
Hides the given channel.
-
markAllRead
final Unit markAllRead()
Marks all of the channels as read.
-
setFilters
final Unit setFilters(FilterObject filterObject)
Allows us to change the filter based on our requirements.
Has no effect on view models constructed for a predefined-filter query — the predefined identity is fixed at construction. A warning is logged in that case.
- Parameters:
filterObject- The new filter to be applied to the query which lets us fetch different data.
-
-
-
-