Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface definitions for message history

Hierarchy

  • MessageLogInterface

Implemented by

Index

Methods

  • clearServerHistoryMsgsWithSync(options: { ext?: string; isDeleteRoam?: boolean; isSyncSelf?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }): void
  • If you delete the message history and message records for sync on the CommsEase server, the message history of the conversation in the local database will also be deleted, but the conversation in the database will be retained. You can delete the conversations in the local database by calling {@link NIMGetInstanceOptions.deleteLocalSession}.

    If isSyncSelf is set to true, the account logged in on multiple devices will trigger onClearServerHistoryMsgs

    Associated function

    Example

    Parameters

    • options: { ext?: string; isDeleteRoam?: boolean; isSyncSelf?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }
      • Optional ext?: string

        Extension field

      • Optional isDeleteRoam?: boolean

        Whether to delete message history for sync. Default value: true

      • Optional isSyncSelf?: boolean

        Specify whether to sync messages across devices. The default value is false

      • scene: "p2p" | "team" | "superTeam"

        Messaging use case

      • to: string

        The user you talk with。 If the current session is a private chat, the IM account (accid) of the peer is used; if the current session is a group chat, the group ID is used.

      • done?:function

    Returns void

  • deleteAllLocalMsgs(options: { done?: any }): void
  • Delete all local messages. This method will clear all conversations in the database at the same time.

    Note: If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned or operated.

    Parameters

    Returns void

  • deleteLocalMsg(options: { msg: NIMMessage; done?: any }): void
  • Description

    Delete a local message.

    • If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned.
    • If the last message of the conversation is deleted, the lastMsg property of the conversation will automatically change to the previous message, and the onupdatesessions callback will be triggered.
    • If the message does not exist, the method call will be evaluated as successful

    Parameters

    Returns void

  • deleteLocalMsgs(options: { end?: number; sessionId: string; start?: number; updateSession?: boolean; done?: any }): void
  • Delete local messages based on conversation ID, start time and end time

    • If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned.
    • The end time must be greater than start time
    • If no start time and end time are specified, delete all local messages of a conversation by calling deleteLocalMsgsBySession

    Example

    Parameters

    • options: { end?: number; sessionId: string; start?: number; updateSession?: boolean; done?: any }
      • Optional end?: number

        Timestamp of the end time for a search

      • sessionId: string

        session.id

      • Optional start?: number

        Timestamp of the start time for a search

      • Optional updateSession?: boolean

        Whether the conversation is synced. The default value is true

      • done?:function
        • done callback. You must code the callback based on the requirements.

          Parameters

          Returns void

    Returns void

  • deleteLocalMsgsBySession(options: { delLastMsg?: boolean; isTag?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }): void
  • Delete all local messages in a specific conversation

    Note: If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned or operated.

    Parameters

    • options: { delLastMsg?: boolean; isTag?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }
      • Optional delLastMsg?: boolean

        Whether session.lastMsg will also be deleted. The default value is false

      • Optional isTag?: boolean

        Whether the message is deleted by tag. The default value is false

        Note: If it is true, the message is deleted physically, and the localCustom local custom extension field inserted for this message cannot be retained. If the value is false, the message is deleted by logic.

      • scene: "p2p" | "team" | "superTeam"

        Messaging use case

      • to: string

        The user you talk with。 If it is a private message, pass the account of the peer. For group chats, pass the group ID.

      • done?:function

    Returns void

  • deleteLocalMsgsByTime(options: { end?: number; start?: number; deletedone?: any; done?: any }): Promise<void>
  • Delete the messages of the specified time range at a time.

    Note: If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned or operated.

    Parameters

    • options: { end?: number; start?: number; deletedone?: any; done?: any }
      • Optional end?: number

        Timestamp of the end time. Use Infinity by default if unspecified.

      • Optional start?: number

        Timestamp of start time in milliseconds, default value: 0

      • deletedone?:function
        • deletedone(data: { deletedMsgCount: number }): void
        • Callback invoked when a message is deleted. You can search for messages after this callback.

          Parameters

          • data: { deletedMsgCount: number }
            • deletedMsgCount: number

          Returns void

      • done?:function
        • done(err: null | NIMCommonError | Error, data: null | { deletedMsgCount: number; sessionUpdateCount: number }): void
        • Parameters

          • err: null | NIMCommonError | Error
          • data: null | { deletedMsgCount: number; sessionUpdateCount: number }

          Returns void

    Returns Promise<void>

  • getHistoryMsgs(options: { asc?: boolean; beginTime?: number; endTime?: number; lastMsgId?: string; limit?: number; msgTypes?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]; reverse?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }): void
  • Get the message history stored on the CommsEase server. The time range is defined by the parameters beginTime and endTime.

    • If reverse is set to false, the endTime of the subsequent query corresponds to the time field of the last message of the previous query.
    • If reverse is set to true, the beginTime of the subsequent query corresponds to the time field of the last message of the previous query
    • If you want to search message history, see MessageLogInterface.msgFtsInServer

    Use cases

    This API call is triggered when users opens a conversation and render the message list or "pulls down to view more messages".

    Notes

    • This API gets the message history on the CommsEase server, but does not insert it into the local database.
    • This API returns the list of returned messages using the options.done callback.
    • In the initialization, if this function is called before the synchronization is completed, the read status of the conversation may be inaccurate

    Example

    Parameters

    • options: { asc?: boolean; beginTime?: number; endTime?: number; lastMsgId?: string; limit?: number; msgTypes?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]; reverse?: boolean; scene: "p2p" | "team" | "superTeam"; to: string; done?: any }
      • Optional asc?: boolean

        Sorting order. The default value is false

        false means that the returned messages are sorted in descending order by time;

        true means the returned messages are sorted in ascending order by time;

      • Optional beginTime?: number

        Timestamp of start time in milliseconds, default value: 0

      • Optional endTime?: number

        Timestamp of the end time in milliseconds. the default value: 0

      • Optional lastMsgId?: string

        The idServer of the last message in the last query. No value for the first query.

      • Optional limit?: number

        limit on the number of queries per page, the default value is 100

      • Optional msgTypes?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]

        Specified message type. All message types if unspecified

      • Optional reverse?: boolean

        Query order. The default value is false, indicating the result is displayed in descending order.

        false Search limit number of history messages forward from endTime

        true Search limit number of history messages backward from beginTime

      • scene: "p2p" | "team" | "superTeam"

        Messaging use case

      • to: string

        The user you talk with。 If it is a private message, pass the account of the peer. For group chats, pass the group ID.

      • done?:function

    Returns void

  • getLocalMsgs(options: { desc?: boolean; end?: number; keyword?: string; limit?: number; sessionId?: string; start?: number; subTypes?: number[]; types?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]; done?: any }): void
  • Description

    Retrieve message history from the local database.

    Use cases

    This API call is triggered when users opens a conversation and render the message list or "pulls down to view more messages".

    Notes

    If the runtime environment does not support the database, or the database is not running, the execution is successful, but no valid data be returned.

    Parameters

    • options: { desc?: boolean; end?: number; keyword?: string; limit?: number; sessionId?: string; start?: number; subTypes?: number[]; types?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]; done?: any }
      • Optional desc?: boolean

        true means search from end, false means search from begin

      • Optional end?: number

        Timestamp of the end time for a search

      • Optional keyword?: string

        [indexedDB only] If parameters are provided, query messages matching this keyword

        Note: The query with this parameter is in the forward index mode, and the query will be quite slow when the amount of data is large. If you need to support full-text search (inverted index structure), see fts interfaces

      • Optional limit?: number

        Pagination limit

      • Optional sessionId?: string

        If specified, search messages in this conversation

      • Optional start?: number

        Timestamp of the start time for a search

      • Optional subTypes?: number[]

        [for indexedDB only] If this parameter is provided, query these subtypes of messages

      • Optional types?: ("custom" | "text" | "image" | "audio" | "video" | "geo" | "notification" | "file" | "tip" | "robot" | "g2")[]

        [for indexedDB only] If this parameter is provided, query this type of message

      • done?:function

    Returns void

  • getLocalMsgsByIdClients(options: { idClients: string[]; done?: any }): void
  • Description

    Get the local message history by the client message IDs (idClients).

    Notes

    If the runtime environment does not support the database, or the database is not running, the execution is successful, but no valid data be returned.

    Parameters

    Returns void

  • msgFtsInServer(options: { fromTime?: number; keyword: string; msgLimit?: number; msgSubTypeList?: string[]; msgTypeList?: string[]; order?: string; p2pList?: string[]; senderList?: string[]; sessionLimit?: number; teamList?: string[]; toTime?: number; done?: any }): void
  • Description

    Full-text search for message history on the server. The returned messages will be classified by session, not by time.

    Use cases

    Search message history of all conversations stored on the CommsEase server based on the time range and keywords.

    Prerequisites

    The "full-text search message" setting has been activated in the CommsEase console.

    Configuration: Select the application, and select IM Basic/Pro > Settings > Global > Full-text message search.

    Parameters

    • options: { fromTime?: number; keyword: string; msgLimit?: number; msgSubTypeList?: string[]; msgTypeList?: string[]; order?: string; p2pList?: string[]; senderList?: string[]; sessionLimit?: number; teamList?: string[]; toTime?: number; done?: any }
      • Optional fromTime?: number

        The start time of the search, the default value 0 means unlimited

      • keyword: string

        Keyword for search

      • Optional msgLimit?: number

        Limit on the number of returned messages per conversation Default value: 5. For example, if you pass 1, each conversation returns 1 matching message.

      • Optional msgSubTypeList?: string[]

        Message subtype, which can be customized when sending messages, and the format is an integer greater than 0. Example: [1, 2]

      • Optional msgTypeList?: string[]

        message type, Example: ['text', 'image', 'audio', 'video', 'geo', 'notification', 'file', 'tip', 'custom']

      • Optional order?: string

        Sorting rule for returned messages. The messages are sorted in descending order DESC by default. optional ASC ascending order.

      • Optional p2pList?: string[]

        Search condition for private chats, account for sessions (p2p-accid1), example: ['accid1', 'accid2', 'accid3']

      • Optional senderList?: string[]

        List of message senders, Example: ['accid1', 'accid2', 'accid3']

      • Optional sessionLimit?: number

        Limit on the number of conversations The default value is 10. For example, if you pass 5, messages in 5 sessions are retrieved and returned

      • Optional teamList?: string[]

        Search condition Group list. Search messages from these groups (team-146694936), example: ['146694936', '13897']

      • Optional toTime?: number

        The end time of the search, the default value is the current time

      • done?:function

    Returns void

  • msgFtsInServerByTiming(options: { fromTime?: number; keyword: string; msgLimit?: number; msgSubTypeList?: string[]; msgTypeList?: string[]; order?: string; p2pList?: string[]; senderList?: string[]; teamList?: string[]; toTime?: number; done?: any }): void
  • Description

    Full-text search for messages (search by time). the returned messages are sorted in descending order by time.

    Use cases

    Search message history of all conversations stored on the CommsEase server based on the time range and keywords.

    Prerequisites

    The "full-text search message" setting has been activated in the CommsEase console.

    Configuration: Select the application, and select IM Basic/Pro > Settings > Global > Full-text message search.

    Parameters

    • options: { fromTime?: number; keyword: string; msgLimit?: number; msgSubTypeList?: string[]; msgTypeList?: string[]; order?: string; p2pList?: string[]; senderList?: string[]; teamList?: string[]; toTime?: number; done?: any }
      • Optional fromTime?: number

        The start time of the search, the default value 0 means unlimited

      • keyword: string

        Keyword for search

      • Optional msgLimit?: number

        Limit on the number of returned messages per conversation Default value: 5. For example, if you pass 1, each conversation returns 1 matching message.

      • Optional msgSubTypeList?: string[]

        Message subtype, which can be customized when sending messages, and the format is an integer greater than 0. Example: [1, 2]

      • Optional msgTypeList?: string[]

        message type, Example: ['text', 'image', 'audio', 'video', 'geo', 'notification', 'file', 'tip', 'custom']

      • Optional order?: string

        Sorting rule for returned messages. The messages are sorted in descending order DESC by default. optional ASC ascending order.

      • Optional p2pList?: string[]

        Search condition for private chats, account for sessions (p2p-accid1), example: ['accid1', 'accid2', 'accid3']

      • Optional senderList?: string[]

        List of message senders, Example: ['accid1', 'accid2', 'accid3']

      • Optional teamList?: string[]

        Search condition Group list. Search messages from these groups (team-146694936), example: ['146694936', '13897']

      • Optional toTime?: number

        The end time of the search, the default value is the current time

      • done?:function

    Returns void

  • saveMsgsToLocal(options: { msgs: NIMMessage[]; done?: any }): void
  • Store the message to the local database

    Note: If the operating environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned or operated.

    Parameters

    Returns void

  • updateLocalMsg(options: { idClient: string; localCustom: string; done?: any }): void
  • Description

    Update local messages. Only localCustom local custom extension fields are allowed to be updated.

    Notes

    If the runtime environment does not support the database, or the database is not running, the execution is successful, but no valid data will be returned.

    Parameters

    • options: { idClient: string; localCustom: string; done?: any }

    Returns void