Suggestions

close search

Conversations

Once authenticated, users can send or receive messages, which are tied to a Conversation

1. Create a conversation

A Conversation is created by calling stringeeClient.createConversation(userIds, options, callback):

    this.refs.client.createConversation(userIds, options, (status, code, message, conversation) => {
      console.log("status-" + status + " code-" + code + " message-" + message + " conversation-" + conversation.name);
    });

In which:

1.1. Chat 1-1

To create a Chat 1-1 Conversation, you must pass userIds with only one user id, isGroup = false, for example:

    var userIds = ["user1"];
    var options = {
      name: "Your conversation name",
      isDistinct: false/true,
      isGroup: false
    };

A Chat 1-1 Conversation is a distinct Conversation by default. You can not add participants to a Chat 1-1 Conversation.

Note:

If you pass userIds with more than one user id, the Conversation is created as a Group Chat Conversation.

1.2. Group Chat

To create a Group Chat Conversation, you pass isGroup = true or userIds with more than one user id:

    var userIds = ["user1", "user2", ...];
    var options = {
      name: "TĂȘn conversation",
      isDistinct: false/true,
      isGroup: true
    };

You can add or remove participants to/from a Conversation.

1.3. Distinct Conversations

If a Conversation is created as a distinct Conversation, it's unique on Stringee server. This means, multiple users independently create distinct Conversations with the same set of users, the server will automatically merge the conversations.

Once a Distinct Conversation has been created between User A and User B, any further attempts by either of these users to create a new Distinct Conversation with these participants will get resolved to the existing Conversation.

Conversations are created as non-distinct Conversations by default.

Creating a distinct Conversation by set isDistinct option:

2. Get Conversations

Conversations are stored on Stringee server and cached on Local Database as well. You can get conversations as follows:

2.1 Get Local Conversations

To get local conversations, you call stringeeClient.getLocalConversations(userId, count, callback):

    this.refs.client.getLocalConversations(userId, count, (status, code, message, conversations) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      conversations.map((conversation) => {
        console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
      });
    });

In which:

2.2 Get Last Conversations

To get lastest conversations from Stringee server, you call stringeeClient.getLastConversations(count, callback):

    this.refs.client.getLocalConversations(count, (status, code, message, conversations) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      conversations.map((conversation) => {
        console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
      });
    });

In which:

2.3 Get Conversations After

To get a list of conversations which have updated time greater than a datetime from server, you call:

    this.refs.client.getConversationsAfter(datetime, count, (status, code, message, conversations) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      conversations.map((conversation) => {
        console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
      });
    });

In which:

2.4 Get Conversations Before

To get a list of conversations which have updated time smaller than datetime from server, you call:

    this.refs.client.getConversationsBefore(datetime, count, (status, code, message, conversations) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      conversations.map((conversation) => {
        console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
      });
    });

In which:

3. Participants

Participants in a Conversation. Any participant can add users into a Conversation or leave a Conversation. Only the participant who created the Conversation can remove other participants from the Conversation:

    // Add
    var userIds = ["user1", "user2"];
    this.refs.client.addParticipants(convId, userIds, (status, code, message, users) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });

    // Remove
    var userIds = ["user1"];
    this.refs.client.removeParticipants(convId, userIds, (status, code, message, users) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });
Note:

To leave a Conversation, you remove yourself from the Conversation.

3. Delete Conversation

In case the Conversation is Chat 1-1, you can delete the Conversation by calling:

    this.refs.client.deleteConversation(convId, (status, code, message) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });

In case the Conversation is Group Chat, you must leave the Conversation before deleting.