Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Oct 21, 2021
1 parent 1ebf835 commit 9f44816
Show file tree
Hide file tree
Showing 69 changed files with 177 additions and 174 deletions.
1 change: 1 addition & 0 deletions benchmark/bench_tddb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "td/telegram/ServerMessageId.h"
#include "td/telegram/UserId.h"

#include "td/db/DbKey.h"
#include "td/db/SqliteConnectionSafe.h"
#include "td/db/SqliteDb.h"

Expand Down
4 changes: 2 additions & 2 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4197,7 +4197,7 @@ deleteChatHistory chat_id:int53 remove_from_chat_list:Bool revoke:Bool = Ok;
deleteChat chat_id:int53 = Ok;

//@description Searches for messages with given words in the chat. Returns the results in reverse chronological order, i.e. in order of decreasing message_id. Cannot be used in secret chats with a non-empty query
//-(searchSecretMessages mmust be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
//-(searchSecretMessages must be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
//@chat_id Identifier of the chat in which to search messages
//@query Query to search for
//@sender Sender of messages to search for; pass null to search for messages from any sender. Not supported in secret chats
Expand Down Expand Up @@ -4725,7 +4725,7 @@ addChatMember chat_id:int53 user_id:int53 forward_limit:int32 = Ok;
//@chat_id Chat identifier @user_ids Identifiers of the users to be added to the chat. The maximum number of added users is 20 for supergroups and 100 for channels
addChatMembers chat_id:int53 user_ids:vector<int53> = Ok;

//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if you need to pass some additional parameters
//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if some additional parameters needs to be passed
//@chat_id Chat identifier @member_id Member identifier. Chats can be only banned and unbanned in supergroups and channels @status The new status of the member in the chat
setChatMemberStatus chat_id:int53 member_id:MessageSender status:ChatMemberStatus = Ok;

Expand Down
8 changes: 4 additions & 4 deletions td/generate/tl_writer_jni_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,

if (!(tree_type->flags & tl::FLAG_BARE)) {
if (is_type_bare(t)) {
if (field_name != "") {
if (!field_name.empty()) {
std::fprintf(stderr, "Do not use non-bare fields with bare type %s\n", name.c_str());
// assert(false);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,
const tl::tl_tree_type *child = static_cast<const tl::tl_tree_type *>(tree_type->children[0]);
res = gen_vector_fetch(field_name, child, vars, parser_type);
} else {
if (field_name == "") {
if (field_name.empty()) {
return gen_main_class_name(tree_type->type) + "::fetch(env, p)";
}
res = "jni::fetch_tl_object<" + gen_main_class_name(tree_type->type) + ">(env, jni::fetch_object(env, p, " +
Expand Down Expand Up @@ -565,14 +565,14 @@ std::string TD_TL_writer_jni_cpp::gen_additional_function(const std::string &fun
" " +
class_name_class + " = jni::get_jclass(env, " + gen_java_class_name(gen_class_name(t->name)) + ");\n";

if (t->args.size()) {
if (!t->args.empty()) {
for (std::size_t i = 0; i < t->args.size(); i++) {
const tl::arg &a = t->args[i];
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
const tl::tl_tree_type *tree_type = static_cast<tl::tl_tree_type *>(a.type);

std::string field_name = gen_field_name(a.name);
assert(field_name.size());
assert(!field_name.empty());
std::string java_field_name = gen_java_field_name(std::string(field_name, 0, field_name.size() - 1));

std::string type_signature = gen_type_signature(tree_type);
Expand Down
1 change: 1 addition & 0 deletions td/mtproto/Ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "td/actor/PromiseFuture.h"

#include "td/utils/common.h"
#include "td/utils/Slice.h"

namespace td {
namespace mtproto {
Expand Down
5 changes: 3 additions & 2 deletions td/mtproto/RawConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,10 @@ class RawConnectionHttp final : public RawConnection {
unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
unique_ptr<StatsCallback> stats_callback) {
#if TD_DARWIN_WATCH_OS
return td::make_unique<RawConnectionHttp>(ip_address, std::move(stats_callback));
return td::make_unique<RawConnectionHttp>(std::move(ip_address), std::move(stats_callback));
#else
return td::make_unique<RawConnectionDefault>(std::move(socket_fd), transport_type, std::move(stats_callback));
return td::make_unique<RawConnectionDefault>(std::move(socket_fd), std::move(transport_type),
std::move(stats_callback));
#endif
}

Expand Down
1 change: 0 additions & 1 deletion td/telegram/CallbackQueriesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Random.h"
#include "td/utils/Status.h"

namespace td {
Expand Down
2 changes: 0 additions & 2 deletions td/telegram/CallbackQueriesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"

#include <unordered_map>

namespace td {

class Td;
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/ClientActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace td {

ClientActor::ClientActor(unique_ptr<TdCallback> callback, Options options) {
Td::Options td_options;
td_options.net_query_stats = options.net_query_stats;
td_options.net_query_stats = std::move(options.net_query_stats);
td_ = create_actor<Td>("Td", std::move(callback), std::move(td_options));
}

Expand Down
1 change: 0 additions & 1 deletion td/telegram/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "td/utils/common.h"
#include "td/utils/FloodControlStrict.h"
#include "td/utils/logging.h"
#include "td/utils/port/IPAddress.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"
Expand Down
6 changes: 3 additions & 3 deletions td/telegram/ContactsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1308,17 +1308,17 @@ class ContactsManager final : public Actor {
void load_secret_chat_from_database_impl(SecretChatId secret_chat_id, Promise<Unit> promise);
void on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value, bool force);

void save_user_full(const UserFull *user_full, UserId user_id);
static void save_user_full(const UserFull *user_full, UserId user_id);
static string get_user_full_database_key(UserId user_id);
static string get_user_full_database_value(const UserFull *user_full);
void on_load_user_full_from_database(UserId user_id, string value);

void save_chat_full(const ChatFull *chat_full, ChatId chat_id);
static void save_chat_full(const ChatFull *chat_full, ChatId chat_id);
static string get_chat_full_database_key(ChatId chat_id);
static string get_chat_full_database_value(const ChatFull *chat_full);
void on_load_chat_full_from_database(ChatId chat_id, string value);

void save_channel_full(const ChannelFull *channel_full, ChannelId channel_id);
static void save_channel_full(const ChannelFull *channel_full, ChannelId channel_id);
static string get_channel_full_database_key(ChannelId channel_id);
static string get_channel_full_database_value(const ChannelFull *channel_full);
void on_load_channel_full_from_database(ChannelId channel_id, string value, const char *source);
Expand Down
2 changes: 0 additions & 2 deletions td/telegram/DelayDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "td/telegram/Global.h"
#include "td/telegram/net/NetQueryDispatcher.h"

#include "td/utils/Status.h"

namespace td {

void DelayDispatcher::send_with_callback(NetQueryPtr query, ActorShared<NetQueryCallback> callback) {
Expand Down
1 change: 0 additions & 1 deletion td/telegram/DialogParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"

#include <limits>

Expand Down
1 change: 1 addition & 0 deletions td/telegram/DraftMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
#pragma once

#include "td/telegram/DialogId.h"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/td_api.h"
Expand Down
1 change: 1 addition & 0 deletions td/telegram/FileReferenceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/WebPageId.h"
#include "td/telegram/WebPagesManager.h"

#include "td/utils/algorithm.h"
Expand Down
1 change: 1 addition & 0 deletions td/telegram/GroupCallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessagesManager.h"
Expand Down
2 changes: 2 additions & 0 deletions td/telegram/MessageContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4006,6 +4006,8 @@ unique_ptr<MessageContent> get_secret_message_content(
FormattedText{std::move(message_text), std::move(entities)}, false,
&load_data_multipromise);
}
default:
break;
}
if (file == nullptr && !is_media_empty) {
LOG(ERROR) << "Received secret message with media, but without a file";
Expand Down
1 change: 1 addition & 0 deletions td/telegram/MessageContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

#include <utility>
Expand Down
6 changes: 4 additions & 2 deletions td/telegram/MessagesDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <array>
#include <iterator>
#include <limits>
#include <tuple>
#include <utility>

namespace td {
Expand Down Expand Up @@ -850,8 +851,9 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
SqliteStatement delete_scheduled_message_stmt_;
SqliteStatement delete_scheduled_server_message_stmt_;

Result<vector<MessagesDbDialogMessage>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
MessageId from_message_id, int32 offset, int32 limit) {
static Result<vector<MessagesDbDialogMessage>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
MessageId from_message_id, int32 offset,
int32 limit) {
LOG_CHECK(dialog_id.is_valid()) << dialog_id;
CHECK(from_message_id.is_valid());

Expand Down
2 changes: 1 addition & 1 deletion td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18167,7 +18167,7 @@ void MessagesManager::on_reorder_dialog_filters(vector<DialogFilterId> dialog_fi
if (result.is_error()) {
// TODO rollback dialog_filters_ changes if error isn't 429
} else {
if (set_dialog_filters_order(server_dialog_filters_, dialog_filter_ids)) {
if (set_dialog_filters_order(server_dialog_filters_, std::move(dialog_filter_ids))) {
save_dialog_filters();
}
}
Expand Down
3 changes: 2 additions & 1 deletion td/telegram/MessagesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "td/telegram/MessageSearchFilter.h"
#include "td/telegram/MessageThreadInfo.h"
#include "td/telegram/MessageTtlSetting.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/Notification.h"
#include "td/telegram/NotificationGroupId.h"
Expand Down Expand Up @@ -1816,7 +1817,7 @@ class MessagesManager final : public Actor {

void on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id, FileId thumbnail_file_id,
bool was_uploaded, bool was_thumbnail_uploaded, string file_reference,
int32 scheduled_date, uint64 generation, Result<int32> &&result);
int32 schedule_date, uint64 generation, Result<int32> &&result);

static MessageId get_persistent_message_id(const Dialog *d, MessageId message_id);

Expand Down
2 changes: 1 addition & 1 deletion td/telegram/StickersManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6643,7 +6643,7 @@ string StickersManager::get_language_emojis_database_key(const string &language_
}

vector<string> StickersManager::search_language_emojis(const string &language_code, const string &text,
bool exact_match) const {
bool exact_match) {
LOG(INFO) << "Search for \"" << text << "\" in language " << language_code;
auto key = get_language_emojis_database_key(language_code, text);
if (exact_match) {
Expand Down
3 changes: 2 additions & 1 deletion td/telegram/StickersManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
#pragma once

#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/FullMessageId.h"
Expand Down Expand Up @@ -658,7 +659,7 @@ class StickersManager final : public Actor {

void on_get_language_codes(const string &key, Result<vector<string>> &&result);

vector<string> search_language_emojis(const string &language_code, const string &text, bool exact_match) const;
static vector<string> search_language_emojis(const string &language_code, const string &text, bool exact_match);

void load_emoji_keywords(const string &language_code, Promise<Unit> &&promise);

Expand Down
1 change: 1 addition & 0 deletions td/telegram/StorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "td/telegram/StorageManager.h"

#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileGcWorker.h"
#include "td/telegram/files/FileStatsWorker.h"
#include "td/telegram/Global.h"
Expand Down
3 changes: 1 addition & 2 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
#include "td/telegram/Td.h"

#include "td/telegram/AccessRights.h"
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h"
Expand Down Expand Up @@ -170,7 +169,7 @@ void Td::ResultHandler::on_result(NetQueryPtr query) {

void Td::ResultHandler::send_query(NetQueryPtr query) {
td->add_handler(query->id(), shared_from_this());
td->send(std::move(query));
send(std::move(query));
}

class GetPromoDataQuery final : public Td::ResultHandler {
Expand Down
1 change: 1 addition & 0 deletions td/telegram/ThemeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "td/utils/logging.h"
#include "td/utils/Random.h"
#include "td/utils/Time.h"
#include "td/utils/tl_helpers.h"

namespace td {

Expand Down
8 changes: 4 additions & 4 deletions td/telegram/TopDialogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
#include "td/telegram/TdParameters.h"
#include "td/telegram/telegram_api.h"

#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/port/Clocks.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
#include "td/utils/tl_helpers.h"
Expand Down Expand Up @@ -124,11 +121,14 @@ class ResetTopPeerRatingQuery final : public Td::ResultHandler {

void on_error(uint64 id, Status status) final {
if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ResetTopPeerRatingQuery")) {
LOG(INFO) << "Receive error for resetTopPeerRating: " << status;
LOG(INFO) << "Receive error for ResetTopPeerRatingQuery: " << status;
}
}
};

TopDialogManager::TopDialogManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}

void TopDialogManager::update_is_enabled(bool is_enabled) {
if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) {
return;
Expand Down
9 changes: 5 additions & 4 deletions td/telegram/TopDialogManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#pragma once

#include "td/telegram/DialogId.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/TopDialogCategory.h"

#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"

#include "td/utils/common.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"

#include <array>
Expand All @@ -24,8 +26,7 @@ class Td;

class TopDialogManager final : public Actor {
public:
TopDialogManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
TopDialogManager(Td *td, ActorShared<> parent);

void init();

Expand Down Expand Up @@ -67,7 +68,7 @@ class TopDialogManager final : public Actor {
size_t limit;
Promise<vector<DialogId>> promise;
};
std::vector<GetTopDialogsQuery> pending_get_top_dialogs_;
vector<GetTopDialogsQuery> pending_get_top_dialogs_;

struct TopDialog {
DialogId dialog_id;
Expand All @@ -80,7 +81,7 @@ class TopDialogManager final : public Actor {
struct TopDialogs {
bool is_dirty = false;
double rating_timestamp = 0;
std::vector<TopDialog> dialogs;
vector<TopDialog> dialogs;
};
template <class StorerT>
friend void store(const TopDialog &top_dialog, StorerT &storer);
Expand Down
Loading

0 comments on commit 9f44816

Please sign in to comment.