Messaging services

Conversations

create conversation:

CMPRoleAttributes *ownerAttributes = [[CMPRoleAttributes alloc] initWithCanSend:YES canAddParticipants:YES canRemoveParticipants:YES];

CMPRoleAttributes *participantAttributes = [[CMPRoleAttributes alloc] initWithCanSend:YES canAddParticipants:NO canRemoveParticipants:NO];

// defines permissions to be applied to conversation
CMPRoles *roles = [[CMPRoles alloc] initWithOwnerAttributes:ownerAttributes participantAttributes:participantAttributes];

CMPConversationParticipant *owner = [[CMPConversationParticipant alloc] initWithID:profileID role:@"owner"];

CMPNewConversation *newConversation = [[CMPNewConversation alloc] initWithID:@"{id}" name:@"{name}" description:@"{description}" roles:roles participants:@[owner] isPublic:@(NO)];

[client.services.messaging addConversation:newConversation completion:^(CMPChatResult<CMPConversation *> *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

update conversation:

CMPConversationUpdate *update = [[CMPConversationUpdate alloc] initWithID:@"{id}" name:@"{name}" description:@"{description}" roles:roles isPublic:@(NO)];

[client.services.messaging updateConversation:@"{id}" eTag:nil conversation:update completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

delete conversation:

[client.services.messaging deleteConversation:@"{id}" eTag:nil completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

Participants

get participants

[client.services.messaging getParticipants:@"{id}" participantIDs:@[@"{id1}", @"{id2}"] completion:^(NSArray<CMPChatParticipant *> *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

add participants

NSArray<CMPConversationParticipant *> *participants = @[[[CMPConversationParticipant alloc] initWithID:@"@{id1}" role:@"{role}"], [[CMPConversationParticipant alloc] initWithID:@"@{id2}" role:@"{role}"]];

[client.services.messaging addParticipants:@"{id}" participants:participants completion:^(CMPChatResult *result) {
    if (result.error) {
    		// error occurred
    } else {
      	// success
    }
}];

remove participants

[client.services.messaging removeParticipants:@"{id}" participants:participants completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

set participant typing

[client.services.messaging participantIsTyping:@"{conversationId}" isTyping:true completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

Messages

send message

CMPMessagePart *part = [[CMPMessagePart alloc] initWithName:@"{name}" type:@"{type}" url:nil data:@"{data}" size:@(123)];

CMPMessageAlert *alert = [[CMPMessageAlert alloc] initWithPlatforms:[[CMPMessageAlertPlatforms alloc] initWithApns:@{} fcm:@{}]];
    
CMPSendableMessage *message = [[CMPSendableMessage alloc] initWithMetadata:@{} parts:@[part] alert:alert];

[client.services.messaging sendMessage:@"{id}" message:message completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

send message with attachments

ContentData *dataFromUrl = [[ContentData alloc] initWithUrl:url type:@"type" name:@"name"];

CMPChatAttachment *attachment = [[CMPChatAttachment alloc] initWithContentData:dataFromUrl folder:@"folder"];

[client.services.messaging sendMessage:@"{id}" message:message attachments:@[attachment] completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

mark message as read

[client.services.messaging markMessagesAsRead:@"{id}" messageIDs:@[@"{id1}", @"{id2}"] completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

Synchronise local store

The local data synchronisation is being called by the SDK on regular basis but can be triggered manually as well.

Local store synchronisation will update conversations and messages.

[client.services.messaging synchroniseStore:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];

You can also update message data for a single conversation by calling:

[client.services.messaging synchroniseConversation:@"{id}" completion:^(CMPChatResult *result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];