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

chat.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 = [
    StringeeUser(userId: 'PARTICIPANT_ID'),
];

StringeeConversationOption options = StringeeConversationOption(isGroup: false, isDistinct: true);

A Chat 1–1 Conversation is a distinct Conversation by default. You cannot 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 = [
    StringeeUser(userId: 'PARTICIPANT_1_ID'),
    StringeeUser(userId: 'PARTICIPANT_2_ID'),
];

StringeeConversationOption options = StringeeConversationOption(isGroup: true, isDistinct: 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, call chat.getLocalConversations():

chat.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 the latest conversations from Stringee Server, call chat.getLastConversation(count):

chat.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:

chat.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:

chat.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 = [
    StringeeUser(userId: 'USER_1_ID'),
    StringeeUser(userId: 'USER_2_ID'),
];
/// Add
_conversation.addParticipants(users).then((value) {
    print("status-${value['status']} code-${value['code']} message-${value['message']}");
});

/// Remove
_conversation.removeParticipants(users).then((value) {
    print("status-${value['status']} code-${value['code']} message-${value['message']}");
});
Note:

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

4. 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.