2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/ChannelId.h"
|
|
|
|
#include "td/telegram/ChatId.h"
|
|
|
|
#include "td/telegram/SecretChatId.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/UserId.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-11-23 17:37:32 +01:00
|
|
|
#include "td/utils/HashTableUtils.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-04-19 15:08:30 +02:00
|
|
|
enum class DialogType : int32 { None, User, Chat, Channel, SecretChat };
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
class DialogId {
|
2021-09-14 16:09:40 +02:00
|
|
|
static constexpr int64 ZERO_SECRET_CHAT_ID = -2000000000000ll;
|
|
|
|
static constexpr int64 ZERO_CHANNEL_ID = -1000000000000ll;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
int64 id = 0;
|
|
|
|
|
2018-02-22 01:36:40 +01:00
|
|
|
static int64 get_peer_id(const tl_object_ptr<telegram_api::Peer> &peer);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
DialogId() = default;
|
|
|
|
|
|
|
|
explicit DialogId(int64 dialog_id) : id(dialog_id) {
|
|
|
|
}
|
|
|
|
template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>>
|
|
|
|
DialogId(T dialog_id) = delete;
|
|
|
|
|
2019-08-19 03:51:03 +02:00
|
|
|
explicit DialogId(const tl_object_ptr<telegram_api::DialogPeer> &dialog_peer);
|
2018-12-31 20:04:05 +01:00
|
|
|
explicit DialogId(const tl_object_ptr<telegram_api::Peer> &peer);
|
|
|
|
explicit DialogId(UserId user_id);
|
|
|
|
explicit DialogId(ChatId chat_id);
|
|
|
|
explicit DialogId(ChannelId channel_id);
|
2021-09-14 16:09:40 +02:00
|
|
|
explicit DialogId(SecretChatId secret_chat_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
int64 get() const {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const DialogId &other) const {
|
|
|
|
return id == other.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const DialogId &other) const {
|
|
|
|
return id != other.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_valid() const;
|
|
|
|
|
|
|
|
DialogType get_type() const;
|
|
|
|
|
|
|
|
UserId get_user_id() const;
|
|
|
|
ChatId get_chat_id() const;
|
|
|
|
ChannelId get_channel_id() const;
|
2019-01-07 16:37:53 +01:00
|
|
|
SecretChatId get_secret_chat_id() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-12-12 19:43:49 +01:00
|
|
|
static DialogId get_message_dialog_id(const telegram_api::Message *message_ptr);
|
|
|
|
|
|
|
|
static DialogId get_message_dialog_id(const tl_object_ptr<telegram_api::Message> &message_ptr);
|
|
|
|
|
2023-03-26 23:39:38 +02:00
|
|
|
static vector<DialogId> get_dialog_ids(const vector<int64> &chat_ids);
|
|
|
|
|
2023-04-01 22:37:36 +02:00
|
|
|
static vector<int64> get_chat_ids(const vector<DialogId> &dialog_ids);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
storer.store_long(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
|
|
|
id = parser.fetch_long();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DialogIdHash {
|
2022-11-23 17:37:32 +01:00
|
|
|
uint32 operator()(DialogId dialog_id) const {
|
|
|
|
return Hash<int64>()(dialog_id.get());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline StringBuilder &operator<<(StringBuilder &string_builder, DialogId dialog_id) {
|
|
|
|
return string_builder << "chat " << dialog_id.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|