Server-side session

Update time: 2024/03/07 11:13:59

Server-side session service

The server-side session service is different from the local recent session. The server provides a service to get the recent session list from the server and does not support synchronization with the local recent session list.

  • The server stores the user's full session history list and the latest message;

  • Clients can get the session list from the server with a specified number of sessions and the obtained sessions are not combined with the local session list.

  • Unread count is not supported.

The recent sessions prototype on the server si RecentSession. The session contains information, such as contact account, time of the last message, extension field, message body and more.

RecentSession:

Field Type Description
sessionId String The ID of a session (friend account or group ID
updateTime int Timestamp when the last message was received
ext String Extension field
lastMsg String Last message in JSON
revokeNotification RevokeMsgNotification When the last message is a notification for recalling messages, the return value is not null.
At this time. The interface can get a RevokeMsgNotification instance that has part of message body or empty body.
recentSession NIMSession New NIMSession with RecentSession information
sessionTypePair String The session type separated from session (not supported on Windows and macOS)
lastMsgType int The type of the last message, 0 or empty indicates regular messages, 1 indicates a notification for unsending messages.

Server-side session list RecentSessionList contains a page of RecentSession data and prompts whether earlier messages exist.

RecentSessionList interface

Field Type Description
hasMore bool Whether earlier messages exists
sessionList List<RecentSession> The list of recent sessions

Get the session list

  • API prototype
dartclass MessageService {
  ///
  /// Get a list of incremental sessions. New sessions are displayed by pagination.
  ///
  /// [minTimestamp] minimum timestamp as the increment call to get the session list. A value of 0 indicates all sessions are retrieved.
  /// [maxTimestamp] maximum timestamp used for pagination|
  /// [needLastMsg]  Whether lastMsg is required. 0 or 1. The default value is 1|
  /// |limit] The limit of retrieved sessions. A maximum of 100 sessions are allowed. The default value is 100.
  /// [hasMore] Whether the result is complete, A value of 0 indicate the result is complete. A value of 1 indicates the result has more data. (Not supported for Windows and macOS).
  ///
  Future<NIMResult<RecentSessionList>> queryMySessionList(
      int minTimestamp,int maxTimestamp,int needLastMsg,int limit,int hasMore)
}

  • Parameters
Parameter Type Description
minTimestamp int The minimum timestamp as the increment call to get the session list. A value of 0 indicates all sessions are retrieved.
maxTimestamp int The maximum timestamp used for pagination
needLastMsg int Whether lastMsg is required. 0 or 1. The default value is 1.
limit int The limit of retrieved sessions. A maximum of 100 sessions are allowed. The default value is 100.
hasMore Whether the result is complete, 0 or 1 (Not supported for Windows and macOS).

Get the specified session

  • API prototype
dart
class MessageService {

  /// Get a session
  ///[sessionId] P2P, team or superTeam. Valid values: p2p|accid, team | tid, and super_team|tid.
  ///
  Future<NIMResult<RecentSession>> queryMySession(String sessionId,NIMSessionType sessionType);
}
  • Parameters
Parameter Type Description
sessionId String Valid values: p2p, team, and superTeam.

Edit the extension filed of the server session

  • API prototype
dartclass MessageService {
  ///
  /// Update the extension field of a session. If the session does not exist, the session will be created. lasMsg does not exist at the moment.
  ///
  /// [sessionId] P2P, team or superTeam. Valid values: p2p|accid, team | tid, and super_team|tid.
  /// [ext] extension field. Visible for the current user only
  ///
 Future<NIMResult<void>> updateMySession(String sessionId,NIMSessionType sessionType,String ext);
}
  • Parameters
Parameter Type Description
sessionId String Valid values: p2p, team, and superTeam.
ext String The extension field of a session. Visible for the current user only.

Delete server sessions

  • API prototype
dartclass MessageService {
  ///
  /// Delete a session
  ///
  /// [sessionList] Valid values: P2P, team or superTeam. Valid format: p2p|accid, team | tid, and super_team|tid.
  ///
  Future<NIMResult<void>> deleteMySession(List<NIMMySessionKey> sessionList);
}
  • Parameters
Parameter Type Description
sessionList List For each session, use p2p, team, or superTeam

Listen for updates of server-side sessions

  • API prototype
dartclass MessageService {
  ///
  /// Listen for updates of server-side sessions
  ///
  final StreamController<RecentSession> onMySessionUpdate =
  StreamController<RecentSession>.broadcast();
}
  • Example
dart NimCore.instance.messageService.onMySessionUpdate.listen((RecentSession event) {
    ///When a session is updated, you can get the updated the server session.
});
Was this page helpful?
Yes
No
  • Get the session list
  • Get the specified session
  • Edit the extension filed of the server session
  • Delete server sessions
  • Listen for updates of server-side sessions