Suggestions

close search

StringeeConversation

Once authenticated, users can send or receive messages, which are tied to the Conversation

1. Create a conversation

The Conversation is created by calling stringeeClient.createConversation(options, participants):

_stringeeClient.createConversation(options, participants).then((ressult) {
  debugPrint('createConversation: message - ${result['message']}');
    if (result['status']) {
      StringeeConversation conversation = result['body'];
    }
});

In which:

1.1 Chat 1-1

To create the 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, isDistinct: true);

The 1-1 conversation is the distinct conversation by default. You can not add participants to the 1-1 conversation.

Note:

If you pass participants with more than one user, the conversation is created as the group conversation.

1.2 Group Chat

To create the group conversation, you pass isGroup = true or participants with more than one user:

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

ConversationOption options = ConversationOption(isGroup: false, isDistinct: false);

You can add/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 the 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 the new distinct conversation with these participants will get resolved to the existing conversation.

Conversations are created as the 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():

_stringeeClient.getLocalConversations().then((result) {
  debugPrint('getLocalConversations: message - ${result['message']}');
  if (result['status']) {
    List<StringeeConversation> conversations = result['body'];
  }
});

2.2 Get lastest conversations

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

_stringeeClient.getLastConversation(count).then((result) {
  debugPrint('getLocalConversations: message - ${result['message']}');
  if (result['status']) {
    List<StringeeConversation> conversations = result['body'];
  }
});

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(count, datetime).then((result) {
  debugPrint('getConversationsAfter: message - ${result['message']}');
  if (result['status']) {
    List<StringeeConversation> conversations = result['body'];
  }
});

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(count, datetime).then((result) {
  debugPrint('getConversationsBefore: message - ${result['message']}');
  if (result['status']) {
    List<StringeeConversation> conversations = result['body'];
  }
});

In which:

3. Participants

Participants in the conversation. Any participant can add users into the conversation or leave from the conversation. Only the participant who created the conversation can remove other participants from the conversation:

List<StringeeUser> users = new List();
users.add(StringeeUser('parrticipant's id));
users.add(StringeeUser('parrticipant's id'));

/// Add
_conversation.addParticipants(List<StringeeUser> participant).then((result) {
  debugPrint('addParticipants: message - ${result['message']}');
});

/// Remove
_conversation.removeParticipants(List<StringeeUser> participant).then((result) {
  debugPrint('removeParticipants: message - ${result['message']}');
});
Note:

To leave from the conversation, you remove yourself from the conversation.

4. Delete Conversation

In case conversation is the 1-1 conversation, you can delete the conversation by calling:

_conversation.delete().then((value) {
  debugPrint('delete: message - ${result['message']}');
});

In case conversation is the group conversation, you must leave from the conversation before deleting.