Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2022-06-05 18:32:00 +02:00
commit f85e534704
27 changed files with 158 additions and 75 deletions

View File

@ -321,6 +321,7 @@ set(TDLIB_SOURCE
td/telegram/DialogParticipant.cpp
td/telegram/DialogParticipantFilter.cpp
td/telegram/DialogSource.cpp
td/telegram/Dimensions.cpp
td/telegram/Document.cpp
td/telegram/DocumentsManager.cpp
td/telegram/DownloadManager.cpp
@ -525,6 +526,7 @@ set(TDLIB_SOURCE
td/telegram/DialogParticipant.h
td/telegram/DialogParticipantFilter.h
td/telegram/DialogSource.h
td/telegram/Dimensions.h
td/telegram/Document.h
td/telegram/DocumentsManager.h
td/telegram/DownloadManager.h
@ -699,6 +701,7 @@ set(TDLIB_SOURCE
td/telegram/AuthManager.hpp
td/telegram/BackgroundType.hpp
td/telegram/DialogFilter.hpp
td/telegram/Dimensions.hpp
td/telegram/Document.hpp
td/telegram/DocumentsManager.hpp
td/telegram/DraftMessage.hpp

View File

@ -59,13 +59,13 @@ set(JAVA_SOURCE_PATH "${TD_API_JAVA_PATH}/${TD_API_JAVA_PACKAGE}")
get_filename_component(JAVA_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin REALPATH BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
file(MAKE_DIRECTORY ${JAVA_OUTPUT_DIRECTORY})
add_custom_target(build_java
COMMAND ${Java_JAVAC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY} ${JAVA_SOURCE_PATH}/example/Example.java ${JAVA_SOURCE_PATH}/Client.java ${JAVA_SOURCE_PATH}/Log.java ${JAVA_SOURCE_PATH}/TdApi.java
COMMAND ${Java_JAVAC_EXECUTABLE} -encoding UTF-8 -d ${JAVA_OUTPUT_DIRECTORY} ${JAVA_SOURCE_PATH}/example/Example.java ${JAVA_SOURCE_PATH}/Client.java ${JAVA_SOURCE_PATH}/Log.java ${JAVA_SOURCE_PATH}/TdApi.java
COMMENT "Building Java code"
DEPENDS td_generate_java_api
)
add_custom_target(generate_javadoc
COMMAND ${Java_JAVADOC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY}/../docs org.drinkless.tdlib
COMMAND ${Java_JAVADOC_EXECUTABLE} -encoding UTF-8 -d ${JAVA_OUTPUT_DIRECTORY}/../docs org.drinkless.tdlib
WORKING_DIRECTORY ${TD_API_JAVA_PATH}
COMMENT "Generating Javadoc documentation"
DEPENDS td_generate_java_api

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/PhotoSize.h"

View File

@ -24,6 +24,8 @@
#include "td/utils/port/RwMutex.h"
#include "td/utils/port/thread.h"
#include "td/utils/Slice.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/utf8.h"
#include <algorithm>
#include <atomic>
@ -679,7 +681,18 @@ static std::atomic<ClientManager::LogMessageCallbackPtr> log_message_callback;
static void log_message_callback_wrapper(int verbosity_level, CSlice message) {
auto callback = log_message_callback.load(std::memory_order_relaxed);
if (callback != nullptr) {
callback(verbosity_level, message.c_str());
if (check_utf8(message)) {
callback(verbosity_level, message.c_str());
} else {
size_t pos = 0;
while (1 <= message[pos] && message[pos] <= 126) {
pos++;
}
CHECK(pos + 1 < message.size());
auto utf8_message = PSTRING() << message.substr(0, pos)
<< url_encode(message.substr(pos, message.size() - pos - 1)) << '\n';
callback(verbosity_level, utf8_message.c_str());
}
}
}

View File

@ -129,7 +129,7 @@ class ClientManager final {
* \param verbosity_level Log verbosity level with which the message was added (-1 - 1024).
* If 0, then TDLib will crash as soon as the callback returns.
* None of the TDLib methods can be called from the callback.
* \param message Null-terminated string with the message added to the log.
* \param message Null-terminated UTF-8-encoded string with the message added to the log.
*/
using LogMessageCallbackPtr = void (*)(int verbosity_level, const char *message);

View File

@ -15810,7 +15810,7 @@ void ContactsManager::reload_dialog_administrators(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::chatAdministrators>> &&promise) {
auto dialog_type = dialog_id.get_type();
if (dialog_type == DialogType::Chat && !get_chat_permissions(dialog_id.get_chat_id()).is_member()) {
return promise.set_value(td_api::object_ptr<td_api::chatAdministrators>());
return promise.set_value(td_api::make_object<td_api::chatAdministrators>());
}
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), dialog_id, promise = std::move(promise)](Result<Unit> &&result) mutable {

View File

@ -532,6 +532,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
return string_builder;
case DialogParticipantStatus::Type::Administrator:
string_builder << status.get_administrator_rights();
if (status.can_be_edited()) {
string_builder << "(can_be_edited)";
}
if (!status.rank_.empty()) {
string_builder << " [" << status.rank_ << "]";
}

View File

@ -0,0 +1,51 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/Dimensions.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
namespace td {
static uint16 get_dimension(int32 size, const char *source) {
if (size < 0 || size > 65535) {
if (source != nullptr) {
LOG(ERROR) << "Wrong image dimension = " << size << " from " << source;
}
return 0;
}
return narrow_cast<uint16>(size);
}
Dimensions get_dimensions(int32 width, int32 height, const char *source) {
Dimensions result;
result.width = get_dimension(width, source);
result.height = get_dimension(height, source);
if (result.width == 0 || result.height == 0) {
result.width = 0;
result.height = 0;
}
return result;
}
uint32 get_dimensions_pixel_count(const Dimensions &dimensions) {
return static_cast<uint32>(dimensions.width) * static_cast<uint32>(dimensions.height);
}
bool operator==(const Dimensions &lhs, const Dimensions &rhs) {
return lhs.width == rhs.width && lhs.height == rhs.height;
}
bool operator!=(const Dimensions &lhs, const Dimensions &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimensions) {
return string_builder << "(" << dimensions.width << ", " << dimensions.height << ")";
}
} // namespace td

28
td/telegram/Dimensions.h Normal file
View File

@ -0,0 +1,28 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
struct Dimensions {
uint16 width = 0;
uint16 height = 0;
};
Dimensions get_dimensions(int32 width, int32 height, const char *source);
uint32 get_dimensions_pixel_count(const Dimensions &dimensions);
bool operator==(const Dimensions &lhs, const Dimensions &rhs);
bool operator!=(const Dimensions &lhs, const Dimensions &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimensions);
} // namespace td

View File

@ -0,0 +1,28 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/Dimensions.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void store(Dimensions dimensions, StorerT &storer) {
store(static_cast<uint32>((static_cast<uint32>(dimensions.width) << 16) | dimensions.height), storer);
}
template <class ParserT>
void parse(Dimensions &dimensions, ParserT &parser) {
uint32 width_height;
parse(width_height, parser);
dimensions.width = static_cast<uint16>(width_height >> 16);
dimensions.height = static_cast<uint16>(width_height & 0xFFFF);
}
} // namespace td

View File

@ -9,6 +9,7 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLocation.h"

View File

@ -711,7 +711,7 @@ static bool tolower_begins_with(Slice str, Slice prefix) {
Result<string> LinkManager::check_link(CSlice link, bool http_only, bool https_only) {
auto result = check_link_impl(link, http_only, https_only);
if (result.is_ok()) {
return std::move(result);
return result;
}
auto error = result.move_as_error();
if (check_utf8(link)) {

View File

@ -19,6 +19,7 @@
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/DocumentsManager.hpp"

View File

@ -23805,6 +23805,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
}
if (from_the_end && last_added_message_id.is_valid()) {
CHECK(next_message != nullptr);
// CHECK(d->first_database_message_id.is_valid());
// CHECK(last_added_message_id >= d->first_database_message_id);
if ((had_full_history || d->have_full_history) && !d->last_new_message_id.is_valid() &&
@ -23820,6 +23821,10 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
}
if (last_added_message_id != d->last_database_message_id && d->last_new_message_id.is_valid()) {
auto debug_last_database_message_id = d->last_database_message_id;
auto debug_set_dialog_last_database_message_id = d->debug_set_dialog_last_database_message_id;
if (!d->first_database_message_id.is_valid() && !d->last_database_message_id.is_valid()) {
set_dialog_first_database_message_id(d, next_message->message_id, "on_get_history_from_database 5");
}
set_dialog_last_database_message_id(d, last_added_message_id, "on_get_history_from_database 5");
if (last_added_message_id < d->first_database_message_id || !d->first_database_message_id.is_valid()) {
CHECK(next_message != nullptr);
@ -23828,7 +23833,10 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
<< last_added_message_id << ' ' << d->first_database_message_id << ' ' << debug_first_database_message_id
<< ' ' << d->last_database_message_id << ' ' << debug_last_database_message_id << ' ' << dialog_id << ' '
<< d->last_new_message_id << ' ' << debug_last_new_message_id << ' ' << d->last_message_id << ' '
<< debug_last_message_id;
<< debug_last_message_id << ' ' << debug_set_dialog_last_database_message_id << ' '
<< d->debug_set_dialog_last_database_message_id << ' ' << first_received_message_id << ' '
<< last_received_message_id << ' ' << d->debug_first_database_message_id << ' '
<< d->debug_last_database_message_id << ' ' << d->debug_last_new_message_id;
CHECK(next_message->message_id <= d->last_database_message_id);
LOG(ERROR) << "Fix first database message in " << dialog_id << " from " << d->first_database_message_id
<< " to " << next_message->message_id;

View File

@ -8,6 +8,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/Global.h"

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/Photo.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileEncryptionKey.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h"

View File

@ -23,43 +23,6 @@
namespace td {
static uint16 get_dimension(int32 size, const char *source) {
if (size < 0 || size > 65535) {
if (source != nullptr) {
LOG(ERROR) << "Wrong image dimension = " << size << " from " << source;
}
return 0;
}
return narrow_cast<uint16>(size);
}
Dimensions get_dimensions(int32 width, int32 height, const char *source) {
Dimensions result;
result.width = get_dimension(width, source);
result.height = get_dimension(height, source);
if (result.width == 0 || result.height == 0) {
result.width = 0;
result.height = 0;
}
return result;
}
static uint32 get_pixel_count(const Dimensions &dimensions) {
return static_cast<uint32>(dimensions.width) * static_cast<uint32>(dimensions.height);
}
bool operator==(const Dimensions &lhs, const Dimensions &rhs) {
return lhs.width == rhs.width && lhs.height == rhs.height;
}
bool operator!=(const Dimensions &lhs, const Dimensions &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimensions) {
return string_builder << "(" << dimensions.width << ", " << dimensions.height << ")";
}
static int32 get_minithumbnail_size(const string &packed) {
if (packed.size() < 3) {
return 0;
@ -447,8 +410,8 @@ bool operator<(const PhotoSize &lhs, const PhotoSize &rhs) {
if (lhs.size != rhs.size) {
return lhs.size < rhs.size;
}
auto lhs_pixels = get_pixel_count(lhs.dimensions);
auto rhs_pixels = get_pixel_count(rhs.dimensions);
auto lhs_pixels = get_dimensions_pixel_count(lhs.dimensions);
auto rhs_pixels = get_dimensions_pixel_count(rhs.dimensions);
if (lhs_pixels != rhs_pixels) {
return lhs_pixels < rhs_pixels;
}

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/net/DcId.h"
@ -24,11 +25,6 @@ namespace td {
class FileManager;
struct Dimensions {
uint16 width = 0;
uint16 height = 0;
};
struct PhotoSize {
int32 type = 0;
Dimensions dimensions;
@ -41,13 +37,6 @@ struct AnimationSize final : public PhotoSize {
double main_frame_timestamp = 0.0;
};
Dimensions get_dimensions(int32 width, int32 height, const char *source);
bool operator==(const Dimensions &lhs, const Dimensions &rhs);
bool operator!=(const Dimensions &lhs, const Dimensions &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimensions);
bool need_update_dialog_photo_minithumbnail(const string &from, const string &to);
td_api::object_ptr<td_api::minithumbnail> get_minithumbnail_object(const string &packed);

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/Dimensions.hpp"
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/Version.h"
@ -15,19 +16,6 @@
namespace td {
template <class StorerT>
void store(Dimensions dimensions, StorerT &storer) {
store(static_cast<uint32>((static_cast<uint32>(dimensions.width) << 16) | dimensions.height), storer);
}
template <class ParserT>
void parse(Dimensions &dimensions, ParserT &parser) {
uint32 width_height;
parse(width_height, parser);
dimensions.width = static_cast<uint16>(width_height >> 16);
dimensions.height = static_cast<uint16>(width_height & 0xFFFF);
}
template <class StorerT>
void store(const PhotoSize &photo_size, StorerT &storer) {
LOG(DEBUG) << "Store photo size " << photo_size;

View File

@ -6,7 +6,7 @@
//
#pragma once
#include "td/telegram/PhotoSize.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/telegram_api.h"

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/FullMessageId.h"

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/SecretInputMedia.h"

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/SecretInputMedia.h"

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/VoiceNotesManager.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/Td.h"

View File

@ -13,6 +13,7 @@
#include "td/telegram/ChannelId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/DocumentsManager.hpp"
@ -21,7 +22,6 @@
#include "td/telegram/Photo.h"
#include "td/telegram/Photo.hpp"
#include "td/telegram/PhotoFormat.h"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/Td.h"
#include "td/telegram/Version.h"
#include "td/telegram/VideosManager.h"

View File

@ -9,6 +9,7 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h"
#include "td/telegram/Document.hpp"
#include "td/telegram/DocumentsManager.h"
@ -22,7 +23,6 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Photo.h"
#include "td/telegram/PhotoFormat.h"
#include "td/telegram/PhotoSize.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"

View File

@ -91,7 +91,7 @@ TDJSON_EXPORT const char *td_execute(const char *request);
* \param verbosity_level Log verbosity level with which the message was added (-1 - 1024).
* If 0, then TDLib will crash as soon as the callback returns.
* None of the TDLib methods can be called from the callback.
* \param message Null-terminated string with the logged message. The string isn't guaranteed to be encoded in UTF-8.
* \param message Null-terminated UTF-8-encoded string with the message added to the log.
*/
typedef void (*td_log_message_callback_ptr)(int verbosity_level, const char *message);