Once authenticated, users can send or receive messages, which are tied to a Conversation
A Conversation is created by calling the following function:
[stringeeClient createConversationWithName:@"Conv-name" participants:parts options:options completionHandler:^(BOOL status, int code, NSString *message, StringeeConversation *conversation) {
}];
In which:
parts: A set of StringeeIdentity object, see StringeeIdentity, for example:
StringeeIdentity *iden1 = [StringeeIdentity new];
iden1.userId = @"user1";
StringeeIdentity *iden2 = [StringeeIdentity new];
iden2.userId = @"user2";
NSSet *parts = [[NSSet alloc] initWithObjects:iden1, iden2, nil];
options: Conversation options to use when constructing this conversation, for example:
StringeeConversationOption *options = [StringeeConversationOption new];
options.distinctByParticipants = YES;
options.isGroup = true;
To create a Chat 1-1 Conversation, you must pass parts with only one StringeeIdentity, isGroup = false, for example:
StringeeIdentity *iden2 = [StringeeIdentity new];
iden2.userId = @"user2";
NSSet *parts = [[NSSet alloc] initWithObjects:iden2, nil];
StringeeConversationOption *options = [StringeeConversationOption new];
options.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 parts with more than one StringeeIdentity, the Conversation is created as a Group Chat Conversation.
To create a Group Chat Conversation, you pass isGroup = true or parts with more than one StringeeIdentity:
StringeeIdentity *iden1 = [StringeeIdentity new];
iden1.userId = @"user1";
StringeeIdentity *iden2 = [StringeeIdentity new];
iden2.userId = @"user2";
NSSet *parts = [[NSSet alloc] initWithObjects:iden1, iden2, nil];
StringeeConversationOption *options = [StringeeConversationOption new];
options.distinctByParticipants = YES;
options.isGroup = true;
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 Conversation 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 which are saved in the local database, you call the following function:
[stringeeClient getLocalConversationsWithCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {
}];
In which:
To get lastest conversations from Stringee server, you call the following function:
[stringeeClient getLastConversationsWithCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {
}];
In which:
To get a list of conversations which have updated time greater than a timestamp from server, you call:
[stringeeClient getConversationsAfter:timestamp withCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {
}];
In which:
To get a list of conversations which have updated time smaller than a timestamp from server, you call:
[stringeeClient getConversationsBefore:timestamp withCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {
}];
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:
// Add
StringeeIdentity *part = [StringeeIdentity new];
part.userId = @"userId";
NSSet *parts = [NSSet setWithObjects:part, nil];
[conversation addParticipants:parts completionHandler:^(BOOL status, int code, NSString *message, id data) {
NSLog(@"addParticipants %@", message);
}];
// Remove
StringeeIdentity *part = [StringeeIdentity new];
part.userId = @"userId";
NSSet *parts = [NSSet setWithObjects:part, nil];
[conversation removeParticipants:parts completionHandler:^(BOOL status, int code, NSString *message, id data) {
NSLog(@"addParticipants %@", message);
}];
In which:
To leave a Conversation, you remove yourself from the Conversation.
You can update conversation's info by the following function:
[conversation updateWithName:@"" strAvatarUrl:@"" completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"====== Delete Conversation %@", message);
}];
In which:
In case the Conversation is Chat 1-1, you can delete the Conversation by calling:
[conversation deleteWithCompletionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"====== Delete Conversation %@", message);
}];
In which:
In case the Conversation is Group Chat, you must leave the Conversation before deleting.