From f9154c4ed076996f0c09ec21e12f8cead49b726b Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 21 Jan 2018 12:05:30 +0300 Subject: [PATCH] Fix albums layout and editing in feed. --- Telegram/SourceFiles/app.cpp | 5 --- Telegram/SourceFiles/data/data_groups.cpp | 10 ++++- Telegram/SourceFiles/data/data_groups.h | 2 +- Telegram/SourceFiles/data/data_session.cpp | 1 + .../history/history_inner_widget.cpp | 2 +- Telegram/SourceFiles/history/history_item.cpp | 10 ++++- .../history/view/history_view_element.cpp | 4 +- .../history/view/history_view_list_widget.cpp | 43 ++++++++++++++++++- .../history/view/history_view_list_widget.h | 2 + .../history/view/history_view_message.cpp | 11 ++--- 10 files changed, 71 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d56bbea78..f7791622a 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1274,11 +1274,6 @@ namespace { } } Auth().notifications().clearFromItem(item); - if (Global::started() - && !App::quitting() - && AuthSession::Exists()) { - Auth().data().notifyItemRemoved(item); - } } void historyUpdateDependent(not_null item) { diff --git a/Telegram/SourceFiles/data/data_groups.cpp b/Telegram/SourceFiles/data/data_groups.cpp index 6f9261d2f..0d4b75591 100644 --- a/Telegram/SourceFiles/data/data_groups.cpp +++ b/Telegram/SourceFiles/data/data_groups.cpp @@ -36,7 +36,7 @@ void Groups::registerMessage(not_null item) { } } -void Groups::unregisterMessage(not_null item) { +void Groups::unregisterMessage(not_null item) { const auto groupId = item->groupId(); if (!groupId) { return; @@ -115,7 +115,13 @@ const Group *Groups::find(not_null item) const { return nullptr; } const auto i = _groups.find(groupId); - return (i != _groups.end()) ? &i->second : nullptr; + if (i != _groups.end()) { + const auto &result = i->second; + if (result.items.size() > 1) { + return &result; + } + } + return nullptr; } void Groups::refreshViews(const HistoryItemsList &items) { diff --git a/Telegram/SourceFiles/data/data_groups.h b/Telegram/SourceFiles/data/data_groups.h index 6686f3059..4e8d83fda 100644 --- a/Telegram/SourceFiles/data/data_groups.h +++ b/Telegram/SourceFiles/data/data_groups.h @@ -24,7 +24,7 @@ public: bool isGrouped(not_null item) const; void registerMessage(not_null item); - void unregisterMessage(not_null item); + void unregisterMessage(not_null item); void refreshMessage(not_null item); const Group *find(not_null item) const; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 1e5e2c7a0..247f90642 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -235,6 +235,7 @@ rpl::producer> Session::itemPlayInlineRequest() con void Session::notifyItemRemoved(not_null item) { _itemRemoved.fire_copy(item); + groups().unregisterMessage(item); } rpl::producer> Session::itemRemoved() const { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index dbaa9c32b..26270f0ef 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2789,7 +2789,7 @@ bool HistoryInner::hasPendingResizedItems() const { void HistoryInner::deleteAsGroup(FullMsgId itemId) { if (const auto item = App::histItemById(itemId)) { const auto group = Auth().data().groups().find(item); - if (!group || group->items.size() < 2) { + if (!group) { return deleteItem(item); } Ui::show(Box( diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 4f5f5ce53..65d977451 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_upload.h" #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" +#include "storage/storage_feed_messages.h" #include "auth_session.h" #include "apiwrap.h" #include "media/media_audio.h" @@ -320,6 +321,13 @@ void HistoryItem::indexAsNewItem() { types, id)); } + if (const auto channel = history()->peer->asChannel()) { + if (const auto feed = channel->feed()) { + Auth().storage().add(Storage::FeedMessagesAddNew( + feed->id(), + position())); + } + } } } @@ -743,7 +751,7 @@ void HistoryItem::drawInDialog( } HistoryItem::~HistoryItem() { - Auth().data().groups().unregisterMessage(this); + Auth().data().notifyItemRemoved(this); App::historyUnregItem(this); if (id < 0 && !App::quitting()) { Auth().uploader().cancel(fullId()); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index ef312d4a1..fa18af56c 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -168,7 +168,9 @@ void Element::refreshMedia() { _media = std::make_unique( this, group->items); - Auth().data().requestViewResize(this); + if (!pendingResize()) { + Auth().data().requestViewResize(this); + } } return; } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 00fe479af..b4d05fc61 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -247,6 +247,10 @@ ListWidget::ListWidget( } } }, lifetime()); + Auth().data().itemRemoved( + ) | rpl::start_with_next( + [this](auto item) { itemRemoved(item); }, + lifetime()); subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) { if (const auto view = viewForItem(query.item)) { const auto top = itemTop(view); @@ -1421,7 +1425,44 @@ void ListWidget::repaintItem(const Element *view) { } void ListWidget::refreshItem(not_null view) { - // #TODO + const auto i = ranges::find(_items, view); + const auto index = i - begin(_items); + if (index < int(_items.size())) { + const auto item = view->data(); + _views.erase(item); + const auto [i, ok] = _views.emplace( + item, + item->createView(_delegate)); + const auto was = view; + const auto now = i->second.get(); + _items[index] = now; + + viewReplaced(view, i->second.get()); + + updateItemsGeometry(); + } +} + +void ListWidget::viewReplaced(not_null was, Element *now) { + if (_visibleTopItem == was) _visibleTopItem = now; + if (_scrollDateLastItem == was) _scrollDateLastItem = now; + if (_mouseActionItem == was) _mouseActionItem = now; + if (_selectedItem == was) _selectedItem = now; +} + +void ListWidget::itemRemoved(not_null item) { + const auto i = _views.find(item); + if (i == end(_views)) { + return; + } + const auto view = i->second.get(); + _items.erase( + ranges::remove(_items, view, [](auto view) { return view.get(); }), + end(_items)); + viewReplaced(view, nullptr); + _views.erase(i); + + updateItemsGeometry(); } QPoint ListWidget::mapPointToItem( diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index c4d9c971b..c2d007c9d 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -156,6 +156,7 @@ private: int itemTop(not_null view) const; void repaintItem(const Element *view); void refreshItem(not_null view); + void itemRemoved(not_null item); QPoint mapPointToItem(QPoint point, const Element *view) const; void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false); @@ -177,6 +178,7 @@ private: not_null findItemByY(int y) const; Element *strictFindItemByY(int y) const; int findNearestItem(Data::MessagePosition position) const; + void viewReplaced(not_null was, Element *now); void checkMoveToOtherViewer(); void updateVisibleTopItem(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 293f05d64..7031a0dcd 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1552,9 +1552,7 @@ int Message::resizeContentGetHeight(int newWidth) { accumulate_min(contentWidth, maxWidth()); accumulate_min(contentWidth, st::msgMaxWidth); if (mediaDisplayed) { - media->resizeGetHeight(bubble - ? std::min(contentWidth, maxWidth()) - : contentWidth); + media->resizeGetHeight(contentWidth); if (media->width() < contentWidth) { const auto textualWidth = plainMaxWidth(); if (media->width() < textualWidth) { @@ -1577,7 +1575,6 @@ int Message::resizeContentGetHeight(int newWidth) { if (contentWidth == maxWidth()) { if (mediaDisplayed) { - media->resizeGetHeight(contentWidth); if (entry) { newHeight += entry->resizeGetHeight(contentWidth); } @@ -1606,7 +1603,7 @@ int Message::resizeContentGetHeight(int newWidth) { if (entry) newHeight += st::mediaInBubbleSkip; } if (mediaDisplayed) { - newHeight += media->resizeGetHeight(contentWidth); + newHeight += media->height(); if (entry) { newHeight += entry->resizeGetHeight(contentWidth); } @@ -1632,8 +1629,8 @@ int Message::resizeContentGetHeight(int newWidth) { reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right()); newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); } - } else if (media && media->isDisplayed()) { - newHeight = media->resizeGetHeight(contentWidth); + } else if (mediaDisplayed) { + newHeight = media->height(); } else { newHeight = 0; }