summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp b/protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp
index 9c69d4ebb5..43c1e392ab 100644
--- a/protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp
+++ b/protocols/Telegram/tdlib/td/td/telegram/DialogId.cpp
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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)
@@ -8,6 +8,7 @@
#include "td/telegram/telegram_api.h"
+#include "td/utils/algorithm.h"
#include "td/utils/logging.h"
#include <limits>
@@ -151,4 +152,33 @@ int64 DialogId::get_peer_id(const tl_object_ptr<telegram_api::Peer> &peer) {
}
}
+DialogId DialogId::get_message_dialog_id(const telegram_api::Message *message_ptr) {
+ CHECK(message_ptr != nullptr);
+ switch (message_ptr->get_id()) {
+ case telegram_api::messageEmpty::ID: {
+ auto message = static_cast<const telegram_api::messageEmpty *>(message_ptr);
+ return message->peer_id_ == nullptr ? DialogId() : DialogId(message->peer_id_);
+ }
+ case telegram_api::message::ID: {
+ auto message = static_cast<const telegram_api::message *>(message_ptr);
+ return DialogId(message->peer_id_);
+ }
+ case telegram_api::messageService::ID: {
+ auto message = static_cast<const telegram_api::messageService *>(message_ptr);
+ return DialogId(message->peer_id_);
+ }
+ default:
+ UNREACHABLE();
+ return DialogId();
+ }
+}
+
+DialogId DialogId::get_message_dialog_id(const tl_object_ptr<telegram_api::Message> &message_ptr) {
+ return get_message_dialog_id(message_ptr.get());
+}
+
+vector<DialogId> DialogId::get_dialog_ids(const vector<int64> &chat_ids) {
+ return transform(chat_ids, [](int64 chat_id) { return DialogId(chat_id); });
+}
+
} // namespace td