deleteConversation
API (Android / iOS and macOS / Windows) to delete a specified conversation.String conversationID = "conversationID";V2TIMManager.getConversationManager().deleteConversation(conversationID, new V2TIMCallback() {@Overridepublic void onSuccess() {// The conversation is deleted successfully.}@Overridepublic void onError(int code, String desc) {// Failed to delete the conversation}});
NSString *conversationID = @"conversationID";[[V2TIMManager sharedInstance] deleteConversation:conversationIDsucc:^{// The conversation is deleted successfully.}fail:^(int code, NSString *desc) {// Failed to delete the conversation}];
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 groupName = u8"conversationID";auto callback = new Callback;callback->SetCallback([=]() {// The conversation is deleted successfully.delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to delete the conversationdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->DeleteConversationGroup(groupName, callback);
deleteConversation
API (Android / iOS and macOS / Windows) to delete specified conversations. When clearMessage
is set to false, the historical messages will be retained; when set to true, client and server messages will be deleted together and cannot be restored.List<String> conversationIDList = new ArrayList<>();conversationIDList.add("c2c_userID");conversationIDList.add("group_groupID");V2TIMManager.getConversationManager().deleteConversationList(conversationIDList, true, new V2TIMValueCallback<List<V2TIMConversationOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMConversationOperationResult> results) {// The conversations are deleted successfully.for (V2TIMConversationOperationResult result : results) {int code = result.getResultCode();String info = result.getResultInfo();String conversationID = result.getConversationID();}}@Overridepublic void onError(int code, String desc) {// Failed to delete the conversations}});
NSMutableArray *conversationIDList = [NSMutableArray array];[conversationIDList addObject:@"c2c_userID"];[conversationIDList addObject:@"group_groupID"];[[V2TIMManager sharedInstance] deleteConversationList:conversationIDListclearMessage:truesucc:^(NSArray<V2TIMConversationOperationResult *> *results) {// The conversations are deleted successfully.for (V2TIMConversationOperationResult *result in results) {int code = result.resultCode;NSString *info = result.resultInfo;NSString *conversationID = result.conversationID;}}fail:^(int code, NSString *desc) {// Failed to delete the conversations}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}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_;};V2TIMStringVector conversationIDList;conversationIDList.PushBack(u8"c2c_userID");conversationIDList.PushBack(u8"group_groupID");auto callback = new ValueCallback<V2TIMConversationOperationResultVector>{};callback->SetCallback([=](const V2TIMConversationOperationResultVector& results) {// The conversations are deleted successfully.for (size_t i = 0; i < results.Size(); ++i) {const V2TIMConversationOperationResult& result = results[i];int code = result.resultCode;V2TIMString info = result.resultInfo;V2TIMString conversationID = result.conversationID;}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to delete the conversationsdelete callback;});V2TIMManager::GetInstance()->GetConversationManager()->DeleteConversationList(conversationIDList, true, callback);
addConversationListener
(Android / iOS & Mac / Windows) to add a conversation listener, you can get the notification that the conversation is deleted in onConversationDeleted
.@Overridepublic void onConversationDeleted(List<String> conversationIDList) {Log.i("imsdk", "onConversationDeleted");}
- (void)onConversationDeleted:(NSArray<NSString *> *)conversationIDList {// Received the notification that the conversation is deleted}
void OnConversationDeleted(const V2TIMStringVector &conversationIDList) override {// Received the notification that the conversation is deleted}
Was this page helpful?