Recent Session
Update time: 2021/12/03 09:43:45
Recent sessions
It contains contact information with respect to recent sessions the user has had, including contact account, contact type, time of the last message, message status, message abbreviation and unread count.
Get the most recent sessions
C++
void OnQuerySessionListCallback(int unread_count, const nim::SessionDataList& session_list)
{
···
}
void foo()
{
nim::Session::QueryAllRecentSessionAsync(&OnQuerySessionListCallback);
}
C#
void foo()
{
NIM.Session.SessionAPI.QueryAllRecentSession((a, b) =>
{
if (b == null || b.SessionList == null) return;
foreach (var item in b.SessionList)
{
···
}
});
}
C
void CallbackQuerySessionListCb(int total_unread_count, const char* session_list, const char *json_exten, const void *user_data)
{
...
}
typedef void(*nim_session_query_all_recent_session_async)(const char *json_extension, nim_session_query_recent_session_cb_func cb, const void* user_data);
void foo()
{
nim_session_query_all_recent_session_async func = (nim_session_query_all_recent_session_async) GetProcAddress(hInst, "nim_session_query_all_recent_session_async");
func(nullptr, &CallbackQuerySessionListCb, nullptr);
}
Listen for the change of recent sessions
While sending and receiving messages, SDK will keep up to date the contact information about the other party in the chat. While receiving and sending out a message, SDK will send out a notification about the latest update to contact information, and use nim_session_reg_change_cb to register the notification callback feature.
Delete the list of recent sessions
SDK also provides an interface for deleting a session and all recent contacts. Note: A session deleted locally is removed from the server as well!
-
Delete a session
C++
void DeleteRecentSessionCb(nim::NIMResCode code, const nim::SessionData &result, int total_unread_counts) { ··· } void DeleteSessionItem(const nim::SessionData& msg) { nim::Session::DeleteRecentSession(msg.type_, msg.id_, &DeleteRecentSessionCb); }
C#
void foo(SessionInfo info) { NIM.Session.SessionAPI.DeleteRecentSession(info.SessionType, info.Id, (a, b, c) => { ··· }); }
C
void CallbackNotifySession(int rescode, const char *result, int total_unread_counts, const char *json_extension, const void *user_data) { // parse result } typedef void(*nim_session_delete_recent_session_async)(NIMSessionType to_type, const char *id, const char *json_extension, nim_session_change_cb_func cb, const void *user_data); void foo(nim::NIMSessionType to_type, const char *id) { nim_session_delete_recent_session_async func = (nim_session_delete_recent_session_async) GetProcAddress(hInst, "nim_session_delete_recent_session_async"); func(to_type, id, "", &CallbackNotifySession, nullptr); }
-
Delete all sessions
C++
void DeleteAllRecentSessionCb(nim::NIMResCode code, const nim::SessionData &result, int total_unread_counts) { ··· } void DeleteAllSessionItem() { nim::Session::DeleteAllRecentSession(&DeleteAllRecentSessionCb); }
C#
void foo() { NIM.Session.SessionAPI.DeleteAllRecentSession((a, b, c) => { ··· }); }
C
void CallbackNotifySession(int rescode, const char *result, int total_unread_counts, const char *json_extension, const void *user_data) { // parse result } typedef void(*nim_session_delete_all_recent_session_async)(const char *json_extension, nim_session_change_cb_func cb, const void *user_data); void foo() { nim_session_delete_all_recent_session_async func = (nim_session_delete_all_recent_session_async) GetProcAddress(hInst, "nim_session_delete_all_recent_session_async"); func("", &CallbackNotifySession, nullptr); }
Reset the unread count
C++
void ResetUnread(const std::string &id, nim::NIMSessionType type)
{
nim::Session::SetUnreadCountZeroAsync(type, id, nim::Session::SetUnreadCountZeroCallback());
nim::MsgLog::BatchStatusReadAsync(id, type, nim::MsgLog::BatchStatusReadCallback());
}
C#
void ResetUnread(SessionInfo info)
{
NIM.Session.SessionAPI.SetUnreadCountZero(info.SessionType, info.Id, (a, b, c) =>
{
···
});
NIM.Messagelog.MessagelogAPI.MarkMessagesStatusRead(info.Id, info.SessionType, (a, b, c) =>
{
···
});
}
C
void CallbackNotifySession(int rescode, const char *result, int total_unread_counts, const char *json_extension, const void *user_data)
{
// parse result
}
void CallbackModifyMultipleMsglog(int res_code
, const char *uid
, nim::NIMSessionType to_type
, const char *json_extension
, const void *callback)
{
···
}
typedef void(*nim_session_set_unread_count_zero_async)(NIMSessionType to_type, const char *id, const char *json_extension, nim_session_change_cb_func cb, const void *user_data);
typedef void(*nim_msglog_batch_status_read_async)(const char* account_id, nim::NIMSessionType to_type, const char *json_extension, nim_msglog_res_ex_cb_func cb, const void* user_data);
void foo(nim::NIMSessionType type, const char *id)
{
nim_msglog_batch_status_read_async batch_func = (nim_msglog_batch_status_read_async) GetProcAddress(hInst, "nim_msglog_batch_status_read_async");
nim_session_set_unread_count_zero_async unread_func = (nim_session_set_unread_count_zero_async) GetProcAddress(hInst, "nim_session_set_unread_count_zero_async");
unread_func(type, id, "", &CallbackNotifySession, nullptr);
batch_func(id, type, "", &CallbackModifyMultipleMsglog, nullptr);
}