Update API scheme to layer 103.

This commit is contained in:
John Preston 2020-04-24 14:31:28 +04:00
parent c70a1f03de
commit 8d632bd2be
15 changed files with 98 additions and 101 deletions

View File

@ -651,7 +651,7 @@ messages.botResults#947ca848 flags:# gallery:flags.0?true query_id:long next_off
exportedMessageLink#5dab1af4 link:string html:string = ExportedMessageLink;
messageFwdHeader#ec338270 flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int = MessageFwdHeader;
messageFwdHeader#353a686b flags:# from_id:flags.0?int from_name:flags.5?string date:int channel_id:flags.1?int channel_post:flags.2?int post_author:flags.3?string saved_from_peer:flags.4?Peer saved_from_msg_id:flags.4?int psa_type:flags.6?string = MessageFwdHeader;
auth.codeTypeSms#72a3158c = auth.CodeType;
auth.codeTypeCall#741cd3e3 = auth.CodeType;
@ -912,9 +912,6 @@ fileHash#6242c773 offset:int limit:int hash:bytes = FileHash;
inputClientProxy#75588b3f address:string port:int = InputClientProxy;
help.proxyDataEmpty#e09e1fb8 expires:int = help.ProxyData;
help.proxyDataPromo#2bf7ee23 expires:int peer:Peer chats:Vector<Chat> users:Vector<User> = help.ProxyData;
help.termsOfServiceUpdateEmpty#e3309f7f expires:int = help.TermsOfServiceUpdate;
help.termsOfServiceUpdate#28ecf961 expires:int terms_of_service:help.TermsOfService = help.TermsOfServiceUpdate;
@ -1140,6 +1137,9 @@ messageInteractionCounters#ad4fc9bd msg_id:int views:int forwards:int = MessageI
stats.broadcastStats#bdf78394 period:StatsDateRangeDays followers:StatsAbsValueAndPrev views_per_post:StatsAbsValueAndPrev shares_per_post:StatsAbsValueAndPrev enabled_notifications:StatsPercentValue growth_graph:StatsGraph followers_graph:StatsGraph mute_graph:StatsGraph top_hours_graph:StatsGraph interactions_graph:StatsGraph iv_interactions_graph:StatsGraph views_by_source_graph:StatsGraph new_followers_by_source_graph:StatsGraph languages_graph:StatsGraph recent_message_interactions:Vector<MessageInteractionCounters> = stats.BroadcastStats;
help.promoDataEmpty#98f6ac75 expires:int = help.PromoData;
help.promoData#8f6adccf flags:# proxy:flags.0?true psa:flags.1?true expires:int peer:Peer chats:Vector<Chat> users:Vector<User> psa_message:flags.2?string = help.PromoData;
---functions---
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@ -1411,7 +1411,6 @@ help.getAppChangelog#9010ef6f prev_app_version:string = Updates;
help.setBotUpdatesStatus#ec22cfcd pending_updates_count:int message:string = Bool;
help.getCdnConfig#52029342 = CdnConfig;
help.getRecentMeUrls#3dc0f114 referer:string = help.RecentMeUrls;
help.getProxyData#3d7758e1 = help.ProxyData;
help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate;
help.acceptTermsOfService#ee72f79a id:DataJSON = Bool;
help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo;
@ -1421,6 +1420,7 @@ help.getPassportConfig#c661ad08 hash:int = help.PassportConfig;
help.getSupportName#d360e72c = help.SupportName;
help.getUserInfo#38a08d3 user_id:InputUser = help.UserInfo;
help.editUserInfo#66b91b70 user_id:InputUser message:string entities:Vector<MessageEntity> = help.UserInfo;
help.getPromoData#c0977421 = help.PromoData;
channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool;
channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector<int> = messages.AffectedMessages;
@ -1494,7 +1494,6 @@ langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLangua
folders.editPeerFolders#6847d0ab folder_peers:Vector<InputFolderPeer> = Updates;
folders.deleteFolder#1c295881 folder_id:int = Updates;
stats.getBroadcastStats#e6300dba flags:# dark:flags.0?true channel:InputChannel tz_offset:int = stats.BroadcastStats;
stats.loadAsyncGraph#621d5fa0 flags:# token:string x:flags.0?long = StatsGraph;
// LAYER 112
// LAYER 113

View File

@ -88,8 +88,8 @@ constexpr auto kMaxUsersPerInvite = 100;
// that was added to this chat.
constexpr auto kForwardMessagesOnAdd = 100;
constexpr auto kProxyPromotionInterval = TimeId(60 * 60);
constexpr auto kProxyPromotionMinDelay = TimeId(10);
constexpr auto kTopPromotionInterval = TimeId(60 * 60);
constexpr auto kTopPromotionMinDelay = TimeId(10);
constexpr auto kSmallDelayMs = 5;
constexpr auto kUnreadMentionsPreloadIfLess = 5;
constexpr auto kUnreadMentionsFirstRequestLimit = 10;
@ -237,7 +237,7 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
, _dialogsLoadState(std::make_unique<DialogsLoadState>())
, _fileLoader(std::make_unique<TaskQueue>(kFileLoaderQueueStopTimeout))
//, _feedReadTimer([=] { readFeeds(); }) // #feed
, _proxyPromotionTimer([=] { refreshProxyPromotion(); })
, _topPromotionTimer([=] { refreshTopPromotion(); })
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this)) {
@ -288,13 +288,13 @@ void ApiWrap::requestChangelog(
).send();
}
void ApiWrap::refreshProxyPromotion() {
void ApiWrap::refreshTopPromotion() {
const auto now = base::unixtime::now();
const auto next = (_proxyPromotionNextRequestTime != 0)
? _proxyPromotionNextRequestTime
const auto next = (_topPromotionNextRequestTime != 0)
? _topPromotionNextRequestTime
: now;
if (_proxyPromotionRequestId) {
getProxyPromotionDelayed(now, next);
if (_topPromotionRequestId) {
getTopPromotionDelayed(now, next);
return;
}
const auto key = [&]() -> std::pair<QString, uint32> {
@ -307,51 +307,48 @@ void ApiWrap::refreshProxyPromotion() {
}
return { proxy.host, proxy.port };
}();
if (_proxyPromotionKey == key && now < next) {
getProxyPromotionDelayed(now, next);
if (_topPromotionKey == key && now < next) {
getTopPromotionDelayed(now, next);
return;
}
_proxyPromotionKey = key;
if (key.first.isEmpty() || !key.second) {
proxyPromotionDone(MTP_help_proxyDataEmpty(
MTP_int(base::unixtime::now() + kProxyPromotionInterval)));
return;
}
_proxyPromotionRequestId = request(MTPhelp_GetProxyData(
)).done([=](const MTPhelp_ProxyData &result) {
_proxyPromotionRequestId = 0;
proxyPromotionDone(result);
_topPromotionKey = key;
_topPromotionRequestId = request(MTPhelp_GetPromoData(
)).done([=](const MTPhelp_PromoData &result) {
_topPromotionRequestId = 0;
topPromotionDone(result);
}).fail([=](const RPCError &error) {
_proxyPromotionRequestId = 0;
_topPromotionRequestId = 0;
const auto now = base::unixtime::now();
const auto next = _proxyPromotionNextRequestTime = now
+ kProxyPromotionInterval;
if (!_proxyPromotionTimer.isActive()) {
getProxyPromotionDelayed(now, next);
const auto next = _topPromotionNextRequestTime = now
+ kTopPromotionInterval;
if (!_topPromotionTimer.isActive()) {
getTopPromotionDelayed(now, next);
}
}).send();
}
void ApiWrap::getProxyPromotionDelayed(TimeId now, TimeId next) {
_proxyPromotionTimer.callOnce(std::min(
std::max(next - now, kProxyPromotionMinDelay),
kProxyPromotionInterval) * crl::time(1000));
void ApiWrap::getTopPromotionDelayed(TimeId now, TimeId next) {
_topPromotionTimer.callOnce(std::min(
std::max(next - now, kTopPromotionMinDelay),
kTopPromotionInterval) * crl::time(1000));
};
void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) {
_proxyPromotionNextRequestTime = proxy.match([&](const auto &data) {
void ApiWrap::topPromotionDone(const MTPhelp_PromoData &proxy) {
_topPromotionNextRequestTime = proxy.match([&](const auto &data) {
return data.vexpires().v;
});
getProxyPromotionDelayed(base::unixtime::now(), _proxyPromotionNextRequestTime);
getTopPromotionDelayed(
base::unixtime::now(),
_topPromotionNextRequestTime);
proxy.match([&](const MTPDhelp_proxyDataEmpty &data) {
_session->data().setProxyPromoted(nullptr);
}, [&](const MTPDhelp_proxyDataPromo &data) {
proxy.match([&](const MTPDhelp_promoDataEmpty &data) {
_session->data().setTopPromoted(nullptr);
}, [&](const MTPDhelp_promoData &data) {
_session->data().processChats(data.vchats());
_session->data().processUsers(data.vusers());
const auto peerId = peerFromMTP(data.vpeer());
const auto peer = _session->data().peer(peerId);
_session->data().setProxyPromoted(peer);
_session->data().setTopPromoted(peer);
if (const auto history = _session->data().historyLoaded(peer)) {
history->owner().histories().requestDialogEntry(history);
}

View File

@ -208,7 +208,7 @@ public:
void requestChangelog(
const QString &sinceVersion,
Fn<void(const MTPUpdates &result)> callback);
void refreshProxyPromotion();
void refreshTopPromotion();
void requestDeepLinkInfo(
const QString &path,
Fn<void(const MTPDhelp_deepLinkInfo &result)> callback);
@ -646,8 +646,8 @@ private:
//void readFeeds(); // #feed
void getProxyPromotionDelayed(TimeId now, TimeId next);
void proxyPromotionDone(const MTPhelp_ProxyData &proxy);
void getTopPromotionDelayed(TimeId now, TimeId next);
void topPromotionDone(const MTPhelp_PromoData &proxy);
void sendNotifySettingsUpdates();
@ -787,10 +787,10 @@ private:
//base::flat_map<not_null<Data::Feed*>, mtpRequestId> _feedReadRequests;
//base::Timer _feedReadTimer;
mtpRequestId _proxyPromotionRequestId = 0;
std::pair<QString, uint32> _proxyPromotionKey;
TimeId _proxyPromotionNextRequestTime = TimeId(0);
base::Timer _proxyPromotionTimer;
mtpRequestId _topPromotionRequestId = 0;
std::pair<QString, uint32> _topPromotionKey;
TimeId _topPromotionNextRequestTime = TimeId(0);
base::Timer _topPromotionTimer;
base::flat_set<not_null<const PeerData*>> _updateNotifySettingsPeers;
base::Timer _updateNotifySettingsTimer;

View File

@ -3713,18 +3713,18 @@ MessageIdsList Session::takeMimeForwardIds() {
return std::move(_mimeForwardIds);
}
void Session::setProxyPromoted(PeerData *promoted) {
if (_proxyPromoted != promoted) {
if (const auto history = historyLoaded(_proxyPromoted)) {
history->cacheProxyPromoted(false);
void Session::setTopPromoted(PeerData *promoted) {
if (_topPromoted != promoted) {
if (const auto history = historyLoaded(_topPromoted)) {
history->cacheTopPromoted(false);
}
const auto old = std::exchange(_proxyPromoted, promoted);
if (_proxyPromoted) {
const auto history = this->history(_proxyPromoted);
history->cacheProxyPromoted(true);
const auto old = std::exchange(_topPromoted, promoted);
if (_topPromoted) {
const auto history = this->history(_topPromoted);
history->cacheTopPromoted(true);
history->requestChatListMessage();
Notify::peerUpdatedDelayed(
_proxyPromoted,
_topPromoted,
Notify::PeerUpdate::Flag::ChannelPromotedChanged);
}
if (old) {
@ -3735,8 +3735,8 @@ void Session::setProxyPromoted(PeerData *promoted) {
}
}
PeerData *Session::proxyPromoted() const {
return _proxyPromoted;
PeerData *Session::topPromoted() const {
return _topPromoted;
}
bool Session::updateWallpapers(const MTPaccount_WallPapers &data) {

View File

@ -678,8 +678,8 @@ public:
void setMimeForwardIds(MessageIdsList &&list);
MessageIdsList takeMimeForwardIds();
void setProxyPromoted(PeerData *promoted);
PeerData *proxyPromoted() const;
void setTopPromoted(PeerData *promoted);
PeerData *topPromoted() const;
bool updateWallpapers(const MTPaccount_WallPapers &data);
void removeWallpaper(const WallPaper &paper);
@ -957,7 +957,7 @@ private:
base::flat_set<not_null<ViewElement*>> _heavyViewParts;
PeerData *_proxyPromoted = nullptr;
PeerData *_topPromoted = nullptr;
NotifySettings _defaultUserNotifySettings;
NotifySettings _defaultChatNotifySettings;

View File

@ -86,12 +86,12 @@ void Entry::cachePinnedIndex(FilterId filterId, int index) {
}
}
void Entry::cacheProxyPromoted(bool promoted) {
if (_isProxyPromoted != promoted) {
_isProxyPromoted = promoted;
void Entry::cacheTopPromoted(bool promoted) {
if (_isTopPromoted != promoted) {
_isTopPromoted = promoted;
updateChatListSortPosition();
updateChatListEntry();
if (!_isProxyPromoted) {
if (!_isTopPromoted) {
updateChatListExistence();
}
}

View File

@ -120,10 +120,10 @@ public:
return lookupPinnedIndex(filterId) != 0;
}
void cachePinnedIndex(FilterId filterId, int index);
bool isProxyPromoted() const {
return _isProxyPromoted;
bool isTopPromoted() const {
return _isTopPromoted;
}
void cacheProxyPromoted(bool promoted);
void cacheTopPromoted(bool promoted);
[[nodiscard]] uint64 sortKeyInChatList(FilterId filterId) const {
return filterId
? computeSortPosition(filterId)
@ -137,7 +137,7 @@ public:
virtual int fixedOnTopIndex() const = 0;
static constexpr auto kArchiveFixOnTopIndex = 1;
static constexpr auto kProxyPromotionFixOnTopIndex = 2;
static constexpr auto kTopPromotionFixOnTopIndex = 2;
virtual bool shouldBeInChatList() const = 0;
virtual int chatListUnreadCount() const = 0;
@ -211,7 +211,7 @@ private:
uint64 _sortKeyInChatList = 0;
uint64 _sortKeyByDate = 0;
base::flat_map<FilterId, int> _pinnedIndex;
bool _isProxyPromoted = false;
bool _isTopPromoted = false;
TimeId _timeId = 0;
};

View File

@ -296,7 +296,7 @@ void paintRow(
namewidth,
st::msgNameFont->height);
const auto promoted = (history && history->useProxyPromotion())
const auto promoted = (history && history->useTopPromotion())
&& !(flags & (Flag::SearchResult/* | Flag::FeedSearchResult*/)); // #feed
if (promoted) {
const auto text = tr::lng_proxy_sponsor(tr::now);

View File

@ -2580,8 +2580,8 @@ void History::updateChatListExistence() {
//}
}
bool History::useProxyPromotion() const {
if (!isProxyPromoted()) {
bool History::useTopPromotion() const {
if (!isTopPromoted()) {
return false;
} else if (const auto channel = peer->asChannel()) {
return !isPinnedDialog(FilterId()) && !channel->amIn();
@ -2590,7 +2590,7 @@ bool History::useProxyPromotion() const {
}
int History::fixedOnTopIndex() const {
return useProxyPromotion() ? kProxyPromotionFixOnTopIndex : 0;
return useTopPromotion() ? kTopPromotionFixOnTopIndex : 0;
}
bool History::trackUnreadMessages() const {
@ -2607,7 +2607,7 @@ bool History::shouldBeInChatList() const {
return true;
} else if (const auto channel = peer->asChannel()) {
if (!channel->amIn()) {
return isProxyPromoted();
return isTopPromoted();
//} else if (const auto feed = channel->feed()) { // #feed
// return !feed->needUpdateInChatList();
}

View File

@ -330,7 +330,7 @@ public:
void setForwardDraft(MessageIdsList &&items);
History *migrateSibling() const;
bool useProxyPromotion() const;
bool useTopPromotion() const;
int fixedOnTopIndex() const override;
void updateChatListExistence() override;
bool shouldBeInChatList() const override;

View File

@ -564,7 +564,7 @@ HistoryWidget::HistoryWidget(
}
}
if (update.flags & UpdateFlag::ChannelPromotedChanged) {
refreshAboutProxyPromotion();
refreshAboutTopPromotion();
updateHistoryGeometry();
updateControlsVisibility();
updateControlsGeometry();
@ -2067,7 +2067,7 @@ void HistoryWidget::updateControlsVisibility() {
if (_contactStatus) {
_contactStatus->show();
}
refreshAboutProxyPromotion();
refreshAboutTopPromotion();
if (!editingMessage() && (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart())) {
if (isBlocked()) {
_joinChannel->hide();
@ -2260,10 +2260,10 @@ void HistoryWidget::updateControlsVisibility() {
updateMouseTracking();
}
void HistoryWidget::refreshAboutProxyPromotion() {
if (_history->useProxyPromotion()) {
if (!_aboutProxyPromotion) {
_aboutProxyPromotion = object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
void HistoryWidget::refreshAboutTopPromotion() {
if (_history->useTopPromotion()) {
if (!_aboutTopPromotion) {
_aboutTopPromotion = object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
this,
object_ptr<Ui::FlatLabel>(
this,
@ -2271,9 +2271,9 @@ void HistoryWidget::refreshAboutProxyPromotion() {
st::historyAboutProxy),
st::historyAboutProxyPadding);
}
_aboutProxyPromotion->show();
_aboutTopPromotion->show();
} else {
_aboutProxyPromotion.destroy();
_aboutTopPromotion.destroy();
}
}
@ -4188,10 +4188,10 @@ void HistoryWidget::moveFieldControls() {
_muteUnmute->setGeometry(fullWidthButtonRect);
}
if (_aboutProxyPromotion) {
_aboutProxyPromotion->moveToLeft(
if (_aboutTopPromotion) {
_aboutTopPromotion->moveToLeft(
0,
fullWidthButtonRect.y() - _aboutProxyPromotion->height());
fullWidthButtonRect.y() - _aboutTopPromotion->height());
}
}
@ -5197,9 +5197,9 @@ void HistoryWidget::updateHistoryGeometry(
}
if (!editingMessage() && (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute())) {
newScrollHeight -= _unblock->height();
if (_aboutProxyPromotion) {
_aboutProxyPromotion->resizeToWidth(width());
newScrollHeight -= _aboutProxyPromotion->height();
if (_aboutTopPromotion) {
_aboutTopPromotion->resizeToWidth(width());
newScrollHeight -= _aboutTopPromotion->height();
}
} else {
if (editingMessage() || _canSendMessages) {
@ -6983,8 +6983,8 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
} else if (const auto error = writeRestriction()) {
drawRestrictedWrite(p, *error);
}
if (_aboutProxyPromotion) {
p.fillRect(_aboutProxyPromotion->geometry(), st::historyReplyBg);
if (_aboutTopPromotion) {
p.fillRect(_aboutTopPromotion->geometry(), st::historyReplyBg);
}
if (_pinnedBar && !_pinnedBar->cancel->isHidden()) {
drawPinnedBar(p);

View File

@ -380,7 +380,7 @@ private:
void handlePeerUpdate();
void setMembersShowAreaActive(bool active);
void handleHistoryChange(not_null<const History*> history);
void refreshAboutProxyPromotion();
void refreshAboutTopPromotion();
void unreadCountUpdated();
[[nodiscard]] int computeMaxFieldHeight() const;
@ -734,7 +734,7 @@ private:
object_ptr<Ui::FlatButton> _joinChannel;
object_ptr<Ui::FlatButton> _muteUnmute;
object_ptr<Ui::FlatButton> _discuss;
object_ptr<Ui::RpWidget> _aboutProxyPromotion = { nullptr };
object_ptr<Ui::RpWidget> _aboutTopPromotion = { nullptr };
object_ptr<Ui::IconButton> _attachToggle;
object_ptr<Ui::EmojiButton> _tabbedSelectorToggle;
object_ptr<Ui::IconButton> _botKeyboardShow;

View File

@ -69,9 +69,9 @@ Session::Session(
notifications().updateAll();
}, _lifetime);
subscribe(Global::RefConnectionTypeChanged(), [=] {
_api->refreshProxyPromotion();
_api->refreshTopPromotion();
});
_api->refreshProxyPromotion();
_api->refreshTopPromotion();
_api->requestTermsUpdate();
_api->requestFullPeer(_user);

View File

@ -150,7 +150,8 @@ AdminLog::OwnedItem GenerateForwardedItem(
MTPint(), // channel_post
MTPstring(), // post_author
MTPPeer(), // saved_from_peer
MTPint()), // saved_from_msg_id
MTPint(), // saved_from_msg_id
MTPstring()), // psa_type
MTPint(), // via_bot_id
MTPint(), // reply_to_msg_id,
MTP_int(base::unixtime::now()), // date

View File

@ -253,7 +253,7 @@ bool Filler::showToggleArchived() {
return false;
}
const auto history = _peer->owner().historyLoaded(_peer);
if (history && history->useProxyPromotion()) {
if (history && history->useTopPromotion()) {
return false;
} else if (!_peer->isNotificationsUser() && !_peer->isSelf()) {
return true;