Fix albums layout and editing in feed.

This commit is contained in:
John Preston 2018-01-21 12:05:30 +03:00
parent b91ebad8be
commit f9154c4ed0
10 changed files with 71 additions and 19 deletions

View File

@ -1274,11 +1274,6 @@ namespace {
}
}
Auth().notifications().clearFromItem(item);
if (Global::started()
&& !App::quitting()
&& AuthSession::Exists()) {
Auth().data().notifyItemRemoved(item);
}
}
void historyUpdateDependent(not_null<HistoryItem*> item) {

View File

@ -36,7 +36,7 @@ void Groups::registerMessage(not_null<HistoryItem*> item) {
}
}
void Groups::unregisterMessage(not_null<HistoryItem*> item) {
void Groups::unregisterMessage(not_null<const HistoryItem*> item) {
const auto groupId = item->groupId();
if (!groupId) {
return;
@ -115,7 +115,13 @@ const Group *Groups::find(not_null<HistoryItem*> 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) {

View File

@ -24,7 +24,7 @@ public:
bool isGrouped(not_null<HistoryItem*> item) const;
void registerMessage(not_null<HistoryItem*> item);
void unregisterMessage(not_null<HistoryItem*> item);
void unregisterMessage(not_null<const HistoryItem*> item);
void refreshMessage(not_null<HistoryItem*> item);
const Group *find(not_null<HistoryItem*> item) const;

View File

@ -235,6 +235,7 @@ rpl::producer<not_null<const HistoryItem*>> Session::itemPlayInlineRequest() con
void Session::notifyItemRemoved(not_null<const HistoryItem*> item) {
_itemRemoved.fire_copy(item);
groups().unregisterMessage(item);
}
rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {

View File

@ -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<DeleteMessagesBox>(

View File

@ -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());

View File

@ -168,7 +168,9 @@ void Element::refreshMedia() {
_media = std::make_unique<HistoryGroupedMedia>(
this,
group->items);
Auth().data().requestViewResize(this);
if (!pendingResize()) {
Auth().data().requestViewResize(this);
}
}
return;
}

View File

@ -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<const Element*> 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<const Element*> 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<const HistoryItem*> 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(

View File

@ -156,6 +156,7 @@ private:
int itemTop(not_null<const Element*> view) const;
void repaintItem(const Element *view);
void refreshItem(not_null<const Element*> view);
void itemRemoved(not_null<const HistoryItem*> item);
QPoint mapPointToItem(QPoint point, const Element *view) const;
void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
@ -177,6 +178,7 @@ private:
not_null<Element*> findItemByY(int y) const;
Element *strictFindItemByY(int y) const;
int findNearestItem(Data::MessagePosition position) const;
void viewReplaced(not_null<const Element*> was, Element *now);
void checkMoveToOtherViewer();
void updateVisibleTopItem();

View File

@ -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;
}