NIM PC Cross Platform SDK
载入中...
搜索中...
未找到
nim::Session类 参考

会话列表管理功能,主要包括查询会话列表、删除会话列表等功能 更多...

#include <nim_cpp_session.h>

Public 类型

typedef std::function< int32_t(const std::string &)> BadgeCountCallback
 app角标未读计数通知回调 (仅iOS有效)
 
typedef std::function< void(NIMResCode, const SessionData &, int)> ChangeCallback
 会话变更通知回调
 
typedef std::function< void(int, const SessionDataList &)> QuerySessionListCallabck
 查询会话列表回调
 
typedef ChangeCallback DeleteRecentSessionCallabck
 删除会话回调
 
typedef ChangeCallback DeleteAllRecentSessionCallabck
 删除全部会话
 
typedef ChangeCallback SetUnreadCountZeroCallback
 会话未读消息数清零回调
 
typedef std::function< void(NIMResCode, const std::list< SessionData > &session_data_list, int unread_count)> SetMultiUnreadCountZeroCallback
 多条会话未读消息数清零回调
 
typedef std::function< void(NIMResCode, const SessionData &)> QuerySessionDataCallback
 会话信息查询结果回调
 
typedef std::function< void(const StickTopSession &)> SetToStickTopSessionNotifyCallback
 置顶会话通知回调
 
typedef std::function< void(const std::string &session_id, nim::NIMSessionType)> CancelStickTopSessionNotifyCallback
 取消置顶会话通知回调
 
typedef std::function< void(const StickTopSession &)> UpdateStickTopSessionNotifyCallback
 更新置顶会话通知回调
 
typedef std::function< void(NIMResCode, const StickTopSession &)> SetToStickTopSessionCallback
 置顶会话回调
 
typedef std::function< void(NIMResCode, const std::string &session_id, nim::NIMSessionType)> CancelStickTopSessionCallback
 取消置顶会话回调
 
typedef std::function< void(NIMResCode, const StickTopSession &)> UpdateStickTopSessionCallback
 更新置顶会话回调
 
typedef std::function< void(NIMResCode, const StickTopSessionList &)> QueryStickTopSessionListCallback
 查询置顶会话列表回调
 
typedef std::function< void(NIMResCode, const SessionRoamMsgHasMoreTagInfo &info)> QueryHasmoreRoammsgCallback
 查询会话的漫游消息是否拉取完整的回调
 
typedef std::function< void(NIMResCode, const std::list< SessionRoamMsgHasMoreTagInfo > &info_list)> QueryAllHasmoreRoammsgCallback
 查询所有“漫游消息未拉取完全”的会话的回调
 
typedef std::function< void(NIMResCode)> UpdateHasmoreRoammsgCallback
 更新会话是漫游消息未拉取信息回调
 
typedef std::function< void(NIMResCode)> DeleteHasmoreRoammsgCallback
 删除会话是漫游消息未拉取信息回调
 
typedef std::function< void(NIMResCode, nim::NIMSessionType, const std::string &session_id)> DeleteSessionRoammsgCallback
 删除会话是漫游消息未拉取信息回调
 

静态 Public 成员函数

static void RegChangeCb (const ChangeCallback &cb, const std::string &json_extension="")
 
static void RegBadgeCountCb (const BadgeCountCallback &cb, const std::string &json_extension="")
 
static void QueryLastFewSessionAsync (int limit, const QuerySessionListCallabck &cb, const std::string &json_extension="")
 
static void QueryAllRecentSessionAsync (const QuerySessionListCallabck &cb, const std::string &json_extension="")
 
static void QueryAllRecentSessionAsnc (NIMMessageType last_msg_excluded_type, const QuerySessionListCallabck &cb, const std::string &json_extension="")
 
static void QueryAllRecentSessionAsyncEx (const std::list< NIMMessageType > &last_msg_excluded_type, const QuerySessionListCallabck &cb, const std::string &json_extension="")
 
static bool DeleteRecentSession (nim::NIMSessionType to_type, const std::string &id, const DeleteRecentSessionCallabck &cb, const std::string &json_extension="")
 
static bool DeleteRecentSessionEx (nim::NIMSessionType to_type, const std::string &id, const DeleteRecentSessionCallabck &cb, bool delete_roaming)
 
static bool DeleteSessionRoamingMessage (nim::NIMSessionType to_type, const std::string &id, const DeleteSessionRoammsgCallback &cb, const std::string &json_extension="")
 
static void DeleteAllRecentSession (const DeleteAllRecentSessionCallabck &cb, const std::string &json_extension="")
 
static bool SetUnreadCountZeroAsync (nim::NIMSessionType to_type, const std::string &id, const SetUnreadCountZeroCallback &cb, const std::string &json_extension="")
 
static bool SetMultiUnreadCountZeroAsync (bool super_team, const std::list< MultiUnreadCountZeroInfo > &unread_zero_info_list, const SetMultiUnreadCountZeroCallback &cb)
 
static bool SetSessionTop (enum NIMSessionType to_type, const std::string &id, bool top, const ChangeCallback &cb, const std::string &json_extension="")
 
static bool SetSessionExtendData (enum NIMSessionType to_type, const std::string &id, const std::string &data, const ChangeCallback &cb, const std::string &json_extension="")
 
static bool SetAllUnreadCountZeroAsync (const SetUnreadCountZeroCallback &cb, const std::string &json_extension="")
 
static void QuerySessionDataById (NIMSessionType to_type, const std::string &id, const QuerySessionDataCallback &cb, const std::string &json_extension="")
 
static void RegSetToStickTopSessionNotifyCB (const SetToStickTopSessionNotifyCallback &cb)
 
static void RegCancelStickTopSessionNotifyCB (const CancelStickTopSessionNotifyCallback &cb)
 
static void RegUpdateStickTopSessionNotifyCB (const UpdateStickTopSessionNotifyCallback &cb)
 
static void QueryStickTopSessionList (const QueryStickTopSessionListCallback &cb)
 
static void SetToStickTopSession (const std::string &session_id, nim::NIMSessionType to_type, const std::string &ext, const SetToStickTopSessionCallback &cb)
 
static void UpdateToStickTopSession (const std::string &session_id, nim::NIMSessionType to_type, const std::string &ext, const UpdateStickTopSessionCallback &cb)
 
static void CancelToStickTopSession (const std::string &session_id, nim::NIMSessionType to_type, const CancelStickTopSessionCallback &cb)
 
static void QueryHasmoreRoammsg (const std::string &session_id, nim::NIMSessionType to_type, const QueryHasmoreRoammsgCallback &cb)
 
static void QueryAllHasmoreRoammsg (const QueryAllHasmoreRoammsgCallback &cb)
 
static void UpdateHasmoreRoammsg (const IMMessage &msg, const UpdateHasmoreRoammsgCallback &cb)
 
static void DeleteHasmoreRoammsg (const std::string &session_id, nim::NIMSessionType to_type, const DeleteHasmoreRoammsgCallback &cb)
 
static void UnregSessionCb ()
 

详细描述

会话列表管理功能,主要包括查询会话列表、删除会话列表等功能

成员类型定义说明

◆ BadgeCountCallback

typedef std::function<int32_t(const std::string&)> nim::Session::BadgeCountCallback

app角标未读计数通知回调 (仅iOS有效)

◆ CancelStickTopSessionCallback

typedef std::function<void(NIMResCode, const std::string& session_id, nim::NIMSessionType)> nim::Session::CancelStickTopSessionCallback

取消置顶会话回调

◆ CancelStickTopSessionNotifyCallback

typedef std::function<void(const std::string& session_id, nim::NIMSessionType)> nim::Session::CancelStickTopSessionNotifyCallback

取消置顶会话通知回调

◆ ChangeCallback

typedef std::function<void(NIMResCode, const SessionData&, int)> nim::Session::ChangeCallback

会话变更通知回调

◆ DeleteAllRecentSessionCallabck

◆ DeleteHasmoreRoammsgCallback

删除会话是漫游消息未拉取信息回调

◆ DeleteRecentSessionCallabck

◆ DeleteSessionRoammsgCallback

typedef std::function<void(NIMResCode, nim::NIMSessionType, const std::string& session_id)> nim::Session::DeleteSessionRoammsgCallback

删除会话是漫游消息未拉取信息回调

◆ QueryAllHasmoreRoammsgCallback

typedef std::function<void(NIMResCode, const std::list<SessionRoamMsgHasMoreTagInfo>& info_list)> nim::Session::QueryAllHasmoreRoammsgCallback

查询所有“漫游消息未拉取完全”的会话的回调

◆ QueryHasmoreRoammsgCallback

查询会话的漫游消息是否拉取完整的回调

◆ QuerySessionDataCallback

typedef std::function<void(NIMResCode, const SessionData&)> nim::Session::QuerySessionDataCallback

会话信息查询结果回调

◆ QuerySessionListCallabck

typedef std::function<void(int, const SessionDataList&)> nim::Session::QuerySessionListCallabck

查询会话列表回调

◆ QueryStickTopSessionListCallback

查询置顶会话列表回调

◆ SetMultiUnreadCountZeroCallback

typedef std::function<void(NIMResCode, const std::list<SessionData>& session_data_list, int unread_count)> nim::Session::SetMultiUnreadCountZeroCallback

多条会话未读消息数清零回调

◆ SetToStickTopSessionCallback

置顶会话回调

◆ SetToStickTopSessionNotifyCallback

置顶会话通知回调

◆ SetUnreadCountZeroCallback

会话未读消息数清零回调

◆ UpdateHasmoreRoammsgCallback

更新会话是漫游消息未拉取信息回调

◆ UpdateStickTopSessionCallback

更新置顶会话回调

◆ UpdateStickTopSessionNotifyCallback

更新置顶会话通知回调

成员函数说明

◆ CancelToStickTopSession()

void nim::Session::CancelToStickTopSession ( const std::string &  session_id,
nim::NIMSessionType  to_type,
const CancelStickTopSessionCallback cb 
)
static

取消置顶会话列表

参数
[in]session_id会话 ID
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]cb取消置顶会话设置结果的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ DeleteAllRecentSession()

static void nim::Session::DeleteAllRecentSession ( const DeleteAllRecentSessionCallabck cb,
const std::string &  json_extension = "" 
)
static

删除全部最近联系人

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb最近会话列表项变更的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ DeleteHasmoreRoammsg()

void nim::Session::DeleteHasmoreRoammsg ( const std::string &  session_id,
nim::NIMSessionType  to_type,
const DeleteHasmoreRoammsgCallback cb 
)
static

删除会话是漫游消息未拉取信息

参数
[in]session_id会话 ID
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]cb结果回调
返回
void 无返回值

◆ DeleteRecentSession()

static bool nim::Session::DeleteRecentSession ( nim::NIMSessionType  to_type,
const std::string &  id,
const DeleteRecentSessionCallabck cb,
const std::string &  json_extension = "" 
)
static

删除最近联系人

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb最近会话列表项变更的回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ DeleteRecentSessionEx()

static bool nim::Session::DeleteRecentSessionEx ( nim::NIMSessionType  to_type,
const std::string &  id,
const DeleteRecentSessionCallabck cb,
bool  delete_roaming 
)
static

删除最近联系人

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]delete_roaming是否同时删除漫游消息
[in]cb最近会话列表项变更的回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ DeleteSessionRoamingMessage()

static bool nim::Session::DeleteSessionRoamingMessage ( nim::NIMSessionType  to_type,
const std::string &  id,
const DeleteSessionRoammsgCallback cb,
const std::string &  json_extension = "" 
)
static

删除某会话的漫游消息

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb删除结果 回调回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ QueryAllHasmoreRoammsg()

void nim::Session::QueryAllHasmoreRoammsg ( const QueryAllHasmoreRoammsgCallback cb)
static

查询所有“漫游消息未拉取完全”的会话

参数
[in]cb结果回调
返回
void 无返回值

◆ QueryAllRecentSessionAsnc()

static void nim::Session::QueryAllRecentSessionAsnc ( NIMMessageType  last_msg_excluded_type,
const QuerySessionListCallabck cb,
const std::string &  json_extension = "" 
)
static

查询会话列表, 若 last_msg_excluded_type 与初始化配置 session_ignore_msg_types_ 不一致时,会从消息数据库重新查询。

参数
[in]last_msg_excluded_type要排除掉的消息类型,如果不排除任何消息,参数请传入 [kNIMMessageTypeUnknown](NIMMessageType::kNIMMessageTypeUnknown )
[in]cb查询会话列表的回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值

◆ QueryAllRecentSessionAsync()

static void nim::Session::QueryAllRecentSessionAsync ( const QuerySessionListCallabck cb,
const std::string &  json_extension = "" 
)
static

查询会话列表,若初始化配置 session_ignore_msg_types_ 不为默认值(默认为空),会从消息数据库查询。

参数
[in]cb查询会话列表的回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值

◆ QueryAllRecentSessionAsyncEx()

static void nim::Session::QueryAllRecentSessionAsyncEx ( const std::list< NIMMessageType > &  last_msg_excluded_type,
const QuerySessionListCallabck cb,
const std::string &  json_extension = "" 
)
static

查询会话列表,要排除掉的消息类型(列表), 若 last_msg_excluded_type 与初始化配置 [session_ignore_msg_types_](nim::SDKConfig::session_ignore_msg_types_) 不一致时,会从消息数据库重新查询。

参数
[in]last_msg_excluded_type要排除掉的消息类型(列表),如果不排除任何消息,传入空列表
[in]cb查询会话列表的回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值

◆ QueryHasmoreRoammsg()

void nim::Session::QueryHasmoreRoammsg ( const std::string &  session_id,
nim::NIMSessionType  to_type,
const QueryHasmoreRoammsgCallback cb 
)
static

查询指定会话的漫游消息是否拉取完全

背景信息:漫游消息存在上限。云信当前支持漫游 7 天内最近 100 个会话,每个会话最近的 100 条消息

参数
[in]session_id会话 ID
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]cb该查询的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ QueryLastFewSessionAsync()

static void nim::Session::QueryLastFewSessionAsync ( int  limit,
const QuerySessionListCallabck cb,
const std::string &  json_extension = "" 
)
static

查询指定数量的最近会话数据(SessionDataList),从消息数据库中查询。

参数
[in]limit要返回的最大数量
[in]cb查询会话列表的回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值

◆ QuerySessionDataById()

static void nim::Session::QuerySessionDataById ( NIMSessionType  to_type,
const std::string &  id,
const QuerySessionDataCallback cb,
const std::string &  json_extension = "" 
)
static

根据给定的id查询相应会话的信息

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]cb会话信息查询结果的回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ QueryStickTopSessionList()

void nim::Session::QueryStickTopSessionList ( const QueryStickTopSessionListCallback cb)
static

查询置顶会话列表

参数
[in]cb置顶会话列表查询结果的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ RegBadgeCountCb()

static void nim::Session::RegBadgeCountCb ( const BadgeCountCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册 App 角标计数回调(仅 iOS 有效)

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cbApp 角标未读计数回调函数
返回
void 无返回值
错误码

200:成功

◆ RegCancelStickTopSessionNotifyCB()

static void nim::Session::RegCancelStickTopSessionNotifyCB ( const CancelStickTopSessionNotifyCallback cb)
static

(全局回调)注册取消置顶会话通知回调

参数
[in]cb取消置顶会话通知回调模板
返回
void 无返回值

◆ RegChangeCb()

static void nim::Session::RegChangeCb ( const ChangeCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册最近会话列表项变更通知

调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb最近会话列表项变更的回调函数
返回
void 无返回值
错误码

200:成功

◆ RegSetToStickTopSessionNotifyCB()

static void nim::Session::RegSetToStickTopSessionNotifyCB ( const SetToStickTopSessionNotifyCallback cb)
static

(全局回调)注册置顶会话通知回调

参数
[in]cb置顶会话通知回调模板
返回
void 无返回值

◆ RegUpdateStickTopSessionNotifyCB()

static void nim::Session::RegUpdateStickTopSessionNotifyCB ( const UpdateStickTopSessionNotifyCallback cb)
static

(全局回调)注册更新置顶会话通知回调

参数
[in]cb更新置顶会话通知回调模板
返回
void 无返回值

◆ SetAllUnreadCountZeroAsync()

static bool nim::Session::SetAllUnreadCountZeroAsync ( const SetUnreadCountZeroCallback cb,
const std::string &  json_extension = "" 
)
static

最近联系人项全部未读数清零

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb最近会话列表项变更的回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ SetMultiUnreadCountZeroAsync()

static bool nim::Session::SetMultiUnreadCountZeroAsync ( bool  super_team,
const std::list< MultiUnreadCountZeroInfo > &  unread_zero_info_list,
const SetMultiUnreadCountZeroCallback cb 
)
static

最近联系人项未读数清零

参数
[in]super_team会话列表中的会话是否是超大群会话
[in]unread_zero_info_list清零的会话信息列表
[in]cb最近会话列表项变更的回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败
  • 10414:参数错误
注解
最多传入50个会话,否则调用失败,返回 10414

◆ SetSessionExtendData()

static bool nim::Session::SetSessionExtendData ( enum NIMSessionType  to_type,
const std::string &  id,
const std::string &  data,
const ChangeCallback cb,
const std::string &  json_extension = "" 
)
static

设置会话项扩展数据(扩展数据只保存在本地)

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]data扩展数据,建议使用灵活可扩展的数据结构,例如JSON
[in]cb回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ SetSessionTop()

static bool nim::Session::SetSessionTop ( enum NIMSessionType  to_type,
const std::string &  id,
bool  top,
const ChangeCallback cb,
const std::string &  json_extension = "" 
)
static

设置会话项是否置顶(置顶属性只保存在本地)

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]top
  • true - 置顶
  • false - 取消置顶
[in]cb回调函数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ SetToStickTopSession()

static void nim::Session::SetToStickTopSession ( const std::string &  session_id,
nim::NIMSessionType  to_type,
const std::string &  ext,
const SetToStickTopSessionCallback cb 
)
static

设置置顶会话

参数
[in]session_id会话 ID
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]ext扩展字段
[in]cb置顶会话设置结果的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

◆ SetUnreadCountZeroAsync()

static bool nim::Session::SetUnreadCountZeroAsync ( nim::NIMSessionType  to_type,
const std::string &  id,
const SetUnreadCountZeroCallback cb,
const std::string &  json_extension = "" 
)
static

最近联系人项未读数清零

参数
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]id
  • 如果会话类型为单聊,则为对方的 IM 账号(accid)
  • 如果为群组或超大群,则为群 ID (tid)
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb最近会话列表项变更的回调函数
返回
bool 检查参数如果不符合要求则返回失败
错误码
  • 200:成功
  • 0:失败

◆ UnregSessionCb()

void nim::Session::UnregSessionCb ( )
static

反注册nim::Session提供的所有回调

返回
void 无返回值

◆ UpdateHasmoreRoammsg()

void nim::Session::UpdateHasmoreRoammsg ( const IMMessage msg,
const UpdateHasmoreRoammsgCallback cb 
)
static

更新会话是漫游消息未拉取信息

参数
[in]msg对应的消息内容
[in]cb结果回调
返回
void 无返回值

◆ UpdateToStickTopSession()

static void nim::Session::UpdateToStickTopSession ( const std::string &  session_id,
nim::NIMSessionType  to_type,
const std::string &  ext,
const UpdateStickTopSessionCallback cb 
)
static

更新置顶会话列表

参数
[in]session_id会话 ID
[in]to_type会话类型,单聊、群组或超大群,具体见NIMSessionType
[in]ext扩展字段
[in]cb更新置顶会话设置结果的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 0:失败

该类的文档由以下文件生成: