Suggestions

close search

Conversations

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

1. Create 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:

1.1. Chat 1-1

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.

Note:

If you pass parts with more than one StringeeIdentity, the Conversation is created as a Group Chat Conversation.

1.2. Group Chat

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.

1.3. Distinct Conversations

If a Conversation is created as a distinct Conversation, it's unique on Stringee server. In other words, 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 get resolved to the existing Conversation.

Conversations are created as non-distinct Conversations by default.

Creating a distinct Conversation by setting 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 saved in the local database, you can call the following function:

    [stringeeClient getLocalConversationsWithCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {

    }];

In which:

2.2 Get Last Conversations

To get the latest conversations from Stringee server, you can call the following function:

    [stringeeClient getLastConversationsWithCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {

    }];

In which:

2.3 Get Conversations After

To get a list of conversations which have greater updated time than a timestamp from server, you call:

    [stringeeClient getConversationsAfter:timestamp withCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {

    }];

In which:

2.4 Get Conversations Before

To get a list of conversations which have smaller updated time than a timestamp from server, you call:

    [stringeeClient getConversationsBefore:timestamp withCount:25 completionHandler:^(BOOL status, int code, NSString *message, NSArray<StringeeConversation *> *conversations) {

    }];

In which:

3. Participants

This refers to 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:

Note:

To leave a Conversation, you remove yourself from the Conversation.

4. Update conversation

You can update a conversation's information using the following function:

    [conversation updateWithName:@"" strAvatarUrl:@"" completionHandler:^(BOOL status, int code, NSString *message) {
        NSLog(@"====== Delete Conversation %@", message);

    }];

In which:

5. Delete Conversation

If 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:

If the Conversation is Group Chat, you must leave the Conversation before deleting it.