# Class CombineV2Message

合并转发 V2 消息

    CombineV2Message encode() 之后长度 < 120KB，会被当做普通消息发送
    >= 120 KB 会被当做媒体消息进行上传

# 示例代码

      private testSendCombineV2Message() {
         // 假如拿到了消息数组
         let msgArray: Array<Message> = new Array();

         let msgNum = 0;
         let nameList: Array<string> = [];
         let summaryList: Array<string> = [];
         let msgList: Array<CombineMsgInfo> = [];
         for (let i = 0; i < msgArray.length; i++) {
            let msg = msgArray[i];
            if (this.canSendCombineV2(msg)) {
               let name = i + "名称"; // 请根据实际消息修改
               let summary = i + "摘要"; // 请根据实际消息修改
               let combineInfo = CombineMsgInfo.createWithMessage(msg);
               nameList.push(name);
               summaryList.push(summary);
               msgList.push(combineInfo);
            }
         }

         let conId = new ConversationIdentifier();
         conId.conversationType = ConversationType.Private;
         conId.targetId = "testTargetId";
         conId.channelId = "testChannelId";

         let combineV2Msg = new CombineV2Message();
         combineV2Msg.name = "测试：发送合并转发 V2 消息";
         combineV2Msg.msgNum = msgNum;
         combineV2Msg.conversationType = ConversationType.Private;
         combineV2Msg.msgList = msgList;
         combineV2Msg.nameList = nameList;
         combineV2Msg.summaryList = summaryList;

         let option: ISendMsgOption = {};

         let msg = new Message(conId, combineV2Msg);

         IMEngine.getInstance().sendMediaMessage(msg, option,
            (msg: Message) => {
               // 消息入库
            },
            (msg: Message, progress: number) => {
            // 消息上传进度
            },
         ).then(result => {
               if (result.code == EngineError.Success) {
                  // 发送合并转发 V2 消息成功
               } else {
                  // 发送合并转发 V2 消息失败
               }
            });
         }

      // 该消息是否被合并转发 V2 版本支持
      private canSendCombineV2(msg: Message | undefined): boolean {
         if (!ObjectChecker.isValid(msg)) {
            return false;
         }
         let objName = msg?.objectName;
         if (TextMessageObjectName == objName) {
            return true;
         }
         if (ImageMessageObjectName == objName) {
            return true;
         }
         if (SightMessageObjectName == objName) {
            return true;
         }
         if (HQVoiceMessageObjectName == objName) {
            return true;
         }
         if (FileMessageObjectName == objName) {
            return true;
         }
         if (CombineV2MessageObjectName == objName) {
            return true;
         }
         return false;
      }

#### Version

1.4.0

#### Hierarchy (View Summary)

- MediaMessageContent
  - CombineV2Message

- Defined in message/content/media/CombineV2Message.ts:113

##### Index

### Constructors

constructor

### Properties

userInfo?
mentionedInfo?
rawString?
destructDuration?
name
localPath
remoteUrl
extra
jsonMsgKey
msgNum
conversationType
nameList
summaryList
msgList

### Methods

getCorrectedLocalPath
encodeBaseData
decodeBaseData
encode
decode
getClassName
getSearchableWord

## Constructors

### constructor

- new CombineV2Message(): CombineV2Message

  无参构造方法

  #### Returns CombineV2Message

  Overrides MediaMessageContent.constructor

  - Defined in message/content/media/CombineV2Message.ts:160

## Properties

### `Optional` userInfo

userInfo?: UserInfo

消息携带的用户信息

Inherited from MediaMessageContent.userInfo

- Defined in message/content/MessageContent.ts:124

### `Optional` mentionedInfo

mentionedInfo?: MentionedInfo

消息的 @ 信息

Inherited from MediaMessageContent.mentionedInfo

- Defined in message/content/MessageContent.ts:128

### `Optional` rawString

rawString?: string

消息的原始内容

SDK 执行消息的 decode 方法正常时，会将数据解析到消息的各个字段，rawString 将会为空

如果 decode 方法异常时会将消息的原始数据保存在 rawString 中

Inherited from MediaMessageContent.rawString

- Defined in message/content/MessageContent.ts:137

### `Optional` destructDuration

destructDuration?: number

阅后即焚时长，单位秒

    destructDuration <= 0 代表是普通消息
    destructDuration > 0 代表是阅后即焚消息，该消息已读后，经过 destructDuration 时间后销毁

#### Version

1.3.0

Inherited from MediaMessageContent.destructDuration

- Defined in message/content/MessageContent.ts:147

### name

name: string = ''

媒体内容的文件名

Overrides MediaMessageContent.name

- Defined in message/content/media/CombineV2Message.ts:117

### localPath

localPath: string = ''

媒体内容的本地路径

Overrides MediaMessageContent.localPath

- Defined in message/content/media/CombineV2Message.ts:121

### remoteUrl

remoteUrl: string = ''

媒体内容上传服务器后的网络地址

Overrides MediaMessageContent.remoteUrl

- Defined in message/content/media/CombineV2Message.ts:125

### extra

extra: string = ''

其他属性

Overrides MediaMessageContent.extra

- Defined in message/content/media/CombineV2Message.ts:129

### jsonMsgKey

jsonMsgKey: string = ''

合并转发的消息列表 Key 。 当被转发的消息长度之和大于等于 BUFFER_MAXSIZE 时才会有此字段，此时不会有 msgList 字段。

- Defined in message/content/media/CombineV2Message.ts:134

### msgNum

msgNum: number = 0

被转发的消息条数

- Defined in message/content/media/CombineV2Message.ts:138

### conversationType

conversationType: ConversationType = ConversationType.Private

会话类型

- Defined in message/content/media/CombineV2Message.ts:142

### nameList

nameList: string[] = []

转发的全部消息的发送者名称列表

- Defined in message/content/media/CombineV2Message.ts:146

### summaryList

summaryList: string[] = []

合并消息的摘要列表

- Defined in message/content/media/CombineV2Message.ts:150

### msgList

msgList: CombineMsgInfo[] = []

消息列表。 当被转发的消息长度之和小于等于 BUFFER_MAXSIZE 时才会有此字段，此时不会有 jsonMsgKey 字段。

- Defined in message/content/media/CombineV2Message.ts:155

## Methods

### getCorrectedLocalPath

- getCorrectedLocalPath(localPath: string): string

  获取正常的 localPath ，去掉 file://

  在鸿蒙系统内部，沙盒路径需要用 file:// 开头才能被 fs 识别

  原生层使用不能以 file:// 开头

  #### Parameters

  - localPath: string

  #### Returns string

  Inherited from MediaMessageContent.getCorrectedLocalPath

  - Defined in message/content/MediaMessageContent.ts:144

### encodeBaseData

- encodeBaseData(): HashMap<string, Object>

  将基类的基础数据保存到 map 中

  #### Returns HashMap<string, Object>

  Inherited from MediaMessageContent.encodeBaseData

  - Defined in message/content/MessageContent.ts:195

### decodeBaseData

- decodeBaseData(map: HashMap<string, Object>): void

  将基类的基础数据从 map 中解析出来

  #### Parameters

  - map: HashMap<string, Object>

  #### Returns void

  Inherited from MediaMessageContent.decodeBaseData

  - Defined in message/content/MessageContent.ts:216

### encode

- encode(): string

  编码方法，将消息转为 json 字符串

  #### Returns string

  json 字符串

  Overrides MediaMessageContent.encode

  - Defined in message/content/media/CombineV2Message.ts:168

### decode

- decode(contentString: string): void

  解码方法，将 json 字符串转为消息

  #### Parameters

  - contentString: string

    json 字符串

  #### Returns void

  Overrides MediaMessageContent.decode

  - Defined in message/content/media/CombineV2Message.ts:209

### getClassName

- getClassName(): string

  获取类名

  #### Returns string

  类名

  Overrides MediaMessageContent.getClassName

  - Defined in message/content/media/CombineV2Message.ts:315

### getSearchableWord

- getSearchableWord(): any

  实现搜索方法

  #### Returns any

  需要搜索的内容

  Overrides MediaMessageContent.getSearchableWord

  - Defined in message/content/media/CombineV2Message.ts:323