# Class Message

消息实体，包含消息的所有属性

#### Version

1.0.0

- Defined in message/Message.ts:20

##### Index

### Constructors

constructor

### Properties

conversationType
targetId
channelId
messageId
direction
senderId
receivedStatus
sentStatus
receivedTime
sentTime
objectName
content
messageUid
extra
messageConfig
pushConfig
canIncludeExpansion
expansion
readReceiptInfo
readReceiptInfoV2
modifyInfo
quoteInfo
needReceipt
sendReceipt

### Methods

checkForSend
checkForSendMedia
checkForDestruct

## Constructors

### constructor

- new Message(conId: ConversationIdentifier, content: MessageContent): Message

  消息构造方法

  conversationType、targetId、channelId、content、objectName 会被赋值

  #### Parameters

  - conId: ConversationIdentifier

    会话标识

  - content: MessageContent

    消息体内容

  #### Returns Message

  - Defined in message/Message.ts:181

## Properties

### conversationType

conversationType: ConversationType = ConversationType.Private

会话类型

#### See

EngineError

- Defined in message/Message.ts:24

### targetId

targetId: string = ''

会话 ID

- Defined in message/Message.ts:28

### channelId

channelId: string = ''

所属会话的业务标识，长度限制 20 字符

仅支持单群聊和超级群，其他类型的会话请传入空字符串

#### See

ConversationIdentifier.channelId

#### Version

1.2.0

- Defined in message/Message.ts:36

### messageId

messageId: number = 0

消息 ID，本地存储的消息的唯一值（数据库索引唯一值）

    发送消息时
    messageId > 0 时，SDK 更新数据库中对应的消息，然后再发送
    messageId <= 0 时，SDK 把消息直接入库，然后再发送
    只有当确实需要更新数据库消息时，设置 messageId > 0 ；其余情况 messageId <= 0

- Defined in message/Message.ts:46

### direction

direction: MessageDirection = MessageDirection.Send

消息方向

- Defined in message/Message.ts:50

### senderId

senderId: string = ''

消息发送者 ID

- Defined in message/Message.ts:54

### receivedStatus

receivedStatus: ReceivedStatus = ...

消息接收状态

- Defined in message/Message.ts:58

### sentStatus

sentStatus: SentStatus = SentStatus.Failed

消息的发送状态(针对发送的消息生效)

单聊消息已读时为 Read

- Defined in message/Message.ts:64

### receivedTime

receivedTime: number = 0

消息的接收毫秒时间戳，本地入库的时间，不能用做消息排序。消息排序用 sentTime

- Defined in message/Message.ts:68

### sentTime

sentTime: number = 0

消息的发送毫秒时间戳，服务端的发送时间，用作消息排序

- Defined in message/Message.ts:72

### objectName

objectName: string = ''

消息类型

- Defined in message/Message.ts:76

### content

content: MessageContent

消息内容，所有消息体的基类，需要根据 objectName 将 content 转为具体的消息类型

        // Message 必须为有效的消息，此处进行简写
        let message : Message;
        if (TextMessageObjectName === message.objectName) {
           // 转成文本消息
           let txtMsg = message.content as TextMessage;
        } else if (ImageMessageObjectName === message.objectName) {
           // 转成图片消息
           let imgMsg= message.content as ImageMessage;
        }

#### See

MessageContent

- Defined in message/Message.ts:93

### messageUid

messageUid: string = ''

服务器消息唯一 ID（在同一个 AppKey 下全局唯一）

固定格式的字符串，例如 ： CH2C-A072-OGM5-E3HL

- Defined in message/Message.ts:99

### extra

extra: string = ''

消息的附加字段

    Message.extra 只保存在本地数据库，卸载重装会丢失，不会随着消息发送出去
    MessageContent.extra 保存在消息体内部，会随着消息发送出去

- Defined in message/Message.ts:107

### messageConfig

messageConfig: MessageConfig = null

消息配置

- Defined in message/Message.ts:111

### pushConfig

pushConfig: PushConfig

推送配置

- Defined in message/Message.ts:116

### canIncludeExpansion

canIncludeExpansion: boolean = false

消息是否可以包含扩展信息

#### Discussion

该属性在消息发送时确定，发送之后不能再做修改

#### Discussion

扩展信息只支持单聊、群聊，其它会话类型不能设置扩展信息

#### Version

1.2.0

- Defined in message/Message.ts:125

### expansion

expansion: any = null

消息扩展信息列表

    默认消息扩展字典 key 长度不超过 32 ，value 长度不超过 4096 ，单次设置扩展数量最大为 20，消息的扩展总数不能超过 300

#### Discussion

扩展信息只支持单聊、群聊，其它会话类型不能设置扩展信息

#### Version

1.2.0

- Defined in message/Message.ts:135

### readReceiptInfo

readReceiptInfo: ReadReceiptInfo = null

群聊消息已读，仅在群聊生效

#### Version

1.3.0

- Defined in message/Message.ts:141

### readReceiptInfoV2

readReceiptInfoV2: ReadReceiptInfoV2 = null

群聊消息已读V2，仅在群聊生效

#### Version

1.4.0

- Defined in message/Message.ts:147

### modifyInfo

modifyInfo: ModifyInfo = null

- Defined in message/Message.ts:153

### quoteInfo

quoteInfo: QuoteInfo = null

引用消息数据，为空表示普通消息

#### Version

26.3.0

- Defined in message/Message.ts:159

### needReceipt

needReceipt: boolean = false

是否需要已读回执

#### Version

1.5.0

- Defined in message/Message.ts:165

### sendReceipt

sendReceipt: boolean = false

是否已经发送已读回执

#### Version

1.5.0

- Defined in message/Message.ts:171

## Methods

### checkForSend

- checkForSend(): EngineError

  检查是否可以发送

  #### Returns EngineError

  是否可以发送，EngineError.Success 代表可以发送；否则代表消息数据有问题无法发送出去

  - Defined in message/Message.ts:204

### checkForSendMedia

- checkForSendMedia(): EngineError

  检查媒体消息是否可以发送

  #### Returns EngineError

  是否可以发送，EngineError.Success 代表可以发送；否则代表消息数据有问题无法发送出去

  - Defined in message/Message.ts:221

### checkForDestruct

- checkForDestruct(): EngineError

  检查消息是否可以阅后即焚

  #### Returns EngineError

  是否支持

  #### Version

  1.3.0

  - Defined in message/Message.ts:245