API Docs for version 1.3.1810

Injectors

Module: Circuit

static

Summary

Injectors that can be implemented by application to extend the Conversation, Item and User objects. Injectors may be synchronous in which case they can return the extended object, or asynchronous in which case a Promise needs to be returned.

See examples in method documentation.

Methods

conversationInjector

Syntax

conversationInjector

(
  • conversation
)
Conversation | Promise

Summary

Define this injector to extend the conversation objects returned in any response or included in any event sent by the API. This method can return the extended conversation object synchronously, or a Promise if this function needs to perform any asynchronous task.

Parameters:

Returns:

Conversation | Promise:

The extended conversation, or a Promise with the extended conversation as parameter

Example:

Circuit.Injectors.conversationInjector = function (conversation) {
    return new Promise(function (resolve, reject) {
        // Get user objects for participant of this conversation
        client.getUsersById(userIds).then(function (users) {
            conversation.users = users;
            resolve(conversation);
        }, function (err) {
            reject(err);
        });
    });
}

itemInjector

Syntax

itemInjector

(
  • item
)
Item | Promise

Summary

Define this injector to extend the item objects returned in any response or included in any event sent by the API. This method can return the extended item object synchronously, or a Promise if this function needs to perform any asynchronous task.

Parameters:

  • item Item

    An item object

Returns:

Item | Promise:

The extended item, or a Promise with the extended item as parameter

Example:

Circuit.Injectors.itemInjector = function (item) {
    // Define a teaser attribute for text items
    if (item.type === 'TEXT') {
        // Create item.teaser attribute with replacing br and hr tags with a space
        item.teaser = item.text.content.replace(/<(br[\/]?|\/li|hr[\/]?)>/gi, ' ');
    } else {
        item.teaser = item.type;
    }
};

participantInjector

Syntax

participantInjector

(
  • user
)
ConversationParticipant | Promise

Summary

Define this injector to extend the participant objects returned by the GetConversationParticipants API. This method can return the extended participant object synchronously, or a Promise if this function needs to perform any asynchronous task.

Parameters:

Returns:

ConversationParticipant | Promise:

The extended participant, or a Promise with the extended participant as parameter

Example:

Circuit.Injectors.participantInjector = function (participant) {
    // Override the avatar if participant does not have one.
    if (!participant.smallImageUri) {
        participant.avatar = 'http://www.aceshowbiz.com/images/photo/chuck_norris.jpg';
        participant.avatarLarge = 'http://www.aceshowbiz.com/images/photo/chuck_norris.jpg';
    }
};

userInjector

Syntax

userInjector

(
  • user
)
User | Promise

Summary

Define this injector to extend the user objects returned in any response or included in any event sent by the API. This method can return the extended user object synchronously, or a Promise if this function needs to perform any asynchronous task.

Parameters:

  • user User

    An user object

Returns:

User | Promise:

The extended user, or a Promise with the extended user as parameter

Example:

Circuit.Injectors.userInjector = function (user) {
    // Override the avatar if user does not have one.
    if (!user.smallImageUri) {
        user.avatar = 'http://www.aceshowbiz.com/images/photo/chuck_norris.jpg';
        user.avatarLarge = 'http://www.aceshowbiz.com/images/photo/chuck_norris.jpg';
    }
};