Merge commit '821398fa211b6a3c53733ccf271ee7a783d9bc75'

Conflicts:
	.gitignore
	td/generate/scheme/td_api.tlo
	td/telegram/ContactsManager.h
This commit is contained in:
Andrea Cavalli 2020-11-04 20:05:50 +01:00
commit 16f41643ed
22 changed files with 222 additions and 151 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ db_backup
*.pyc
docs/
.idea/
vcpkg/

View File

@ -76,5 +76,5 @@ CFlags: -I\"\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}\"
Libs: -L\"\${prefix}/${CMAKE_INSTALL_LIBDIR}\" -l${TARGET}
${REQUIRES}${LIBRARIES}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endfunction()

View File

@ -21,6 +21,10 @@ if (POLICY CMP0054)
# do not expand quoted arguments
cmake_policy(SET CMP0054 NEW)
endif()
if (POLICY CMP0060)
# link libraries by full path
cmake_policy(SET CMP0060 NEW)
endif()
include(PreventInSourceBuild)
prevent_in_source_build()
@ -82,9 +86,9 @@ if (EMSCRIPTEN)
set(ZLIB_INCLUDE_DIR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s MEMFS_APPEND_TO_TYPED_ARRAYS=1 -s USE_ZLIB=1 -s MODULARIZE=1 \
-s EXPORT_NAME=\"'createTdwebModule'\" -s WEBSOCKET_URL=\"'wss:#'\" -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['FS','cwrap']\" -lidbfs.js -lworkerfs.js")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s MEMFS_APPEND_TO_TYPED_ARRAYS=1 -s USE_ZLIB=1 -s \
MODULARIZE=1 -s EXPORT_NAME=\"'createTdwebModule'\" -s WEBSOCKET_URL=\"'wss:#'\" -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['FS','cwrap']\" -lidbfs.js -lworkerfs.js")
-s EXPORT_NAME=\"'createTdwebModule'\" -s WEBSOCKET_URL=\"'wss:#'\" -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['FS','cwrap']\" -lidbfs.js -lworkerfs.js")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s MEMFS_APPEND_TO_TYPED_ARRAYS=1 -s USE_ZLIB=1 -s MODULARIZE=1 \
-s EXPORT_NAME=\"'createTdwebModule'\" -s WEBSOCKET_URL=\"'wss:#'\" -s EXTRA_EXPORTED_RUNTIME_METHODS=\"['FS','cwrap']\" -lidbfs.js -lworkerfs.js")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1")
@ -118,6 +122,14 @@ endif()
include(TdSetUpCompiler)
td_set_up_compiler()
if (MSVC)
option(TD_ENABLE_MULTI_PROCESSOR_COMPILATION "Use \"ON\" to enable multi-processor compilation.")
if (TD_ENABLE_MULTI_PROCESSOR_COMPILATION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
endif()
if (CLANG OR GCC)
if (MEMPROF)
include(CheckCXXCompilerFlag)

View File

@ -10,13 +10,12 @@ select.large { font-size: large; }
</style>
</head>
<body onload="onLoad(true)">
<body onpopstate="onLoad(false)">
<body onload="onLoad(true)" onpopstate="onLoad(false)">
<div class="main">
<div id="languageSelectDiv" align="center">
<div id="languageSelectDiv" style="text-align:center;">
<p>Choose a programming language, from which you want to use TDLib:</p>
<select id="languageSelect" onchange="onLanguageChanged(false)" autofocus="true" class="large">
<select id="languageSelect" onchange="onLanguageChanged(false)" autofocus class="large">
<option>Choose a programming language:</option>
<option>Python</option>
<option>JavaScript</option>
@ -42,7 +41,7 @@ select.large { font-size: large; }
</select>
</div>
<div id="osSelectDiv" class="hide" align="center">
<div id="osSelectDiv" class="hide" style="text-align:center;">
<p>Choose an operating system, on which you want to use TDLib:</p>
<select id="osSelect" onchange="onOsChanged()" class="large">
<option>Choose an operating system:</option>
@ -50,7 +49,7 @@ select.large { font-size: large; }
<p></p>
</div>
<div id="linuxSelectDiv" class="hide" align="center">
<div id="linuxSelectDiv" class="hide" style="text-align:center;">
<p>Choose a Linux distro, on which you want to use TDLib:</p>
<select id="linuxSelect" onchange="onOsChanged()" class="large">
<option>Choose a Linux distro:</option>
@ -67,13 +66,13 @@ select.large { font-size: large; }
<p></p>
</div>
<div id="buildOptionsDiv" class="hide" align="center">
<div id="buildOptionsDiv" class="hide" style="text-align:center;">
<div id="buildLtoDiv" class="hide">
<label><input type="checkbox" id="buildLtoCheckbox" onchange="onOptionsChanged()"/>Enable Link Time Optimization (requires CMake >= 3.9.0). It can significantly reduce binary size and increase performance, but sometimes it can lead to build failures.</label>
</div>
<div id="buildDebugDiv" class="hide">
<label><input type="checkbox" id="buildDebugCheckbox" onchange="onOptionsChanged()"/>Build debug binary. Debug binaries are much larger and slower than release one.</label>
<label><input type="checkbox" id="buildDebugCheckbox" onchange="onOptionsChanged()"/>Build the debug binary. Debug binaries are much larger and slower than the release one.</label>
</div>
<div id="buildInstallLocalDiv" class="hide">
@ -129,12 +128,12 @@ select.large { font-size: large; }
<p></p>
</div>
<div id="buildTextDiv" class="hide" align="center">
<div id="buildTextDiv" class="hide" style="text-align:center;">
<p id="buildText">Hidden text</p>
</div>
<div id="buildCommandsDiv" class="hide" align="left">
<p id="buildCommandsHeader" align="center">Here is complete instruction for TDLib binaries building:</p>
<div id="buildCommandsDiv" class="hide" style="text-align:left;">
<p id="buildCommandsHeader" style="text-align:center;">Here is complete instruction for TDLib binaries building:</p>
<p id="buildPre">Hidden text</p>
<code id="buildCommands">Empty commands</code>
</div>
@ -486,7 +485,7 @@ function onOptionsChanged() {
if (os_windows) {
let win10_sdk = (target === 'C++/CX' ? ' and Windows 10 SDK' : '');
if (target !== 'C++/CLI' && target !== 'C++/CX') {
pre_text.push('Note that Windows Subsystem for Linux (WSL) and Cygwin are not Windows environments, so you need to use instructions for Linux instead for them.');
pre_text.push('Note that Windows Subsystem for Linux (WSL) and Cygwin are not Windows environments, so you need to use instructions for Linux for them instead.');
}
pre_text.push('Download and install <a href="https://visualstudio.microsoft.com/ru/vs/community/">Microsoft Visual Studio</a>. Enable C++' + win10_sdk + ' support while installing.');
pre_text.push('Download and install <a href="https://cmake.org/download/">CMake</a>; choose "Add CMake to the system PATH" option while installing.');
@ -523,15 +522,15 @@ function onOptionsChanged() {
pre_text.push('Note that for Node.js &le; 9.11.2 you must build TDLib with OpenSSL 1.0.* and for Node.js &ge; 10 with OpenSSL 1.1.* instead, so you may need to modify the following commands to install a proper OpenSSL version.');
}
if (os_freebsd) {
pre_text.push('Note that following instruction is for FreeBSD 11.');
pre_text.push('Note that following calls to <code>pkg</code> needs to be run as <code>root</code>.');
pre_text.push('Note that the following instruction is for FreeBSD 11.');
pre_text.push('Note that the following calls to <code>pkg</code> needs to be run as <code>root</code>.');
}
if (os_openbsd) {
pre_text.push('Note that following instruction is for OpenBSD 6.7 and default KSH shell.');
pre_text.push('Note that the following instruction is for OpenBSD 6.7 and default KSH shell.');
pre_text.push('Note that building requires a lot of memory, so you may need to increase allowed per-process memory usage in /etc/login.conf or build from root.');
}
if (os_netbsd) {
pre_text.push('Note that following instruction is for NetBSD 8.0 and default SH shell.');
pre_text.push('Note that the following instruction is for NetBSD 8.0 and default SH shell.');
}
var terminal_name = (function () {
@ -553,7 +552,7 @@ function onOptionsChanged() {
return 'Bash';
})();
if (os_windows) {
pre_text.push('Close and re-open ' + terminal_name + ' if PATH environment variable was changed.');
pre_text.push('Close and re-open ' + terminal_name + ' if the PATH environment variable was changed.');
}
pre_text.push('Run these commands in ' + terminal_name + ' to build TDLib and to install it to ' + install_dir + ':');
document.getElementById('buildPre').innerHTML = '<ul><li>' + pre_text.join('</li><li>') + '</li></ul>';
@ -904,4 +903,3 @@ function onOptionsChanged() {
</body>
</html>

View File

@ -1691,8 +1691,8 @@ messagePassportDataSent types:vector<PassportElementType> = MessageContent;
//@description Telegram Passport data has been received; for bots only @elements List of received Telegram Passport elements @credentials Encrypted data credentials
messagePassportDataReceived elements:vector<encryptedPassportElement> credentials:encryptedCredentials = MessageContent;
//@description A user in the chat came within proximity alert range @approacher The user or chat, which approached another user @observer The user or chat, which subscribed for the proximity alert @distance The distance between the users
messageProximityAlertTriggered approacher:MessageSender observer:MessageSender distance:int32 = MessageContent;
//@description A user in the chat came within proximity alert range @traveler The user or chat, which triggered the proximity alert @watcher The user or chat, which subscribed for the proximity alert @distance The distance between the users
messageProximityAlertTriggered traveler:MessageSender watcher:MessageSender distance:int32 = MessageContent;
//@description Message content that is not supported in the current TDLib version
messageUnsupported = MessageContent;
@ -3668,7 +3668,7 @@ getCreatedPublicChats type:PublicChatType = Chats;
//@description Checks whether the maximum number of owned public chats has been reached. Returns corresponding error if the limit was reached @type Type of the public chats, for which to check the limit
checkCreatedPublicChatsLimit type:PublicChatType = Ok;
//@description Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Basic group chats need to be first upgraded to supergroups before they can be set as a discussion group
//@description Returns a list of basic group and supergroup chats, which can be used as a discussion group for a channel. Returned basic group chats must be first upgraded to supergroups before they can be set as a discussion group. To set a returned supergroup as a discussion group, access to its old messages must be enabled using toggleSupergroupIsAllHistoryAvailable first
getSuitableDiscussionChats = Chats;
//@description Returns a list of recently inactive supergroups and channels. Can be used when user reaches limit on the number of joined supergroups and channels and receives CHANNELS_TOO_MUCH error
@ -3754,7 +3754,7 @@ getChatMessageCount chat_id:int53 filter:SearchMessagesFilter return_local:Bool
//@description Returns all scheduled messages in a chat. The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id) @chat_id Chat identifier
getChatScheduledMessages chat_id:int53 = Messages;
//@description Returns forwarded copies of a channel message to another public channels. For optimal performance the number of returned messages is chosen by the library. The method is under development and may or may not work
//@description Returns forwarded copies of a channel message to different public channels. For optimal performance the number of returned messages is chosen by the library
//@chat_id Chat identifier of the message
//@message_id Message identifier
//@offset Offset of the first entry to return as received from the previous request; use empty string to get first chunk of results
@ -4113,7 +4113,7 @@ setChatClientData chat_id:int53 client_data:string = Ok;
setChatDescription chat_id:int53 description:string = Ok;
//@description Changes the discussion group of a channel chat; requires can_change_info rights in the channel if it is specified @chat_id Identifier of the channel chat. Pass 0 to remove a link from the supergroup passed in the second argument to a linked channel chat (requires can_pin_messages rights in the supergroup) @discussion_chat_id Identifier of a new channel's discussion group. Use 0 to remove the discussion group.
//-Use the method getSuitableDiscussionChats to find all suitable groups. Basic group chats need to be first upgraded to supergroup chats. If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable needs to be used first to change that
//-Use the method getSuitableDiscussionChats to find all suitable groups. Basic group chats need to be first upgraded to supergroup chats. If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable must be used first to change that
setChatDiscussionGroup chat_id:int53 discussion_chat_id:int53 = Ok;
//@description Changes the location of a chat. Available only for some location-based supergroups, use supergroupFullInfo.can_set_location to check whether the method is allowed to use @chat_id Chat identifier @location New location for the chat; must be valid and not null
@ -4641,7 +4641,7 @@ getChatStatisticsUrl chat_id:int53 parameters:string is_dark:Bool = HttpUrl;
//@description Returns detailed statistics about a chat. Currently this method can be used only for supergroups and channels. Can be used only if SupergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics;
//@description Returns detailed statistics about a message. Can be used only if Message.can_get_statistics == true. The method is under development and may or may not work @chat_id Chat identifier @message_id Message identifier @is_dark Pass true if a dark theme is used by the application
//@description Returns detailed statistics about a message. Can be used only if Message.can_get_statistics == true @chat_id Chat identifier @message_id Message identifier @is_dark Pass true if a dark theme is used by the application
getMessageStatistics chat_id:int53 message_id:int53 is_dark:Bool = MessageStatistics;
//@description Loads asynchronous or zoomed in chat or message statistics graph @chat_id Chat identifier @token The token for graph loading @x X-value for zoomed in graph or 0 otherwise

View File

@ -4074,10 +4074,13 @@ bool ContactsManager::have_input_peer_channel(const Channel *c, ChannelId channe
if (is_public) {
return true;
}
if (!from_linked) {
if (!from_linked && c->has_linked_channel) {
auto linked_channel_id = get_linked_channel_id(channel_id);
if (linked_channel_id.is_valid() &&
have_input_peer_channel(get_channel(linked_channel_id), linked_channel_id, access_rights, true)) {
if (linked_channel_id.is_valid() && have_channel(linked_channel_id)) {
if (have_input_peer_channel(get_channel(linked_channel_id), linked_channel_id, access_rights, true)) {
return true;
}
} else {
return true;
}
}
@ -4085,11 +4088,13 @@ bool ContactsManager::have_input_peer_channel(const Channel *c, ChannelId channe
return true;
}
} else {
if (!from_linked && c->is_megagroup && !td_->auth_manager_->is_bot()) {
if (!from_linked && c->is_megagroup && !td_->auth_manager_->is_bot() && c->has_linked_channel) {
auto linked_channel_id = get_linked_channel_id(channel_id);
if (linked_channel_id.is_valid()) {
if (linked_channel_id.is_valid() && (is_public || have_channel(linked_channel_id))) {
return is_public ||
have_input_peer_channel(get_channel(linked_channel_id), linked_channel_id, AccessRights::Read, true);
} else {
return true;
}
}
}
@ -5974,7 +5979,7 @@ void ContactsManager::send_get_channel_stats_query(DcId dc_id, ChannelId channel
}
}
bool ContactsManager::can_get_channel_message_statistics(DialogId dialog_id) {
bool ContactsManager::can_get_channel_message_statistics(DialogId dialog_id) const {
if (dialog_id.get_type() != DialogType::Channel) {
return false;
}
@ -5985,11 +5990,16 @@ bool ContactsManager::can_get_channel_message_statistics(DialogId dialog_id) {
return false;
}
auto channel_full = get_channel_full_force(channel_id, "can_get_channel_message_statistics");
if (channel_full == nullptr) {
return c->status.is_administrator();
if (td_->auth_manager_->is_bot()) {
return false;
}
return channel_full->stats_dc_id.is_exact();
auto channel_full = get_channel_full(channel_id);
if (channel_full != nullptr) {
return channel_full->stats_dc_id.is_exact();
}
return c->status.is_administrator();
}
void ContactsManager::get_channel_message_statistics(FullMessageId full_message_id, bool is_dark,
@ -13002,17 +13012,23 @@ bool ContactsManager::get_channel_has_linked_channel(const Channel *c) {
}
ChannelId ContactsManager::get_channel_linked_channel_id(ChannelId channel_id) {
auto channel_full = get_channel_full_force(channel_id, "get_channel_linked_channel_id");
auto channel_full = get_channel_full_const(channel_id);
if (channel_full == nullptr) {
return ChannelId();
channel_full = get_channel_full_force(channel_id, "get_channel_linked_channel_id");
if (channel_full == nullptr) {
return ChannelId();
}
}
return channel_full->linked_channel_id;
}
int32 ContactsManager::get_channel_slow_mode_delay(ChannelId channel_id) {
auto channel_full = get_channel_full_force(channel_id, "get_channel_slow_mode_delay");
auto channel_full = get_channel_full_const(channel_id);
if (channel_full == nullptr) {
return 0;
channel_full = get_channel_full_force(channel_id, "get_channel_slow_mode_delay");
if (channel_full == nullptr) {
return 0;
}
}
return channel_full->slow_mode_delay;
}
@ -13096,7 +13112,7 @@ void ContactsManager::reload_channel(ChannelId channel_id, Promise<Unit> &&promi
td_->create_handler<GetChannelsQuery>(std::move(promise))->send(std::move(input_channel));
}
const ContactsManager::ChannelFull *ContactsManager::get_channel_full(ChannelId channel_id) const {
const ContactsManager::ChannelFull *ContactsManager::get_channel_full_const(ChannelId channel_id) const {
auto p = channels_full_.find(channel_id);
if (p == channels_full_.end()) {
return nullptr;
@ -13105,6 +13121,10 @@ const ContactsManager::ChannelFull *ContactsManager::get_channel_full(ChannelId
}
}
const ContactsManager::ChannelFull *ContactsManager::get_channel_full(ChannelId channel_id) const {
return get_channel_full_const(channel_id);
}
ContactsManager::ChannelFull *ContactsManager::get_channel_full(ChannelId channel_id, const char *source) {
auto p = channels_full_.find(channel_id);
if (p == channels_full_.end()) {

View File

@ -376,7 +376,7 @@ class ContactsManager : public Actor {
void get_channel_statistics(DialogId dialog_id, bool is_dark,
Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise);
bool can_get_channel_message_statistics(DialogId dialog_id);
bool can_get_channel_message_statistics(DialogId dialog_id) const;
void get_channel_message_statistics(FullMessageId full_message_id, bool is_dark,
Promise<td_api::object_ptr<td_api::messageStatistics>> &&promise);
@ -1125,6 +1125,7 @@ class ContactsManager : public Actor {
const ChannelFull *get_channel_full(ChannelId channel_id) const;
const ChannelFull *get_channel_full_internal(ChannelId channel_id) const;
const ChannelFull *get_channel_full_const(ChannelId channel_id) const;
ChannelFull *get_channel_full(ChannelId channel_id, const char *source);
ChannelFull *get_channel_full_internal(ChannelId channel_id, const char *source);
ChannelFull *get_channel_full_force(ChannelId channel_id, const char *source);

View File

@ -1388,11 +1388,8 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
Location l(inline_message_geo->geo_);
location->location_ = l.get_location_object();
} else {
Slice latitude;
Slice longitude;
Slice horizontal_accuracy;
std::tie(latitude, longitude) = split(Slice(result->description_));
Location l(to_double(latitude), to_double(longitude), 0.0, 0);
auto latitude_longitude = split(Slice(result->description_));
Location l(to_double(latitude_longitude.first), to_double(latitude_longitude.second), 0.0, 0);
location->location_ = l.get_location_object();
}
location->thumbnail_ = register_thumbnail(std::move(result->thumb_));

View File

@ -33,8 +33,8 @@
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageEntity.hpp"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageSearchFilter.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/Payments.h"
@ -690,13 +690,13 @@ class MessageDice : public MessageContent {
class MessageProximityAlertTriggered : public MessageContent {
public:
DialogId approacher_dialog_id;
DialogId observer_dialog_id;
DialogId traveler_dialog_id;
DialogId watcher_dialog_id;
int32 distance = 0;
MessageProximityAlertTriggered() = default;
MessageProximityAlertTriggered(DialogId approacher_dialog_id, DialogId observer_dialog_id, int32 distance)
: approacher_dialog_id(approacher_dialog_id), observer_dialog_id(observer_dialog_id), distance(distance) {
MessageProximityAlertTriggered(DialogId traveler_dialog_id, DialogId watcher_dialog_id, int32 distance)
: traveler_dialog_id(traveler_dialog_id), watcher_dialog_id(watcher_dialog_id), distance(distance) {
}
MessageContentType get_type() const override {
@ -973,8 +973,8 @@ static void store(const MessageContent *content, StorerT &storer) {
}
case MessageContentType::ProximityAlertTriggered: {
auto m = static_cast<const MessageProximityAlertTriggered *>(content);
store(m->approacher_dialog_id, storer);
store(m->observer_dialog_id, storer);
store(m->traveler_dialog_id, storer);
store(m->watcher_dialog_id, storer);
store(m->distance, storer);
break;
}
@ -1346,8 +1346,8 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
}
case MessageContentType::ProximityAlertTriggered: {
auto m = make_unique<MessageProximityAlertTriggered>();
parse(m->approacher_dialog_id, parser);
parse(m->observer_dialog_id, parser);
parse(m->traveler_dialog_id, parser);
parse(m->watcher_dialog_id, parser);
parse(m->distance, parser);
content = std::move(m);
break;
@ -3212,8 +3212,8 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::ProximityAlertTriggered: {
auto old_ = static_cast<const MessageProximityAlertTriggered *>(old_content);
auto new_ = static_cast<const MessageProximityAlertTriggered *>(new_content);
if (old_->approacher_dialog_id != new_->approacher_dialog_id ||
old_->observer_dialog_id != new_->observer_dialog_id || old_->distance != new_->distance) {
if (old_->traveler_dialog_id != new_->traveler_dialog_id || old_->watcher_dialog_id != new_->watcher_dialog_id ||
old_->distance != new_->distance) {
need_update = true;
}
break;
@ -4428,15 +4428,15 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionGeoProximityReached::ID: {
auto geo_proximity_reached = move_tl_object_as<telegram_api::messageActionGeoProximityReached>(action);
DialogId approacher_id(geo_proximity_reached->from_id_);
DialogId observer_id(geo_proximity_reached->to_id_);
DialogId traveler_id(geo_proximity_reached->from_id_);
DialogId watcher_id(geo_proximity_reached->to_id_);
int32 distance = geo_proximity_reached->distance_;
if (!approacher_id.is_valid() || !observer_id.is_valid() || distance < 0) {
if (!traveler_id.is_valid() || !watcher_id.is_valid() || distance < 0) {
LOG(ERROR) << "Receive invalid " << oneline(to_string(geo_proximity_reached));
break;
}
return make_unique<MessageProximityAlertTriggered>(approacher_id, observer_id, distance);
return make_unique<MessageProximityAlertTriggered>(traveler_id, watcher_id, distance);
}
default:
UNREACHABLE();
@ -4644,8 +4644,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::ProximityAlertTriggered: {
const MessageProximityAlertTriggered *m = static_cast<const MessageProximityAlertTriggered *>(content);
return make_tl_object<td_api::messageProximityAlertTriggered>(
td->messages_manager_->get_message_sender_object(m->approacher_dialog_id),
td->messages_manager_->get_message_sender_object(m->observer_dialog_id), m->distance);
td->messages_manager_->get_message_sender_object(m->traveler_dialog_id),
td->messages_manager_->get_message_sender_object(m->watcher_dialog_id), m->distance);
}
default:
UNREACHABLE();
@ -5154,8 +5154,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
break;
case MessageContentType::ProximityAlertTriggered: {
auto content = static_cast<const MessageProximityAlertTriggered *>(message_content);
add_message_sender_dependencies(dependencies, content->approacher_dialog_id);
add_message_sender_dependencies(dependencies, content->observer_dialog_id);
add_message_sender_dependencies(dependencies, content->traveler_dialog_id);
add_message_sender_dependencies(dependencies, content->watcher_dialog_id);
break;
}
default:

View File

@ -108,22 +108,34 @@ bool MessageReplyInfo::update_max_message_ids(MessageId other_max_message_id,
return result;
}
void MessageReplyInfo::add_reply(DialogId replier_dialog_id, MessageId reply_message_id) {
bool MessageReplyInfo::add_reply(DialogId replier_dialog_id, MessageId reply_message_id, int diff) {
CHECK(!is_empty());
CHECK(diff == +1 || diff == -1);
reply_count++;
if (is_comment && replier_dialog_id.is_valid() &&
(recent_replier_dialog_ids.empty() || recent_replier_dialog_ids[0] != replier_dialog_id)) {
if (diff == -1 && reply_count == 0) {
return false;
}
reply_count += diff;
if (is_comment && replier_dialog_id.is_valid()) {
td::remove(recent_replier_dialog_ids, replier_dialog_id);
recent_replier_dialog_ids.insert(recent_replier_dialog_ids.begin(), replier_dialog_id);
if (recent_replier_dialog_ids.size() > 3) {
recent_replier_dialog_ids.pop_back();
if (diff > 0) {
recent_replier_dialog_ids.insert(recent_replier_dialog_ids.begin(), replier_dialog_id);
if (recent_replier_dialog_ids.size() > 3) {
recent_replier_dialog_ids.pop_back();
}
} else {
auto max_repliers = static_cast<size_t>(reply_count);
if (recent_replier_dialog_ids.size() > max_repliers) {
recent_replier_dialog_ids.resize(max_repliers);
}
}
}
if (reply_message_id > max_message_id) {
if (diff > 0 && reply_message_id > max_message_id) {
max_message_id = reply_message_id;
}
return true;
}
td_api::object_ptr<td_api::messageReplyInfo> MessageReplyInfo::get_message_reply_info_object(

View File

@ -46,7 +46,7 @@ struct MessageReplyInfo {
bool update_max_message_ids(const MessageReplyInfo &other);
void add_reply(DialogId replier_dialog_id, MessageId reply_message_id);
bool add_reply(DialogId replier_dialog_id, MessageId reply_message_id, int diff);
td_api::object_ptr<td_api::messageReplyInfo> get_message_reply_info_object(
ContactsManager *contacts_manager, const MessagesManager *messages_manager) const;

View File

@ -5815,6 +5815,40 @@ int32 MessagesManager::get_message_index_mask(DialogId dialog_id, const Message
return index_mask;
}
void MessagesManager::update_reply_count_by_message(Dialog *d, int diff, const Message *m) {
if (td_->auth_manager_->is_bot() || !m->top_thread_message_id.is_valid() ||
m->top_thread_message_id == m->message_id || !m->message_id.is_server()) {
return;
}
auto replier_dialog_id =
has_message_sender_user_id(d->dialog_id, m) ? DialogId(m->sender_user_id) : m->sender_dialog_id;
update_message_reply_count(d, m->top_thread_message_id, replier_dialog_id, m->message_id, diff);
}
void MessagesManager::update_message_reply_count(Dialog *d, MessageId message_id, DialogId replier_dialog_id,
MessageId reply_message_id, int diff, bool is_recursive) {
if (d == nullptr) {
return;
}
Message *m = get_message(d, message_id);
if (m == nullptr || !is_active_message_reply_info(d->dialog_id, m->reply_info)) {
return;
}
LOG(INFO) << "Update reply count to " << message_id << " in " << d->dialog_id << " by " << diff << " from "
<< reply_message_id << " sent by " << replier_dialog_id;
if (m->reply_info.add_reply(replier_dialog_id, reply_message_id, diff)) {
on_message_reply_info_changed(d->dialog_id, m);
on_message_changed(d, m, true, "update_message_reply_count_by_message");
}
if (!is_recursive && is_discussion_message(d->dialog_id, m)) {
update_message_reply_count(get_dialog(m->forward_info->from_dialog_id), m->forward_info->from_message_id,
replier_dialog_id, reply_message_id, diff, true);
}
}
vector<MessageId> MessagesManager::get_message_ids(const vector<int64> &input_message_ids) {
vector<MessageId> message_ids;
message_ids.reserve(input_message_ids.size());
@ -7067,7 +7101,7 @@ void MessagesManager::on_user_dialog_action(DialogId dialog_id, MessageId top_th
if (td_->auth_manager_->is_bot() || !user_id.is_valid() || is_broadcast_channel(dialog_id)) {
return;
}
if (!td_->messages_manager_->have_dialog(dialog_id)) {
if (!have_dialog(dialog_id)) {
LOG(DEBUG) << "Ignore typing in unknown " << dialog_id;
return;
}
@ -13147,7 +13181,7 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
bool need_update_dialog_pos = false;
MessageId old_message_id = find_old_message_id(dialog_id, message_id);
bool need_add_active_live_location = false;
bool is_sent_message = false;
LOG(INFO) << "Found temporarily " << old_message_id << " for " << FullMessageId{dialog_id, message_id};
if (old_message_id.is_valid() || old_message_id.is_valid_scheduled()) {
Dialog *d = get_dialog(dialog_id);
@ -13225,10 +13259,7 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
send_update_message_send_succeeded(d, old_message_id, new_message.get());
if (!message_id.is_scheduled()) {
need_add_active_live_location = true;
// add_message_to_dialog will not update counts, because need_update == false
update_message_count_by_index(d, +1, new_message.get());
is_sent_message = true;
}
if (!from_update) {
@ -13257,8 +13288,12 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
return FullMessageId();
}
if (need_add_active_live_location) {
if (is_sent_message) {
try_add_active_live_location(dialog_id, m);
// add_message_to_dialog will not update counts, because need_update == false
update_message_count_by_index(d, +1, m);
update_reply_count_by_message(d, +1, m);
}
auto pcc_it = pending_created_dialogs_.find(dialog_id);
@ -14730,6 +14765,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
}
update_message_count_by_index(d, -1, result.get());
update_reply_count_by_message(d, -1, result.get());
}
on_message_deleted(d, result.get(), is_permanently_deleted, source);
@ -14979,13 +15015,9 @@ void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force,
if (!input_dialog_ids.empty() && !force) {
const size_t MAX_SLICE_SIZE = 100;
if (input_dialog_ids.size() <= MAX_SLICE_SIZE) {
td_->create_handler<GetDialogsQuery>(std::move(promise))->send(std::move(input_dialog_ids));
return;
}
MultiPromiseActorSafe mpas{"GetFilterDialogsFromServerMultiPromiseActor"};
mpas.add_promise(std::move(promise));
mpas.set_ignore_errors(true);
auto lock = mpas.get_promise();
for (size_t i = 0; i < input_dialog_ids.size(); i += MAX_SLICE_SIZE) {
@ -16338,6 +16370,7 @@ FullMessageId MessagesManager::get_replied_message(DialogId dialog_id, MessageId
return FullMessageId();
}
message_id = get_persistent_message_id(d, message_id);
auto m = get_message_force(d, message_id, "get_replied_message");
if (m == nullptr) {
if (force) {
@ -16822,8 +16855,8 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
if (for_comment) {
auto *top_m = get_message_force(d, m->top_thread_message_id, "get_public_message_link");
if (is_discussion_message(dialog_id, top_m) && is_active_message_reply_info(dialog_id, top_m->reply_info)) {
auto linked_dialog_id = top_m->forward_info->sender_dialog_id;
auto linked_message_id = top_m->forward_info->message_id;
auto linked_dialog_id = top_m->forward_info->from_dialog_id;
auto linked_message_id = top_m->forward_info->from_message_id;
auto linked_d = get_dialog(linked_dialog_id);
CHECK(linked_d != nullptr);
CHECK(linked_dialog_id.get_type() == DialogType::Channel);
@ -18975,11 +19008,11 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
max_thread_message_id = top_m->reply_info.max_message_id;
if (is_discussion_message(dialog_id, top_m)) {
auto linked_dialog_id = top_m->forward_info->sender_dialog_id;
auto linked_dialog_id = top_m->forward_info->from_dialog_id;
auto linked_d = get_dialog(linked_dialog_id);
CHECK(linked_d != nullptr);
CHECK(linked_dialog_id.get_type() == DialogType::Channel);
auto *linked_m = get_message_force(linked_d, top_m->forward_info->message_id, "view_messages 4");
auto *linked_m = get_message_force(linked_d, top_m->forward_info->from_message_id, "view_messages 4");
if (linked_m != nullptr && is_active_message_reply_info(linked_dialog_id, linked_m->reply_info)) {
if (linked_m->reply_info.last_read_inbox_message_id < prev_last_read_inbox_message_id) {
prev_last_read_inbox_message_id = linked_m->reply_info.last_read_inbox_message_id;
@ -22770,7 +22803,7 @@ void MessagesManager::fix_server_reply_to_message_id(DialogId dialog_id, Message
}
if (!message_id.is_scheduled() && !reply_in_dialog_id.is_valid() && reply_to_message_id >= message_id) {
if (reply_to_message_id.get() - message_id.get() <= MessageId(ServerMessageId(2000000000)).get() ||
if (reply_to_message_id.get() - message_id.get() <= MessageId(ServerMessageId(1000000)).get() ||
dialog_id.get_type() == DialogType::Channel) {
LOG(ERROR) << "Receive reply to wrong " << reply_to_message_id << " in " << message_id << " in " << dialog_id;
}
@ -24984,16 +25017,16 @@ bool MessagesManager::is_discussion_message(DialogId dialog_id, const Message *m
return false;
}
}
if (!m->forward_info->sender_dialog_id.is_valid() || !m->forward_info->message_id.is_valid()) {
if (!m->forward_info->from_dialog_id.is_valid() || !m->forward_info->from_message_id.is_valid()) {
return false;
}
if (dialog_id.get_type() != DialogType::Channel || is_broadcast_channel(dialog_id)) {
return false;
}
if (m->forward_info->sender_dialog_id == dialog_id) {
if (m->forward_info->from_dialog_id == dialog_id) {
return false;
}
if (m->forward_info->sender_dialog_id.get_type() != DialogType::Channel) {
if (m->forward_info->from_dialog_id.get_type() != DialogType::Channel) {
return false;
}
return true;
@ -28520,6 +28553,7 @@ void MessagesManager::fail_send_message(FullMessageId full_message_id, int error
if (!m->message_id.is_scheduled()) {
// add_message_to_dialog will not update counts, because need_update == false
update_message_count_by_index(d, +1, m);
update_reply_count_by_message(d, +1, m); // no-op because the message isn't server
}
register_new_local_message_id(d, m);
@ -28833,7 +28867,9 @@ void MessagesManager::on_update_dialog_last_pinned_message_id(DialogId dialog_id
void MessagesManager::set_dialog_last_pinned_message_id(Dialog *d, MessageId pinned_message_id) {
CHECK(d != nullptr);
CHECK(d->last_pinned_message_id != pinned_message_id);
if (d->last_pinned_message_id == pinned_message_id) {
return;
}
d->last_pinned_message_id = pinned_message_id;
d->is_last_pinned_message_id_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_last_pinned_message_id");
@ -30231,9 +30267,7 @@ void MessagesManager::unpin_all_dialog_messages(DialogId dialog_id, Promise<Unit
on_message_changed(d, m, true, "unpin_all_dialog_messages");
}
if (d->last_pinned_message_id != MessageId()) {
set_dialog_last_pinned_message_id(d, MessageId());
}
set_dialog_last_pinned_message_id(d, MessageId());
if (d->message_count_by_index[message_search_filter_index(MessageSearchFilter::Pinned)] != 0) {
d->message_count_by_index[message_search_filter_index(MessageSearchFilter::Pinned)] = 0;
on_dialog_updated(dialog_id, "unpin_all_dialog_messages");
@ -31201,7 +31235,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
message->sender_dialog_id = dialog_id;
} else {
if (is_discussion_message(dialog_id, message.get())) {
message->sender_dialog_id = message->forward_info->sender_dialog_id;
message->sender_dialog_id = message->forward_info->from_dialog_id;
} else {
LOG(ERROR) << "Failed to repair sender chat in " << message_id << " in " << dialog_id;
}
@ -31483,10 +31517,10 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
Message *top_m = get_message(d, message->top_thread_message_id);
CHECK(top_m != nullptr);
if (is_active_message_reply_info(dialog_id, top_m->reply_info) && is_discussion_message(dialog_id, top_m) &&
have_message_force({top_m->forward_info->sender_dialog_id, top_m->forward_info->message_id},
have_message_force({top_m->forward_info->from_dialog_id, top_m->forward_info->from_message_id},
"preload discussed message")) {
LOG(INFO) << "Preloaded discussed "
<< FullMessageId{top_m->forward_info->sender_dialog_id, top_m->forward_info->message_id}
<< FullMessageId{top_m->forward_info->from_dialog_id, top_m->forward_info->from_message_id}
<< " from database";
}
}
@ -31715,6 +31749,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
if (*need_update) {
update_message_count_by_index(d, +1, message.get());
update_reply_count_by_message(d, +1, message.get());
}
if (auto_attach && message_id > d->last_message_id && message_id >= d->last_new_message_id) {
set_dialog_last_message_id(d, message_id, "add_message_to_dialog");
@ -31837,28 +31872,6 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
UNREACHABLE();
}
}
if (!td_->auth_manager_->is_bot() && m->top_thread_message_id.is_valid() &&
m->top_thread_message_id != message_id && message_id.is_server()) {
Message *top_m = get_message(d, m->top_thread_message_id);
if (top_m != nullptr && is_active_message_reply_info(dialog_id, top_m->reply_info)) {
auto replier_dialog_id =
has_message_sender_user_id(dialog_id, m) ? DialogId(m->sender_user_id) : m->sender_dialog_id;
top_m->reply_info.add_reply(replier_dialog_id, message_id);
on_message_reply_info_changed(dialog_id, top_m);
on_message_changed(d, top_m, true, "update_message_reply_count 1");
if (is_discussion_message(dialog_id, top_m)) {
auto channel_dialog_id = top_m->forward_info->sender_dialog_id;
Message *channel_m = get_message({channel_dialog_id, top_m->forward_info->message_id});
if (channel_m != nullptr && is_active_message_reply_info(channel_dialog_id, channel_m->reply_info)) {
channel_m->reply_info.add_reply(replier_dialog_id, message_id);
on_message_reply_info_changed(channel_dialog_id, channel_m);
on_message_changed(get_dialog(channel_dialog_id), channel_m, true, "update_message_reply_count 2");
}
}
}
}
}
Message *result_message = treap_insert_message(&d->messages, std::move(message));
@ -31923,7 +31936,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
if (!td_->auth_manager_->is_bot() && from_update && m->forward_info != nullptr &&
m->forward_info->sender_dialog_id.is_valid() && m->forward_info->message_id.is_valid() &&
!is_discussion_message(dialog_id, m)) {
(!is_discussion_message(dialog_id, m) || m->forward_info->sender_dialog_id != m->forward_info->from_dialog_id ||
m->forward_info->message_id != m->forward_info->from_message_id)) {
update_forward_count(m->forward_info->sender_dialog_id, m->forward_info->message_id);
}
@ -32487,9 +32501,9 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
if (new_message->forward_info != nullptr) {
if (!replace_legacy) {
LOG(ERROR) << message_id << " in " << dialog_id << " has received forward info " << *new_message->forward_info
<< ", really forwarded from " << old_message->real_forward_from_dialog_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
<< ", really forwarded from " << old_message->real_forward_from_message_id << " in "
<< old_message->real_forward_from_dialog_id << ", message content type is "
<< old_message->content->get_type() << '/' << new_message->content->get_type();
}
old_message->forward_info = std::move(new_message->forward_info);
need_send_update = true;
@ -32505,8 +32519,9 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
if (!is_forward_info_sender_hidden(new_message->forward_info.get()) && !replace_legacy) {
LOG(ERROR) << message_id << " in " << dialog_id << " has changed forward info from "
<< *old_message->forward_info << " to " << *new_message->forward_info << ", really forwarded from "
<< old_message->real_forward_from_dialog_id << ", message content type is "
<< old_message->content->get_type() << '/' << new_message->content->get_type();
<< old_message->real_forward_from_message_id << " in " << old_message->real_forward_from_dialog_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
}
old_message->forward_info = std::move(new_message->forward_info);
need_send_update = true;
@ -32514,9 +32529,9 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
} else if (is_new_available) {
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
<< old_message->sender_dialog_id << " has lost forward info " << *old_message->forward_info
<< ", really forwarded from " << old_message->real_forward_from_dialog_id
<< ", message content type is " << old_message->content->get_type() << '/'
<< new_message->content->get_type();
<< ", really forwarded from " << old_message->real_forward_from_message_id << " in "
<< old_message->real_forward_from_dialog_id << ", message content type is "
<< old_message->content->get_type() << '/' << new_message->content->get_type();
old_message->forward_info = nullptr;
need_send_update = true;
}
@ -35047,9 +35062,9 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ
LOG(INFO) << "Can't apply postponed channel updates";
} else {
// otherwise we protecting from getChannelDifference repeating calls by dropping pending updates
LOG(ERROR) << "Failed to apply postponed updates of type " << update_id << " in " << dialog_id
<< " with pts " << d->pts << ", update pts is " << update_pts << ", update pts count is "
<< update_pts_count;
LOG(WARNING) << "Failed to apply postponed updates of type " << update_id << " in " << dialog_id
<< " with pts " << d->pts << ", update pts is " << update_pts << ", update pts count is "
<< update_pts_count;
d->postponed_channel_updates.clear();
}
break;

View File

@ -2083,6 +2083,11 @@ class MessagesManager : public Actor {
int32 get_message_index_mask(DialogId dialog_id, const Message *m) const;
void update_reply_count_by_message(Dialog *d, int diff, const Message *m);
void update_message_reply_count(Dialog *d, MessageId message_id, DialogId replier_dialog_id,
MessageId reply_message_id, int diff, bool is_recursive = false);
Message *add_message_to_dialog(DialogId dialog_id, unique_ptr<Message> message, bool from_update, bool *need_update,
bool *need_update_dialog_pos, const char *source);

View File

@ -8,7 +8,6 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessagesManager.h"

View File

@ -2202,6 +2202,7 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
s->short_name = std::move(set->short_name_);
s->thumbnail = std::move(thumbnail);
s->is_thumbnail_reloaded = true;
s->are_legacy_thumbnails_reloaded = true;
s->sticker_count = set->count_;
s->hash = set->hash_;
s->is_official = is_official;
@ -2240,9 +2241,10 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
s->thumbnail = std::move(thumbnail);
s->is_changed = true;
}
if (!s->is_thumbnail_reloaded) {
LOG(INFO) << "Thumbnail of " << set_id << " was reloaded";
if (!s->is_thumbnail_reloaded || !s->are_legacy_thumbnails_reloaded) {
LOG(INFO) << "Sticker thumbnails and thumbnail of " << set_id << " was reloaded";
s->is_thumbnail_reloaded = true;
s->are_legacy_thumbnails_reloaded = true;
s->need_save_to_database = true;
}
@ -3424,7 +3426,7 @@ void StickersManager::on_load_sticker_set_from_database(StickerSetId sticker_set
<< format::as_hex_dump<4>(Slice(value));
}
}
if (!sticker_set->is_thumbnail_reloaded) {
if (!sticker_set->is_thumbnail_reloaded || !sticker_set->are_legacy_thumbnails_reloaded) {
do_reload_sticker_set(sticker_set_id, get_input_sticker_set(sticker_set), Auto());
}

View File

@ -348,6 +348,7 @@ class StickersManager : public Actor {
bool is_masks = false;
bool is_viewed = true;
bool is_thumbnail_reloaded = false;
bool are_legacy_thumbnails_reloaded = false;
mutable bool was_update_sent = false; // does the sticker set is known to the client
bool is_changed = true; // have new changes that need to be sent to the client and database
bool need_save_to_database = true; // have new changes that need only to be saved to the database

View File

@ -135,6 +135,7 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
STORE_FLAG(has_thumbnail);
STORE_FLAG(sticker_set->is_thumbnail_reloaded);
STORE_FLAG(sticker_set->is_animated);
STORE_FLAG(sticker_set->are_legacy_thumbnails_reloaded);
END_STORE_FLAGS();
store(sticker_set->id.get(), storer);
store(sticker_set->access_hash, storer);
@ -195,6 +196,7 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
PARSE_FLAG(has_thumbnail);
PARSE_FLAG(sticker_set->is_thumbnail_reloaded);
PARSE_FLAG(is_animated);
PARSE_FLAG(sticker_set->are_legacy_thumbnails_reloaded);
END_PARSE_FLAGS();
int64 sticker_set_id;
int64 access_hash;

View File

@ -3114,7 +3114,7 @@ void Td::on_alarm_timeout(int64 alarm_id) {
return;
}
if (alarm_id == PING_SERVER_ALARM_ID) {
if (!close_flag_ && updates_manager_ != nullptr) {
if (!close_flag_ && updates_manager_ != nullptr && auth_manager_->is_authorized()) {
updates_manager_->ping_server();
alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID,
PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5));
@ -3635,7 +3635,7 @@ void Td::on_result(NetQueryPtr query) {
updates_manager_->schedule_get_difference("failed to fetch update");
} else {
updates_manager_->on_get_updates(std::move(ptr));
if (auth_manager_->is_bot()) {
if (auth_manager_->is_bot() && auth_manager_->is_authorized()) {
alarm_timeout_.set_timeout_in(PING_SERVER_ALARM_ID,
PING_SERVER_TIMEOUT + Random::fast(0, PING_SERVER_TIMEOUT / 5));
}

View File

@ -1072,10 +1072,12 @@ void UpdatesManager::on_get_difference(tl_object_ptr<telegram_api::updates_Diffe
set_date(difference->date_, false, "on_get_difference_empty");
seq_ = difference->seq_;
if (!pending_seq_updates_.empty()) {
LOG(ERROR) << "Drop " << pending_seq_updates_.size() << " pending seq updates after receive empty difference";
LOG(WARNING) << "Drop " << pending_seq_updates_.size() << " pending seq updates after receive empty difference";
pending_seq_updates_.clear();
}
if (!pending_qts_updates_.empty()) {
LOG(ERROR) << "Drop " << pending_qts_updates_.size() << " pending qts updates after receive empty difference";
LOG(WARNING) << "Drop " << pending_qts_updates_.size() << " pending qts updates after receive empty difference";
pending_qts_updates_.clear();
}
break;
}
@ -1518,6 +1520,9 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
}
void UpdatesManager::process_pending_seq_updates() {
if (!pending_seq_updates_.empty()) {
LOG(DEBUG) << "Trying to process " << pending_seq_updates_.size() << " pending seq updates";
}
while (!pending_seq_updates_.empty() && !running_get_difference_) {
auto update_it = pending_seq_updates_.begin();
auto seq_begin = update_it->second.seq_begin;

View File

@ -63,7 +63,8 @@ NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &fun
total_timeout_limit = 8;
}
if ((auth_manager == nullptr || !auth_manager->was_authorized()) && auth_flag == NetQuery::AuthFlag::On &&
tl_constructor != telegram_api::auth_exportAuthorization::ID) {
tl_constructor != telegram_api::auth_exportAuthorization::ID &&
tl_constructor != telegram_api::auth_bindTempAuthKey::ID) {
LOG(ERROR) << "Send query before authorization: " << to_string(function);
}
}

View File

@ -219,7 +219,7 @@ StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o) {
length += 4 + opt.long_key.size();
}
if (opt.type != OptionParser::Option::Type::NoArg) {
length += 5;
length += 6;
}
if (length > max_length) {
max_length = length;
@ -247,8 +247,8 @@ StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o) {
length -= 4 + opt.long_key.size();
}
if (opt.type != OptionParser::Option::Type::NoArg) {
sb << "<arg>";
length -= 5;
sb << "=<arg>";
length -= 6;
}
sb << string(length, ' ') << opt.description;
sb << '\n';

View File

@ -391,7 +391,7 @@ class SocketFdImpl {
auto write_res = detail::skip_eintr([&] {
#ifdef MSG_NOSIGNAL
msghdr msg;
memset(&msg, 0, sizeof(msg));
std::memset(&msg, 0, sizeof(msg));
msg.msg_iov = const_cast<iovec *>(slices.begin());
msg.msg_iovlen = slices_size;
return sendmsg(native_fd, &msg, MSG_NOSIGNAL);