Home Reference Source
import ManagedConversationList from 'js-chat-demo/utils/ManagedConversationList.jsx'
public class | source

ManagedConversationList

A managed list of conversations for the current user. Note: You must be logged in to use this.

Constructor Summary

Public Constructor
public

constructor(options: object)

Member Summary

Public Members
public get

List length (like the array length property)

Method Summary

Public Methods
public

add(conversation: Conversation): ManagedConversationList

Add a conversation, no-op if the conversation already exists.

public

If you used pubsubSync, you must call this function when the list is no longer needed to prevent a memory leak.

public

Fetches list of conversations from the server.

public

filter(predicate: function): Array

List filter method (like the array filter method)

public

get(indexOrID: number | string): Conversation

Get a Conversation

public

map(mappingFunction: function): Array

List mapping method (like the array map method)

public

Remove a conversation, no-op if the conversation doesn't exist.

public

Subscribe to list updates, handler will be called with one argument: this object.

public

Cancel a subscription.

public

update(conversation: Conversation): ManagedConversationList

Update a conversation, no-op if the conversation updatedAt date is older than existing.

Public Constructors

public constructor(options: object) source

Params:

NameTypeAttributeDescription
options object
  • optional
  • default: {}
options.initialFetch boolean
  • optional
  • default: true

Automatically fetch list of conversations on creation.

options.pubsubSync boolean
  • optional
  • default: true

Keep list synchronized with server using PubSub.

options.sortBy function
  • optional
  • default: new ConversationSorting('last update',descending')

How the list is sorted, you can use ConversationSorting wrapper to create one or provide your own.

Public Members

public get length: number source

List length (like the array length property)

Public Methods

public add(conversation: Conversation): ManagedConversationList source

Add a conversation, no-op if the conversation already exists.

Params:

NameTypeAttributeDescription
conversation Conversation

public destroy() source

If you used pubsubSync, you must call this function when the list is no longer needed to prevent a memory leak.

public fetch(): Promise<ManagedConversationList> source

Fetches list of conversations from the server.

Return:

Promise<ManagedConversationList>

Promise of this object, resolves if the fetch is successful.

public filter(predicate: function): Array source

List filter method (like the array filter method)

Params:

NameTypeAttributeDescription
predicate function

Return:

Array

public get(indexOrID: number | string): Conversation source

Get a Conversation

Params:

NameTypeAttributeDescription
indexOrID number | string

Either the list index (number) or conversation ID (string) without type prefix.

Return:

Conversation

public map(mappingFunction: function): Array source

List mapping method (like the array map method)

Params:

NameTypeAttributeDescription
mappingFunction function

Return:

Array

public remove(conversationID: string): ManagedConversationList source

Remove a conversation, no-op if the conversation doesn't exist.

Params:

NameTypeAttributeDescription
conversationID string

Conversation ID without type prefix.

public subscribe(handler: function): number source

Subscribe to list updates, handler will be called with one argument: this object.

Params:

NameTypeAttributeDescription
handler function

Return:

number

Subscription ID

public unsubscribe(subID: number) source

Cancel a subscription.

Params:

NameTypeAttributeDescription
subID number

The subscription ID returned by the subscribe function.

public update(conversation: Conversation): ManagedConversationList source

Update a conversation, no-op if the conversation updatedAt date is older than existing. Conversation will be added if it's not in the list.

Params:

NameTypeAttributeDescription
conversation Conversation