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
|
//
// 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/WebDomainException.h"
#include "td/utils/algorithm.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
namespace td {
WebDomainException::WebDomainException(
telegram_api::object_ptr<telegram_api::webDomainException> &&web_domain_exception)
: domain_(std::move(web_domain_exception->domain_))
, url_(std::move(web_domain_exception->url_))
, title_(std::move(web_domain_exception->title_))
, favicon_custom_emoji_id_(web_domain_exception->favicon_) {
if (!favicon_custom_emoji_id_.is_valid() && favicon_custom_emoji_id_ != CustomEmojiId()) {
LOG(ERROR) << "Receive favicon " << favicon_custom_emoji_id_;
favicon_custom_emoji_id_ = {};
}
}
bool WebDomainException::has_domain_or_subdomain(Slice domain) const {
return ends_with(domain, domain_) &&
(domain.size() == domain_.size() || domain[domain.size() - domain_.size() - 1] == '.');
}
td_api::object_ptr<td_api::webDomainException> WebDomainException::get_web_domain_exception_object() const {
return td_api::make_object<td_api::webDomainException>(url_, domain_, title_.empty() ? domain_ : title_,
favicon_custom_emoji_id_.get());
}
vector<WebDomainException> WebDomainException::get_web_domain_exceptions(
vector<telegram_api::object_ptr<telegram_api::webDomainException>> &&web_domain_exceptions) {
return transform(std::move(web_domain_exceptions),
[](telegram_api::object_ptr<telegram_api::webDomainException> &&web_domain_exception) {
return WebDomainException(std::move(web_domain_exception));
});
}
vector<td_api::object_ptr<td_api::webDomainException>> WebDomainException::get_web_domain_exceptions_object(
const vector<WebDomainException> &web_domain_exceptions) {
return transform(web_domain_exceptions, [](const WebDomainException &web_domain_exception) {
return web_domain_exception.get_web_domain_exception_object();
});
}
bool operator==(const WebDomainException &lhs, const WebDomainException &rhs) {
return lhs.domain_ == rhs.domain_ && lhs.url_ == rhs.url_ && lhs.title_ == rhs.title_ &&
lhs.favicon_custom_emoji_id_ == rhs.favicon_custom_emoji_id_;
}
bool operator!=(const WebDomainException &lhs, const WebDomainException &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const WebDomainException &web_domain_exception) {
return string_builder << "WebDomainException[domain = " << web_domain_exception.domain_
<< ", URL = " << web_domain_exception.url_ << ", title = " << web_domain_exception.title_
<< ", favicon = " << web_domain_exception.favicon_custom_emoji_id_ << ']';
}
} // namespace td
|