Build activity indicators and badges with information about a location and its threads
Overview # This method allows you to observe summary information about a
location , including live updates.
React: import { thread } from '@cord-sdk/react';
const summary = thread.useLocationSummary({page: 'document_details'}, {partialMatch: true});
return (
<div>
{!summary && "Loading..."}
{summary && (
<p>Total threads: {summary.total}</p>
<p>Unread threads: {summary.unread}</p>
<p>Unread subscribed threads: {summary.unreadSubscribed}</p>
<p>Resolved threads: {summary.resolved}</p>
)}
</div>
);
Vanilla JavaScript: const ref = window.CordSDK.thread.observeLocationSummary(
{page: 'document_details'},
(summary) => {
// Received an update!
console.log("Total threads", summary.total);
console.log("Unread threads", summary.unread);
console.log("Unread subscribed threads", summary.unreadSubscribed);
console.log("Resolved threads", summary.resolved);
},
{partialMatch: true}
);
// ... Later, when updates are no longer needed ...
window.CordSDK.thread.unobserveLocationSummary(ref);
import { thread } from '@cord-sdk/react' ;
const summary = thread . useLocationSummary ( { page : 'document_details' } , { partialMatch : true } ) ;
return (
< div >
{ ! summary && "Loading..." }
{ summary && (
< p > Total threads : { summary . total } < / p >
< p > Unread threads : { summary . unread } < / p >
< p > Unread subscribed threads : { summary . unreadSubscribed } < / p >
< p > Resolved threads : { summary . resolved } < / p >
) }
< / div >
) ;
React Vanilla JavaScript
Copy
Available Data # The API provides an object which has the following fields:
The total number of threads, both resolved and unresolved. This does not include threads in which all messages have been deleted.
The total number of threads that contain at least one unread message in the thread.
This will count all threads with unread messages, whether the current user is subscribed to the thread or not.
unreadSubscribed # number
The number of threads that have messages the current user hasn't seen yet and is subscribed to.
A user is automatically subscribed to threads relevant to them, for example because they have sent a message or have been @-mentioned in them. unreadSubscribed
is always less than or equal to unread
.
The total number of threads that the user has never seen before at all, i.e., every message in the thread is unread.
This will count all threads with unread messages, whether the current user is subscribed to the thread or not.
The number of resolved threads. This refers to threads that users have manually marked as resolved within Cord's UI components.
The number of thread with no visible messages. This refers to threads in which all the messages have been deleted.
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 # React Vanilla JavaScript
location # required
Location
The
location to fetch summary information for.
options # optional
ObserveThreadActivitySummaryOptions
Options that control which threads are returned.
This is an object with the following fields:
partialMatch # optional
boolean
If
true
, perform
partial matching on the specified location. If
false
, fetch information for only exactly the location specified.
If unset, defaults to false
.