Home Reference Source
import {SkygearChatCloudContainer} from 'skygear-chat/lib/cloud.js'
public class | source

SkygearChatCloudContainer

You can directly use an instance of this class. cloudContainer

Method Summary

Public Methods
public

afterConversationCreated(func: function(conversation: Record, participants: Record[], context: Object))

After conversation created hook.

public

afterConversationDeleted(func: function(conversation: Record, participants: Record[], context: Object))

After conversation deleted hook.

public

afterConversationUpdated(func: function(conversation: Record, participants: Record[], context: Object))

After conversation updated hook.

public

afterMessageDeleted(func: function(message: Record, conversation: Record, participants: Record[], context: Object))

After message deleted hook.

public

afterMessageSent(func: function(message: Record, conversation: Record, participants: Record[], context: Object))

After message sent hook.

public

afterMessageUpdated(func: function(message: Record, conversation: Record, participants: Record[], context: Object))

After message updated hook.

public

afterUsersAddedToConversation(func: function(conversation: Record, participants: Record[], newUsers: Record[], context: Object))

After user added to conversation hook.

public

afterUsersRemovedFromConversation(func: function(conversation: Record, participants: Record[], oldUsers: Record[], context: Object))

After user removed from conversation hook.

public

chatHook(name: *, func: *)

public

typingStarted(func: function(conversation: Record, participants: Record[], event: Object, context: Object))

Typing started hook.

Public Methods

public afterConversationCreated(func: function(conversation: Record, participants: Record[], context: Object)) source

After conversation created hook.

This hook will be triggered once a conversation is created.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], context: Object)

function to be registered

public afterConversationDeleted(func: function(conversation: Record, participants: Record[], context: Object)) source

After conversation deleted hook.

This hook will be triggered once a conversation is deleted.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], context: Object)

function to be registered

public afterConversationUpdated(func: function(conversation: Record, participants: Record[], context: Object)) source

After conversation updated hook.

This hook will be triggered once a conversation is updated.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], context: Object)

function to be registered

public afterMessageDeleted(func: function(message: Record, conversation: Record, participants: Record[], context: Object)) source

After message deleted hook.

This hook will be triggered once a message is deleted.

Params:

NameTypeAttributeDescription
func function(message: Record, conversation: Record, participants: Record[], context: Object)

function to be registered

public afterMessageSent(func: function(message: Record, conversation: Record, participants: Record[], context: Object)) source

After message sent hook.

This hook will be triggered once a message is sent by an user.

Params:

NameTypeAttributeDescription
func function(message: Record, conversation: Record, participants: Record[], context: Object)

function to be registered

Example:

const chat = require('skygear-chat');
chat.cloud.afterMessageSent((message, conversation, participants, context) => {
  const title = conversation.title;
  const participantIds = participants.map((p) => p._id && p._id != context.userId);
  const currentUser = participants.find((p) => p._id == context.userId);
  let body = '';
  if (message.body) {
    body = currentUser.username + ": " + message.body;
  } else {
    body = currentUser.username + ":" + "sent you a file.";
  }
  const payload = {'gcm': {'notification': {'title': title, 'body': body}}}
  container.push.sendToUser(participantIds, payload);
});

public afterMessageUpdated(func: function(message: Record, conversation: Record, participants: Record[], context: Object)) source

After message updated hook.

This hook will be triggered once a message is updated.

Params:

NameTypeAttributeDescription
func function(message: Record, conversation: Record, participants: Record[], context: Object)

function to be registered

public afterUsersAddedToConversation(func: function(conversation: Record, participants: Record[], newUsers: Record[], context: Object)) source

After user added to conversation hook.

This hook will be triggered once one or more users are added to a conversation.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], newUsers: Record[], context: Object)

function to be registered

public afterUsersRemovedFromConversation(func: function(conversation: Record, participants: Record[], oldUsers: Record[], context: Object)) source

After user removed from conversation hook.

This hook will be triggered once one or more users are removed from a conversation.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], oldUsers: Record[], context: Object)

function to be registered

public chatHook(name: *, func: *) source

Params:

NameTypeAttributeDescription
name *
func *

public typingStarted(func: function(conversation: Record, participants: Record[], event: Object, context: Object)) source

Typing started hook.

This hook will be triggered once an user starts typing.

Params:

NameTypeAttributeDescription
func function(conversation: Record, participants: Record[], event: Object, context: Object)

function to be registered