Merge tag 'v5.1.7' into dev

# Conflicts:
#	Telegram/Resources/winrc/Telegram.rc
#	Telegram/Resources/winrc/Updater.rc
#	Telegram/SourceFiles/core/version.h
#	Telegram/lib_ui
#	snap/snapcraft.yaml
This commit is contained in:
AlexeyZavar
2024-06-14 21:43:44 +03:00
69 changed files with 1525 additions and 934 deletions
+55 -131
View File
@@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/qt/qt_key_modifiers.h"
#include "base/options.h"
#include "dialogs/ui/chat_search_tabs.h"
#include "dialogs/ui/chat_search_in.h"
#include "dialogs/ui/dialogs_stories_content.h"
#include "dialogs/ui/dialogs_stories_list.h"
#include "dialogs/ui/dialogs_suggestions.h"
@@ -340,7 +340,23 @@ Widget::Widget(
) | rpl::start_with_next([=] {
searchCursorMoved();
}, lifetime());
_inner->cancelSearchFromUserRequests(
_inner->changeSearchTabRequests(
) | rpl::filter([=](ChatSearchTab tab) {
return _searchState.tab != tab;
}) | rpl::start_with_next([=](ChatSearchTab tab) {
auto copy = _searchState;
copy.tab = tab;
applySearchState(std::move(copy));
}, lifetime());
_inner->cancelSearchRequests(
) | rpl::start_with_next([=] {
cancelSearch({
.forceFullCancel = true,
.jumpBackToSearchedChat = true,
});
controller->widget()->setInnerFocus();
}, lifetime());
_inner->cancelSearchFromRequests(
) | rpl::start_with_next([=] {
auto copy = _searchState;
copy.fromPeer = nullptr;
@@ -349,10 +365,9 @@ Widget::Widget(
}
applySearchState(std::move(copy));
}, lifetime());
_inner->cancelSearchRequests(
_inner->changeSearchFromRequests(
) | rpl::start_with_next([=] {
setInnerFocus(true);
applySearchState({});
showSearchFrom();
}, lifetime());
_inner->chosenRow(
) | rpl::start_with_next([=](const ChosenRow &row) {
@@ -410,7 +425,9 @@ Widget::Widget(
}, lifetime());
}
_cancelSearch->setClickedCallback([this] { cancelSearch(); });
_cancelSearch->setClickedCallback([this] {
cancelSearch({ .jumpBackToSearchedChat = true });
});
_jumpToDate->entity()->setClickedCallback([this] { showCalendar(); });
_chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); });
rpl::single(rpl::empty) | rpl::then(
@@ -680,7 +697,7 @@ void Widget::setupMoreChatsBar() {
controller()->activeChatsFilter(
) | rpl::start_with_next([=](FilterId id) {
storiesToggleExplicitExpand(false);
const auto cancelled = cancelSearch(true);
const auto cancelled = cancelSearch({ .forceFullCancel = true });
const auto guard = gsl::finally([&] {
if (cancelled) {
controller()->content()->dialogsCancelled();
@@ -1113,9 +1130,6 @@ void Widget::updateControlsVisibility(bool fast) {
updateJumpToDateVisibility(fast);
updateSearchFromVisibility(fast);
}
if (_searchTabs) {
_searchTabs->show();
}
if (_connecting) {
_connecting->setForceHidden(false);
}
@@ -1170,7 +1184,7 @@ bool Widget::cancelSearchByMouseBack() {
return _searchHasFocus
&& !_searchSuggestionsLocked
&& !_searchState.inChat
&& cancelSearch();
&& cancelSearch({ .jumpBackToSearchedChat = true });
}
void Widget::processSearchFocusChange() {
@@ -1259,102 +1273,6 @@ void Widget::updateSuggestions(anim::type animated) {
}
}
void Widget::updateSearchTabs() {
const auto has = _searchState.inChat || _searchingHashtag;
if (!has) {
if (_searchTabs) {
_searchTabs = nullptr;
updateControlsGeometry();
}
return;
} else if (!_searchTabs) {
const auto savedSession = &session();
const auto markedTextContext = [=](Fn<void()> repaint) {
return Core::MarkedTextContext{
.session = savedSession,
.customEmojiRepaint = std::move(repaint),
};
};
_searchTabs = std::make_unique<ChatSearchTabs>(
this,
_searchState.tab,
std::move(markedTextContext));
_searchTabs->setVisible(!_showAnimation);
_searchTabs->tabChanges(
) | rpl::filter([=](ChatSearchTab tab) {
return (_searchState.tab != tab);
}) | rpl::start_with_next([=](ChatSearchTab tab) {
auto copy = _searchState;
copy.tab = tab;
applySearchState(std::move(copy));
}, _searchTabs->lifetime());
}
const auto sublist = _searchState.inChat.sublist();
const auto topic = _searchState.inChat.topic();
const auto peer = _searchState.inChat.owningHistory()
? _searchState.inChat.owningHistory()->peer.get()
: _openedForum
? _openedForum->channel().get()
: nullptr;
const auto topicShortLabel = !topic
? TextWithEntities()
: topic->iconId()
? Ui::Text::SingleCustomEmoji(
Data::SerializeCustomEmojiId(topic->iconId()))
: Ui::Text::SingleCustomEmoji(Data::TopicIconEmojiEntity({
.title = (topic->isGeneral()
? Data::ForumGeneralIconTitle()
: topic->title()),
.colorId = (topic->isGeneral()
? Data::ForumGeneralIconColor(st::windowSubTextFg->c)
: topic->colorId()),
}));
const auto peerShortLabel = peer
? Ui::Text::SingleCustomEmoji(
session().data().customEmojiManager().peerUserpicEmojiData(
peer,
{},
true))
: sublist
? Ui::Text::SingleCustomEmoji(
session().data().customEmojiManager().peerUserpicEmojiData(
sublist->peer(),
{},
true))
: TextWithEntities();
const auto myShortLabel = DefaultShortLabel(ChatSearchTab::MyMessages);
const auto publicShortLabel = _searchingHashtag
? DefaultShortLabel(ChatSearchTab::PublicPosts)
: TextWithEntities();
if ((_searchState.tab == ChatSearchTab::ThisTopic
&& !_searchState.inChat.topic())
|| (_searchState.tab == ChatSearchTab::ThisPeer
&& !_searchState.inChat
&& !_openedForum)
|| (_searchState.tab == ChatSearchTab::PublicPosts
&& !_searchingHashtag)) {
_searchState.tab = _searchState.inChat.topic()
? ChatSearchTab::ThisTopic
: (_searchState.inChat.owningHistory()
|| _searchState.inChat.sublist())
? ChatSearchTab::ThisPeer
: ChatSearchTab::MyMessages;
}
const auto peerTabType = (peer && peer->isBroadcast())
? ChatSearchPeerTabType::Channel
: (peer && (peer->isChat() || peer->isMegagroup()))
? ChatSearchPeerTabType::Group
: ChatSearchPeerTabType::Chat;
_searchTabs->setTabShortLabels({
{ ChatSearchTab::ThisTopic, topicShortLabel },
{ ChatSearchTab::ThisPeer, peerShortLabel },
{ ChatSearchTab::MyMessages, myShortLabel },
{ ChatSearchTab::PublicPosts, publicShortLabel },
}, _searchState.tab, peerTabType);
updateControlsGeometry();
}
void Widget::changeOpenedSubsection(
FnMut<void()> change,
bool fromRight,
@@ -1405,7 +1323,7 @@ void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) {
return;
}
changeOpenedSubsection([&] {
cancelSearch(true);
cancelSearch({ .forceFullCancel = true });
closeChildList(anim::type::instant);
controller()->closeForum();
_openedFolder = folder;
@@ -1459,7 +1377,7 @@ void Widget::changeOpenedForum(Data::Forum *forum, anim::type animated) {
return;
}
changeOpenedSubsection([&] {
cancelSearch(true);
cancelSearch({ .forceFullCancel = true });
closeChildList(anim::type::instant);
_openedForum = forum;
_searchState.tab = forum
@@ -1949,7 +1867,7 @@ void Widget::slideFinished() {
}
void Widget::escape() {
if (!cancelSearch()) {
if (!cancelSearch({ .jumpBackToSearchedChat = true })) {
if (controller()->shownForum().current()) {
controller()->closeForum();
} else if (controller()->openedFolder().current()) {
@@ -2756,9 +2674,8 @@ QString Widget::validateSearchQuery() {
setSearchQuery(fixed.text, fixed.cursorPosition);
}
return fixed.text;
} else if (_searchingHashtag != IsHashtagSearchQuery(query)) {
_searchingHashtag = !_searchingHashtag;
updateSearchTabs();
} else {
_searchingHashtag = IsHashtagSearchQuery(query);
}
return query;
}
@@ -2804,7 +2721,7 @@ void Widget::showForum(
changeOpenedForum(forum, params.animated);
return;
}
cancelSearch(true);
cancelSearch({ .forceFullCancel = true });
openChildList(forum, params);
}
@@ -2935,6 +2852,9 @@ bool Widget::applySearchState(SearchState state) {
}
hideChildList();
}
if (state.inChat && _layout == Layout::Main) {
controller()->closeFolder();
}
// Adjust state to be consistent.
if (const auto peer = state.inChat.peer()) {
@@ -2956,7 +2876,7 @@ bool Widget::applySearchState(SearchState state) {
state.tab = (_openedForum && !state.inChat)
? ChatSearchTab::ThisPeer
: ChatSearchTab::MyMessages;
} else if (!state.inChat && !_searchTabs) {
} else if (!state.inChat && !_searchingHashtag) {
state.tab = (forum || _openedForum)
? ChatSearchTab::ThisPeer
: ChatSearchTab::MyMessages;
@@ -2990,6 +2910,20 @@ bool Widget::applySearchState(SearchState state) {
return false;
}
if ((state.tab == ChatSearchTab::ThisTopic
&& !state.inChat.topic())
|| (state.tab == ChatSearchTab::ThisPeer
&& !state.inChat
&& !_openedForum)
|| (state.tab == ChatSearchTab::PublicPosts
&& !_searchingHashtag)) {
state.tab = state.inChat.topic()
? ChatSearchTab::ThisTopic
: (state.inChat.owningHistory() || state.inChat.sublist())
? ChatSearchTab::ThisPeer
: ChatSearchTab::MyMessages;
}
const auto migrateFrom = (peer && !topic)
? peer->migrateFrom()
: nullptr;
@@ -3003,7 +2937,6 @@ bool Widget::applySearchState(SearchState state) {
}
if (inChatChanged) {
controller()->setSearchInChat(_searchState.inChat);
updateSearchTabs();
}
if (queryChanged || inChatChanged) {
updateCancelSearch();
@@ -3028,10 +2961,6 @@ bool Widget::applySearchState(SearchState state) {
_peerSearchQuery = QString();
}
if (_searchState.inChat && _layout == Layout::Main) {
controller()->closeFolder();
}
if (_searchState.query != currentSearchQuery()) {
setSearchQuery(_searchState.query);
}
@@ -3358,9 +3287,6 @@ void Widget::updateControlsGeometry() {
if (_forumRequestsBar) {
_forumRequestsBar->resizeToWidth(barw);
}
if (_searchTabs) {
_searchTabs->resizeToWidth(barw);
}
_updateScrollGeometryCached = [=] {
const auto moreChatsBarTop = expandedStoriesTop
+ ((!_stories || _stories->isHidden()) ? 0 : _aboveScrollAdded);
@@ -3382,13 +3308,8 @@ void Widget::updateControlsGeometry() {
if (_forumReportBar) {
_forumReportBar->bar().move(0, forumReportTop);
}
const auto searchTabsTop = forumReportTop
const auto scrollTop = forumReportTop
+ (_forumReportBar ? _forumReportBar->bar().height() : 0);
if (_searchTabs) {
_searchTabs->move(0, searchTabsTop);
}
const auto scrollTop = searchTabsTop
+ (_searchTabs ? _searchTabs->height() : 0);
const auto scrollHeight = height() - scrollTop - bottomSkip;
const auto wasScrollHeight = _scroll->height();
_scroll->setGeometry(0, scrollTop, scrollWidth, scrollHeight);
@@ -3680,10 +3601,11 @@ void Widget::setSearchQuery(const QString &query, int cursorPosition) {
}
}
bool Widget::cancelSearch(bool forceFullCancel) {
bool Widget::cancelSearch(CancelSearchOptions options) {
cancelSearchRequest();
auto updatedState = _searchState;
const auto clearingQuery = !updatedState.query.isEmpty();
const auto forceFullCancel = options.forceFullCancel;
auto clearingInChat = (forceFullCancel || !clearingQuery)
&& (updatedState.inChat
|| updatedState.fromPeer
@@ -3692,7 +3614,9 @@ bool Widget::cancelSearch(bool forceFullCancel) {
updatedState.query = QString();
}
if (clearingInChat) {
if (updatedState.inChat && controller()->adaptive().isOneColumn()) {
if (options.jumpBackToSearchedChat
&& updatedState.inChat
&& controller()->adaptive().isOneColumn()) {
if (const auto thread = updatedState.inChat.thread()) {
controller()->showThread(thread);
} else {