• UIKit
  • SDK
  • 서버 API
Chat/
SDK/
Android/
메시지/
SDK
  • Chat SDK 설치
  • Chat SDK 초기화
  • 로그인 및 로그아웃
  • 메시지
    • 개요
    • 메시지 보내기
    • 메시지 받기
    • 메시지 검색
    • 메시지 전달
    • 메시지 수정
    • 삽입 메시지
    • 메시지 삭제
    • 과거 메시지 비우기
    • 메시지 철회
    • 온라인 메시지 보내기
    • 메시지 읽음 확인
    • 메시지 조회
    • 알림
    • 지향적 그룹 메시지
    • 알림 차단
    • Key-Value 확장
    • 반응
    • 번역
    • 메시지 최상단 고정
  • 대화
    • 개요
    • 대화 목록
    • 대화 획득
    • 읽지 않은 메시지 수
    • 대화 최상단 고정
    • 대화 삭제
    • 초안
    • 마크
    • 대화 그룹
  • 그룹
    • 개요
    • 그룹 관리
    • 정보
    • 멤버 관리
    • 멤버 정보
    • 속성
    • 카운터
  • 커뮤니티 및 화제
    • 커뮤니티 관리
    • 권한 그룹
  • 사용자
    • 사용자 정보
    • 사용자 상태
    • 친구 관리
    • 친구 그룹화
    • 블록리스트
    • Follow
  • 국부 검색
    • 메시지 검색
    • 친구 검색
    • 그룹 검색
    • 그룹 멤버 검색
  • 시그널링
  • 인터페이스 참고 문서
    • Java
  • Guideline for Beginners
  • 콘솔 안내
    • 애플리케이션 생성 및 업그레이드
    • 기본 구성
    • 기능 구성
    • 계정 관리
    • 그룹 관리
    • 콜백 구성
  • 제품 소개
    • 메시지 관리
      • 1대1 메시지
      • 메시지 저장
      • 오프라인 푸시
      • 그룹 메시지
      • 메시지 포맷
    • 계정 시스템
      • 로그인 인증
      • 온라인 상태 관리
    • 그룹 관련
      • 그룹 시스템
      • 그룹 관리
    • 사용자 정보 및 관계망
      • 정보 관리
      • 관계망 관리
  • 구매 가이드
    • 과금 개요
    • 가격
  • 에러코드
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

메시지 전달

Feature Description

You can combine and forward messages in the following steps:
1. Create a combined message based on the list of original messages.
2. Send the combined message to the receiver.
3. The receiver receives the combined message and parses the list of original messages.
The title and digest are needed to display the combined message, as shown below:
Combine and Forward
Display of Combined Message
Click Combined Message to Download Message List for Display










Combining and Forwarding Messages

Creating and sending a combined message

A combined message can be created by setting the message list along with the combined message title and digest. The process is as follows:
1. Call the createMergerMessage API (Android / iOS and macOSWindows)  to create a combined message. The list of original messages as well as the combined message title and digest also need to be set.



Attribute
Description
Remarks
messageList
List of original messages
List of original messages to be combined and forwarded
title
Title
Title of the combined message, such as "Chat History of xixiyah and Hello" as shown above
abstractList
Digest list
Digest list of the combined message as shown above. The original message digests need to be displayed for the combined message, which will be unfolded after the user clicks the cell.
compatibleText
Compatibility text message
If the early SDK version does not support the combined message, the user will receive a text message with the content compatibleText by default.
Sample code:
Android
iOS and macOS
Windows
// List of messages to be forwarded, which can contain combined messages but not group tips
List<V2TIMMessage> msgs = new ArrayList<>();
msgs.add(message1);
msgs.add(message2);
// Title of the combined message
String title = "Chat History of vinson and lynx";
// Digest list of the combined message
List<String> abstactList = new ArrayList<>();
msgs.add("abstract1");
msgs.add("abstract2");
msgs.add("abstract3");
// Compatibility text of the combined message. If the early SDK version does not support the combined message, the user will receive a text message with the content `compatibleText` by default.
String compatibleText = "Upgrade to the latest version to check the merged message";
// Create a combined message
V2TIMMessage mergeMessage = V2TIMManager.getMessageManager().createMergerMessage(msgs, title, abstractList, compatibleText);
// List of messages to be forwarded, which can contain combined messages but not group tips
NSArray *msgs = @[message1,message2...];
// Title of the combined message
NSString *title = @"Chat History of vinson and lynx";
// Digest list of the combined message
NSArray *abstactList = @[@"abstract1",@"abstract2",@"abstract3"];
// Compatibility text of the combined message. If the SDK on an early version does not support the combined message, the user will receive a text message with the content `compatibleText` by default.
NSString *compatibleText = @"Upgrade to the latest version to check the merged message";
// Create a combined message
V2TIMMessage *mergeMessage = [[V2TIMManager sharedInstance] createMergerMessage:msgs title:title
abstractList:abstactList compatibleText:compatibleText];
// List of messages to be forwarded, which can contain combined messages but not group tips
V2TIMMessageVector messageList;
messageList.PushBack(message1);
messageList.PushBack(message2);
// Title of the combined message
V2TIMString title = "Chat History of vinson and lynx";
// Digest list of the combined message
V2TIMStringVector abstractList;
abstractList.PushBack("abstract1");
abstractList.PushBack("abstract2");
abstractList.PushBack("abstract3");
// Compatibility text of the combined message. If the early SDK version does not support the combined message,
// the user will receive a text message with the content `compatibleText` by default.
V2TIMString compatibleText = "Upgrade to the latest version to check the merged message";
// Create a combined message
V2TIMMessage mergerMessage = V2TIMManager::GetInstance()->GetMessageManager()->CreateMergerMessage(
messageList, title, abstractList, compatibleText);
2. Call the sendMessage API (Android / iOS and macOSWindows) to send the combined message.
Sample code:
Android
iOS and macOS
Windows
// Send the combined message to the user `denny`
V2TIMManager.getMessageManager().sendMessage(mergeMessage, "denny", null, V2TIMMessage.V2TIM_PRIORITY_NORMAL, false, null, new V2TIMSendCallback<V2TIMMessage>() {
@Override
public void onProgress(int progress) {}

@Override
public void onSuccess(V2TIMMessage v2TIMMessage) {}

@Override
public void onError(int code, String desc) {}
})
// Send the combined message to the user `denny`
[[V2TIMManager sharedInstance] sendMessage:mergeMessage receiver:@"denny" groupID:nil
priority:V2TIM_PRIORITY_NORMAL onlineUserOnly:NO offlinePushInfo:nil progress:nil succ:nil fail:nil];
class SendCallback final : public V2TIMSendCallback {
public:
using SuccessCallback = std::function<void(const V2TIMMessage&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;
using ProgressCallback = std::function<void(uint32_t)>;

SendCallback() = default;
~SendCallback() override = default;

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

void OnSuccess(const V2TIMMessage& message) override {
if (success_callback_) {
success_callback_(message);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}
void OnProgress(uint32_t progress) override {
if (progress_callback_) {
progress_callback_(progress);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
ProgressCallback progress_callback_;
};

auto callback = new SendCallback{};
callback->SetCallback([=](const V2TIMMessage& message) { delete callback; },
[=](int error_code, const V2TIMString& error_message) { delete callback; },
[=](uint32_t progress) {});

V2TIMManager::GetInstance()->GetMessageManager()->SendMessage(
mergerMessage, "denny", {}, V2TIMMessagePriority::V2TIM_PRIORITY_NORMAL, false, {}, callback);

Receiving a combined message

Adding a listener

The receiver can call addAdvancedMsgListener (Android / iOS and macOSWindows) to add the advanced message listener. We recommend it be called early, such as after the chat page is initialized, to ensure timely message receiving in the application.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getMessageManager().addAdvancedMsgListener(advancedMsgListener);
// `self` is id<V2TIMAdvancedMsgListener>
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
// Members ...
};

// Note that `advancedMsgListener` should not be released before the IM SDK is uninitialized,
// otherwise the message callback cannot be called.
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);

Parsing a message

After the listener is added, the receiver will receive the combined message V2TIMMessage in onRecvNewMessage. You can use the combined message element V2TIMMergerElem (Android / iOS and macOSWindows) to get the title and abstractList for UI display. Then, when the user clicks the combined message, you can call the downloadMergerMessage API (Android / iOS and macOSWindows) to download the combined message list for UI display.
Sample code:
Android
iOS and macOS
Windows
@Override
public void onRecvNewMessage(V2TIMMessage msg) {
if (msg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_MERGER) {
// Get the elements of the combined message
V2TIMMergerElem mergerElem = msg.getMergerElem();
// Get the `title`
String title = mergerElem.getTitle();
// Get the digest list
List<String> abstractList = mergerElem.getAbstractList();
// Download the combined message list when the user clicks the combined message
mergerElem.downloadMergerMessage(new V2TIMValueCallback<List<V2TIMMessage>>() {
@Override
public void onSuccess(List<V2TIMMessage> v2TIMMessages) {
// Downloaded successfully. `v2TIMMessages` is the combined message list.
for (V2TIMMessage subMsg : v2TIMMessages) {
// If the combined message list still contains a combined message, continue to parse the message.
if (subMsg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_MERGER) {
V2TIMMergerElem mergerElem = subMsg.getMergerElem();
// Get the `title`
String title = mergerElem.getTitle();
// Get the digest list
List<String> abstractList = mergerElem.getAbstractList();
// Download the combined message list when the user clicks the combined message
......
}
}
}

@Override
public void onError(int code, String desc) {
// Download failed
}
});
}
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
if (msg.elemType == V2TIM_ELEM_TYPE_MERGER) {
// Get the elements of the combined message
V2TIMMergerElem *mergerElem = msg.mergerElem;
// Get the `title`
NSString *title = mergerElem.title;
// Get the digest list
NSArray *abstractList = mergerElem.abstractList;
// Download the combined message list when the user clicks the combined message
[msg.mergerElem downloadMergerMessage:^(NSArray<V2TIMMessage *> *msgs) {
// Downloaded successfully. `msgs` is the combined message list.
for (V2TIMMessage *subMsg in msgs) {
// If the combined message list still contains a combined message, continue to parse the message.
if (subMsg.elemType == V2TIM_ELEM_TYPE_MERGER) {
V2TIMMergerElem *mergerElem = subMsg.mergerElem;
// Get the `title`
NSString *title = mergerElem.title;
// Get the digest list
NSArray *abstractList = mergerElem.abstractList;
// Download the combined message list when the user clicks the combined message
[msg.mergerElem downloadMergerMessage:nil fail:nil];
}
}
} fail:^(int code, NSString *desc) {
// Download failed
}];
}
}
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_;
};

class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
void OnRecvNewMessage(const V2TIMMessage& message) override {
if (message.elemList.Size() == 1) {
V2TIMElem* elem = message.elemList[0];
if (elem->elemType == V2TIMElemType::V2TIM_ELEM_TYPE_MERGER) {
// Get the elements of the combined message
auto mergerElem = static_cast<V2TIMMergerElem*>(elem);
// Get the `title`
V2TIMString title = mergerElem->title;
/// Get the digest list
V2TIMStringVector abstractList = mergerElem->abstractList;

// Download the combined message list when the user clicks the combined message
auto callback = new ValueCallback<V2TIMMessageVector>{};
callback->SetCallback(
[=](const V2TIMMessageVector& messageList) {
// Downloaded successfully. `v2TIMMessages` is the combined message list.
for (size_t i = 0; i < messageList.Size(); ++i) {
const V2TIMMessage& message = messageList[i];
if (message.elemList.Size() == 1) {
V2TIMElem* elem = message.elemList[0];
// If the combined message list still contains a combined message, continue to parse the message.
if (elem->elemType == V2TIMElemType::V2TIM_ELEM_TYPE_MERGER) {
// ...
}
}
}
delete callback;
},
[=](int error_code, const V2TIMString& error_message) { delete callback; });

mergerElem->DownloadMergerMessage(callback);
}
}
}
// Other members ...
};

// Note that `advancedMsgListener` should not be released before the IM SDK is uninitialized,
// otherwise the message callback cannot be called.
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);

Removing a listener

To stop receiving messages, the receiver can call removeAdvancedMsgListener (Android / iOS and macOSWindows) to remove the advanced message listener.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getMessageManager().removeAdvancedMsgListener(advancedMsgListener);
// `self` is id<V2TIMAdvancedMsgListener>
[[V2TIMManager sharedInstance] removeAdvancedMsgListener:self];
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
// Members ...
};

// `advancedMsgListener` is the instance of AdvancedMsgListener
V2TIMManager::GetInstance()->GetMessageManager()->RemoveAdvancedMsgListener(&advancedMsgListener);

Forwarding Messages One by One

To forward a single message, create a message identical to the original message through the createForwardMessage API (Android / iOS and macOSWindows) first, and then call the sendMessage API (Android / iOS and macOSWindows) to send the message.
Sample code:
Android
iOS and macOS
Windows
// Create a message with the same elements as the original message
V2TIMMessage forwardMessage = V2TIMManager.getMessageManager().createForwardMessage(originMsg);
// Send the message to the user `denny`
V2TIMManager.getMessageManager().sendMessage(forwardMessage, "denny", null, V2TIMMessage.V2TIM_PRIORITY_NORMAL, false, null, new V2TIMSendCallback<V2TIMMessage>() {
@Override
public void onProgress(int progress) {
}

@Override
public void onSuccess(V2TIMMessage message) {
}

@Override
public void onError(int code, String desc) {
}
});
// Create a message with the same elements as the original message
V2TIMMessage *forwardMessage = [[V2TIMManager sharedInstance] createForwardMessage:originMsg];
// Send the message to the user `denny`
[[V2TIMManager sharedInstance] sendMessage:forwardMessage receiver:@"denny" groupID:nil
priority:V2TIM_PRIORITY_NORMAL onlineUserOnly:NO offlinePushInfo:nil progress:nil succ:nil fail:nil];
class SendCallback final : public V2TIMSendCallback {
public:
using SuccessCallback = std::function<void(const V2TIMMessage&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;
using ProgressCallback = std::function<void(uint32_t)>;

SendCallback() = default;
~SendCallback() override = default;

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

void OnSuccess(const V2TIMMessage& message) override {
if (success_callback_) {
success_callback_(message);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}
void OnProgress(uint32_t progress) override {
if (progress_callback_) {
progress_callback_(progress);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
ProgressCallback progress_callback_;
};

// Create a message with the same elements as the original message
V2TIMMessage forwardMessage = V2TIMManager::GetInstance()->GetMessageManager()->CreateForwardMessage(originMsg);

auto callback = new SendCallback{};
callback->SetCallback([=](const V2TIMMessage& message) { delete callback; },
[=](int error_code, const V2TIMString& error_message) { delete callback; },
[=](uint32_t progress) {});

// Send the message to the user `denny`
V2TIMManager::GetInstance()->GetMessageManager()->SendMessage(
forwardMessage, "denny", {}, V2TIMMessagePriority::V2TIM_PRIORITY_NORMAL, false, {}, callback);