Once authenticated, users can send or receive messages which are tied to a Conversation
A Conversation is created by calling stringeeClient.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:
options: StringeeConversationOption to use when constructing this conversation, for example:
StringeeConversationOption options = StringeeConversationOption(isGroup: false);
participants: List of StringeeUser.
value: result.
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 cannot add participants to a Chat 1–1 Conversation.
If you pass participants with more than one user, the Conversation is created as a Group Chat Conversation.
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.
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:
Conversations are stored on Stringee server and cached on Local Database as well. You can get conversations as follows:
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:
To get last conversations from Stringee server, you call stringeeClient.getLastConversations(count, callback):
chat.getLastConversation(count).then((value) {
List<StringeeConversation> conversations = value['body'];
print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});
In which:
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:
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:
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']);
});
To leave a Conversation, you remove yourself from the 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.