Once authenticated, users can send or receive messages which are tied to 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:
options: StringeeConversationOption to use when constructing this conversation, for example:
StringeeConversationOption options = StringeeConversationOption(isGroup: false, isDistinct: true);
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 = [
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.
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 = [
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.
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, call chat.getLocalConversations():
chat.getLocalConversations().then((value) {
List<StringeeConversation> conversations = value['body'];
print("status-${value['status']} code-${value['code']} message-${value['message']}");
});
In which:
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:
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 = [
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']}");
});
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.