1 // 2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #pragma once 8 9 #include "td/telegram/DialogId.h" 10 #include "td/telegram/FolderId.h" 11 #include "td/telegram/td_api.h" 12 13 #include "td/utils/common.h" 14 #include "td/utils/tl_helpers.h" 15 16 namespace td { 17 18 class Td; 19 20 class DialogActionBar { 21 int32 distance_ = -1; // distance to the peer 22 int32 join_request_date_ = 0; 23 string join_request_dialog_title_; 24 25 bool can_report_spam_ = false; 26 bool can_add_contact_ = false; 27 bool can_block_user_ = false; 28 bool can_share_phone_number_ = false; 29 bool can_report_location_ = false; 30 bool can_unarchive_ = false; 31 bool can_invite_members_ = false; 32 bool is_join_request_broadcast_ = false; 33 34 friend bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogActionBar> &rhs); 35 36 public: 37 static unique_ptr<DialogActionBar> create(bool can_report_spam, bool can_add_contact, bool can_block_user, 38 bool can_share_phone_number, bool can_report_location, bool can_unarchive, 39 int32 distance, bool can_invite_members, string join_request_dialog_title, 40 bool is_join_request_broadcast, int32 join_request_date); 41 42 bool is_empty() const; 43 can_report_spam()44 bool can_report_spam() const { 45 return can_report_spam_; 46 } 47 can_unarchive()48 bool can_unarchive() const { 49 return can_unarchive_; 50 } 51 52 td_api::object_ptr<td_api::ChatActionBar> get_chat_action_bar_object(DialogType dialog_type, 53 bool hide_unarchive) const; 54 55 void fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, FolderId folder_id); 56 57 bool on_dialog_unarchived(); 58 59 bool on_user_contact_added(); 60 61 bool on_user_deleted(); 62 63 bool on_outgoing_message(); 64 65 template <class StorerT> store(StorerT & storer)66 void store(StorerT &storer) const { 67 bool has_distance = distance_ >= 0; 68 bool has_join_request = !join_request_dialog_title_.empty(); 69 BEGIN_STORE_FLAGS(); 70 STORE_FLAG(can_report_spam_); 71 STORE_FLAG(can_add_contact_); 72 STORE_FLAG(can_block_user_); 73 STORE_FLAG(can_share_phone_number_); 74 STORE_FLAG(can_report_location_); 75 STORE_FLAG(can_unarchive_); 76 STORE_FLAG(can_invite_members_); 77 STORE_FLAG(has_distance); 78 STORE_FLAG(is_join_request_broadcast_); 79 STORE_FLAG(has_join_request); 80 END_STORE_FLAGS(); 81 if (has_distance) { 82 td::store(distance_, storer); 83 } 84 if (has_join_request) { 85 td::store(join_request_dialog_title_, storer); 86 td::store(join_request_date_, storer); 87 } 88 } 89 90 template <class ParserT> parse(ParserT & parser)91 void parse(ParserT &parser) { 92 bool has_distance; 93 bool has_join_request; 94 BEGIN_PARSE_FLAGS(); 95 PARSE_FLAG(can_report_spam_); 96 PARSE_FLAG(can_add_contact_); 97 PARSE_FLAG(can_block_user_); 98 PARSE_FLAG(can_share_phone_number_); 99 PARSE_FLAG(can_report_location_); 100 PARSE_FLAG(can_unarchive_); 101 PARSE_FLAG(can_invite_members_); 102 PARSE_FLAG(has_distance); 103 PARSE_FLAG(is_join_request_broadcast_); 104 PARSE_FLAG(has_join_request); 105 END_PARSE_FLAGS(); 106 if (has_distance) { 107 td::parse(distance_, parser); 108 } 109 if (has_join_request) { 110 td::parse(join_request_dialog_title_, parser); 111 td::parse(join_request_date_, parser); 112 } 113 } 114 }; 115 116 bool operator==(const unique_ptr<DialogActionBar> &lhs, const unique_ptr<DialogActionBar> &rhs); 117 118 } // namespace td 119