Skip to content

Commit

Permalink
Don't allow forwarding local items by drag.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 1, 2024
1 parent 715dff0 commit e54204b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
35 changes: 24 additions & 11 deletions Telegram/SourceFiles/history/history_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,9 @@ std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
updateDragSelection(nullptr, nullptr, false);
_selectScroll.cancel();

if (!urls.isEmpty()) mimeData->setUrls(urls);
if (!urls.isEmpty()) {
mimeData->setUrls(urls);
}
if (uponSelected && !_controller->adaptive().isOneColumn()) {
auto selectedState = getSelectionState();
if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) {
Expand All @@ -1752,34 +1754,45 @@ std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
== forwardSelectionState.canForwardCount)) {
forwardIds = getSelectedItems();
} else if (_mouseCursorState == CursorState::Date) {
forwardIds = session().data().itemOrItsGroup(_mouseActionItem);
const auto item = _mouseActionItem;
if (item && item->allowsForward()) {
forwardIds = session().data().itemOrItsGroup(item);
}
} else if ((pressedView->isHiddenByGroup() && pressedHandler)
|| (pressedView->media()
&& pressedView->media()->dragItemByHandler(pressedHandler))) {
const auto item = _dragStateItem
? _dragStateItem
: _mouseActionItem;
forwardIds = MessageIdsList(1, item->fullId());
}
if (forwardIds.empty()) {
return nullptr;
if (item && item->allowsForward()) {
forwardIds = MessageIdsList(1, item->fullId());
}
}
session().data().setMimeForwardIds(std::move(forwardIds));
auto result = std::make_unique<QMimeData>();
result->setData(u"application/x-td-forward"_q, "1");

if (pressedHandler) {
const auto lnkDocument = reinterpret_cast<DocumentData*>(
pressedHandler->property(
kDocumentLinkMediaProperty).toULongLong());
if (lnkDocument) {
const auto filepath = lnkDocument->filepath(true);
if (!filepath.isEmpty()) {
QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath));
result->setUrls(urls);
}
}
}

if (forwardIds.empty() && urls.isEmpty()) {
return nullptr;
}

auto result = std::make_unique<QMimeData>();
if (!forwardIds.empty()) {
session().data().setMimeForwardIds(std::move(forwardIds));
result->setData(u"application/x-td-forward"_q, "1");
}
if (!urls.isEmpty()) {
result->setUrls(urls);
}
return result;
}
return nullptr;
Expand Down
22 changes: 14 additions & 8 deletions Telegram/SourceFiles/history/view/history_view_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3778,25 +3778,31 @@ std::unique_ptr<QMimeData> ListWidget::prepareDrag() {
forwardIds = MessageIdsList(1, exactItem->fullId());
}
}
if (forwardIds.empty()) {
return nullptr;
}
session().data().setMimeForwardIds(std::move(forwardIds));
auto result = std::make_unique<QMimeData>();
result->setData(u"application/x-td-forward"_q, "1");

if (pressedHandler) {
const auto lnkDocument = reinterpret_cast<DocumentData*>(
pressedHandler->property(
kDocumentLinkMediaProperty).toULongLong());
if (lnkDocument) {
const auto filepath = lnkDocument->filepath(true);
if (!filepath.isEmpty()) {
QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath));
result->setUrls(urls);
}
}
}

if (forwardIds.empty() && urls.isEmpty()) {
return nullptr;
}

auto result = std::make_unique<QMimeData>();
if (!forwardIds.empty()) {
session().data().setMimeForwardIds(std::move(forwardIds));
result->setData(u"application/x-td-forward"_q, "1");
}
if (!urls.isEmpty()) {
result->setUrls(urls);
}
return result;
}
return nullptr;
Expand Down

0 comments on commit e54204b

Please sign in to comment.