Package 

Class ChannelListViewModel

    • 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

      • getChannelsState

         final ChannelsState getChannelsState()

        The current state of the channels screen. It holds all the information required to render the UI.

      • getSelectedChannel

         final MutableState<Channel> getSelectedChannel()

        Currently selected channel, if any. Used to show the bottom drawer information when long tapping on a list item.

      • getActiveChannelAction

         final ChannelAction getActiveChannelAction()

        Currently active channel action, if any. Used to show a dialog for deleting or leaving a channel/conversation.

      • 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.

      • refresh

         final Unit refresh()

        Refreshes either channels or search results.

      • 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 initialFilters set through the constructor.

        Warning: The filter that's applied will override the initialFilters set 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).

      • loadMore

         final Unit loadMore()

        Loads more data when the user reaches the end of the channels list.

      • 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.
      • 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.
      • 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.