# `Jido.Chat.Thread`
[🔗](https://github.com/agentjido/jido_chat/blob/v1.0.0/lib/jido/chat/thread.ex#L1)

Thread handle with posting, lifecycle, state, and discovery helpers.

# `t`

```elixir
@type t() :: %Jido.Chat.Thread{
  adapter: any(),
  adapter_name: atom(),
  channel_id: nil | nil | binary(),
  external_room_id: any(),
  external_thread_id: nil | nil | binary(),
  id: binary(),
  is_dm: boolean(),
  metadata: map()
}
```

# `all_messages`

```elixir
@spec all_messages(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  {:ok, [Jido.Chat.Message.t()]} | {:error, term()}
```

Fetches all available messages by following pagination cursors when supported.

# `all_messages_stream`

```elixir
@spec all_messages_stream(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  Enumerable.t()
```

Alias for `messages_stream/2` to mirror full-history stream naming.

# `channel`

```elixir
@spec channel(Jido.Chat.t(), t()) :: Jido.Chat.ChannelRef.t()
```

Returns a channel reference tied to this thread's room.

# `channel_id`

```elixir
@spec channel_id(t()) :: String.t()
```

Returns the logical channel id for this thread.

# `edit`

```elixir
@spec edit(t(), String.t() | integer(), String.t(), keyword()) ::
  Jido.Chat.Adapter.send_result()
```

Edits a previously-sent message via adapter `edit_message/4` when supported.

# `from_map`

```elixir
@spec from_map(map()) :: t()
```

Builds a thread from serialized map data.

# `mention_user`

```elixir
@spec mention_user(t(), String.t() | integer() | Jido.Chat.Author.t() | map()) ::
  String.t()
```

Renders a user mention string for this thread's adapter.

# `messages`

```elixir
@spec messages(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  {:ok, Jido.Chat.MessagePage.t()} | {:error, term()}
```

Fetches a page of normalized messages for the thread when supported.

# `messages_stream`

```elixir
@spec messages_stream(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  Enumerable.t()
```

Returns a lazy stream over thread messages using cursor pagination.

# `new`

Creates a thread handle.

# `open_modal`

```elixir
@spec open_modal(t(), Jido.Chat.Modal.t() | map(), keyword()) ::
  {:ok, Jido.Chat.ModalResult.t()} | {:error, term()}
```

Opens a modal in the thread when supported by the adapter.

# `post`

```elixir
@spec post(
  t(),
  String.t() | Jido.Chat.Postable.t() | map() | Enumerable.t(),
  keyword()
) ::
  {:ok, Jido.Chat.SentMessage.t()} | {:error, term()}
```

Posts string/postable/stream content and returns a sent-message handle.

# `post_ephemeral`

```elixir
@spec post_ephemeral(
  t(),
  String.t() | integer() | Jido.Chat.Author.t() | map(),
  String.t() | Jido.Chat.Postable.t() | map(),
  keyword()
) :: {:ok, Jido.Chat.EphemeralMessage.t()} | {:error, term()}
```

Posts an ephemeral message to a user with optional DM fallback policy.

# `recent_messages`

```elixir
@spec recent_messages(
  t(),
  keyword()
) :: {:ok, [Jido.Chat.Message.t()]} | {:error, term()}
```

Fetches a recent message list with default limit `20`.

# `refresh`

```elixir
@spec refresh(
  t(),
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Refreshes thread metadata when adapter supports fetch_thread callback.

# `schema`

Returns the Zoi schema for Thread.

# `send_file`

```elixir
@spec send_file(t(), Jido.Chat.FileUpload.input(), keyword()) ::
  {:ok, Jido.Chat.SentMessage.t()} | {:error, term()}
```

Uploads a file to the thread when supported by the adapter.

# `set_state`

```elixir
@spec set_state(Jido.Chat.t(), t(), atom() | term(), map() | term()) :: Jido.Chat.t()
```

Sets thread state in chat struct using :replace, :merge, or key/value modes.

# `start_typing`

```elixir
@spec start_typing(t(), String.t() | nil) :: :ok | {:error, term()}
```

Starts a typing indicator in the thread when supported.

# `state`

```elixir
@spec state(Jido.Chat.t(), t(), term() | nil) :: map() | term()
```

Gets thread state map or a single key from chat struct state.

# `subscribe`

```elixir
@spec subscribe(Jido.Chat.t(), t()) :: Jido.Chat.t()
```

Subscribes this thread in a pure `Jido.Chat` state struct.

# `subscribed?`

```elixir
@spec subscribed?(Jido.Chat.t(), t()) :: boolean()
```

Returns true when the thread is subscribed in a pure `Jido.Chat` state struct.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Serializes thread into a plain map with type marker.

# `unsubscribe`

```elixir
@spec unsubscribe(Jido.Chat.t(), t()) :: Jido.Chat.t()
```

Unsubscribes this thread in a pure `Jido.Chat` state struct.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
