2018-01-25 10:10:52 +00:00
|
|
|
/*
|
|
|
|
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 "history/view/history_view_context_menu.h"
|
|
|
|
|
|
|
|
#include "history/view/history_view_list_widget.h"
|
2018-01-28 15:08:34 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
|
|
|
#include "history/history.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-28 15:08:34 +00:00
|
|
|
#include "history/history_message.h"
|
2018-01-26 15:40:11 +00:00
|
|
|
#include "history/history_item_text.h"
|
2018-12-18 10:45:06 +00:00
|
|
|
#include "history/media/history_media.h"
|
|
|
|
#include "history/media/history_media_web_page.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-04-04 10:02:22 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2018-01-28 15:08:34 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2018-11-26 11:55:02 +00:00
|
|
|
#include "boxes/sticker_set_box.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_media_types.h"
|
2018-01-28 15:08:34 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_groups.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "core/file_utilities.h"
|
2019-06-03 14:41:23 +00:00
|
|
|
#include "platform/platform_info.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2019-07-25 18:55:11 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
#include "mainwidget.h"
|
2019-06-24 15:09:37 +00:00
|
|
|
#include "mainwindow.h" // App::wnd()->sessionController
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-07-16 19:41:43 +00:00
|
|
|
#include "apiwrap.h"
|
2018-01-25 10:10:52 +00:00
|
|
|
|
|
|
|
namespace HistoryView {
|
|
|
|
namespace {
|
|
|
|
|
2019-04-05 11:50:16 +00:00
|
|
|
// If we can't cloud-export link for such time we export it locally.
|
|
|
|
constexpr auto kExportLocalTimeout = crl::time(1000);
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
//void AddToggleGroupingAction( // #feed
|
|
|
|
// not_null<Ui::PopupMenu*> menu,
|
|
|
|
// not_null<PeerData*> peer) {
|
|
|
|
// if (const auto channel = peer->asChannel()) {
|
|
|
|
// const auto grouped = (channel->feed() != nullptr);
|
|
|
|
// menu->addAction( // #feed
|
2019-06-19 15:09:03 +00:00
|
|
|
// grouped ? tr::lng_feed_ungroup(tr::now) : tr::lng_feed_group(tr::now),
|
2019-04-15 11:54:03 +00:00
|
|
|
// [=] { Window::ToggleChannelGrouping(channel, !grouped); });
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-25 10:10:52 +00:00
|
|
|
|
|
|
|
void SavePhotoToFile(not_null<PhotoData*> photo) {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (photo->isNull() || !photo->loaded()) {
|
2018-01-25 10:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog::GetWritePath(
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().getFileDialogParent(),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_save_photo(tr::now),
|
2018-01-25 10:10:52 +00:00
|
|
|
qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(),
|
|
|
|
filedialogDefaultName(qsl("photo"), qsl(".jpg")),
|
2019-07-24 11:13:51 +00:00
|
|
|
crl::guard(&photo->session(), [=](const QString &result) {
|
2018-01-25 10:10:52 +00:00
|
|
|
if (!result.isEmpty()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
photo->large()->original().save(result, "JPG");
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyImage(not_null<PhotoData*> photo) {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (photo->isNull() || !photo->loaded()) {
|
2018-01-25 10:10:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
QApplication::clipboard()->setImage(photo->large()->original());
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-01-28 15:08:34 +00:00
|
|
|
void ShowStickerPackInfo(not_null<DocumentData*> document) {
|
2019-06-24 15:09:37 +00:00
|
|
|
StickerSetBox::Show(App::wnd()->sessionController(), document);
|
2018-01-28 15:08:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 19:41:43 +00:00
|
|
|
void ToggleFavedSticker(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FullMsgId contextId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
document->session().api().toggleFavedSticker(
|
2018-07-16 19:41:43 +00:00
|
|
|
document,
|
|
|
|
contextId,
|
|
|
|
!Stickers::IsFaved(document));
|
2018-01-28 15:08:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
void AddPhotoActions(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
not_null<PhotoData*> photo) {
|
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_context_save_image(tr::now),
|
2018-01-25 10:10:52 +00:00
|
|
|
App::LambdaDelayed(
|
|
|
|
st::defaultDropdownMenu.menu.ripple.hideDuration,
|
2019-07-24 11:13:51 +00:00
|
|
|
&photo->session(),
|
2018-01-25 10:10:52 +00:00
|
|
|
[=] { SavePhotoToFile(photo); }));
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_copy_image(tr::now), [=] {
|
2018-01-25 10:10:52 +00:00
|
|
|
CopyImage(photo);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGif(FullMsgId itemId) {
|
2019-04-25 12:45:15 +00:00
|
|
|
if (const auto item = Auth().data().message(itemId)) {
|
2018-01-25 10:10:52 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().showDocument(document, item);
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowInFolder(not_null<DocumentData*> document) {
|
|
|
|
const auto filepath = document->filepath(
|
2019-03-13 09:35:47 +00:00
|
|
|
DocumentData::FilePathResolve::Checked);
|
2018-01-25 10:10:52 +00:00
|
|
|
if (!filepath.isEmpty()) {
|
|
|
|
File::ShowInFolder(filepath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSaveDocumentAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
2018-01-25 10:10:52 +00:00
|
|
|
not_null<DocumentData*> document) {
|
2019-02-27 11:36:19 +00:00
|
|
|
const auto save = [=] {
|
2019-03-11 14:35:11 +00:00
|
|
|
DocumentSaveClickHandler::Save(
|
|
|
|
origin,
|
|
|
|
document,
|
|
|
|
DocumentSaveClickHandler::Mode::ToNewFile);
|
2019-02-27 11:36:19 +00:00
|
|
|
};
|
2019-06-19 15:09:03 +00:00
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(document->isVideoFile()
|
|
|
|
? tr::lng_context_save_video(tr::now)
|
2018-01-25 10:10:52 +00:00
|
|
|
: (document->isVoiceMessage()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_save_audio(tr::now)
|
2018-01-25 10:10:52 +00:00
|
|
|
: (document->isAudioFile()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_save_audio_file(tr::now)
|
2018-01-25 10:10:52 +00:00
|
|
|
: (document->sticker()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_save_image(tr::now)
|
|
|
|
: tr::lng_context_save_file(tr::now))))),
|
2018-01-25 10:10:52 +00:00
|
|
|
App::LambdaDelayed(
|
|
|
|
st::defaultDropdownMenu.menu.ripple.hideDuration,
|
2019-07-24 11:13:51 +00:00
|
|
|
&document->session(),
|
2019-02-27 11:36:19 +00:00
|
|
|
save));
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddDocumentActions(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FullMsgId contextId) {
|
|
|
|
if (document->loading()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_cancel_download(tr::now), [=] {
|
2018-01-25 10:10:52 +00:00
|
|
|
document->cancel();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (document->loaded() && document->isGifv()) {
|
|
|
|
if (!cAutoPlayGif()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
|
2018-01-25 10:10:52 +00:00
|
|
|
OpenGif(contextId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-01-28 15:08:34 +00:00
|
|
|
if (document->sticker()
|
|
|
|
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
|
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(document->isStickerSetInstalled()
|
|
|
|
? tr::lng_context_pack_info(tr::now)
|
|
|
|
: tr::lng_context_pack_add(tr::now)),
|
2018-01-28 15:08:34 +00:00
|
|
|
[=] { ShowStickerPackInfo(document); });
|
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(Stickers::IsFaved(document)
|
|
|
|
? tr::lng_faved_stickers_remove(tr::now)
|
|
|
|
: tr::lng_faved_stickers_add(tr::now)),
|
2018-07-16 19:41:43 +00:00
|
|
|
[=] { ToggleFavedSticker(document, contextId); });
|
2018-01-28 15:08:34 +00:00
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
if (!document->filepath(
|
2019-03-13 09:35:47 +00:00
|
|
|
DocumentData::FilePathResolve::Checked).isEmpty()) {
|
2018-01-25 10:10:52 +00:00
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(Platform::IsMac()
|
|
|
|
? tr::lng_context_show_in_finder(tr::now)
|
|
|
|
: tr::lng_context_show_in_folder(tr::now)),
|
2018-01-25 10:10:52 +00:00
|
|
|
[=] { ShowInFolder(document); });
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
AddSaveDocumentAction(menu, contextId, document);
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-01-28 15:08:34 +00:00
|
|
|
void AddPostLinkAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request) {
|
|
|
|
const auto item = request.item;
|
|
|
|
if (!item
|
|
|
|
|| !item->hasDirectLink()
|
|
|
|
|| request.pointState == PointState::Outside) {
|
|
|
|
return;
|
|
|
|
} else if (request.link
|
|
|
|
&& !request.link->copyToClipboardContextItemText().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto itemId = item->fullId();
|
|
|
|
menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(item->history()->peer->isMegagroup()
|
|
|
|
? tr::lng_context_copy_link
|
|
|
|
: tr::lng_context_copy_post_link)(tr::now),
|
2018-01-28 15:08:34 +00:00
|
|
|
[=] { CopyPostLink(itemId); });
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageIdsList ExtractIdsList(const SelectedItems &items) {
|
|
|
|
return ranges::view::all(
|
|
|
|
items
|
|
|
|
) | ranges::view::transform([](const auto &item) {
|
|
|
|
return item.msgId;
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddForwardSelectedAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
if (!request.overSelection || request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ranges::find_if(request.selectedItems, [](const auto &item) {
|
|
|
|
return !item.canForward;
|
|
|
|
}) != end(request.selectedItems)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_forward_selected(tr::now), [=] {
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto weak = make_weak(list);
|
2019-07-25 18:55:11 +00:00
|
|
|
const auto callback = [=] {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (const auto strong = weak.data()) {
|
|
|
|
strong->cancelSelection();
|
|
|
|
}
|
2019-07-25 18:55:11 +00:00
|
|
|
};
|
|
|
|
Window::ShowForwardMessagesBox(
|
|
|
|
request.navigation,
|
|
|
|
ExtractIdsList(request.selectedItems),
|
|
|
|
callback);
|
2018-01-28 15:08:34 +00:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddForwardMessageAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
const auto item = request.item;
|
|
|
|
if (!request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
} else if (!item || !item->allowsForward()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &item->history()->owner();
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto asGroup = (request.pointState != PointState::GroupPart);
|
|
|
|
if (asGroup) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = owner->groups().find(item)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (ranges::find_if(group->items, [](auto item) {
|
|
|
|
return !item->allowsForward();
|
|
|
|
}) != end(group->items)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto itemId = item->fullId();
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_forward_msg(tr::now), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2019-07-25 18:55:11 +00:00
|
|
|
Window::ShowForwardMessagesBox(
|
|
|
|
request.navigation,
|
|
|
|
(asGroup
|
|
|
|
? owner->itemOrItsGroup(item)
|
|
|
|
: MessageIdsList{ 1, itemId }));
|
2018-01-28 15:08:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddForwardAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
AddForwardSelectedAction(menu, request, list);
|
|
|
|
AddForwardMessageAction(menu, request, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddDeleteSelectedAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
if (!request.overSelection || request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ranges::find_if(request.selectedItems, [](const auto &item) {
|
|
|
|
return !item.canDelete;
|
|
|
|
}) != end(request.selectedItems)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_delete_selected(tr::now), [=] {
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto weak = make_weak(list);
|
|
|
|
auto items = ExtractIdsList(request.selectedItems);
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto box = Ui::show(Box<DeleteMessagesBox>(
|
2019-07-25 18:55:11 +00:00
|
|
|
&request.navigation->session(),
|
2019-07-24 14:00:30 +00:00
|
|
|
std::move(items)));
|
2018-01-28 15:08:34 +00:00
|
|
|
box->setDeleteConfirmedCallback([=] {
|
|
|
|
if (const auto strong = weak.data()) {
|
|
|
|
strong->cancelSelection();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddDeleteMessageAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
const auto item = request.item;
|
|
|
|
if (!request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
} else if (!item || !item->canDelete()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &item->history()->owner();
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto asGroup = (request.pointState != PointState::GroupPart);
|
|
|
|
if (asGroup) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = owner->groups().find(item)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (ranges::find_if(group->items, [](auto item) {
|
|
|
|
return !IsServerMsgId(item->id) || !item->canDelete();
|
|
|
|
}) != end(group->items)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto itemId = item->fullId();
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_delete_msg(tr::now), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (asGroup) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = owner->groups().find(item)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
Ui::show(Box<DeleteMessagesBox>(
|
2019-07-24 14:00:30 +00:00
|
|
|
&owner->session(),
|
2019-07-24 11:13:51 +00:00
|
|
|
owner->itemsToIds(group->items)));
|
2018-01-28 15:08:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (const auto message = item->toHistoryMessage()) {
|
|
|
|
if (message->uploading()) {
|
|
|
|
App::main()->cancelUploadLayer(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto suggestModerateActions = true;
|
|
|
|
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddDeleteAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
if (!AddDeleteSelectedAction(menu, request, list)) {
|
|
|
|
AddDeleteMessageAction(menu, request, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddClearSelectionAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
if (!request.overSelection || request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_clear_selection(tr::now), [=] {
|
2018-01-28 15:08:34 +00:00
|
|
|
list->cancelSelection();
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddSelectMessageAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
const auto item = request.item;
|
|
|
|
if (request.overSelection && !request.selectedItems.empty()) {
|
|
|
|
return false;
|
|
|
|
} else if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &item->history()->owner();
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto itemId = item->fullId();
|
|
|
|
const auto asGroup = (request.pointState != PointState::GroupPart);
|
2019-06-19 15:09:03 +00:00
|
|
|
menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (asGroup) {
|
|
|
|
list->selectItemAsGroup(item);
|
|
|
|
} else {
|
|
|
|
list->selectItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSelectionAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
if (!AddClearSelectionAction(menu, request, list)) {
|
|
|
|
AddSelectMessageAction(menu, request, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddMessageActions(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ContextMenuRequest &request,
|
|
|
|
not_null<ListWidget*> list) {
|
|
|
|
AddPostLinkAction(menu, request);
|
|
|
|
AddForwardAction(menu, request, list);
|
|
|
|
AddDeleteAction(menu, request, list);
|
|
|
|
AddSelectionAction(menu, request, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddCopyLinkAction(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
|
|
|
const ClickHandlerPtr &link) {
|
|
|
|
if (!link) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto action = link->copyToClipboardContextItemText();
|
|
|
|
if (action.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto text = link->copyToClipboardText();
|
|
|
|
menu->addAction(
|
|
|
|
action,
|
|
|
|
[=] { QApplication::clipboard()->setText(text); });
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
ContextMenuRequest::ContextMenuRequest(
|
|
|
|
not_null<Window::SessionNavigation*> navigation)
|
|
|
|
: navigation(navigation) {
|
2019-07-24 14:00:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> FillContextMenu(
|
|
|
|
not_null<ListWidget*> list,
|
|
|
|
const ContextMenuRequest &request) {
|
2018-07-19 14:27:09 +00:00
|
|
|
auto result = base::make_unique_q<Ui::PopupMenu>(list);
|
2018-01-25 10:10:52 +00:00
|
|
|
|
|
|
|
const auto link = request.link;
|
|
|
|
const auto view = request.view;
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto item = request.item;
|
2018-01-25 10:10:52 +00:00
|
|
|
const auto itemId = item ? item->fullId() : FullMsgId();
|
|
|
|
const auto rawLink = link.get();
|
|
|
|
const auto linkPhoto = dynamic_cast<PhotoClickHandler*>(rawLink);
|
|
|
|
const auto linkDocument = dynamic_cast<DocumentClickHandler*>(rawLink);
|
|
|
|
const auto linkPeer = dynamic_cast<PeerClickHandler*>(rawLink);
|
|
|
|
const auto photo = linkPhoto ? linkPhoto->photo().get() : nullptr;
|
|
|
|
const auto document = linkDocument
|
|
|
|
? linkDocument->document().get()
|
|
|
|
: nullptr;
|
|
|
|
const auto isVideoLink = document ? document->isVideoFile() : false;
|
|
|
|
const auto isVoiceLink = document ? document->isVoiceMessage() : false;
|
|
|
|
const auto isAudioLink = document ? document->isAudioFile() : false;
|
|
|
|
const auto hasSelection = !request.selectedItems.empty()
|
2019-04-08 15:10:06 +00:00
|
|
|
|| !request.selectedText.empty();
|
2018-01-25 10:10:52 +00:00
|
|
|
|
|
|
|
if (request.overSelection) {
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = request.selectedItems.empty()
|
|
|
|
? tr::lng_context_copy_selected(tr::now)
|
|
|
|
: tr::lng_context_copy_selected_items(tr::now);
|
2018-01-28 15:08:34 +00:00
|
|
|
result->addAction(text, [=] {
|
2019-04-08 15:10:06 +00:00
|
|
|
SetClipboardText(list->getSelectedText());
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linkPhoto) {
|
|
|
|
AddPhotoActions(result, photo);
|
|
|
|
} else if (linkDocument) {
|
|
|
|
AddDocumentActions(result, document, itemId);
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (linkPeer) { // #feed
|
|
|
|
// const auto peer = linkPeer->peer();
|
|
|
|
// if (peer->isChannel()
|
|
|
|
// && peer->asChannel()->feed() != nullptr
|
|
|
|
// && (list->delegate()->listContext() == Context::Feed)) {
|
|
|
|
// Window::PeerMenuAddMuteAction(peer, [&](
|
|
|
|
// const QString &text,
|
|
|
|
// Fn<void()> handler) {
|
|
|
|
// return result->addAction(text, handler);
|
|
|
|
// });
|
|
|
|
// AddToggleGroupingAction(result, linkPeer->peer());
|
|
|
|
// }
|
2018-01-28 15:08:34 +00:00
|
|
|
} else if (!request.overSelection && view && !hasSelection) {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &view->data()->history()->owner();
|
2018-12-18 11:06:57 +00:00
|
|
|
const auto media = view->media();
|
2018-01-28 15:08:34 +00:00
|
|
|
const auto mediaHasTextForCopy = media && media->hasTextForCopy();
|
2018-12-18 11:06:57 +00:00
|
|
|
if (const auto document = media ? media->getDocument() : nullptr) {
|
|
|
|
AddDocumentActions(result, document, view->data()->fullId());
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
2018-01-28 15:08:34 +00:00
|
|
|
if (!link && (view->hasVisibleText() || mediaHasTextForCopy)) {
|
|
|
|
const auto asGroup = (request.pointState != PointState::GroupPart);
|
2019-06-19 15:09:03 +00:00
|
|
|
result->addAction(tr::lng_context_copy_text(tr::now), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(itemId)) {
|
2018-01-28 15:08:34 +00:00
|
|
|
if (asGroup) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = owner->groups().find(item)) {
|
2019-04-08 15:10:06 +00:00
|
|
|
SetClipboardText(HistoryGroupText(group));
|
2018-01-28 15:08:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 15:10:06 +00:00
|
|
|
SetClipboardText(HistoryItemText(item));
|
2018-01-28 15:08:34 +00:00
|
|
|
}
|
|
|
|
});
|
2018-01-25 10:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-28 15:08:34 +00:00
|
|
|
|
|
|
|
AddCopyLinkAction(result, link);
|
|
|
|
AddMessageActions(result, request, list);
|
2018-01-25 10:10:52 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-04-04 10:02:22 +00:00
|
|
|
void CopyPostLink(FullMsgId itemId) {
|
2019-04-25 12:45:15 +00:00
|
|
|
const auto item = Auth().data().message(itemId);
|
2019-04-05 11:50:16 +00:00
|
|
|
if (!item || !item->hasDirectLink()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QApplication::clipboard()->setText(
|
|
|
|
item->history()->session().api().exportDirectMessageLink(item));
|
2019-04-04 10:02:22 +00:00
|
|
|
|
2019-04-05 11:50:16 +00:00
|
|
|
const auto channel = item->history()->peer->asChannel();
|
|
|
|
Assert(channel != nullptr);
|
2019-04-04 10:02:22 +00:00
|
|
|
|
2019-06-21 12:27:46 +00:00
|
|
|
Ui::Toast::Show(channel->hasUsername()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_channel_public_link_copied(tr::now)
|
|
|
|
: tr::lng_context_about_private_link(tr::now));
|
2019-04-04 10:02:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
void StopPoll(FullMsgId itemId) {
|
2019-04-05 11:50:16 +00:00
|
|
|
const auto stop = [=] {
|
|
|
|
Ui::hideLayer();
|
2019-04-25 12:45:15 +00:00
|
|
|
if (const auto item = Auth().data().message(itemId)) {
|
2019-04-05 11:50:16 +00:00
|
|
|
item->history()->session().api().closePoll(item);
|
|
|
|
}
|
|
|
|
};
|
2018-12-19 11:20:04 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_polls_stop_warning(tr::now),
|
|
|
|
tr::lng_polls_stop_sure(tr::now),
|
|
|
|
tr::lng_cancel(tr::now),
|
2019-04-05 11:50:16 +00:00
|
|
|
stop));
|
2018-12-19 11:20:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
} // namespace HistoryView
|