Injectors
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.
Item Index
Methods
conversationInjector
Syntax
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:
-
conversation
ConversationA conversation object
Returns:
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
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
ItemAn item object
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
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:
-
user
ConversationParticipantA conversation participant object
Returns:
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
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
UserAn user object
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';
}
};