fetchPrevious method
Future<List<CallLog> >
fetchPrevious({
- required dynamic onSuccess(),
- required dynamic onError(
- CometChatCallsException excep
Fetches the previous batch of call logs.
The onSuccess
function is called with a list of CallLog objects when the call logs are successfully fetched.
The onError
function is called with a CometChatCallsException object when there is an error while fetching the call logs.
Returns a Future that resolves to a list of CallLog objects.
Example:
fetchPrevious(
onSuccess: (callLogs) {
// Process the fetched call logs
},
onError: (exception) {
// Handle the error
},
);
Implementation
Future<List<CallLog>> fetchPrevious(
{required Function(List<CallLog> callLogs) onSuccess,
required Function(CometChatCallsException excep) onError}) async {
if (!await CometChatCalls.isInitialized()) {
onError(CometChatCallsException(
CometChatCallsConstants.codeCometChatCallsSDKInitError,
CometChatCallsConstants.messageCometChatCallsSDKInit,
CometChatCallsConstants.messageCometChatCallsSDKInit));
} else if (authToken == null) {
onError(CometChatCallsException(
CometChatCallsConstants.codeUserAuthTokenNull,
CometChatCallsConstants.messageCodeUserAuthTokenNull,
CometChatCallsConstants.messageCodeUserAuthTokenNull));
} else if (authToken!.isEmpty) {
onError(CometChatCallsException(
CometChatCallsConstants.codeUserAuthTokenNull,
CometChatCallsConstants.messageCodeUserAuthTokenBlankOrEmpty,
CometChatCallsConstants.messageCodeUserAuthTokenBlankOrEmpty));
}
if (currentPage == 1) {
onSuccess(<CallLog>[]);
return [];
}
ApiConnection().getCallLogList(getParams(false), authToken!,
(String response) {
getCallLogList(onSuccess, onError, response);
}, (CometChatCallsException e) {
CometChatCallsUtils.showLog(_tag, "generateToken onError: ${e.message}");
onError(e);
});
return [];
}