From cbd4b2a8a4e465049f0a98ff7e0d811e77c15e9e Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 11 Aug 2019 02:10:21 +0300 Subject: [PATCH] Add MessagesManager::generate_new_media_album_id() method. GitOrigin-RevId: 1a0c71404b09585f66728ea494a8bd920795664c --- td/telegram/MessagesManager.cpp | 23 ++++++++++++----------- td/telegram/MessagesManager.h | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 93bf18b8..c55cb347 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -16313,6 +16313,15 @@ Result MessagesManager::process_input_message_content( return std::move(content); } +int64 MessagesManager::generate_new_media_album_id() { + int64 media_album_id = 0; + do { + media_album_id = Random::secure_int64(); + } while (media_album_id >= 0 || pending_message_group_sends_.count(media_album_id) != 0); + pending_message_group_sends_[media_album_id]; // reserve place for the group + return media_album_id; +} + Result> MessagesManager::send_message_group( DialogId dialog_id, MessageId reply_to_message_id, bool disable_notification, bool from_background, vector> &&input_message_contents) { @@ -16344,9 +16353,7 @@ Result> MessagesManager::send_message_group( int64 media_album_id = 0; if (message_contents.size() > 1) { - do { - media_album_id = Random::secure_int64(); - } while (media_album_id >= 0 || pending_message_group_sends_.count(media_album_id) != 0); + media_album_id = generate_new_media_album_id(); } // there must be no errors after get_message_to_send calls @@ -18575,11 +18582,7 @@ Result> MessagesManager::forward_messages(DialogId to_dialog_i } if (allow_album) { - int64 media_album_id = 0; - do { - media_album_id = Random::secure_int64(); - } while (media_album_id >= 0 || pending_message_group_sends_.count(media_album_id) != 0); - + int64 media_album_id = generate_new_media_album_id(); for (auto m : forwarded_messages) { m->media_album_id = media_album_id; } @@ -18605,9 +18608,7 @@ Result> MessagesManager::forward_messages(DialogId to_dialog_i } if (allow_album) { - do { - media_album_id = Random::secure_int64(); - } while (media_album_id >= 0 || pending_message_group_sends_.count(media_album_id) != 0); + media_album_id = generate_new_media_album_id(); } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 8395a4ac..14a4225e 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1434,6 +1434,8 @@ class MessagesManager : public Actor { bool is_message_unload_enabled() const; + int64 generate_new_media_album_id(); + static bool can_forward_message(DialogId from_dialog_id, const Message *m); static bool can_delete_channel_message(DialogParticipantStatus status, const Message *m, bool is_bot);