Fix albums layout and editing in feed.
This commit is contained in:
		
							parent
							
								
									b91ebad8be
								
							
						
					
					
						commit
						f9154c4ed0
					
				
					 10 changed files with 71 additions and 19 deletions
				
			
		| 
						 | 
					@ -1274,11 +1274,6 @@ namespace {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Auth().notifications().clearFromItem(item);
 | 
							Auth().notifications().clearFromItem(item);
 | 
				
			||||||
		if (Global::started()
 | 
					 | 
				
			||||||
			&& !App::quitting()
 | 
					 | 
				
			||||||
			&& AuthSession::Exists()) {
 | 
					 | 
				
			||||||
			Auth().data().notifyItemRemoved(item);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void historyUpdateDependent(not_null<HistoryItem*> item) {
 | 
						void historyUpdateDependent(not_null<HistoryItem*> item) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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();
 | 
						const auto groupId = item->groupId();
 | 
				
			||||||
	if (!groupId) {
 | 
						if (!groupId) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -115,7 +115,13 @@ const Group *Groups::find(not_null<HistoryItem*> item) const {
 | 
				
			||||||
		return nullptr;
 | 
							return nullptr;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const auto i = _groups.find(groupId);
 | 
						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) {
 | 
					void Groups::refreshViews(const HistoryItemsList &items) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool isGrouped(not_null<HistoryItem*> item) const;
 | 
						bool isGrouped(not_null<HistoryItem*> item) const;
 | 
				
			||||||
	void registerMessage(not_null<HistoryItem*> item);
 | 
						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);
 | 
						void refreshMessage(not_null<HistoryItem*> item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const Group *find(not_null<HistoryItem*> item) const;
 | 
						const Group *find(not_null<HistoryItem*> item) const;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -235,6 +235,7 @@ rpl::producer<not_null<const HistoryItem*>> Session::itemPlayInlineRequest() con
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Session::notifyItemRemoved(not_null<const HistoryItem*> item) {
 | 
					void Session::notifyItemRemoved(not_null<const HistoryItem*> item) {
 | 
				
			||||||
	_itemRemoved.fire_copy(item);
 | 
						_itemRemoved.fire_copy(item);
 | 
				
			||||||
 | 
						groups().unregisterMessage(item);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {
 | 
					rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2789,7 +2789,7 @@ bool HistoryInner::hasPendingResizedItems() const {
 | 
				
			||||||
void HistoryInner::deleteAsGroup(FullMsgId itemId) {
 | 
					void HistoryInner::deleteAsGroup(FullMsgId itemId) {
 | 
				
			||||||
	if (const auto item = App::histItemById(itemId)) {
 | 
						if (const auto item = App::histItemById(itemId)) {
 | 
				
			||||||
		const auto group = Auth().data().groups().find(item);
 | 
							const auto group = Auth().data().groups().find(item);
 | 
				
			||||||
		if (!group || group->items.size() < 2) {
 | 
							if (!group) {
 | 
				
			||||||
			return deleteItem(item);
 | 
								return deleteItem(item);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Ui::show(Box<DeleteMessagesBox>(
 | 
							Ui::show(Box<DeleteMessagesBox>(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "storage/file_upload.h"
 | 
					#include "storage/file_upload.h"
 | 
				
			||||||
#include "storage/storage_facade.h"
 | 
					#include "storage/storage_facade.h"
 | 
				
			||||||
#include "storage/storage_shared_media.h"
 | 
					#include "storage/storage_shared_media.h"
 | 
				
			||||||
 | 
					#include "storage/storage_feed_messages.h"
 | 
				
			||||||
#include "auth_session.h"
 | 
					#include "auth_session.h"
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
#include "media/media_audio.h"
 | 
					#include "media/media_audio.h"
 | 
				
			||||||
| 
						 | 
					@ -320,6 +321,13 @@ void HistoryItem::indexAsNewItem() {
 | 
				
			||||||
				types,
 | 
									types,
 | 
				
			||||||
				id));
 | 
									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() {
 | 
					HistoryItem::~HistoryItem() {
 | 
				
			||||||
	Auth().data().groups().unregisterMessage(this);
 | 
						Auth().data().notifyItemRemoved(this);
 | 
				
			||||||
	App::historyUnregItem(this);
 | 
						App::historyUnregItem(this);
 | 
				
			||||||
	if (id < 0 && !App::quitting()) {
 | 
						if (id < 0 && !App::quitting()) {
 | 
				
			||||||
		Auth().uploader().cancel(fullId());
 | 
							Auth().uploader().cancel(fullId());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -168,7 +168,9 @@ void Element::refreshMedia() {
 | 
				
			||||||
				_media = std::make_unique<HistoryGroupedMedia>(
 | 
									_media = std::make_unique<HistoryGroupedMedia>(
 | 
				
			||||||
					this,
 | 
										this,
 | 
				
			||||||
					group->items);
 | 
										group->items);
 | 
				
			||||||
				Auth().data().requestViewResize(this);
 | 
									if (!pendingResize()) {
 | 
				
			||||||
 | 
										Auth().data().requestViewResize(this);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -247,6 +247,10 @@ ListWidget::ListWidget(
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, lifetime());
 | 
						}, lifetime());
 | 
				
			||||||
 | 
						Auth().data().itemRemoved(
 | 
				
			||||||
 | 
						) | rpl::start_with_next(
 | 
				
			||||||
 | 
							[this](auto item) { itemRemoved(item); },
 | 
				
			||||||
 | 
							lifetime());
 | 
				
			||||||
	subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) {
 | 
						subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) {
 | 
				
			||||||
		if (const auto view = viewForItem(query.item)) {
 | 
							if (const auto view = viewForItem(query.item)) {
 | 
				
			||||||
			const auto top = itemTop(view);
 | 
								const auto top = itemTop(view);
 | 
				
			||||||
| 
						 | 
					@ -1421,7 +1425,44 @@ void ListWidget::repaintItem(const Element *view) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ListWidget::refreshItem(not_null<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(
 | 
					QPoint ListWidget::mapPointToItem(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -156,6 +156,7 @@ private:
 | 
				
			||||||
	int itemTop(not_null<const Element*> view) const;
 | 
						int itemTop(not_null<const Element*> view) const;
 | 
				
			||||||
	void repaintItem(const Element *view);
 | 
						void repaintItem(const Element *view);
 | 
				
			||||||
	void refreshItem(not_null<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;
 | 
						QPoint mapPointToItem(QPoint point, const Element *view) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
 | 
						void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
 | 
				
			||||||
| 
						 | 
					@ -177,6 +178,7 @@ private:
 | 
				
			||||||
	not_null<Element*> findItemByY(int y) const;
 | 
						not_null<Element*> findItemByY(int y) const;
 | 
				
			||||||
	Element *strictFindItemByY(int y) const;
 | 
						Element *strictFindItemByY(int y) const;
 | 
				
			||||||
	int findNearestItem(Data::MessagePosition position) const;
 | 
						int findNearestItem(Data::MessagePosition position) const;
 | 
				
			||||||
 | 
						void viewReplaced(not_null<const Element*> was, Element *now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void checkMoveToOtherViewer();
 | 
						void checkMoveToOtherViewer();
 | 
				
			||||||
	void updateVisibleTopItem();
 | 
						void updateVisibleTopItem();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1552,9 +1552,7 @@ int Message::resizeContentGetHeight(int newWidth) {
 | 
				
			||||||
	accumulate_min(contentWidth, maxWidth());
 | 
						accumulate_min(contentWidth, maxWidth());
 | 
				
			||||||
	accumulate_min(contentWidth, st::msgMaxWidth);
 | 
						accumulate_min(contentWidth, st::msgMaxWidth);
 | 
				
			||||||
	if (mediaDisplayed) {
 | 
						if (mediaDisplayed) {
 | 
				
			||||||
		media->resizeGetHeight(bubble
 | 
							media->resizeGetHeight(contentWidth);
 | 
				
			||||||
			? std::min(contentWidth, maxWidth())
 | 
					 | 
				
			||||||
			: contentWidth);
 | 
					 | 
				
			||||||
		if (media->width() < contentWidth) {
 | 
							if (media->width() < contentWidth) {
 | 
				
			||||||
			const auto textualWidth = plainMaxWidth();
 | 
								const auto textualWidth = plainMaxWidth();
 | 
				
			||||||
			if (media->width() < textualWidth) {
 | 
								if (media->width() < textualWidth) {
 | 
				
			||||||
| 
						 | 
					@ -1577,7 +1575,6 @@ int Message::resizeContentGetHeight(int newWidth) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (contentWidth == maxWidth()) {
 | 
							if (contentWidth == maxWidth()) {
 | 
				
			||||||
			if (mediaDisplayed) {
 | 
								if (mediaDisplayed) {
 | 
				
			||||||
				media->resizeGetHeight(contentWidth);
 | 
					 | 
				
			||||||
				if (entry) {
 | 
									if (entry) {
 | 
				
			||||||
					newHeight += entry->resizeGetHeight(contentWidth);
 | 
										newHeight += entry->resizeGetHeight(contentWidth);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -1606,7 +1603,7 @@ int Message::resizeContentGetHeight(int newWidth) {
 | 
				
			||||||
				if (entry) newHeight += st::mediaInBubbleSkip;
 | 
									if (entry) newHeight += st::mediaInBubbleSkip;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (mediaDisplayed) {
 | 
								if (mediaDisplayed) {
 | 
				
			||||||
				newHeight += media->resizeGetHeight(contentWidth);
 | 
									newHeight += media->height();
 | 
				
			||||||
				if (entry) {
 | 
									if (entry) {
 | 
				
			||||||
					newHeight += entry->resizeGetHeight(contentWidth);
 | 
										newHeight += entry->resizeGetHeight(contentWidth);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -1632,8 +1629,8 @@ int Message::resizeContentGetHeight(int newWidth) {
 | 
				
			||||||
			reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
 | 
								reply->resize(contentWidth - st::msgPadding.left() - st::msgPadding.right());
 | 
				
			||||||
			newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
 | 
								newHeight += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (media && media->isDisplayed()) {
 | 
						} else if (mediaDisplayed) {
 | 
				
			||||||
		newHeight = media->resizeGetHeight(contentWidth);
 | 
							newHeight = media->height();
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		newHeight = 0;
 | 
							newHeight = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue