Options
All
  • Public
  • Public/Protected
  • All
Menu

调用方式:

nim.msgLog.deleteRoamingMsgs(options)

Hierarchy

  • MsgLogServiceInterface

Index

Methods

  • 批量删除服务器上某些会话的漫游消息。只支持 p2p 消息和 team 群消息,不支持 superTeam 超级群消息

    删除后,消息的历史记录仍可以查询到

    要想让下次同步时不再接到这个会话:

    1. resetSessionUnreadCount 重置过这个会话的已读信息
    2. deleteRoamingMsgs 删除服务器漫游消息

    Parameters

    Returns Promise<void>

  • 云端消息全文检索

    example
    // 搜索最近一个月内,包含关键字 hello 的文本消息
    const t = Date.now() - 24 * 60 * 60 * 1000 * 30
    const res = await nim.msgLog.ftsCloudMsgLogs({
    keyword: 'hello',
    fromTime: t,
    msglogsLimit: 20,
    msgTypeList: ['text'],
    orderRule: 'DESC'
    })

    Parameters

    Returns Promise<IMMessage[]>

  • 云端消息全文检索,按会话维度进行聚合。

    注意返回的结果会先根据 会话排序,然后相同会话的消息根据时间排序

    • 该接口可以限制返回的会话数量。使用 sessionLimit 字段控制
    • 该接口可以限制每个会话中,返回的匹配消息数量。使用 msglogsLimit 字段控制
    • 返回的结果会先根据会话排序,再根据消息时间排序
    // 搜索最近一个月内,包含关键字 hello 的文本消息
    // 最多返回 10 个会话,且每个会话返回的结果数量不超过 5 条
    const t = Date.now() - 24 * 60 * 60 * 1000 * 30
    const res = await nim.msgLog.ftsCloudMsgLogsAggWithSession({
    keyword: 'hello',
    fromTime: t,
    msglogsLimit: 5,
    sessionLimit: 10,
    msgTypeList: ['text'],
    orderRule: 'DESC'
    })

    Parameters

    Returns Promise<IMMessage[]>

  • 获取存储在云信服务端的历史消息。由参数beginTime和endTime来控制时间范围。

    注意事项

    • 该接口应该在收到 syncdone 事件之后再调用,否则会话的未读数可能会不准确
    • 当reverse为false时, 后续查询的endTime,应设置为上次查询的最后一条消息的time字段
    • 当reverse为true时, 后续查询的beginTime,应设置为上次查询的最后一条消息的time字段
    • 为了避免设置边界值时,得到重复的消息,可以在固定时间,切换分页查询时,设置 lastMsgId 为上一次查询最后一条消息的 idServer 字段

    示例场景

    example
    const store = {sessionMsgs: {}}

    async function loadMoreMsgOfSession(scene, to, limit) {
    const sessionId = `${scene}-${to}`
    store.sessionMsgs[sessionId] = store.sessionMsgs[sessionId] || {
    msgArr: [],
    fetching: false,
    complete: false
    }

    // 已经拉到了所有历史消息,或者正在拉取历史消息,则不重复拉取
    if (store.sessionMsgs[sessionId].complete || store.sessionMsgs[sessionId].fetching) {
    return
    }

    const msgArr = store.sessionMsgs[sessionId].msgArr
    const lastMsg = msgArr[msgArr.length - 1]

    const params = {
    // 返回的结果按时间降序排列
    asc: false,
    scene: scene,
    to: to,
    beginTime: 0,
    limit: limit,
    endTime: lastMsg ? lastMsg.time : 0,
    // 从endTime开始往前查找
    reverse: false
    }

    // 设置分割线
    // 该参数主要作用是避免有多个消息的时间等于 endTime,或者 beginTime,导致重复拉取
    if (lastMsg) {
    params.lastMsgId = lastMsg.idServer
    }

    store.sessionMsgs[sessionId].fetching = true
    try {
    const msgs = await nim.msgLog.getHistoryMsgs(params)
    store.sessionMsgs[sessionId].fetching = false
    store.sessionMsgs[sessionId].msgArr = msgArr.concat(msgs)

    // 拉取的消息长度 < 分页长度,因此 complete = true
    if (msgs.length < limit) {
    store.sessionMsgs[sessionId].complete = true
    }
    } catch(err) {
    console.error('loadMoreMsgOfSession Error: ', err)
    store.sessionMsgs[sessionId].fetching = false
    }
    }

    Parameters

    Returns Promise<IMMessage[]>