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

ManagedMessageList

A managed list of messages for the specified conversation.

Constructor Summary

Public Constructor
public

constructor(conversation: Conversation, options: object)

Member Summary

Public Members
public get

List length (like the array length property)

Method Summary

Public Methods
public

add(message: Message): ManagedMessageList

Add a message, no-op if the message 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): Message

Get a Message

public

map(mappingFunction: function): Array

List mapping method (like the array map method)

public

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

public

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

public

Cancel a subscription.

public

update(message: Message): ManagedMessageList

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

Public Constructors

public constructor(conversation: Conversation, options: object) source

Params:

NameTypeAttributeDescription
conversation Conversation
options object
  • optional
  • default: {}
options.initialFetch number | boolean
  • optional
  • default: 50

Fetch messages on creation, provide limit of messages to fetch or false to disable.

options.pubsubSync boolean
  • optional
  • default: true

Keep list synchronized with server using PubSub.

options.autoRead boolean
  • optional
  • default: true

Automatically mark all recieved messages as read.

Public Members

public get length: number source

List length (like the array length property)

Public Methods

public add(message: Message): ManagedMessageList source

Add a message, no-op if the message already exists. Will mark the message as read if the autoRead option is true.

Params:

NameTypeAttributeDescription
message Message

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(resultLimit: number): Promise<ManagedMessageList> source

Fetches list of conversations from the server.

Params:

NameTypeAttributeDescription
resultLimit number
  • optional
  • default: 50

Limit of the number of messages to fetch.

Return:

Promise<ManagedMessageList>

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): Message source

Get a Message

Params:

NameTypeAttributeDescription
indexOrID number | string

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

Return:

Message

public map(mappingFunction: function): Array source

List mapping method (like the array map method)

Params:

NameTypeAttributeDescription
mappingFunction function

Return:

Array

public remove(messageID: string): ManagedMessageList source

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

Params:

NameTypeAttributeDescription
messageID string

Message 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(message: Message): ManagedMessageList source

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

Params:

NameTypeAttributeDescription
message Message