2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
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"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#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
|
|
|
|
|
|
|
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 {
|
|
|
|
std::size_t operator()(DialogId dialog_id) const {
|
|
|
|
return std::hash<int64>()(dialog_id.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline StringBuilder &operator<<(StringBuilder &string_builder, DialogId dialog_id) {
|
|
|
|
return string_builder << "chat " << dialog_id.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|