Once authenticated, users can send or receive messages, which are tied to a Conversation
A Conversation is created by calling stringeeClient.createConversation(userIds, options, callback):
this.client.current.createConversation(userIds, options, (status, code, message, conversation) => {
console.log("status-" + status + " code-" + code + " message-" + message + " conversation-" + conversation.name);
});
In which:
userIds: A set of participants' ID, for example:
var userIds = ["user1", "user2"];
options: Conversation options to use when constructing this conversation, for example:
var options = {
name: "Your conversation name",
isDistinct: false,
isGroup: true
};
callback: The result returned
To create a Chat 1-1 Conversation, you must pass userIds with only one user id, isGroup = false, for example:
var userIds = ["user1"];
var options = {
name: "Your conversation name",
isDistinct: false/true,
isGroup: false
};
A Chat 1-1 Conversation is a distinct Conversation by default. You can not add participants to a Chat 1-1 Conversation.
If you pass userIds with more than one user id, the Conversation is created as a Group Chat Conversation.
To create a Group Chat Conversation, you pass isGroup = true or userIds with more than one user id:
var userIds = ["user1", "user2", ...];
var options = {
name: "TĂȘn conversation",
isDistinct: false/true,
isGroup: true
};
You can add or remove participants to/from a Conversation.
If a Conversation is created as a distinct Conversation, it is unique on the Stringee server. This means that if 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 be resolved into the existing Conversation.
Conversations are created as non-distinct Conversations by default.
Creating a distinct Conversation by setting the isDistinct option:
Conversations are stored on the Stringee server as well as cached on the Local Database. You can get conversations as follows:
To get local conversations, you call getLocalConversations(userId, count, isAscending, callback):
this.client.current.getLocalConversations(userId, count, isAscending, (status, code, message, conversations) => {
console.log("status-" + status + " code-" + code + " message-" + message);
conversations.map((conversation) => {
console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
});
});
In which:
Get the latest conversations from the Stringee server by calling getLastConversations(count, isAscending, callback):
this.client.current.getLastConversations (count, isAscending, (status, code, message, conversations) => {
console.log("status-" + status + " code-" + code + " message-" + message);
conversations.map((conversation) => {
console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
});
});
In which:
Get a list of conversations of which updated time is greater than the datetime from the server by calling:
this.client.current.getConversationsAfter(datetime, count, isAscending, (status, code, message, conversations) => {
console.log("status-" + status + " code-" + code + " message-" + message);
conversations.map((conversation) => {
console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
});
});
In which:
Get a list of conversations of which updated time is smaller than the datetime from the server by calling:
this.client.current.getConversationsBefore(datetime, count, isAscending, (status, code, message, conversations) => {
console.log("status-" + status + " code-" + code + " message-" + message);
conversations.map((conversation) => {
console.log("conversation Info:" + conversation.id + "===== " +conversation.name);
});
});
In which:
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:
// Add
var userIds = ["user1", "user2"];
this.client.current.addParticipants(convId, userIds, (status, code, message, users) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});
// Remove
var userIds = ["user1"];
this.client.current.removeParticipants(convId, userIds, (status, code, message, users) => {
console.log("status-" + status + " code-" + code + " message-" + 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:
this.client.current.deleteConversation(convId, (status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});
In case the Conversation is Group Chat, you must leave the Conversation before deleting.