PhiaUi.Components.Collab.ThreadHelpers (phia_ui v0.1.17)

Copy Markdown View Source

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(threads, opts)

@spec filter_threads(
  [map()],
  keyword()
) :: [map()]

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(threads, arg2)

@spec sort_threads([map()], atom()) :: [map()]

Sort threads by the given strategy.

Strategies:

  • :date — newest first by created_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, ...}]

thread_is_resolved(arg1)

@spec thread_is_resolved(map()) :: boolean()

Check if a thread is resolved.

Examples

iex> thread_is_resolved(%{resolved: true})
true

iex> thread_is_resolved(%{resolved: false})
false

thread_participants(arg1)

@spec thread_participants(map()) :: [String.t()]

Get unique participant user IDs in a thread.

Examples

iex> thread_participants(%{comments: [%{user_id: "a"}, %{user_id: "b"}, %{user_id: "a"}]})
["a", "b"]

thread_reply_count(arg1)

@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