-
public final class ChannelListViewModel extends ViewModel
ViewModel managing the state of a given Channel List.
-
-
Field Summary
Fields Modifier and Type Field Description private final SearchQuerysearchQueryprivate ChannelsStatechannelsStateprivate MutableState<Channel>selectedChannelprivate ChannelActionactiveChannelActionprivate final StateFlow<ConnectionState>connectionStateprivate final StateFlow<User>userprivate final StateFlow<List<ChannelMute>>channelMutesprivate final ChatClientchatClient
-
Constructor Summary
Constructors Constructor Description ChannelListViewModel(ChatClient chatClient, QuerySorter<Channel> initialSort, FilterObject initialFilters, Integer channelLimit, Integer memberLimit, Integer messageLimit, ChatEventHandlerFactory chatEventHandlerFactory, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)Creates a view model that queries channels by an explicit filter and sort. ChannelListViewModel(ChatClient chatClient, String predefinedFilterName, Map<String, Object> filterValues, Map<String, Object> sortValues, Integer channelLimit, Integer memberLimit, Integer messageLimit, ChatEventHandlerFactory chatEventHandlerFactory, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)Creates a view model that queries channels using a predefined filter resolved by the server. ChannelListViewModel(String groupKey, ChatClient chatClient, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)Grouped channel list constructor.
-
Method Summary
Modifier and Type Method Description final SearchQuerygetSearchQuery()The current search query. final ChannelsStategetChannelsState()The current state of the channels screen. final UnitsetChannelsState(ChannelsState channelsState)final MutableState<Channel>getSelectedChannel()Currently selected channel, if any. final UnitsetSelectedChannel(MutableState<Channel> selectedChannel)final ChannelActiongetActiveChannelAction()Currently active channel action, if any. final UnitsetActiveChannelAction(ChannelAction activeChannelAction)final StateFlow<ConnectionState>getConnectionState()The state of our network connection - if we're online, connecting or offline. final StateFlow<User>getUser()The state of the currently logged in user. final StateFlow<List<ChannelMute>>getChannelMutes()Gives us the information about the list of channels mutes by the current user. final ChatClientgetChatClient()final Unitrefresh()Refreshes either channels or search results. final UnitselectChannel(Channel channel)Changes the currently selected channel state. final UnitsetSearchQuery(SearchQuery searchQuery)Changes the current query state. final UnitsetFilters(FilterObject newFilters)Allows for the change of filters used for channel queries. final UnitsetQuerySort(QuerySorter<Channel> querySort)Allows for the change of the query sort used for channel queries. final UnitloadMore()Loads more data when the user reaches the end of the channels list. final UnitexecuteOrConfirm(ChannelAction action)Executes the given ChannelAction immediately if it doesn't require confirmation, or stores it as activeChannelAction to show a confirmation dialog. final UnitconfirmPendingAction()Executes the currently pending activeChannelAction after user confirmation and dismisses it from the UI. final UnitmuteChannel(Channel channel)Mutes a channel. final UnitpinChannel(Channel channel)Pins a channel. final UnitunpinChannel(Channel channel)Unpins a channel. final UnitarchiveChannel(Channel channel)final UnitunarchiveChannel(Channel channel)final UnitunmuteChannel(Channel channel)Unmutes a channel. final UnitdeleteConversation(Channel channel)Deletes a channel, after the user chooses the delete ChannelAction. final UnitleaveGroup(Channel channel)Leaves a channel, after the user chooses the leave ChannelAction. final UnitmuteUser(String userId)Mutes a user (used for DM channels). final UnitunmuteUser(String userId)Unmutes a user (used for DM channels). final UnitblockUser(String userId)Blocks a user (used for DM channels). final UnitunblockUser(String userId)Unblocks a user (used for DM channels). final BooleanisChannelMuted(String cid)Checks if the channel is muted for the current user. final BooleanisUserMuted(String userId)Checks if a user is muted by the current user. final BooleanisUserBlocked(String userId)Checks if a user is blocked by the current user. final UnitdismissChannelAction()Dismisses the activeChannelAction and removes it from the UI. -
-
Constructor Detail
-
ChannelListViewModel
ChannelListViewModel(ChatClient chatClient, QuerySorter<Channel> initialSort, FilterObject initialFilters, Integer channelLimit, Integer memberLimit, Integer messageLimit, ChatEventHandlerFactory chatEventHandlerFactory, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)
Creates a view model that queries channels by an explicit filter and sort.- Parameters:
chatClient- The prepared ChatClient instance required for fetching the data.initialSort- The initial sort used for Channels.initialFilters- The data filter.channelLimit- How many channels we fetch per page.memberLimit- How many members are fetched for each channel item when loading channels.messageLimit- How many messages are fetched for each channel item when loading channels.chatEventHandlerFactory- The instance of ChatEventHandlerFactory used to create ChatEventHandler.searchDebounceMs- The debounce time for search queries.draftMessagesEnabled- If the draft message feature is enabled.messageSearchSort- Sorting for message search results.globalState- A flow emitting the current GlobalState.
-
ChannelListViewModel
ChannelListViewModel(ChatClient chatClient, String predefinedFilterName, Map<String, Object> filterValues, Map<String, Object> sortValues, Integer channelLimit, Integer memberLimit, Integer messageLimit, ChatEventHandlerFactory chatEventHandlerFactory, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)
Creates a view model that queries channels using a predefined filter resolved by the server.- Parameters:
chatClient- The prepared ChatClient instance required for fetching the data.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.channelLimit- How many channels we fetch per page.memberLimit- How many members are fetched for each channel item when loading channels.messageLimit- How many messages are fetched for each channel item when loading channels.chatEventHandlerFactory- The instance of ChatEventHandlerFactory used to create ChatEventHandler.searchDebounceMs- The debounce time for search queries.draftMessagesEnabled- If the draft message feature is enabled.messageSearchSort- Sorting for message search results.globalState- A flow emitting the current GlobalState.
-
ChannelListViewModel
ChannelListViewModel(String groupKey, ChatClient chatClient, Long searchDebounceMs, Boolean draftMessagesEnabled, QuerySorter<Message> messageSearchSort, Flow<GlobalState> globalState)
Grouped channel list constructor.- Parameters:
groupKey- The name of the channels group.chatClient- The prepared ChatClient instance required for fetching the data.searchDebounceMs- The debounce time for search queries.draftMessagesEnabled- If the draft message feature is enabled.messageSearchSort- Sorting for message search results.globalState- A flow emitting the current GlobalState.
-
-
Method Detail
-
getSearchQuery
final SearchQuery getSearchQuery()
The current search query.
-
getChannelsState
final ChannelsState getChannelsState()
The current state of the channels screen. It holds all the information required to render the UI.
-
setChannelsState
final Unit setChannelsState(ChannelsState channelsState)
-
getSelectedChannel
final MutableState<Channel> getSelectedChannel()
Currently selected channel, if any. Used to show the bottom drawer information when long tapping on a list item.
-
setSelectedChannel
final Unit setSelectedChannel(MutableState<Channel> selectedChannel)
-
getActiveChannelAction
final ChannelAction getActiveChannelAction()
Currently active channel action, if any. Used to show a dialog for deleting or leaving a channel/conversation.
-
setActiveChannelAction
final Unit setActiveChannelAction(ChannelAction activeChannelAction)
-
getConnectionState
final StateFlow<ConnectionState> getConnectionState()
The state of our network connection - if we're online, connecting or offline.
-
getUser
final StateFlow<User> getUser()
The state of the currently logged in user.
-
getChannelMutes
final StateFlow<List<ChannelMute>> getChannelMutes()
Gives us the information about the list of channels mutes by the current user.
-
getChatClient
final ChatClient getChatClient()
-
selectChannel
final Unit selectChannel(Channel channel)
Changes the currently selected channel state. This updates the UI state and allows us to observe the state change.
-
setSearchQuery
final Unit setSearchQuery(SearchQuery searchQuery)
Changes the current query state. This updates the data flow and triggers another query operation.
The new operation will hold the channels that match the new query.
-
setFilters
final Unit setFilters(FilterObject newFilters)
Allows for the change of filters used for channel queries.
Use this if you need to support runtime filter changes, through custom filters UI. The applied filter overrides the
initialFiltersset through the constructor.Warning: The filter that's applied will override the
initialFiltersset through the constructor. Has no effect on view models constructed for a predefined-filter query (predefined identity is fixed at construction) or for a grouped query (the group's filter is server-owned).- Parameters:
newFilters- The new filters to be used as a baseline for filtering channels.
-
setQuerySort
final Unit setQuerySort(QuerySorter<Channel> querySort)
Allows for the change of the query sort used for channel queries.
Use this if you need to support runtime sort changes, through custom sort UI.
Has no effect on view models constructed for a predefined-filter query (sort is resolved by the server) or for a grouped query (the group's sort is fixed).
-
executeOrConfirm
final Unit executeOrConfirm(ChannelAction action)
Executes the given ChannelAction immediately if it doesn't require confirmation, or stores it as activeChannelAction to show a confirmation dialog.
- Parameters:
action- The action to execute or confirm.
-
confirmPendingAction
final Unit confirmPendingAction()
Executes the currently pending activeChannelAction after user confirmation and dismisses it from the UI.
-
muteChannel
final Unit muteChannel(Channel channel)
Mutes a channel.
- Parameters:
channel- The channel to mute.
-
pinChannel
final Unit pinChannel(Channel channel)
Pins a channel.
- Parameters:
channel- The channel to pin.
-
unpinChannel
final Unit unpinChannel(Channel channel)
Unpins a channel.
- Parameters:
channel- The channel to unpin.
-
archiveChannel
final Unit archiveChannel(Channel channel)
-
unarchiveChannel
final Unit unarchiveChannel(Channel channel)
-
unmuteChannel
final Unit unmuteChannel(Channel channel)
Unmutes a channel.
- Parameters:
channel- The channel to unmute.
-
deleteConversation
final Unit deleteConversation(Channel channel)
Deletes a channel, after the user chooses the delete ChannelAction. It also removes the activeChannelAction, to remove the dialog from the UI.
- Parameters:
channel- The channel to delete.
-
leaveGroup
final Unit leaveGroup(Channel channel)
Leaves a channel, after the user chooses the leave ChannelAction. It also removes the activeChannelAction, to remove the dialog from the UI.
- Parameters:
channel- The channel to leave.
-
muteUser
final Unit muteUser(String userId)
Mutes a user (used for DM channels).
- Parameters:
userId- The ID of the user to mute.
-
unmuteUser
final Unit unmuteUser(String userId)
Unmutes a user (used for DM channels).
- Parameters:
userId- The ID of the user to unmute.
-
blockUser
final Unit blockUser(String userId)
Blocks a user (used for DM channels).
- Parameters:
userId- The ID of the user to block.
-
unblockUser
final Unit unblockUser(String userId)
Unblocks a user (used for DM channels).
- Parameters:
userId- The ID of the user to unblock.
-
isChannelMuted
final Boolean isChannelMuted(String cid)
Checks if the channel is muted for the current user.
- Parameters:
cid- The CID of the channel that needs to be checked.
-
isUserMuted
final Boolean isUserMuted(String userId)
Checks if a user is muted by the current user.
- Parameters:
userId- The ID of the user to check.
-
isUserBlocked
final Boolean isUserBlocked(String userId)
Checks if a user is blocked by the current user.
- Parameters:
userId- The ID of the user to check.
-
dismissChannelAction
final Unit dismissChannelAction()
Dismisses the activeChannelAction and removes it from the UI.
-
-
-
-