From 89e0dd6a06dcdc75795bf24a44e1e8135118e77f Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 12 May 2020 03:14:20 +0300 Subject: [PATCH] Add DialogFilterId class. GitOrigin-RevId: 050b0934a7646e3bdefa5875bb922b7dce06c408 --- CMakeLists.txt | 1 + td/telegram/DialogFilterId.h | 65 +++++++++++++++++++++++++++++++++++ td/telegram/MessagesManager.h | 1 + 3 files changed, 67 insertions(+) create mode 100644 td/telegram/DialogFilterId.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ec9bee26..954657936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -547,6 +547,7 @@ set(TDLIB_SOURCE td/telegram/DialogAdministrator.h td/telegram/DialogDate.h td/telegram/DialogDb.h + td/telegram/DialogFilterId.h td/telegram/DialogId.h td/telegram/DialogLocation.h td/telegram/DialogParticipant.h diff --git a/td/telegram/DialogFilterId.h b/td/telegram/DialogFilterId.h new file mode 100644 index 000000000..f7155b8ae --- /dev/null +++ b/td/telegram/DialogFilterId.h @@ -0,0 +1,65 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/utils/common.h" +#include "td/utils/StringBuilder.h" + +#include +#include + +namespace td { + +class DialogFilterId { + int32 id = 0; + + public: + DialogFilterId() = default; + + explicit DialogFilterId(int32 dialog_filter_id) : id(dialog_filter_id) { + } + template ::value>> + DialogFilterId(T dialog_filter_id) = delete; + + bool is_valid() const { + return id > 0; + } + + int32 get() const { + return id; + } + + bool operator==(const DialogFilterId &other) const { + return id == other.id; + } + + bool operator!=(const DialogFilterId &other) const { + return id != other.id; + } + + template + void store(StorerT &storer) const { + storer.store_int(id); + } + + template + void parse(ParserT &parser) { + id = parser.fetch_int(); + } +}; + +struct DialogFilterIdHash { + std::size_t operator()(DialogFilterId dialog_filter_id) const { + return std::hash()(dialog_filter_id.get()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, DialogFilterId dialog_filter_id) { + return string_builder << "chat filter " << dialog_filter_id.get(); +} + +} // namespace td diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index aea15dc6d..13fc04e1a 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -16,6 +16,7 @@ #include "td/telegram/DialogAdministrator.h" #include "td/telegram/DialogDate.h" #include "td/telegram/DialogDb.h" +#include "td/telegram/DialogFilterId.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/DialogParticipant.h"