blob: d1ec368b7ebe4bf69db4e7dff7c94a022fabae9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// 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)
//
#include "td/telegram/ProfileTab.h"
#include "td/utils/logging.h"
namespace td {
static bool is_allowed_profile_tab(ProfileTab profile_tab, ChannelType channel_type) {
switch (channel_type) {
case ChannelType::Broadcast:
return true;
case ChannelType::Megagroup:
return profile_tab != ProfileTab::Gifts;
case ChannelType::Unknown:
return profile_tab == ProfileTab::Posts || profile_tab == ProfileTab::Gifts;
default:
UNREACHABLE();
return false;
}
}
ProfileTab get_profile_tab(telegram_api::object_ptr<telegram_api::ProfileTab> &&profile_tab, ChannelType channel_type) {
if (profile_tab == nullptr) {
return ProfileTab::Default;
}
ProfileTab result = [&] {
switch (profile_tab->get_id()) {
case telegram_api::profileTabPosts::ID:
return ProfileTab::Posts;
case telegram_api::profileTabGifts::ID:
return ProfileTab::Gifts;
case telegram_api::profileTabMedia::ID:
return ProfileTab::Media;
case telegram_api::profileTabFiles::ID:
return ProfileTab::Files;
case telegram_api::profileTabMusic::ID:
return ProfileTab::Music;
case telegram_api::profileTabVoice::ID:
return ProfileTab::Voice;
case telegram_api::profileTabLinks::ID:
return ProfileTab::Links;
case telegram_api::profileTabGifs::ID:
return ProfileTab::Gifs;
default:
UNREACHABLE();
return ProfileTab::Default;
}
}();
if (!is_allowed_profile_tab(result, channel_type)) {
LOG(ERROR) << "Receive " << result << " for " << channel_type;
result = ProfileTab::Default;
}
return result;
}
Result<ProfileTab> get_profile_tab(const td_api::object_ptr<td_api::ProfileTab> &profile_tab,
ChannelType channel_type) {
if (profile_tab == nullptr) {
return Status::Error(400, "Profile tab must be non-empty");
}
ProfileTab result = [&] {
switch (profile_tab->get_id()) {
case td_api::profileTabPosts::ID:
return ProfileTab::Posts;
case td_api::profileTabGifts::ID:
return ProfileTab::Gifts;
case td_api::profileTabMedia::ID:
return ProfileTab::Media;
case td_api::profileTabFiles::ID:
return ProfileTab::Files;
case td_api::profileTabMusic::ID:
return ProfileTab::Music;
case td_api::profileTabVoice::ID:
return ProfileTab::Voice;
case td_api::profileTabLinks::ID:
return ProfileTab::Links;
case td_api::profileTabGifs::ID:
return ProfileTab::Gifs;
default:
UNREACHABLE();
return ProfileTab::Default;
}
}();
if (!is_allowed_profile_tab(result, channel_type)) {
return Status::Error(400, "Invalid profile tab specified for the chat");
}
return result;
}
telegram_api::object_ptr<telegram_api::ProfileTab> get_input_profile_tab(ProfileTab profile_tab) {
switch (profile_tab) {
case ProfileTab::Default:
UNREACHABLE();
return nullptr;
case ProfileTab::Posts:
return telegram_api::make_object<telegram_api::profileTabPosts>();
case ProfileTab::Gifts:
return telegram_api::make_object<telegram_api::profileTabGifts>();
case ProfileTab::Media:
return telegram_api::make_object<telegram_api::profileTabMedia>();
case ProfileTab::Files:
return telegram_api::make_object<telegram_api::profileTabFiles>();
case ProfileTab::Music:
return telegram_api::make_object<telegram_api::profileTabMusic>();
case ProfileTab::Voice:
return telegram_api::make_object<telegram_api::profileTabVoice>();
case ProfileTab::Links:
return telegram_api::make_object<telegram_api::profileTabLinks>();
case ProfileTab::Gifs:
return telegram_api::make_object<telegram_api::profileTabGifs>();
default:
UNREACHABLE();
return nullptr;
}
}
td_api::object_ptr<td_api::ProfileTab> get_profile_tab_object(ProfileTab profile_tab) {
switch (profile_tab) {
case ProfileTab::Default:
return nullptr;
case ProfileTab::Posts:
return td_api::make_object<td_api::profileTabPosts>();
case ProfileTab::Gifts:
return td_api::make_object<td_api::profileTabGifts>();
case ProfileTab::Media:
return td_api::make_object<td_api::profileTabMedia>();
case ProfileTab::Files:
return td_api::make_object<td_api::profileTabFiles>();
case ProfileTab::Music:
return td_api::make_object<td_api::profileTabMusic>();
case ProfileTab::Voice:
return td_api::make_object<td_api::profileTabVoice>();
case ProfileTab::Links:
return td_api::make_object<td_api::profileTabLinks>();
case ProfileTab::Gifs:
return td_api::make_object<td_api::profileTabGifs>();
default:
UNREACHABLE();
return nullptr;
}
}
StringBuilder &operator<<(StringBuilder &string_builder, ProfileTab profile_tab) {
string_builder << "profile tab ";
switch (profile_tab) {
case ProfileTab::Default:
return string_builder << "Default";
case ProfileTab::Posts:
return string_builder << "Posts";
case ProfileTab::Gifts:
return string_builder << "Gifts";
case ProfileTab::Media:
return string_builder << "Media";
case ProfileTab::Files:
return string_builder << "Files";
case ProfileTab::Music:
return string_builder << "Music";
case ProfileTab::Voice:
return string_builder << "Voice";
case ProfileTab::Links:
return string_builder << "Links";
case ProfileTab::Gifs:
return string_builder << "Gifs";
default:
UNREACHABLE();
return string_builder;
}
}
} // namespace td
|