From 475dec30149189c36b66bbdc596d2dfaa479746d Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 24 Nov 2024 17:49:15 +0400 Subject: [PATCH] Allow adding media to text with a link preview. --- .../SourceFiles/boxes/edit_caption_box.cpp | 2 +- Telegram/SourceFiles/history/history_item.cpp | 2 +- .../SourceFiles/history/history_widget.cpp | 2 +- .../history_view_compose_controls.cpp | 2 +- .../info/channels/info_channels_widget.cpp | 97 ------------------- .../info/channels/info_channels_widget.h | 74 -------------- 6 files changed, 4 insertions(+), 175 deletions(-) delete mode 100644 Telegram/SourceFiles/info/channels/info_channels_widget.cpp delete mode 100644 Telegram/SourceFiles/info/channels/info_channels_widget.h diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index f6e48b221..ae2cbc3d7 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -254,7 +254,7 @@ EditCaptionBox::EditCaptionBox( , _initialList(std::move(list)) , _saved(std::move(saved)) { Expects(!_initialList.files.empty()); - Expects(!item->media() || item->media()->allowsEditCaption()); + Expects(item->allowsEditMedia()); _mediaEditManager.start(item, spoilered, invertCaption); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 2c566ab1a..a63b7b6c3 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -2244,7 +2244,7 @@ bool HistoryItem::allowsEdit(TimeId now) const { bool HistoryItem::allowsEditMedia() const { return !awaitingVideoProcessing() - && (!_media || _media->allowsEditMedia()); + && (!_media || _media->allowsEditMedia() || _media->webpage()); } bool HistoryItem::canBeEdited() const { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index f9f3445de..49fea20a1 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -8555,7 +8555,7 @@ void HistoryWidget::updateReplyEditTexts(bool force) { _mediaEditManager.start(_replyEditMsg); } _canReplaceMedia = _editMsgId && _replyEditMsg->allowsEditMedia(); - if (editMedia) { + if (editMedia && editMedia->allowsEditMedia()) { _canAddMedia = false; } else { _canAddMedia = base::take(_canReplaceMedia); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index a2eefd668..0196405c9 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1960,7 +1960,7 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) { if (const auto item = _history->owner().message(editingId)) { const auto media = item->media(); _canReplaceMedia = item->allowsEditMedia(); - if (media) { + if (media && media->allowsEditMedia()) { _canAddMedia = false; } else { _canAddMedia = base::take(_canReplaceMedia); diff --git a/Telegram/SourceFiles/info/channels/info_channels_widget.cpp b/Telegram/SourceFiles/info/channels/info_channels_widget.cpp deleted file mode 100644 index 3b6c115a1..000000000 --- a/Telegram/SourceFiles/info/channels/info_channels_widget.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "info/channels/info_channels_widget.h" - -#include "info/feed/info_feed_channels.h" -#include "info/info_controller.h" -#include "ui/widgets/scroll_area.h" -#include "styles/style_info.h" - -namespace Info { -namespace Channels { - -Memento::Memento(not_null controller) -: Memento(controller->feed()) { -} - -Memento::Memento(not_null feed) -: ContentMemento(feed) { -} - -Section Memento::section() const { - return Section(Section::Type::Channels); -} - -object_ptr Memento::createWidget( - QWidget *parent, - not_null controller, - const QRect &geometry) { - auto result = object_ptr( - parent, - controller); - result->setInternalState(geometry, this); - return result; -} - -void Memento::setState(std::unique_ptr state) { - _state = std::move(state); -} - -std::unique_ptr Memento::state() { - return std::move(_state); -} - -Memento::~Memento() = default; - -Widget::Widget( - QWidget *parent, - not_null controller) -: ContentWidget(parent, controller) { - _inner = setInnerWidget(object_ptr( - this, - controller)); -} - -bool Widget::showInternal(not_null memento) { - if (!controller()->validateMementoPeer(memento)) { - return false; - } - if (auto membersMemento = dynamic_cast(memento.get())) { - restoreState(membersMemento); - return true; - } - return false; -} - -void Widget::setInternalState( - const QRect &geometry, - not_null memento) { - setGeometry(geometry); - Ui::SendPendingMoveResizeEvents(this); - restoreState(memento); -} - -std::unique_ptr Widget::doCreateMemento() { - auto result = std::make_unique(controller()); - saveState(result.get()); - return result; -} - -void Widget::saveState(not_null memento) { - memento->setScrollTop(scrollTopSave()); - memento->setState(_inner->saveState()); -} - -void Widget::restoreState(not_null memento) { - _inner->restoreState(memento->state()); - auto scrollTop = memento->scrollTop(); - scrollTopRestore(memento->scrollTop()); -} - -} // namespace Channels -} // namespace Info diff --git a/Telegram/SourceFiles/info/channels/info_channels_widget.h b/Telegram/SourceFiles/info/channels/info_channels_widget.h deleted file mode 100644 index 431f94ec1..000000000 --- a/Telegram/SourceFiles/info/channels/info_channels_widget.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "info/info_content_widget.h" - -struct PeerListState; - -namespace Data { -class Feed; -} // namespace Data - -namespace Info { -namespace FeedProfile { -class Channels; -struct ChannelsState; -} // namespace FeedProfile - -namespace Channels { - -using SavedState = FeedProfile::ChannelsState; - -class Memento final : public ContentMemento { -public: - explicit Memento(not_null controller); - explicit Memento(not_null feed); - - object_ptr createWidget( - QWidget *parent, - not_null controller, - const QRect &geometry) override; - - Section section() const override; - - void setState(std::unique_ptr state); - std::unique_ptr state(); - - ~Memento(); - -private: - std::unique_ptr _state; - -}; - -class Widget final : public ContentWidget { -public: - Widget( - QWidget *parent, - not_null controller); - - bool showInternal( - not_null memento) override; - - void setInternalState( - const QRect &geometry, - not_null memento); - -private: - void saveState(not_null memento); - void restoreState(not_null memento); - - std::unique_ptr doCreateMemento() override; - - FeedProfile::Channels *_inner = nullptr; - -}; - -} // namespace Channels -} // namespace Info