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(participants, options, new CallbackListener<Conversation>() {
    @Override
    public void onSuccess(final Conversation conv) {
    }
    @Override
    public void onError(final StringeeError error) {
    }
});

In which:

1.1. Chat 1-1

To create a Chat 1-1 Conversation, you must pass participants with only one user and options as below:

ConversationOptions options = new ConversationOptions();
options.setName(conversation's name);
options.setGroup(false);
options.setDistinct(true);

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 participants with more than one user, the Conversation is created as a Group Chat Conversation.

1.2. Group Chat

To create a Group Chat Conversation, you pass options as:

ConversationOptions options = new ConversationOptions();
options.setGroup(true);

You can add or remove participants to/from a Group Chat 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, new CallbackListener<List<Conversation>>() {
    @Override
    public void onSuccess(final List<Conversation> conversations) {
    }
});

In which:

2.2 Get latest Conversations

To get latest conversations from Stringee server, you call:

stringeeClient.getLastConversations(count, new CallbackListener<List<Conversation>>() {
    @Override
    public void onSuccess(final List<Conversation> conversations) {
    }
});

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:

stringeeClient.getConversationsAfter(datetime, count, new CallbackListener<List<Conversation>>() {
    @Override
    public void onSuccess(final List<Conversation> conversations) {
    }
});

In which:

2.4 Get Conversations Before

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

stringeeClient.getConversationsBefore(datetime, count, new CallbackListener<List<Conversation>>() {
    @Override
    public void onSuccess(final List<Conversation> conversations) {
    }
});

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
conversation.addParticipants(stringeeClient, participants, new CallbackListener<List<User>>() {
    @Override
    public void onSuccess(List<User> users) {
        // return added users here
    }

    @Override
    public void onError(StringeeError error) {
    }
});
// Remove
conversation.removeParticipants(stringeeClient, participants, new CallbackListener<List<User>>() {
    @Override
    public void onSuccess(List<User> users) {
        // return removed users here
    }

    @Override
    public void onError(StringeeError error) {
    }
});
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:

conversation.delete(stringeeClient, new StatusListener() {
    @Override
    public void onSuccess() {
    }
    @Override
    public void onError(StringeeError error) {
    }
});

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