Helper functions for thread management in collaboration components.
Provides utilities for counting replies, extracting participants, checking resolution status, and sorting/filtering thread collections.
Summary
Functions
Filter threads by criteria.
Sort threads by the given strategy.
Check if a thread is resolved.
Get unique participant user IDs in a thread.
Count replies in a thread (excludes the root comment).
Functions
Filter threads by criteria.
Supported options:
:user_id— only threads where the user participated:resolved— only threads matching the resolved status
Examples
iex> filter_threads(threads, user_id: "user-1")
[%{...}]
iex> filter_threads(threads, resolved: false)
[%{resolved: false, ...}]
Sort threads by the given strategy.
Strategies:
:date— newest first bycreated_at:activity— most recently active first (last comment time):unresolved_first— unresolved threads before resolved ones
Examples
iex> sort_threads(threads, :unresolved_first)
[%{resolved: false, ...}, %{resolved: true, ...}]
Check if a thread is resolved.
Examples
iex> thread_is_resolved(%{resolved: true})
true
iex> thread_is_resolved(%{resolved: false})
false
Get unique participant user IDs in a thread.
Examples
iex> thread_participants(%{comments: [%{user_id: "a"}, %{user_id: "b"}, %{user_id: "a"}]})
["a", "b"]
@spec thread_reply_count(map()) :: non_neg_integer()
Count replies in a thread (excludes the root comment).
Examples
iex> thread_reply_count(%{comments: [%{}, %{}, %{}]})
2
iex> thread_reply_count(%{comments: []})
0
iex> thread_reply_count(%{})
0