Observe thread summary information

Build activity indicators and badges with information about a thread and its messages


Overview

This method allows you to observe summary information about a thread, including live updates.

import { thread } from '@cord-sdk/react';
const summary = thread.useThreadSummary(threadId, options);
Copy

Usage

import { thread } from '@cord-sdk/react';
const summary = thread.useThreadSummary('my-awesome-thread-id');
return (
  <div>
    {!summary && "Loading..."}
    {summary && (
      <p>Total messages: {summary.total}</p>
      <p>Unread messages: {summary.unread}</p>
    )}
  </div>
);
Copy

Available Data

Graphic showing example uses of the Cord Thread Summary API

The API provides an object which has the following fields:


id

string
The id for this particular thread.

organizationID

string
The id for the organization containing this thread.

total

number
The total number of messages in the thread.

unread

number
The number of messages that the current user hasn't seen yet.

resolved

boolean
Whether the thread is resolved or not.

participants

object[]

Contains information about users that are subscribed to this thread. An array of objects, one for each subscriber. Each object contains the following fields:


lastSeenTimestamp

string
format: date-time
The timestamp of the most recent message or reaction that this user has seen in this thread. Is null if this participant has never viewed this thread.

userID

string
The user ID of the participant. Can be null if the current viewer no longer shares an organization with this participant (and therefore can no longer access that participant's information).

typing

string[]
A list of IDs of the users that are currently typing on this thread.

viewerIsThreadParticipant

boolean
Whether the current viewer has either left a message or reacted to this thread.

name

string

The name of the thread. This typically defaults to the title of the page where the thread was created, but it can be set manually by the Thread component. You might use this in places where a short name or header is useful to distinguish the thread.

Never null, but can be empty.


location

location
The location of this thread.

firstMessage

object | null

Contains information about the first (i.e., oldest) message in the thread. null if the thread is empty. Otherwise, contains the following fields:


id

string
The id for this particular message.

createdTimestamp

Date
The time this message was created and sent.

deletedTimestamp

Date | null
The time this message was deleted. null if the message is not deleted.

seen

boolean
Whether this message has been seen by the current viewer.

What this function returns

The hook will initially return undefined while the data loads from our API. Once it has loaded, your component will re-render and the hook will return an object containing the fields described under "Available Data" above. The component will automatically re-render if any of the data changes, i.e., this data is always "live".


Arguments this function takes


threadId

required
string

The thread ID to fetch summary information for. If a thread with this ID does not exist, it will be created.


options

optional
object

Miscellaneous options. See below.


The "options" argument


threadName

optional
string

Loading information for a thread ID which does not exist will create that thread. If that happens, this will be the name of the new thread.

If unset, this will default to the current page's title.


location

optional
location

Loading information for a thread ID which does not exist will create that thread. If that happens, this will be the location of the new thread.

If unset, this will default to the location provided to theuseCordLocation hook if that was used. Otherwise, will default to the current page's URL.`