Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4887,8 +4887,8 @@ public final class io/getstream/chat/android/compose/viewmodel/channel/ChannelIn

public final class io/getstream/chat/android/compose/viewmodel/channels/ChannelListViewModel : androidx/lifecycle/ViewModel {
public static final field $stable I
public fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;JZLkotlinx/coroutines/flow/Flow;)V
public synthetic fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;JZLkotlinx/coroutines/flow/Flow;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;JZLio/getstream/chat/android/models/querysort/QuerySorter;Lkotlinx/coroutines/flow/Flow;)V
public synthetic fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;JZLio/getstream/chat/android/models/querysort/QuerySorter;Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun archiveChannel (Lio/getstream/chat/android/models/Channel;)V
public final fun deleteConversation (Lio/getstream/chat/android/models/Channel;)V
public final fun dismissChannelAction ()V
Expand Down Expand Up @@ -4920,8 +4920,8 @@ public final class io/getstream/chat/android/compose/viewmodel/channels/ChannelL
public final class io/getstream/chat/android/compose/viewmodel/channels/ChannelViewModelFactory : androidx/lifecycle/ViewModelProvider$Factory {
public static final field $stable I
public fun <init> ()V
public fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;Z)V
public synthetic fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;ZLio/getstream/chat/android/models/querysort/QuerySorter;)V
public synthetic fun <init> (Lio/getstream/chat/android/client/ChatClient;Lio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/models/FilterObject;ILjava/lang/Integer;Ljava/lang/Integer;Lio/getstream/chat/android/state/event/handler/chat/factory/ChatEventHandlerFactory;ZLio/getstream/chat/android/models/querysort/QuerySorter;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun create (Ljava/lang/Class;)Landroidx/lifecycle/ViewModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import kotlin.coroutines.cancellation.CancellationException
* @param chatEventHandlerFactory The instance of [ChatEventHandlerFactory] used to create [ChatEventHandler].
* @param searchDebounceMs The debounce time for search queries.
* @param isDraftMessageEnabled If the draft message feature is enabled.
* @param messageSearchSort Sorting for message search results. When `null`, the server-side default is used.
* @param globalState A flow emitting the current [GlobalState].
*/
@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -103,6 +104,7 @@ public class ChannelListViewModel(
private val chatEventHandlerFactory: ChatEventHandlerFactory = ChatEventHandlerFactory(chatClient.clientState),
searchDebounceMs: Long = SEARCH_DEBOUNCE_MS,
private val isDraftMessageEnabled: Boolean = false,
private val messageSearchSort: QuerySorter<Message>? = null,
private val globalState: Flow<GlobalState> = chatClient.globalStateFlow,
) : ViewModel() {

Expand Down Expand Up @@ -367,14 +369,15 @@ public class ChannelListViewModel(
currentState: SearchMessageState,
channelFilter: FilterObject,
): SearchMessageState {
val offset = currentState.messages.size
val limit = channelLimit
logger.v { "[searchMessages] #$src; query: '${currentState.query}', offset: $offset, limit: $limit" }
val next = currentState.next
logger.v { "[searchMessages] #$src; query: '${currentState.query}', next: $next, limit: $limit" }
val result = chatClient.searchMessages(
channelFilter = channelFilter,
messageFilter = Filters.autocomplete("text", currentState.query),
offset = offset,
sort = messageSearchSort,
limit = limit,
next = next,
).await()
return when (result) {
is io.getstream.result.Result.Success -> {
Expand All @@ -383,15 +386,15 @@ public class ChannelListViewModel(
messages = currentState.messages + result.value.messages,
isLoading = false,
isLoadingMore = false,
canLoadMore = result.value.messages.size >= limit,
canLoadMore = !result.value.next.isNullOrEmpty(),
next = result.value.next,
)
}
is io.getstream.result.Result.Failure -> {
logger.e { "[searchMessages] #$src; failed: ${result.value}" }
currentState.copy(
isLoading = false,
isLoadingMore = false,
canLoadMore = true,
)
}
}
Expand Down Expand Up @@ -773,6 +776,7 @@ public class ChannelListViewModel(
private data class SearchMessageState(
val query: String = "",
val canLoadMore: Boolean = true,
val next: String? = null,
val messages: List<Message> = emptyList(),
val isLoading: Boolean = false,
val isLoadingMore: Boolean = false,
Expand All @@ -784,7 +788,8 @@ public class ChannelListViewModel(
"messages.size=${messages.size}, " +
"isLoading=$isLoading, " +
"isLoadingMore=$isLoadingMore, " +
"canLoadMore=$canLoadMore)"
"canLoadMore=$canLoadMore, " +
"next=$next)"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModelProvider
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.FilterObject
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.querysort.QuerySortByField
import io.getstream.chat.android.models.querysort.QuerySorter
import io.getstream.chat.android.state.event.handler.chat.ChatEventHandler
Expand All @@ -39,6 +40,7 @@ import io.getstream.chat.android.state.event.handler.chat.factory.ChatEventHandl
* @param messageLimit How many messages are fetched for each channel item when loading channels.
* When `null`, the server-side default is used.
* @param chatEventHandlerFactory The instance of [ChatEventHandlerFactory] used to create [ChatEventHandler].
* @param messageSearchSort Optional sorting for message search results. When `null`, the server-side default is used.
*/
public class ChannelViewModelFactory(
private val chatClient: ChatClient = ChatClient.instance(),
Expand All @@ -49,6 +51,7 @@ public class ChannelViewModelFactory(
private val messageLimit: Int? = null,
private val chatEventHandlerFactory: ChatEventHandlerFactory = ChatEventHandlerFactory(chatClient.clientState),
private val isDraftMessageEnabled: Boolean = false,
private val messageSearchSort: QuerySorter<Message>? = null,
) : ViewModelProvider.Factory {

/**
Expand All @@ -68,6 +71,7 @@ public class ChannelViewModelFactory(
memberLimit = memberLimit,
chatEventHandlerFactory = chatEventHandlerFactory,
isDraftMessageEnabled = isDraftMessageEnabled,
messageSearchSort = messageSearchSort,
) as T
}
}
Loading
Loading