2020-10-11 16:27:57 +02:00
|
|
|
package it.tdlight.common;
|
2020-05-05 17:08:39 +02:00
|
|
|
|
2020-10-13 01:31:32 +02:00
|
|
|
import it.tdlight.jni.TdApi;
|
2020-05-05 17:08:39 +02:00
|
|
|
|
|
|
|
public interface TelegramClient {
|
|
|
|
|
2021-01-24 13:19:13 +01:00
|
|
|
/**
|
|
|
|
* Initialize the client synchronously.
|
|
|
|
* @param updatesHandler Handler in which the updates are received
|
|
|
|
* @param updateExceptionHandler Handler in which the errors from updates are received
|
|
|
|
* @param defaultExceptionHandler Handler that receives exceptions triggered in a handler
|
|
|
|
*/
|
|
|
|
void initialize(UpdatesHandler updatesHandler,
|
|
|
|
ExceptionHandler updateExceptionHandler,
|
|
|
|
ExceptionHandler defaultExceptionHandler);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the client synchronously.
|
|
|
|
* @param updateHandler Handler in which the updates are received
|
|
|
|
* @param updateExceptionHandler Handler in which the errors from updates are received
|
|
|
|
* @param defaultExceptionHandler Handler that receives exceptions triggered in a handler
|
|
|
|
*/
|
|
|
|
default void initialize(ResultHandler updateHandler,
|
|
|
|
ExceptionHandler updateExceptionHandler,
|
|
|
|
ExceptionHandler defaultExceptionHandler) {
|
|
|
|
this.initialize((UpdatesHandler) updates -> updates.forEach(updateHandler::onResult),
|
|
|
|
updateExceptionHandler,
|
|
|
|
defaultExceptionHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-02 14:56:46 +02:00
|
|
|
/**
|
2020-10-13 01:31:32 +02:00
|
|
|
* Sends a request to the TDLib.
|
|
|
|
*
|
|
|
|
* @param query Object representing a query to the TDLib.
|
|
|
|
* @param resultHandler Result handler with onResult method which will be called with result
|
|
|
|
* of the query or with TdApi.Error as parameter. If it is null, nothing
|
|
|
|
* will be called.
|
|
|
|
* @param exceptionHandler Exception handler with onException method which will be called on
|
|
|
|
* exception thrown from resultHandler. If it is null, then
|
|
|
|
* defaultExceptionHandler will be called.
|
|
|
|
* @throws NullPointerException if query is null.
|
2020-09-02 14:56:46 +02:00
|
|
|
*/
|
2020-10-13 01:31:32 +02:00
|
|
|
void send(TdApi.Function query, ResultHandler resultHandler, ExceptionHandler exceptionHandler);
|
2020-05-05 17:08:39 +02:00
|
|
|
|
2020-09-02 14:56:46 +02:00
|
|
|
/**
|
2020-10-13 01:31:32 +02:00
|
|
|
* Sends a request to the TDLib with an empty ExceptionHandler.
|
2020-09-02 14:56:46 +02:00
|
|
|
*
|
2020-10-13 01:31:32 +02:00
|
|
|
* @param query Object representing a query to the TDLib.
|
|
|
|
* @param resultHandler Result handler with onResult method which will be called with result
|
|
|
|
* of the query or with TdApi.Error as parameter. If it is null, then
|
|
|
|
* defaultExceptionHandler will be called.
|
|
|
|
* @throws NullPointerException if query is null.
|
|
|
|
*/
|
|
|
|
default void send(TdApi.Function query, ResultHandler resultHandler) {
|
|
|
|
send(query, resultHandler, null);
|
2020-09-02 14:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-13 01:31:32 +02:00
|
|
|
* Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously.
|
2020-09-02 14:56:46 +02:00
|
|
|
*
|
2020-10-13 01:31:32 +02:00
|
|
|
* @param query Object representing a query to the TDLib.
|
2020-10-13 23:22:21 +02:00
|
|
|
* @return request result or {@link TdApi.Error}.
|
2020-10-13 01:31:32 +02:00
|
|
|
* @throws NullPointerException if query is null.
|
2020-09-02 14:56:46 +02:00
|
|
|
*/
|
2020-10-13 01:31:32 +02:00
|
|
|
TdApi.Object execute(TdApi.Function query);
|
2020-05-05 17:08:39 +02:00
|
|
|
}
|