Skip to content

Commit

Permalink
Merge commit '60edadab90d7aeb8d7a44764344b8848abf5b8bb'
Browse files Browse the repository at this point in the history
Conflicts:
	td/telegram/MessagesManager.cpp
  • Loading branch information
cavallium committed Nov 7, 2020
2 parents b22a1a4 + 60edada commit 6f28ad3
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 157 deletions.
23 changes: 14 additions & 9 deletions td/telegram/ContactsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9497,10 +9497,17 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
return promise.set_value(Unit());
}

ChannelFull *channel = add_channel_full(channel_id);

bool have_participant_count = (channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_PARTICIPANT_COUNT) != 0;
auto participant_count = have_participant_count ? channel_full->participants_count_ : 0;
auto administrator_count =
(channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_ADMINISTRATOR_COUNT) != 0 ? channel_full->admins_count_ : 0;
auto administrator_count = 0;
if ((channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_ADMINISTRATOR_COUNT) != 0) {
administrator_count = channel_full->admins_count_;
} else if (c->is_megagroup || c->status.is_administrator()) {
// in megagroups and administrated channels don't drop known number of administrators
administrator_count = channel->administrator_count;
}
auto restricted_count =
(channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_BANNED_COUNT) != 0 ? channel_full->banned_count_ : 0;
auto banned_count =
Expand All @@ -9525,7 +9532,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
can_view_statistics = false;
}

ChannelFull *channel = add_channel_full(channel_id);
channel->repair_request_version = 0;
channel->expires_at = Time::now() + CHANNEL_FULL_EXPIRE_TIME;
if (channel->description != channel_full->about_ || channel->participant_count != participant_count ||
Expand All @@ -9550,12 +9556,11 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
channel->sticker_set_id = sticker_set_id;

channel->is_changed = true;

if (have_participant_count && c->participant_count != participant_count) {
c->participant_count = participant_count;
c->is_changed = true;
update_channel(c, channel_id);
}
}
if (have_participant_count && c->participant_count != participant_count) {
c->participant_count = participant_count;
c->is_changed = true;
update_channel(c, channel_id);
}
if (!channel->is_can_view_statistics_inited) {
channel->is_can_view_statistics_inited = true;
Expand Down
433 changes: 300 additions & 133 deletions td/telegram/MessagesManager.cpp

Large diffs are not rendered by default.

30 changes: 24 additions & 6 deletions td/telegram/MessagesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ class MessagesManager : public Actor {
};
MessagesInfo on_get_messages(tl_object_ptr<telegram_api::messages_Messages> &&messages_ptr, const char *source);

void get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
Promise<MessagesInfo> &&promise);

void on_get_messages(vector<tl_object_ptr<telegram_api::Message>> &&messages, bool is_channel_message,
bool is_scheduled, const char *source);

Expand Down Expand Up @@ -612,8 +615,9 @@ class MessagesManager : public Actor {

td_api::object_ptr<td_api::messageThreadInfo> get_message_thread_info_object(const MessageThreadInfo &info);

void on_get_discussion_message(DialogId dialog_id, MessageId message_id, vector<FullMessageId> full_message_ids,
Promise<MessageThreadInfo> &&promise);
void process_discussion_message(telegram_api::object_ptr<telegram_api::messages_discussionMessage> &&result,
DialogId dialog_id, MessageId message_id, DialogId expected_dialog_id,
MessageId expected_message_id, Promise<vector<FullMessageId>> promise);

bool is_message_edited_recently(FullMessageId full_message_id, int32 seconds);

Expand Down Expand Up @@ -809,7 +813,7 @@ class MessagesManager : public Actor {
void on_resolved_username(const string &username, DialogId dialog_id);
void drop_username(const string &username);

tl_object_ptr<telegram_api::InputNotifyPeer> get_input_notify_peer(DialogId dialogId) const;
tl_object_ptr<telegram_api::InputNotifyPeer> get_input_notify_peer(DialogId dialog_id) const;

void on_update_dialog_notify_settings(DialogId dialog_id,
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings,
Expand Down Expand Up @@ -2073,7 +2077,7 @@ class MessagesManager : public Actor {

void load_folder_dialog_list_from_database(FolderId folder_id, int32 limit, Promise<Unit> &&promise);

void preload_folder_dialog_list(FolderId folderId);
void preload_folder_dialog_list(FolderId folder_id);

static void invalidate_message_indexes(Dialog *d);

Expand Down Expand Up @@ -2645,6 +2649,13 @@ class MessagesManager : public Actor {
void on_get_message_link_discussion_message(MessageLinkInfo &&info, DialogId comment_dialog_id,
Promise<MessageLinkInfo> &&promise);

void process_discussion_message_impl(telegram_api::object_ptr<telegram_api::messages_discussionMessage> &&result,
DialogId dialog_id, MessageId message_id, DialogId expected_dialog_id,
MessageId expected_message_id, Promise<vector<FullMessageId>> promise);

void on_get_discussion_message(DialogId dialog_id, MessageId message_id, vector<FullMessageId> full_message_ids,
Promise<MessageThreadInfo> &&promise);

static MessageId get_first_database_message_id_by_index(const Dialog *d, MessageSearchFilter filter);

void on_search_dialog_messages_db_result(int64 random_id, DialogId dialog_id, MessageId from_message_id,
Expand Down Expand Up @@ -2773,6 +2784,11 @@ class MessagesManager : public Actor {

void set_channel_pts(Dialog *d, int32 new_pts, const char *source);

bool need_channel_difference_to_add_message(DialogId dialog_id,
const tl_object_ptr<telegram_api::Message> &message_ptr);

void run_after_channel_difference(DialogId dialog_id, Promise<Unit> &&promise);

bool running_get_channel_difference(DialogId dialog_id) const;

void on_channel_get_difference_timeout(DialogId dialog_id);
Expand Down Expand Up @@ -2957,6 +2973,8 @@ class MessagesManager : public Actor {

static int32 get_message_schedule_date(const Message *m);

static DialogId get_message_original_sender(const Message *m);

int32 recently_found_dialogs_loaded_ = 0; // 0 - not loaded, 1 - load request was sent, 2 - loaded
MultiPromiseActor resolve_recently_found_dialogs_multipromise_{"ResolveRecentlyFoundDialogsMultiPromiseActor"};

Expand Down Expand Up @@ -3090,8 +3108,6 @@ class MessagesManager : public Actor {
}
};

std::unordered_map<DialogId, vector<PendingGetMessageRequest>, DialogIdHash> postponed_get_message_requests_;

std::unordered_map<string, vector<Promise<Unit>>> search_public_dialogs_queries_;
std::unordered_map<string, vector<DialogId>> found_public_dialogs_; // TODO time bound cache
std::unordered_map<string, vector<DialogId>> found_on_server_dialogs_; // TODO time bound cache
Expand Down Expand Up @@ -3224,6 +3240,8 @@ class MessagesManager : public Actor {
vector<PendingOnGetDialogs> pending_on_get_dialogs_;
std::unordered_map<DialogId, PendingOnGetDialogs, DialogIdHash> pending_channel_on_get_dialogs_;

std::unordered_map<DialogId, vector<Promise<Unit>>, DialogIdHash> run_after_get_channel_difference_;

ChangesProcessor<unique_ptr<PendingSecretMessage>> pending_secret_messages_;

std::unordered_map<DialogId, vector<DialogId>, DialogIdHash>
Expand Down
3 changes: 2 additions & 1 deletion tdutils/td/utils/AtomicRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "td/utils/common.h"
#include "td/utils/port/thread.h"
#include "td/utils/type_traits.h"

#include <atomic>
#include <cstring>
Expand All @@ -21,7 +22,7 @@ class AtomicRead {
public:
void read(T &dest) const {
while (true) {
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
static_assert(TD_IS_TRIVIALLY_COPYABLE(T), "T must be trivially copyable");
auto version_before = version.load();
if (version_before % 2 == 0) {
std::memcpy(&dest, &value, sizeof(dest));
Expand Down
2 changes: 1 addition & 1 deletion tdutils/td/utils/ThreadLocalStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ThreadLocalStorage {

private:
struct Node {
T value{};
T value;
char padding[TD_CONCURRENCY_PAD];
};
static constexpr int32 MAX_THREAD_ID = 128;
Expand Down
9 changes: 2 additions & 7 deletions tdutils/td/utils/as.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
#pragma once

#include "td/utils/type_traits.h"

#include <cstring>
#include <type_traits>

Expand Down Expand Up @@ -64,13 +66,6 @@ class ConstAs {

} // namespace detail

// no std::is_trivially_copyable in libstdc++ before 5.0
#if __GLIBCXX__
#define TD_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define TD_IS_TRIVIALLY_COPYABLE(T) ::std::is_trivially_copyable<T>::value
#endif

template <class ToT, class FromT,
std::enable_if_t<TD_IS_TRIVIALLY_COPYABLE(ToT) && TD_IS_TRIVIALLY_COPYABLE(FromT), int> = 0>
detail::As<ToT> as(FromT *from) {
Expand Down
11 changes: 11 additions & 0 deletions tdutils/td/utils/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
//
#pragma once

#include "td/utils/int_types.h"

#include <type_traits>

namespace td {

template <class FunctionT>
Expand All @@ -27,4 +31,11 @@ constexpr size_t member_function_argument_count() {
return member_function_class<FunctionT>::argument_count();
}

// no std::is_trivially_copyable in libstdc++ before 5.0
#if __GLIBCXX__
#define TD_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define TD_IS_TRIVIALLY_COPYABLE(T) ::std::is_trivially_copyable<T>::value
#endif

} // namespace td

0 comments on commit 6f28ad3

Please sign in to comment.