# ICThread

Within imiconnect, all In-App messages are compartmentalized into logical threads of conversation. The ICThread class is the local representation of thread data within the imiconnect SDK.

Threads can be managed via the SDK using the methods exposed by the [ICMessaging](https://developers.imiconnect.io/docs/icmessaging) class and support data attributes such as title, category, status, and extras.

Before messages can be published from the SDK a thread must be provisioned within the imiconnect platform via [ICMessaging.createThread](https://developers.imiconnect.io/docs/icmessaging#section-create-thread-a-stream) or via the [web APIs](https://developers.imiconnect.io/docs/icmessaging#createthread-1).

When replying to an existing thread, obtain an ICThread instance from an incoming [ICMessage](https://developers.imiconnect.io/docs/icmessage) or from the [ICMessaging.fetchThreads](https://developers.imiconnect.io/docs/icmessaging#section-fetch-messages) method.

[block:parameters]
{
  "data": {
    "h-0": "Return Type",
    "h-1": "Method",
    "0-0": "JSONObject",
    "0-1": "[fromJSON()](https://developers.imiconnect.io/docs/icthread#fromjsona-thread)",
    "1-0": "String",
    "1-1": "[getCategory()](https://developers.imiconnect.io/docs/icthread#getcategory)",
    "2-0": "Date",
    "2-1": "[getCreatedAt()](https://developers.imiconnect.io/docs/icthread#getcreatedat)",
    "3-0": "String",
    "3-1": "[getExternalId()](https://developers.imiconnect.io/docs/icthread#getexternalid)",
    "4-0": "Bundle",
    "4-1": "[getExtras()](https://developers.imiconnect.io/docs/icthread#section-get-extras-a-thread)",
    "5-0": "String",
    "5-1": "[getId()](https://developers.imiconnect.io/docs/icthread#getid)",
    "6-0": "[ICThreadStatus](https://developers.imiconnect.io/docs/enumerations-2#section-icthreadstatus)",
    "6-1": "[getStatus()](https://developers.imiconnect.io/docs/icthread#getstatus)",
    "7-0": "String",
    "7-1": "[getTitle()](https://developers.imiconnect.io/docs/icthread#gettitle)",
    "8-0": "[ICThreadType](https://developers.imiconnect.io/docs/enumerations-2#section-icthreadtype)",
    "8-1": "[getType()](https://developers.imiconnect.io/docs/icthread#gettype)",
    "9-0": "Date",
    "9-1": "[getUpdatedAt()](https://developers.imiconnect.io/docs/icthread#getupdatedat)",
    "10-0": "void",
    "10-1": "[setCategory(String category)](https://developers.imiconnect.io/docs/icthread#setcategory)",
    "11-0": "void",
    "11-1": "[setExternalId(String id)](https://developers.imiconnect.io/docs/icthread#setexternalid)",
    "12-0": "void",
    "12-1": "[setExtras(Bundle extras)](https://developers.imiconnect.io/docs/icthread#setextras)",
    "13-0": "void",
    "13-1": "[setTitle(String title)](https://developers.imiconnect.io/docs/icthread#settitle)",
    "14-0": "JSONObject",
    "14-1": "[toJSON()](https://developers.imiconnect.io/docs/icthread#tojson)"
  },
  "cols": 2,
  "rows": 15
}
[/block]

\##fromJSON

Instantiates an ICThread instance from a JSONObject. The JSONObject must contain valid thread data.

  **Syntax:** `static ICThread fromJSON(JSONObject jsonObj)`

  **Return Value:** A new ICThread instance. Returns null if jsonObj is null.

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "jsonObj",
    "0-1": "JSONObject",
    "0-2": "A JSONObject instance containing valid thread data."
  },
  "cols": 3,
  "rows": 1
}
[/block]

\##getCategory

Gets the thread category.

  **Syntax:** `String getCategory()`

  **Return Value:** The thread category.

\##getCreatedAt

Gets the date on which the thread was created within the imiconnect platform.

  **Syntax:** `Date getCreatedAt()`

  **Return Value:** The thread creation date.

\##getExternalId

Gets the external id associated with the thread. An external id is a value that may be used to associate the thread with an entity in an external system.

  **Syntax:** `String getExternalId()`

  **Return Value:** The external id, if present, otherwise null.

\##getExtras

Returns a bundle of any extra data associated with the thread. Extras may be used to associate custom data with a thread.

  **Syntax:** `Bundle getExtras()`

  **Return Value:**  Extra data elements associated to the thread, or null if none exists.

\##getId

Gets the unique identifier of the thread. This value is generated by the imiconnect platform when the thread is provisioned.

  **Syntax:** `String getId()`

  **Return Value:** The thread id.

\##getStatus

Returns the status of the thread. See [ICThreadStatus](https://developers.imiconnect.io/docs/enumerations-2#section-icthreadstatus) for possible values.

  **Syntax:** [ICThreadStatus](https://developers.imiconnect.io/docs/enumerations-2#section-icthreadstatus)`getStatus()`

  **Return Value:** The threads current status.

\##getTitle

Returns the title of the thread.

  **Syntax:** `String getTitle()`

  **Return Value:** The thread title.

\##getType

Returns the type of thread. See [ICThreadType](https://developers.imiconnect.io/docs/enumerations-2#section-icthreadtype) for possible options.

  **Syntax:** `ICThreadType getType()`

  **Return Value:**  Returns  the thread type.

\##getUpdatedAt

Returns the date on which the thread was last updated. Changes to thread data, or publication of messages on the thread, will affect this date.

  **Syntax:** `Date getUpdatedAt()`

  **Return Value:** The date the thread was last updated.

\##setCategory

Sets the category thread.

  **Syntax:** `void setCategory(String category)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "category",
    "0-1": "String",
    "0-2": "Category of the  thread."
  },
  "cols": 3,
  "rows": 1
}
[/block]

\##setExternalId

Sets the external id value. External ids can be used to associate a thread with an entity in an external system.

  **Syntax:** `void setExternalId(String externalId)`

  **Parameters:**

[block:parameters]
{
  "data": {
    "0-0": "externalId",
    "0-1": "String",
    "0-2": "The external id value",
    "h-0": "Parameter",
    "h-2": "Description",
    "h-1": "Type"
  },
  "cols": 3,
  "rows": 1
}
[/block]

\##setExtras

Sets extra data to be associated with the thread.

  **Syntax:** `void setExtras(Bundle extras)`

  \**Parameters:*

[block:parameters]
{
  "data": {
    "0-1": "Bundle",
    "0-0": "Extras",
    "0-2": "The extra data",
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description"
  },
  "cols": 3,
  "rows": 1
}
[/block]

\##setTitle

Sets the thread title.

  **Syntax:** `void setTitle(String title)`
cx
  **Parameters:**

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "title",
    "0-1": "String",
    "0-2": "Title of the thread."
  },
  "cols": 3,
  "rows": 1
}
[/block]

\##toJSON

Returns a JSON representation of the thread.

  **Syntax:** `JSONObject toJSON()`

  **Return Value:** Thread data as a JSONObject