Compare commits

...

8 Commits

Author SHA1 Message Date
Andrea Cavalli
4d77c73e95 Add logOutAsync and loadChatListMainAsync 2024-03-21 00:56:40 +01:00
Andrea Cavalli
c2ad58fa70 Update example 2024-03-21 00:39:25 +01:00
Andrea Cavalli
fa1c197614 Update tdlib 2024-03-21 00:34:56 +01:00
Andrea Cavalli
5afc402682 Update example libraries 2024-02-22 01:34:07 +01:00
Andrea Cavalli
fed5626b81 Add MacOS arm64 2024-02-22 01:32:11 +01:00
Andrea Cavalli
6407c10c92 Update example 2024-02-21 18:35:34 +01:00
Andrea Cavalli
eb6a8d55c8 Update tdlight 2024-02-21 18:30:00 +01:00
Andrea Cavalli
616bd6a203 Update example 2023-11-12 18:59:00 +01:00
8 changed files with 82 additions and 30 deletions

View File

@ -23,7 +23,7 @@
- amd64 (Linux, Windows, MacOS)
- armhf (Linux)
- arm64 (Linux)
- arm64 (Linux, MacOS)
- ppc64el (Linux)
- riscv64 (linux)
@ -148,6 +148,7 @@ To use TDLight Java you need to include the native libraries, by specifying one
- `linux_ppc64el_gnu_ssl3`
- `linux_riscv64_gnu_ssl3`
- `windows_amd64`
- `macos_arm64`
- `macos_amd64`
Advanced: If you want to use a different precompiled native, please set the java property `it.tdlight.native.workdir`. (Please note that you must build [this](https://github.com/tdlight-team/tdlight-java-natives), you can't put random precompiled tdlib binaries found on the internet)

View File

@ -8,8 +8,8 @@
<name>TDLight Java BOM</name>
<properties>
<revision>3.0.0.0-SNAPSHOT</revision>
<tdlight.natives.version>4.0.495</tdlight.natives.version>
<tdlight.api.version>4.0.465</tdlight.api.version>
<tdlight.natives.version>4.0.506</tdlight.natives.version>
<tdlight.api.version>4.0.476</tdlight.api.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
@ -150,6 +150,12 @@
<version>${tdlight.natives.version}</version>
<classifier>macos_amd64</classifier>
</dependency>
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlight-natives</artifactId>
<version>${tdlight.natives.version}</version>
<classifier>macos_arm64</classifier>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -26,7 +26,7 @@
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlight-java-bom</artifactId>
<version>3.2.1+td.1.8.21</version>
<version>3.4.0+td.1.8.26</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -66,17 +66,22 @@
<artifactId>tdlight-natives</artifactId>
<classifier>macos_amd64</classifier>
</dependency>
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlight-natives</artifactId>
<classifier>macos_arm64</classifier>
</dependency>
<!-- log4j logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.20.0</version>
<version>2.22.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
@ -98,15 +103,15 @@
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>17</source>
@ -115,15 +120,15 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>3.1.1</version>
</plugin>
</plugins>
</build>

View File

@ -12,7 +12,9 @@ import it.tdlight.client.SimpleTelegramClientFactory;
import it.tdlight.client.TDLibSettings;
import it.tdlight.jni.TdApi;
import it.tdlight.jni.TdApi.AuthorizationState;
import it.tdlight.jni.TdApi.CreatePrivateChat;
import it.tdlight.jni.TdApi.FormattedText;
import it.tdlight.jni.TdApi.GetChat;
import it.tdlight.jni.TdApi.InputMessageText;
import it.tdlight.jni.TdApi.Message;
import it.tdlight.jni.TdApi.MessageContent;
@ -75,9 +77,12 @@ public final class Example {
// Get me
TdApi.User me = app.getClient().getMeAsync().get(1, TimeUnit.MINUTES);
// Create the "saved messages" chat
var savedMessagesChat = app.getClient().send(new CreatePrivateChat(me.id, true)).get(1, TimeUnit.MINUTES);
// Send a test message
var req = new SendMessage();
req.chatId = me.id;
req.chatId = savedMessagesChat.id;
var txt = new InputMessageText();
txt.text = new FormattedText("TDLight test", new TextEntity[0]);
req.inputMessageContent = txt;

View File

@ -48,7 +48,7 @@ final class AuthorizationStateWaitRegistrationHandler implements GenericUpdateHa
exceptionHandler.onException(new IllegalArgumentException("Last name must be under 64 characters"));
return;
}
RegisterUser response = new RegisterUser(firstName, lastName);
RegisterUser response = new RegisterUser(firstName, lastName, true);
client.send(response, ok -> {
if (ok.getConstructor() == TdApi.Error.CONSTRUCTOR) {
throw new TelegramError((TdApi.Error) ok);

View File

@ -37,8 +37,6 @@ final class AuthorizationStateWaitTdlibParametersHandler implements GenericUpdat
params.deviceModel = settings.getDeviceModel();
params.systemVersion = settings.getSystemVersion();
params.applicationVersion = settings.getApplicationVersion();
params.enableStorageOptimizer = settings.isStorageOptimizerEnabled();
params.ignoreFileNames = settings.isIgnoreFileNames();
params.databaseEncryptionKey = null;
client.send(params, ok -> {
if (ok.getConstructor() == TdApi.Error.CONSTRUCTOR) {

View File

@ -12,6 +12,8 @@ import it.tdlight.jni.TdApi;
import it.tdlight.jni.TdApi.ChatListArchive;
import it.tdlight.jni.TdApi.ChatListMain;
import it.tdlight.jni.TdApi.Function;
import it.tdlight.jni.TdApi.LoadChats;
import it.tdlight.jni.TdApi.LogOut;
import it.tdlight.jni.TdApi.Message;
import it.tdlight.jni.TdApi.Update;
import it.tdlight.jni.TdApi.User;
@ -504,6 +506,22 @@ public final class SimpleTelegramClient implements Authenticable, MutableTelegra
return meGetter.getMeAsync();
}
/**
* Loads more chats from the main chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded.
*
**/
public CompletableFuture<Void> loadChatListMainAsync() {
return send(new LoadChats(new ChatListMain(), 2000)).thenAccept(ok -> {});
}
/**
* Closes the TDLib instance after a proper logout. Requires an available network connection. All local data will be destroyed. After the logout completes, updateAuthorizationState with authorizationStateClosed will be sent.
*
**/
public CompletableFuture<Void> logOutAsync() {
return send(new LogOut()).thenAccept(ok -> {});
}
public boolean isMainChatsListLoaded() {
return mainChatsLoader.isLoaded();
}

View File

@ -29,9 +29,8 @@ public final class TDLibSettings {
private String deviceModel;
private String systemVersion;
private String applicationVersion;
private boolean enableStorageOptimizer;
private boolean ignoreFileNames;
@Deprecated
private TDLibSettings(boolean useTestDatacenter,
Path databaseDirectoryPath,
Path downloadedFilesDirectoryPath,
@ -45,6 +44,31 @@ public final class TDLibSettings {
String applicationVersion,
boolean enableStorageOptimizer,
boolean ignoreFileNames) {
this(useTestDatacenter,
databaseDirectoryPath,
downloadedFilesDirectoryPath,
fileDatabaseEnabled,
chatInfoDatabaseEnabled,
messageDatabaseEnabled,
apiToken,
systemLanguageCode,
deviceModel,
systemVersion,
applicationVersion
);
}
private TDLibSettings(boolean useTestDatacenter,
Path databaseDirectoryPath,
Path downloadedFilesDirectoryPath,
boolean fileDatabaseEnabled,
boolean chatInfoDatabaseEnabled,
boolean messageDatabaseEnabled,
APIToken apiToken,
String systemLanguageCode,
String deviceModel,
String systemVersion,
String applicationVersion) {
this.useTestDatacenter = useTestDatacenter;
this.databaseDirectoryPath = databaseDirectoryPath;
this.downloadedFilesDirectoryPath = downloadedFilesDirectoryPath;
@ -56,8 +80,6 @@ public final class TDLibSettings {
this.deviceModel = deviceModel;
this.systemVersion = systemVersion;
this.applicationVersion = applicationVersion;
this.enableStorageOptimizer = enableStorageOptimizer;
this.ignoreFileNames = ignoreFileNames;
}
public static TDLibSettings create(APIToken apiToken) {
@ -165,20 +187,22 @@ public final class TDLibSettings {
this.applicationVersion = applicationVersion;
}
@Deprecated
public boolean isStorageOptimizerEnabled() {
return enableStorageOptimizer;
return false;
}
@Deprecated
public void setEnableStorageOptimizer(boolean enableStorageOptimizer) {
this.enableStorageOptimizer = enableStorageOptimizer;
}
@Deprecated
public boolean isIgnoreFileNames() {
return ignoreFileNames;
return false;
}
@Deprecated
public void setIgnoreFileNames(boolean ignoreFileNames) {
this.ignoreFileNames = ignoreFileNames;
}
@Override
@ -193,7 +217,6 @@ public final class TDLibSettings {
return useTestDatacenter == that.useTestDatacenter && fileDatabaseEnabled == that.fileDatabaseEnabled
&& chatInfoDatabaseEnabled == that.chatInfoDatabaseEnabled
&& messageDatabaseEnabled == that.messageDatabaseEnabled
&& enableStorageOptimizer == that.enableStorageOptimizer && ignoreFileNames == that.ignoreFileNames
&& Objects.equals(databaseDirectoryPath, that.databaseDirectoryPath) && Objects.equals(
downloadedFilesDirectoryPath,
that.downloadedFilesDirectoryPath
@ -214,9 +237,7 @@ public final class TDLibSettings {
systemLanguageCode,
deviceModel,
systemVersion,
applicationVersion,
enableStorageOptimizer,
ignoreFileNames
applicationVersion
);
}
@ -234,8 +255,6 @@ public final class TDLibSettings {
.add("deviceModel='" + deviceModel + "'")
.add("systemVersion='" + systemVersion + "'")
.add("applicationVersion='" + applicationVersion + "'")
.add("enableStorageOptimizer=" + enableStorageOptimizer)
.add("ignoreFileNames=" + ignoreFileNames)
.toString();
}
}