From 13648d1fcab2eb7e1e647860e927d0d54a72316f Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 8 Oct 2023 16:59:20 +0200 Subject: [PATCH] Apply tdlight patch --- .github/workflows/build.yaml | 50 +++++++ .gitignore | 8 ++ CHANGELOG.md | 6 +- CMakeLists.txt | 13 +- README.md | 54 ++++++-- build.html | 50 +++---- example/README.md | 24 ++-- example/ios/README.md | 4 +- example/java/README.md | 2 +- example/uwp/extension.vsixmanifest | 2 +- example/web/README.md | 2 +- example/web/tdweb/README.md | 4 +- example/web/tdweb/src/index.js | 2 +- td/generate/scheme/.gitignore | 1 + td/generate/scheme/td_api.tl | 26 ++++ td/generate/tl-parser/tl-parser.c | 112 +++++++-------- td/generate/tl-parser/tlc.c | 2 +- td/telegram/AnimationsManager.cpp | 23 +++- td/telegram/AnimationsManager.h | 2 + td/telegram/AnimationsManager.hpp | 22 ++- td/telegram/AudiosManager.cpp | 5 + td/telegram/AudiosManager.h | 2 + td/telegram/AudiosManager.hpp | 15 +- td/telegram/AutoDownloadSettings.cpp | 27 +++- td/telegram/BackgroundManager.cpp | 14 ++ td/telegram/BackgroundManager.h | 2 + td/telegram/ContactsManager.cpp | 141 +++++++++++++++++++ td/telegram/ContactsManager.h | 6 + td/telegram/Document.cpp | 37 ++--- td/telegram/DocumentsManager.cpp | 4 + td/telegram/DocumentsManager.h | 1 + td/telegram/DocumentsManager.hpp | 18 ++- td/telegram/FileReferenceManager.cpp | 6 + td/telegram/FileReferenceManager.h | 2 + td/telegram/Global.cpp | 4 + td/telegram/Global.h | 57 ++++++++ td/telegram/GroupCallManager.cpp | 27 +++- td/telegram/GroupCallManager.h | 4 + td/telegram/InlineQueriesManager.cpp | 11 ++ td/telegram/InlineQueriesManager.h | 2 + td/telegram/MemoryManager.cpp | 196 +++++++++++++++++++++++++++ td/telegram/MemoryManager.h | 63 +++++++++ td/telegram/MessageContent.cpp | 2 + td/telegram/MessagesManager.cpp | 115 +++++++++++++++- td/telegram/MessagesManager.h | 2 + td/telegram/NotificationManager.cpp | 4 + td/telegram/OptionManager.cpp | 39 ++++++ td/telegram/Photo.cpp | 10 +- td/telegram/Photo.hpp | 20 ++- td/telegram/PhotoSize.cpp | 23 +++- td/telegram/PollManager.cpp | 14 ++ td/telegram/PollManager.h | 2 + td/telegram/StickersManager.cpp | 26 ++++ td/telegram/StickersManager.h | 2 + td/telegram/Td.cpp | 41 +++++- td/telegram/Td.h | 13 +- td/telegram/TdDb.cpp | 12 +- td/telegram/TdDb.h | 5 + td/telegram/VideoNotesManager.cpp | 12 +- td/telegram/VideoNotesManager.h | 2 + td/telegram/VideosManager.cpp | 12 +- td/telegram/VideosManager.h | 2 + td/telegram/VideosManager.hpp | 21 ++- td/telegram/WebPagesManager.cpp | 13 ++ td/telegram/WebPagesManager.h | 2 + td/telegram/files/FileManager.cpp | 15 +- td/telegram/files/FileManager.h | 2 + tdutils/CMakeLists.txt | 2 +- tdutils/td/utils/logging.cpp | 12 ++ tdutils/td/utils/logging.h | 4 + 70 files changed, 1290 insertions(+), 192 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 td/generate/scheme/.gitignore create mode 100644 td/telegram/MemoryManager.cpp create mode 100644 td/telegram/MemoryManager.h diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..41bbce82b --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,50 @@ +name: Build TDLib + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * 0' # weekly + +jobs: + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + arch: [linux/386, linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64, linux/ppc64le] + + steps: + - name: Setup variables + run: | + ARCH=${{ matrix.arch }} + SAFE_ARCH=$(echo $ARCH | sed 's/\//\-/g') + echo "SAFE_ARCH=$SAFE_ARCH" >> $GITHUB_ENV + - name: Install sudo package + run: | + (apt-get update || true) 2>/dev/null + (apt-get install -y sudo || true) 2>/dev/null + sudo apt update + - uses: actions/checkout@v2 + with: + submodules: "recursive" + - name: Cache ccache + id: cache-ccache + uses: actions/cache@v2 + with: + path: ~/.ccache + key: ${{ runner.os }}-${{ env.SAFE_ARCH }}-ccache-all + restore-keys: | + ${{ runner.os }}-${{ env.SAFE_ARCH }}-ccache- + - name: Install build tools + run: sudo apt-get install -y make git zlib1g-dev libssl-dev gperf php-cli cmake clang-6.0 libc++-dev libc++abi-dev ccache + - name: Build + run: | + mkdir build + cd build + CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang-10 CXX=/usr/bin/clang++-10 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=../tdlib .. + cmake --build . --target install -- -j4 + - uses: actions/upload-artifact@v2 + with: + name: tdlight-${{ env.SAFE_ARCH }} + path: tdlib/lib + diff --git a/.gitignore b/.gitignore index 4f950ed98..98ae6f079 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,12 @@ **/auto/ docs/ tdlib/ +.idea/ vcpkg/ +*.tlo + +td.binlog + +tg_cli.log + +tg_cli.log.old diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3cd3346..aced62e7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1024,7 +1024,7 @@ Changes in 1.5.0 (9 Sep 2019): * Added the class `chatEventPollStopped` representing the closing of a poll in a message in the chat event log. * Added ability to specify the exact types of problems with a call in the method `sendCallRating` and the new class `CallProblem`. -* Changes in [tdweb](https://github.com/tdlib/td/blob/master/example/web/): +* Changes in [tdweb](https://github.com/tdlight-team/tdlight/blob/master/example/web/): - Supported non-zero `offset` and `limit` in `readFilePart`. ----------------------------------------------------------------------------------------------------------------------- @@ -1034,7 +1034,7 @@ Changes in 1.4.0 (1 May 2019): * Added a [TDLib build instructions generator](https://tdlib.github.io/td/build.html), covering in details TDLib building on the most popular operating systems. * Added an example of TDLib building and usage from a browser. - See https://github.com/tdlib/td/blob/master/example/web/ for more details. + See https://github.com/tdlight-team/tdlight/blob/master/example/web/ for more details. * Allowed to pass NULL pointer to `td_json_client_execute` instead of a previously created JSON client. Now you can use synchronous TDLib methods through a JSON interface before creating a TDLib JSON client. * Added support for media streaming by allowing to download any part of a file: @@ -1285,7 +1285,7 @@ Changes in 1.4.0 (1 May 2019): Changes in 1.3.0 (5 Sep 2018): -* Added a review of existing TDLib based [frameworks](https://github.com/tdlib/td/blob/master/example/README.md) +* Added a review of existing TDLib based [frameworks](https://github.com/tdlight-team/tdlight/blob/master/example/README.md) in different programming languages. * Added a [Getting started](https://core.telegram.org/tdlib/getting-started) guide describing the main TDLib concepts and basic principles required for library usage. diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f1e9681a..135096f08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,9 +207,13 @@ add_subdirectory(sqlite) add_subdirectory(tddb) -add_subdirectory(test) +option(TD_SKIP_TEST "Use \"ON\" to skip building/running the test harness.") +if (NOT TD_SKIP_TEST) + add_subdirectory(test) +endif() -if (NOT CMAKE_CROSSCOMPILING) +option(TD_SKIP_BENCHMARK "Use \"ON\" to skip building/running the benchmarks.") +if (NOT CMAKE_CROSSCOMPILING AND NOT TD_SKIP_BENCHMARK) add_subdirectory(benchmark) endif() @@ -505,6 +509,7 @@ set(TDLIB_SOURCE td/telegram/StickersManager.cpp td/telegram/StickerType.cpp td/telegram/StorageManager.cpp + td/telegram/MemoryManager.cpp td/telegram/StoryContent.cpp td/telegram/StoryContentType.cpp td/telegram/StoryDb.cpp @@ -850,6 +855,7 @@ set(TDLIB_SOURCE td/telegram/StickersManager.h td/telegram/StickerType.h td/telegram/StorageManager.h + td/telegram/MemoryManager.h td/telegram/StoryContent.h td/telegram/StoryContentType.h td/telegram/StoryDb.h @@ -1124,6 +1130,8 @@ endif() #EXECUTABLES if (NOT CMAKE_CROSSCOMPILING) +option(TD_SKIP_TG_CLI "Use \"ON\" to skip building tg_cli.") +if (NOT CMAKE_CROSSCOMPILING AND NOT TD_SKIP_TG_CLI) add_executable(tg_cli td/telegram/cli.cpp ${TL_TD_JSON_SOURCE}) if (NOT READLINE_FOUND) @@ -1152,6 +1160,7 @@ if (NOT CMAKE_CROSSCOMPILING) target_link_libraries(tg_cli PRIVATE memprof tdclient tdcore) add_dependencies(tg_cli tl_generate_json) endif() +endif() #Exported libraries add_library(TdStatic INTERFACE) diff --git a/README.md b/README.md index a92c908c9..2fe619d86 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ -# TDLib +# TDLight -TDLib (Telegram Database library) is a cross-platform library for building [Telegram](https://telegram.org) clients. It can be easily used from almost any programming language. +TDLight is a fork of TDLib, a cross-platform library for building [Telegram](https://telegram.org) clients. It can be easily used from almost any programming language. ## Table of Contents - [Features](#features) +- [TDLight extra features](#tdlight-extra-features) +- [TDLight extra API functions](#tdlight-extra-api-functions) +- [TDLight recommended options](#tdlight-recommended-options) - [Examples and documentation](#usage) - [Dependencies](#dependencies) - [Building](#building) @@ -28,17 +31,42 @@ TDLib (Telegram Database library) is a cross-platform library for building [Tele * **Secure**: all local data is encrypted using a user-provided encryption key. * **Fully-asynchronous**: requests to `TDLib` don't block each other or anything else, responses are sent when they are available. + +### TDLight extra features +#### TDLight extra options +* **disable_minithumbnails** (true/**false**) This setting removes minithumbnails everywhere. It reduces memory usage because tdlib keeps them in RAM +* **disable_document_filenames** (true/**false**) If you don't care about having the original filenames of every file stored in RAM, you can disable them using this option. It reduces memory usage +* **disable_notifications** (true/**false**) In TDLib pending notification updates are stored in ram until you "read" them. This option disables completely notifications and keeps the pending notifications queue empty, reducing memory usage +* **ignore_update_chat_last_message** (true/**false**) If you don't care about have updateChatLastMessage updates enable this +* **ignore_update_chat_read_inbox** (true/**false**) If you don't care about have updateChatReadInbox updates enable this +* **ignore_update_user_chat_action** (true/**false**) If you don't care about have updateUserChatAction updates enable this +* **ignore_server_deletes_and_reads** (true/**false**) If you don't care about receiving read receipts and remote deletes from other users, enable this, it will reduce memory usage +* **receive_access_hashes** (true/**false**) Receive chats and users access hash as updates +* **disable_auto_download** (true/**false**) Forcefully ignore auto download settings of all sessions + +### TDLight extra API functions +#### TdApi.GetMemoryStatistics +This method is used to read the size of all the internal TDLib data structures. +The output contains a string that can be parsed as a JSON. + +## TDLight recommended options +* Options: + * ignore_inline_thumbnails: true + * disable_top_chats: true + * ignore_platform_restrictions: true + * ignore_sensitive_content_restrictions: true +* Disable all the databases (messages_db, users_db, files_db) ## Examples and documentation See our [Getting Started](https://core.telegram.org/tdlib/getting-started) tutorial for a description of basic TDLib concepts. -Take a look at our [examples](https://github.com/tdlib/td/blob/master/example/README.md#tdlib-usage-and-build-examples). +Take a look at our [examples](https://github.com/tdlight-team/tdlight/blob/master/example/README.md#tdlib-usage-and-build-examples). -See a [TDLib build instructions generator](https://tdlib.github.io/td/build.html) for detailed instructions on how to build TDLib. +See a [TDLight build instructions generator](https://tdlight-team.github.io/tdlight/build.html) for detailed instructions on how to build TDLib. See description of our [JSON](#using-json), [C++](#using-cxx), [Java](#using-java) and [.NET](#using-dotnet) interfaces. -See the [td_api.tl](https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl) scheme or the automatically generated [HTML documentation](https://core.telegram.org/tdlib/docs/td__api_8h.html) +See the [td_api.tl](https://github.com/tdlight-team/tdlight/blob/master/td/generate/scheme/td_api.tl) scheme or the automatically generated [HTML documentation](https://core.telegram.org/tdlib/docs/td__api_8h.html) for a list of all available `TDLib` [methods](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html) and [classes](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_object.html). @@ -55,7 +83,7 @@ for a list of all available `TDLib` [methods](https://core.telegram.org/tdlib/do ## Building -The simplest way to build `TDLib` is to use our [TDLib build instructions generator](https://tdlib.github.io/td/build.html). +The simplest way to build `TDLight` is to use our [TDLight build instructions generator](https://tdlight-team.github.io/tdlight/build.html). You need only to choose your programming language and target operating system to receive complete build instructions. In general, you need to install all `TDLib` [dependencies](#dependencies), enter directory containing `TDLib` sources and compile them using CMake: @@ -67,7 +95,7 @@ cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build . ``` -To build `TDLib` on low memory devices you can run [SplitSource.php](https://github.com/tdlib/td/blob/master/SplitSource.php) script +To build `TDLib` on low memory devices you can run [SplitSource.php](https://github.com/tdlight-team/tdlight/blob/master/SplitSource.php) script before compiling main `TDLib` source code and compile only needed targets: ``` mkdir build @@ -106,21 +134,21 @@ Or you could install `TDLib` and then reference it in your CMakeLists.txt like t find_package(Td 1.8.26 REQUIRED) target_link_libraries(YourTarget PRIVATE Td::TdStatic) ``` -See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/blob/master/example/cpp/CMakeLists.txt). +See [example/cpp/CMakeLists.txt](https://github.com/tdlight-team/tdlight/blob/master/example/cpp/CMakeLists.txt). ## Using in Java projects `TDLib` provides native Java interface through JNI. To enable it, specify option `-DTD_ENABLE_JNI=ON` to CMake. -See [example/java](https://github.com/tdlib/td/tree/master/example/java) for example of using `TDLib` from Java and detailed build and usage instructions. +See [example/java](https://github.com/tdlight-team/tdlight/tree/master/example/java) for example of using `TDLib` from Java and detailed build and usage instructions. ## Using in .NET projects `TDLib` provides native .NET interface through `C++/CLI` and `C++/CX`. To enable it, specify option `-DTD_ENABLE_DOTNET=ON` to CMake. .NET Core supports `C++/CLI` only since version 3.1 and only on Windows, so if older .NET Core is used or portability is needed, then `TDLib` JSON interface should be used through P/Invoke instead. -See [example/csharp](https://github.com/tdlib/td/tree/master/example/csharp) for example of using `TDLib` from C# and detailed build and usage instructions. -See [example/uwp](https://github.com/tdlib/td/tree/master/example/uwp) for example of using `TDLib` from C# UWP application and detailed build and usage instructions for Visual Studio Extension "TDLib for Universal Windows Platform". +See [example/csharp](https://github.com/tdlight-team/tdlight/tree/master/example/csharp) for example of using `TDLib` from C# and detailed build and usage instructions. +See [example/uwp](https://github.com/tdlight-team/tdlight/tree/master/example/uwp) for example of using `TDLib` from C# UWP application and detailed build and usage instructions for Visual Studio Extension "TDLib for Universal Windows Platform". When `TDLib` is built with `TD_ENABLE_DOTNET` option enabled, `C++` documentation is removed from some files. You need to checkout these files to return `C++` documentation back: ``` @@ -132,13 +160,13 @@ git checkout td/telegram/Client.h td/telegram/Log.h td/tl/TlObject.h `TDLib` provides efficient native C++, Java, and .NET interfaces. But for most use cases we suggest to use the JSON interface, which can be easily used with any programming language that is able to execute C functions. See [td_json_client](https://core.telegram.org/tdlib/docs/td__json__client_8h.html) documentation for detailed JSON interface description, -the [td_api.tl](https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl) scheme or the automatically generated [HTML documentation](https://core.telegram.org/tdlib/docs/td__api_8h.html) for a list of +the [td_api.tl](https://github.com/tdlight-team/tdlight/blob/master/td/generate/scheme/td_api.tl) scheme or the automatically generated [HTML documentation](https://core.telegram.org/tdlib/docs/td__api_8h.html) for a list of all available `TDLib` [methods](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html) and [classes](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_object.html). `TDLib` JSON interface adheres to semantic versioning and versions with the same major version number are binary and backward compatible, but the underlying `TDLib` API can be different for different minor and even patch versions. If you need to support different `TDLib` versions, then you can use a value of the `version` option to find exact `TDLib` version to use appropriate API methods. -See [example/python/tdjson_example.py](https://github.com/tdlib/td/blob/master/example/python/tdjson_example.py) for an example of such usage. +See [example/python/tdjson_example.py](https://github.com/tdlight-team/tdlight/tree/master/example/python/tdjson_example.py) for an example of such usage. ## License diff --git a/build.html b/build.html index b3829c87a..30b7d326f 100644 --- a/build.html +++ b/build.html @@ -2,7 +2,7 @@ - TDLib build instructions + TDLight build instructions