please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Android/
Conversation/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Retrieve Messages
    • Forward Messages
    • Modify a Message
    • Insert a Message
    • Delete Messages
    • Clear History Messages
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Mentions
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Reactions
    • Translation
    • Pin Messages
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Draft
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Manage Group
    • Profile
    • Manage Members
    • Member Profile
    • Attribute
    • Counter
  • Community and Topic
    • Manage Community
    • Permission Group
  • User
    • User Profile
    • User Status
    • Manage Friends
    • Friend Group
    • Block Lists
    • Follow
  • Local Search
    • Search Messages
    • Search Friends
    • Search Groups
    • Search Group Members
  • Signaling
  • API Reference
    • Java
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Draft

Overview

When sending a message, the user may want to switch to another chat window before finishing the message. The unfinished message can be saved through the setConversationDraft API, so that the user can get back to it through the draftText field of the V2TIMConversation object and finish it.
Note
1. A conversation draft can contain only text.
2. A conversation draft will be stored only in the local database and not on the server. Therefore, it cannot be synced across devices and will not be available after the application is uninstalled and reinstalled.

Effect

You can achieve the conversation draft effect shown in the figure below using this feature. Click on that conversation to enter the chat interface, and the draft content will automatically be filled into the input box:




Interface Description

Setting a Conversation Draft

Call the setConversationDraft API (Android / iOS and macOS / Windows) to set a conversation draft. If the draftText parameter is empty, the draft is cleared.
Sample code:
Android
iOS and macOS
Windows
String conversationID = "conversationID";
String draftText = "The draft text";
V2TIMManager.getConversationManager().setConversationDraft(conversationID, draftText, new V2TIMCallback() {
@Override
public void onSuccess() {
Log.i("imsdk", "success");
}

@Override
public void onError(int code, String desc) {
Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
}
});
NSString *conversationID = @"conversationID";
NSString *draftText = "The draft text";
[[V2TIMManager sharedInstance] setConversationDraft:conversationID draftText:draftText succ:^{
NSLog(@"success");
} fail:^(int code, NSString *desc) {
NSLog(@"failure, code:%d, desc:%@", code, desc);
}];
class Callback final : public V2TIMCallback {
public:
using SuccessCallback = std::function<void()>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

Callback() = default;
~Callback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess() override {
if (success_callback_) {
success_callback_();
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMString conversationID = u8"conversationID";
V2TIMString draftText = u8"The draft text";

auto callback = new Callback;
callback->SetCallback(
[=]() {
// Set the conversation draft successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to set the conversation draft
delete callback;
});

V2TIMManager::GetInstance()->GetConversationManager()->SetConversationDraft(conversationID, draftText,
callback);