Server-side sessions
Update time: 2023/02/09 16:28:36
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 complete 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.
Get the session list
Get the session list from the server:
/**
* Block for getting the server session list
*
* @param error error. If the operation succeeds, the error parameter returns nil
* @param recentSessions retrieved recent sessions
* @param hasMore The minimum timestamp will only be returned when the first page is requested. The timestamp will be included in the request parameters in the next incremental synchronization
*/
typedef void(^NIMFetchRecentSessionsHistoryBlock)(NSError * __nullable error,
NSArray<NIMRecentSession *> * __nullable recentSessions,
BOOL hasMore);
@protocol NIMConversationManager <NSObject>
/**
* Get paginated history messages from the server.
*
* @param option pagination option. Optional, If unspecified, all history messages are obtained.
*
*@param completion Completion callback
*/
- (void)fetchServerSessions:(nullable NIMFetchServerSessionOption *)option
completion:(nullable NIMFetchRecentSessionsHistoryBlock)completion;
@end
Properties
Parameter | Type | Description |
---|---|---|
option | NIMFetchServerSessionOption | Options for getting recent sesssions from the server |
completion | NIMFetchRecentSessionsHistoryBlock | Callback that returns the result |
NIMRecentSession representation:
Parameter | Type | Description |
---|---|---|
session | NIMSession | Current session |
unreadCount | NSInteger | The number of unread messages |
localExt | NSDictionary | local extension |
updateTime | NSTimeInterval | The latest update time of the server session. The parameter is invalid for local sessions. |
serverExt | NSString | The extension field. This field is invalid for local sessions |
lastMessageType | NIMLastMsgType | The type of the last message (this field is invalid for local sessions) |
lastMessage | NIMMessage | The last message. |
lastRevokeNotification | NIMRevokeMessageNotification | The type of the last message (this field is invalid for local sessions) |
Example
// Next page
NIMFetchServerSessionOption * option = [[NIMFetchServerSessionOption alloc] init];
option.needLastMessage = needLastMsg;
option.minTimestamp = min;
option.maxTimestamp = currentMin - 1;
option.limit = limit;
[[NIMSDK sharedSDK].conversationManager fetchServerSessions:option completion:^(NSError * _Nullable error, NSArray<NIMRecentSession *> * _Nullable recentSessions, BOOL hasMore) {}];
Get the specified session
Get the details of a specified session from the server.
@protocol NIMConversationManager <NSObject>
/**
* Get messages from the server.
*
*@param session Target session
*
*@param completion Completion callback
*/
- (void)fetchServerSessionBySession:(NIMSession *)session
completion:(nullable NIMFetchRecentSessionHistoryBlock)completion;
@end
Properties
Parameter | Type | Description |
---|---|---|
session | NIMSession | Target session |
completion | NIMFetchRecentSessionHistoryBlock | The callback that returns the session information. |
Example
[[NIMSDK sharedSDK].conversationManager fetchServerSessionBySession:recent.session completion:^(NSError * _Nullable error, NIMRecentSession * _Nullable recentSession) {}];
Edit the extension filed of the server session
Updating recent sessions on the server;
@protocol NIMConversationManager <NSObject>
/**
* Update messages from the server
*
* @param ext extension
*
* @param session Target recent session
*
*@param completion Completion callback
*/
- (void)updateServerSessionExt:(NSString *)ext
session:(NIMSession *)session
completion:(nullable NIMRemoteRecentSessionBlock)completion;
@end
Properties
Parameter | Type | Description |
---|---|---|
ext | NSString | New value for the extension field. |
session | NIMSession | Target session. |
completion | NIMRemoteRecentSessionBlock | Callback for completion. |
Example
[[NIMSDK sharedSDK].conversationManager updateServerSessionExt:@"newServerExt" session:recentSession.session completion:^(NSError * _Nullable error) { }];
Delete server sessions
@protocol NIMConversationManager <NSObject>
/**
* Delete sessions from the server
*
* @param sessions Target sessions
*
*@param completion Completion callback
*/
- (void)deleteServerSessions:(NSArray<NIMSession *> *)sessions
completion:(nullable NIMRemoteRecentSessionBlock)completion;
@end
Properties
Parameter | Type | Description |
---|---|---|
sessions | NSArray | Target sessions |
completion | NIMRemoteRecentSessionBlock | Callback for completion. |
Example
[[NIMSDK sharedSDK].conversationManager deleteServerSessions:@[recentSession.session] completion:^(NSError * _Nullable error) {}];