Suggestions

close search

StringeeConversation

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(options, participants):

_client.createConversation(options, participants).then((value) {
    StringeeConversation conversation = value['body'];
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message'] + " conversation-" + conversation.name);
});

In which:

1.1. Chat 1-1

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

List<StringeeUser> participants = new List();
StringeeUser user = StringeeUser('participant's id');
participants.add(user);

StringeeConversationOption options = StringeeConversationOption(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 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 isGroup = true or participants with more than one user:

List<StringeeUser> participants = new List();
StringeeUser user = StringeeUser('participant's id');
participants.add(user);
StringeeUser user2 = StringeeUser('participant2's id');
participants.add(user2);

ConversationOption options = ConversationOption(isGroup: false);

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 StringeeConversationOption 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():

_client.getLocalConversations().then((value) {
    List<StringeeConversation> conversations = value['body'];
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

In which:

2.2 Get Last Conversations

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

_client.getLastConversation(count).then((value) {
    List<StringeeConversation> conversations = value['body'];
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

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:

_client.getConversationsAfter(count, datetime).then((value) {
    List<StringeeConversation> conversations = value['body'];
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

In which:

2.4 Get Conversations Before

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

_client.getConversationsBefore(count, datetime).then((value) {
    List<StringeeConversation> conversations = value['body'];
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

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:

    List<StringeeUser> users = new List();
    StringeeUser user1 = StringeeUser('user1's id);
    StringeeUser user2 = StringeeUser('user2's id');
    users.add(user1);
    users.add(user2);
    /// Add
    _conversation.addParticipants(List<StringeeUser> participant).then((value) {
      print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
    });

    /// Remove
    _conversation.removeParticipants(List<StringeeUser> participant).then((value) {
      print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['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:

_conversation.delete().then((value) {
  print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

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