Chat SDK for React Native 1.14.0
    Preparing search index...

    Class ChatMessage

    消息类,用于定义一条要发送或接收的消息。

    例如,构造一条文本消息:

      let msg = ChatMessage.createTextMessage(
    'asteriskhx2',
    Date.now().toString(),
    ChatMessageChatType.PeerChat
    );
    Index

    Constructors

    • 构造消息。

      Parameters

      • params: {
            attributes?: any;
            body: any;
            chatType?: number;
            conversationId?: string;
            deliverOnlineOnly?: boolean;
            direction?: string;
            from?: string;
            groupAckCount?: number;
            hasDeliverAck?: boolean;
            hasRead?: boolean;
            hasReadAck?: boolean;
            isBroadcast?: boolean;
            isChatThread?: boolean;
            isContentReplaced?: boolean;
            isOnline?: boolean;
            localMsgId?: string;
            localTime?: number;
            msgId?: string;
            needGroupAck?: boolean;
            receiverList?: string[];
            serverTime?: number;
            status?: number;
            to?: string;
        }

      Returns ChatMessage

    Properties

    attributes: Record<string, any>

    消息的扩展属性。

    消息体实例,详见 ChatMessageBody

    chatType: ChatMessageChatType = ChatMessageChatType.ChatRoom

    会话类型,包括单聊,群聊和聊天室。详见 ChatType。

    conversationId: string = ''

    会话 ID。

    deliverOnlineOnly: boolean

    消息是否只投递给在线用户:

    • true:只有消息接收方在线时才能投递成功。若接收方离线,则消息会被丢弃。
    • (默认)false:如果用户在线,则直接投递;如果用户离线,消息会在用户上线时投递。

    消息方向,详见 ChatMessageDirection

    from: string = ''

    消息发送者的用户 ID。

    groupAckCount: number = 0

    群聊时,已阅读消息的群成员数量。群成员已读消息后调用 ChatManager.sendGroupMessageReadAck 或者 ChatManager.sendConversationReadAck 发送已读回执。若需要开启已读回执功能,初始化时需设置 ChatOptions.requireAcktrue, 并且发送消息时设置 isNeedGroupAck 为 true

    hasDeliverAck: boolean = false

    单聊时,发送的消息是否送达至接收方。要使该参数生效,初始化时需接收方设置 ChatOptions.requireDeliveryAcktrue。群消息不支持送达回执。

    • true:是。
    • (默认)false:否。
    hasRead: boolean = false

    单聊或群聊时,接收方是否已读了消息。该参数的值影响会话的未读消息数。阅读消息后,接收方可以调用 ChatManager.markMessageAsRead 或者 ChatManager.markAllMessagesAsRead 将消息设置为已读。

    • true:是。
    • (默认)false:否。
    hasReadAck: boolean = false

    单聊时,发送方是否收到了接收方的已读回执。接收方阅读消息后会调用 ChatManager.sendMessageReadAck 或者 ChatManager.sendConversationReadAck 发送已读回执。若需要已读回执,SDK 初始化时需设置 ChatOptions.requireAcktrue

    • true:是。
    • (默认)false:否。
    isBroadcast: boolean

    是否是广播消息。

    isChatThread: boolean

    消息是否为子区消息:

    • true:是。你需将消息接收方的用户 ID 设置为子区 ID。详见 to
    • false:否。

    注意

    该参数仅对群聊有效。

    isContentReplaced: boolean

    消息内容是否被替换过。

    该属性仅在 ChatOptions.useReplacedMessageContents 开启时有效。

    isOnline: boolean

    消息是否为在线时收到的消息。

    • true: 是。这种情况下,如果应用在后台运行可以弹出消息提示框。
    • false: 否,离线时收到的消息。
    localMsgId: string = ''

    本地消息 ID。

    localTime: number = ...

    消息创建的本地 Unix 时间戳。单位为毫秒。

    msgId: string = ...

    服务器生成的消息 ID。

    needGroupAck: boolean = false

    群聊时,是否需要消息已读回执。

    • true:是。
    • (默认)false:否。
    receiverList?: string[]

    消息接收对象列表。

    默认为 undefined,表示群组或聊天室中的所有成员均能收到该消息。

    该属性只在群组或者聊天室中使用。

    serverTime: number = ...

    服务器收到该消息的 Unix 时间戳。单位为毫秒。

    消息发送状态,详见 ChatMessageStatus

    to: string = ''

    消息接收方的用户 ID:

    • 单聊:消息接收方的用户 ID;
    • 群聊:群组 ID;
    • 聊天室:聊天室 ID;
    • 子区:子区 ID。
    TAG: string = 'ChatMessage'

    Accessors

    • get groupReadCount(): Promise<number | undefined>

      获取群组消息的已读人数。

      Returns Promise<number | undefined>

    Methods

    • 创建一条待发送的命令消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊:接收方的用户 ID。
        • 群聊:群组 ID。
        • 聊天室:聊天室 ID。
      • action: string

        命令内容。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • receiverList: 消息接收人列表。
    • 创建合并类型消息体。

      Parameters

      • targetId: string

        消息接收方。

        • 单聊时是接收方的用户 ID。
        • 群聊时是群组 ID。
        • 聊天室则是聊天室 ID。
      • messageIdList: string[]

        合并的消息列表 ID。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。 详见 ChatType.

      • Optionalopt: {
            compatibleText?: string;
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
            summary?: string;
            title?: string;
        }

      Returns ChatMessage

      The message instance.

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。
        • true:是;
        • (默认)false:否。
      • isOnline: 是否为在线时收到的消息。
        • true:是;
        • false:否。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
        • true:是。只有消息接收方在线时才能投递成功。若接收方离线,则消息会被丢弃。
        • (默认)false:否。如果用户在线,则直接投递;如果用户离线,消息会在用户上线时投递。
      • title: 合并消息的标题。
      • summary: 合并消息的概要。
      • compatibleText: 合并消息的兼容信息。该字段用于需要兼容不支持合并转发消息的版本。
      • receiverList: 消息接收人列表。
    • 创建一条待发送的自定义类型消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊:接收方的用户 ID。
        • 群聊:群组 ID。
        • 聊天室:聊天室 ID。
      • event: string

        消息触发的自定义事件。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            params: Record<string, string>;
            receiverList?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • params: 自定义参数。key-value格式。
      • receiverList: 消息接收人列表。
    • 创建一条待发送的文件类型消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊时为接收方的用户 ID。
        • 群聊时为群组 ID。
        • 聊天室则为聊天室 ID。
      • filePath: string

        文件路径。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。详见 ChatType。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            displayName: string;
            fileSize?: number;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
    • 创建一条待发送的图片消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊:接收方的用户 ID。
        • 群聊:群组 ID。
        • 聊天室:聊天室 ID。
      • filePath: string

        图片路径。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            displayName: string;
            fileSize?: number;
            height: number;
            isChatThread?: boolean;
            isGif?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
            sendOriginalImage?: boolean;
            thumbnailLocalPath?: string;
            width: number;
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • displayName: 图片名称。
      • thumbnailLocalPath: 缩略图本地地址。
      • sendOriginalImage: 是否发送原图。
      • width: 图片宽度。
      • height: 图片高度。
      • fileSize: 图片大小。
      • receiverList: 消息接收人列表。
    • 创建一条待发送的位置消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊:接收方的用户 ID。
        • 群聊:群组 ID。
        • 聊天室:聊天室 ID。
      • latitude: string

        纬度。

      • longitude: string

        经度。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            address: string;
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • address: 地址信息。
      • receiverList: 消息接收人列表。
    • 创建一条接收消息。

      Parameters

      • params: any

        接收的消息。

      Returns ChatMessage

      消息对象。

    • Parameters

      • params: {
            body: ChatMessageBody;
            chatType: ChatMessageChatType;
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
            targetId: string;
        }

      Returns ChatMessage

    • 创建一条待发送的文本消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊时是接收方的用户 ID。
        • 群聊时是群组 ID。
        • 聊天室则是聊天室 ID。
      • content: string

        文本消息内容。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。详见 ChatType。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
            targetLanguageCodes?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
    • 创建一条待发送的视频消息。

      Parameters

      • targetId: string

        消息接收方的用户 ID。

        • 单聊时是接收方的用户 ID。
        • 群聊时是群组 ID。
        • 聊天室则是聊天室 ID。
      • filePath: string

        视频文件路径。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            displayName: string;
            duration: number;
            fileSize?: number;
            height: number;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
            thumbnailLocalPath: string;
            width: number;
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • displayName: 文件名称。
      • thumbnailLocalPath: 缩略图本地地址。
      • duration: 视频时长。
      • width: 视频宽度。
      • height: 视频高度。
      • fileSize: 文件大小。
      • receiverList: 消息接收人列表。
    • 创建一条待发送的语音消息。

      Parameters

      • targetId: string

        消息接收方 ID。

        • 单聊时是接收方的用户 ID。
        • 群聊时是群组 ID。
        • 聊天室则是聊天室 ID。
      • filePath: string

        语音文件路径。

      • chatType: ChatMessageChatType = ChatMessageChatType.PeerChat

        会话类型。

      • Optionalopt: {
            deliverOnlineOnly?: boolean;
            displayName?: string;
            duration: number;
            fileSize?: number;
            isChatThread?: boolean;
            isOnline?: boolean;
            receiverList?: string[];
        }

      Returns ChatMessage

      消息实例。

      opt 消息扩展参数。

      • isChatThread: 是否是子区消息。默认不是子区消息。
      • isOnline: 是否为在线时收到的消息。
      • deliverOnlineOnly: 消息是否只投递给在线用户。
      • displayName: 文件名称。
      • thumbnailLocalPath: 缩略图本地地址。
      • duration: 语音时长。
      • fileSize: 文件大小。
      • receiverList: 消息接收人列表。