logo
On this page

Cancel Media Message Sending


Feature Overview

The ZIM SDK supports canceling messages containing local media files that are currently being sent. After a successful cancellation, the message status will change to "Failed to Send".

Note
  • Supported from version 2.22.0.
  • Only messages containing local media files of the following message types can be canceled: Multiple(10), Image(11), File(12), Audio(13), Video(14).

Cancel the Media Message Being Sent

When a user sends a message containing a local media file, due to the time required for file upload, the file upload can be terminated by calling cancelSendingMessage during this period.

Note

When a multi item messages containing both ordinary text and media files is canceled, the entire message (including ordinary text) will be canceled.


void onMessageSentStatusChanged(zim::ZIM *zim, const std::vector<ZIMMessageSentStatusChangeInfo> &messageSentStatusChangeInfoList{
    // Message sent status changed
}


// User A sends a message, taking a single-chat file message as an example

zim::ZIMMediaMessage *message = nullptr;
auto fileMessage = zim::ZIMFileMessage();
// Enter the local path in UTF-8 format
fileMessage.fileLocalPath = "D:\\file\\files.zip";
// If a network URL is entered here, the SDK will pass through the path without ZIM background service processing. If both the network URL and the local path are entered, the SDK will prioritize the network URL that you want to use.
fileMessage.fileDownloadUrl = "";

zim::ZIMMessageSendConfig sendConfig;
sendConfig.priority = zim::ZIM_MESSAGE_PRIORITY_MEDIUM;

message = &fileMessage;

auto notification = std::make_shared<zim::ZIMMessageSendNotification>(
            [=](const std::shared_ptr<zim::ZIMMessage> &message) { 
                // Developers can listen to this callback to execute the business logic before message sending
            },
            [=](const std::shared_ptr<zim::ZIMMediaMessage> &message,
                unsigned long long currentFileSize,
                unsigned long long totalFileSize) { 
                // Cancel sending when the file is being uploaded
                zim::ZIMSendingMessageCancelConfig cancelConfig;
                zim_->cancelSendingMessage(message, cancelConfig, [=](const zim::ZIMError &errorInfo) {

                });
            });

zim_->sendMessage(message, receiver_id, zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER, sendConfig, notification,
    [=](const std::shared_ptr<zim::ZIMMessage> &message, const zim::ZIMError &errorInfo) {

    });

Previous

Send and receive targeted messages in groups

Next

Call invitation (signaling)

On this page

Back to top