From 3dd2a6bb5be482c10b202d0668213fbf8b2947a3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 23 Apr 2019 17:28:44 +0400 Subject: [PATCH] Update archive row on chat list name change. --- Telegram/SourceFiles/data/data_folder.cpp | 31 +++++++++++++++++-- Telegram/SourceFiles/data/data_folder.h | 2 ++ Telegram/SourceFiles/data/data_peer.cpp | 15 ++++----- .../dialogs/dialogs_inner_widget.cpp | 7 +++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/data/data_folder.cpp b/Telegram/SourceFiles/data/data_folder.cpp index b20a29110..76a3fb088 100644 --- a/Telegram/SourceFiles/data/data_folder.cpp +++ b/Telegram/SourceFiles/data/data_folder.cpp @@ -17,9 +17,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" //#include "storage/storage_feed_messages.h" // #feed #include "auth_session.h" +#include "observer_peer.h" #include "apiwrap.h" #include "mainwidget.h" -#include "styles/style_dialogs.h" // st::dialogsArchiveUserpic +#include "styles/style_dialogs.h" namespace Data { namespace { @@ -55,6 +56,18 @@ Folder::Folder(not_null owner, FolderId id) , _chatsList(PinnedDialogsInFolderMaxValue()) , _name(lang(lng_archived_name)) { indexNameParts(); + + Notify::PeerUpdateViewer( + Notify::PeerUpdate::Flag::NameChanged + ) | rpl::start_with_next([=](const Notify::PeerUpdate &update) { + for (const auto history : _unreadHistoriesLast) { + if (history->peer == update.peer) { + ++_chatListViewVersion; + updateChatListEntry(); + return; + } + } + }, _lifetime); } FolderId Folder::id() const { @@ -227,9 +240,21 @@ void Folder::paintUserpic( p.setBrush(st::historyPeerArchiveUserpicBg); { PainterHighQualityEnabler hq(p); - p.drawRoundedRect(x, y, size, size, size / 3., size / 3.); + p.drawEllipse(x, y, size, size); + } + if (size == st::dialogsPhotoSize) { + st::dialogsArchiveUserpic.paintInCenter(p, { x, y, size, size }); + } else { + p.save(); + const auto ratio = size / float64(st::dialogsPhotoSize); + p.translate(x + size / 2., y + size / 2.); + p.scale(ratio, ratio); + const auto skip = st::dialogsPhotoSize; + st::dialogsArchiveUserpic.paintInCenter( + p, + { -skip, -skip, 2 * skip, 2 * skip }); + p.restore(); } - st::dialogsArchiveUserpic.paintInCenter(p, { x, y, size, size }); //const auto small = (size - st::lineWidth) / 2; // #feed //const auto delta = size - small; //auto index = 0; diff --git a/Telegram/SourceFiles/data/data_folder.h b/Telegram/SourceFiles/data/data_folder.h index 2504f0046..1350b8007 100644 --- a/Telegram/SourceFiles/data/data_folder.h +++ b/Telegram/SourceFiles/data/data_folder.h @@ -108,6 +108,8 @@ private: uint32 _chatListViewVersion = 0; //rpl::variable _unreadPosition; + rpl::lifetime _lifetime; + }; } // namespace Data diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 4e5ee73dc..7a59bee14 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -115,7 +115,7 @@ void PeerData::updateNameDelayed( const QString &newName, const QString &newNameOrPhone, const QString &newUsername) { - if (name == newName) { + if (name == newName && nameVersion > 1) { if (isUser()) { if (asUser()->nameOrPhone == newNameOrPhone && asUser()->username == newUsername) { @@ -129,15 +129,14 @@ void PeerData::updateNameDelayed( return; } } - ++nameVersion; name = newName; nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions()); refreshEmptyUserpic(); - Notify::PeerUpdate update(this); - update.flags |= UpdateFlag::NameChanged; - update.oldNameFirstLetters = nameFirstLetters(); - + if (nameVersion++ > 1) { + update.flags |= UpdateFlag::NameChanged; + update.oldNameFirstLetters = nameFirstLetters(); + } if (isUser()) { if (asUser()->username != newUsername) { asUser()->username = newUsername; @@ -157,7 +156,9 @@ void PeerData::updateNameDelayed( } } fillNames(); - Notify::PeerUpdated().notify(update, true); + if (update.flags) { + Notify::PeerUpdated().notify(update, true); + } } std::unique_ptr PeerData::createEmptyUserpic() const { diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 81f095ec1..05d28e27e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2016,7 +2016,7 @@ void DialogsInner::refresh(bool toTop) { loadPeerPhotos(); } _controller->dialogsListDisplayForced().set( - _searchInChat || !_filter.isEmpty(), + _openedFolder || _searchInChat || !_filter.isEmpty(), true); update(); } @@ -2058,6 +2058,9 @@ void DialogsInner::searchInChat(Dialogs::Key key, UserData *from) { _searchInChat = key; _searchFromUser = from; if (_searchInChat) { + if (_openedFolder) { + changeOpenedFolder(nullptr); + } onHashtagFilterUpdate(QStringRef()); _cancelSearchInChat->show(); refreshSearchInChatLabel(); @@ -2070,7 +2073,7 @@ void DialogsInner::searchInChat(Dialogs::Key key, UserData *from) { _cancelSearchFromUser->hide(); } _controller->dialogsListDisplayForced().set( - _searchInChat || !_filter.isEmpty(), + _openedFolder || _searchInChat || !_filter.isEmpty(), true); }