tdlib-session-container/src/main/java/it/tdlight/reactiveapi/Event.java

83 lines
2.3 KiB
Java
Raw Normal View History

2021-12-05 15:15:28 +01:00
package it.tdlight.reactiveapi;
2022-05-05 20:25:00 +02:00
import it.tdlight.common.utils.LibraryVersion;
2021-12-05 15:15:28 +01:00
import it.tdlight.jni.TdApi;
2022-05-05 20:25:00 +02:00
import java.nio.charset.StandardCharsets;
2021-12-07 02:25:01 +01:00
import java.time.Instant;
2022-06-27 00:06:53 +02:00
import java.util.Arrays;
2021-12-05 15:15:28 +01:00
/**
* Any event received from a session
*/
2022-05-05 20:25:00 +02:00
public sealed interface Event {
2022-06-27 00:06:53 +02:00
int SERIAL_VERSION = Arrays.hashCode(LibraryVersion.VERSION.getBytes(StandardCharsets.US_ASCII));
2021-12-05 15:15:28 +01:00
/**
* Event received after choosing the user id of the session
*/
2022-05-05 20:25:00 +02:00
sealed interface ClientBoundEvent extends Event {
2021-12-05 15:15:28 +01:00
/**
*
* @return telegram user id of the session
*/
long userId();
}
2022-05-05 20:25:00 +02:00
sealed interface ServerBoundEvent extends Event {}
2021-12-07 02:25:01 +01:00
2021-12-05 15:15:28 +01:00
/**
* TDLib is asking for an authorization code
*/
2022-05-05 20:25:00 +02:00
sealed interface OnLoginCodeRequested extends ClientBoundEvent {}
2021-12-05 15:15:28 +01:00
2022-06-27 00:06:53 +02:00
record OnUserLoginCodeRequested(long userId, long phoneNumber) implements OnLoginCodeRequested {}
2021-12-07 02:25:01 +01:00
2022-06-27 00:06:53 +02:00
record OnBotLoginCodeRequested(long userId, String token) implements OnLoginCodeRequested {}
2021-12-07 02:25:01 +01:00
2022-06-27 00:06:53 +02:00
record OnOtherDeviceLoginRequested(long userId, String link) implements ClientBoundEvent {}
2021-12-05 15:15:28 +01:00
2022-06-27 00:06:53 +02:00
record OnPasswordRequested(long userId, String passwordHint, boolean hasRecoveryEmail,
2022-01-09 18:27:14 +01:00
String recoveryEmailPattern) implements ClientBoundEvent {}
2021-12-05 15:15:28 +01:00
2022-06-27 00:06:53 +02:00
record Ignored(long userId) implements ClientBoundEvent {}
2022-05-05 20:25:00 +02:00
2021-12-05 15:15:28 +01:00
/**
* Event received from TDLib
*/
2022-05-05 20:25:00 +02:00
sealed interface OnUpdate extends ClientBoundEvent {}
2021-12-05 15:15:28 +01:00
2022-06-27 00:06:53 +02:00
record OnUpdateData(long userId, TdApi.Update update) implements OnUpdate {}
2021-12-05 15:15:28 +01:00
2022-06-27 00:06:53 +02:00
record OnUpdateError(long userId, TdApi.Error error) implements OnUpdate {}
2021-12-07 02:25:01 +01:00
2022-05-05 20:25:00 +02:00
sealed interface OnRequest<T extends TdApi.Object> extends ServerBoundEvent {
2022-09-10 20:25:54 +02:00
record Request<T extends TdApi.Object>(long userId, long clientId, long requestId, TdApi.Function<T> request,
2022-06-27 00:06:53 +02:00
Instant timeout) implements OnRequest<T> {}
2022-09-10 20:25:54 +02:00
record InvalidRequest<T extends TdApi.Object>(long userId, long clientId, long requestId) implements OnRequest<T> {}
long userId();
2022-06-27 00:06:53 +02:00
long clientId();
long requestId();
}
sealed interface OnResponse<T extends TdApi.Object> extends ClientBoundEvent {
record Response<T extends TdApi.Object>(long clientId, long requestId, long userId,
T response) implements OnResponse<T> {}
record InvalidResponse<T extends TdApi.Object>(long clientId, long requestId, long userId) implements
OnResponse<T> {}
long clientId();
long requestId();
2021-12-07 02:25:01 +01:00
}
2021-12-05 15:15:28 +01:00
}