mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added Up arrow shortcut to edit scheduled messages.
This commit is contained in:
parent
e862215efb
commit
11018d76f1
9 changed files with 88 additions and 27 deletions
|
@ -527,4 +527,19 @@ int32 ScheduledMessages::countListHash(const List &list) const {
|
||||||
return HashFinalize(hash);
|
return HashFinalize(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HistoryItem *ScheduledMessages::lastSentMessage(not_null<History*> history) {
|
||||||
|
const auto i = _data.find(history);
|
||||||
|
if (i == end(_data)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
auto &list = i->second;
|
||||||
|
|
||||||
|
sort(list);
|
||||||
|
const auto items = ranges::view::reverse(list.items);
|
||||||
|
const auto it = ranges::find_if(
|
||||||
|
items,
|
||||||
|
&HistoryItem::canBeEditedFromHistory);
|
||||||
|
return (it == end(items)) ? nullptr : (*it).get();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
|
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
|
||||||
[[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
|
[[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
|
||||||
[[nodiscard]] int count(not_null<History*> history) const;
|
[[nodiscard]] int count(not_null<History*> history) const;
|
||||||
|
[[nodiscard]] HistoryItem *lastSentMessage(not_null<History*> history);
|
||||||
|
|
||||||
void checkEntitiesAndUpdate(const MTPDmessage &data);
|
void checkEntitiesAndUpdate(const MTPDmessage &data);
|
||||||
void apply(const MTPDupdateNewScheduledMessage &update);
|
void apply(const MTPDupdateNewScheduledMessage &update);
|
||||||
|
|
|
@ -2895,20 +2895,7 @@ HistoryItem *History::lastSentMessage() const {
|
||||||
for (const auto &block : ranges::view::reverse(blocks)) {
|
for (const auto &block : ranges::view::reverse(blocks)) {
|
||||||
for (const auto &message : ranges::view::reverse(block->messages)) {
|
for (const auto &message : ranges::view::reverse(block->messages)) {
|
||||||
const auto item = message->data();
|
const auto item = message->data();
|
||||||
// Skip if message is editing media.
|
if (item->canBeEditedFromHistory()) {
|
||||||
if (item->isEditingMedia()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Skip if message is video message or sticker.
|
|
||||||
if (const auto media = item->media()) {
|
|
||||||
// Skip only if media is not webpage.
|
|
||||||
if (!media->webpage() && !media->allowsEditCaption()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (IsServerMsgId(item->id)
|
|
||||||
&& !item->serviceMsg()
|
|
||||||
&& (item->out() || peer->isSelf())) {
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -721,6 +721,26 @@ bool HistoryItem::canUpdateDate() const {
|
||||||
return isScheduled();
|
return isScheduled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HistoryItem::canBeEditedFromHistory() const {
|
||||||
|
// Skip if message is editing media.
|
||||||
|
if (isEditingMedia()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Skip if message is video message or sticker.
|
||||||
|
if (const auto m = media()) {
|
||||||
|
// Skip only if media is not webpage.
|
||||||
|
if (!m->webpage() && !m->allowsEditCaption()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((IsServerMsgId(id) || isScheduled())
|
||||||
|
&& !serviceMsg()
|
||||||
|
&& (out() || history()->peer->isSelf())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryItem::sendFailed() {
|
void HistoryItem::sendFailed() {
|
||||||
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
||||||
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed));
|
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed));
|
||||||
|
|
|
@ -335,6 +335,8 @@ public:
|
||||||
void updateDate(TimeId newDate);
|
void updateDate(TimeId newDate);
|
||||||
[[nodiscard]] bool canUpdateDate() const;
|
[[nodiscard]] bool canUpdateDate() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool canBeEditedFromHistory() const;
|
||||||
|
|
||||||
virtual ~HistoryItem();
|
virtual ~HistoryItem();
|
||||||
|
|
||||||
MsgId id;
|
MsgId id;
|
||||||
|
|
|
@ -460,6 +460,15 @@ rpl::producer<> ComposeControls::cancelRequests() const {
|
||||||
return _cancelRequests.events();
|
return _cancelRequests.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<not_null<QKeyEvent*>> ComposeControls::keyEvents() const {
|
||||||
|
return _wrap->events(
|
||||||
|
) | rpl::map([=](not_null<QEvent*> e) -> not_null<QKeyEvent*> {
|
||||||
|
return static_cast<QKeyEvent*>(e.get());
|
||||||
|
}) | rpl::filter([=](not_null<QEvent*> event) {
|
||||||
|
return (event->type() == QEvent::KeyPress);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<> ComposeControls::sendRequests() const {
|
rpl::producer<> ComposeControls::sendRequests() const {
|
||||||
auto filter = rpl::filter([=] {
|
auto filter = rpl::filter([=] {
|
||||||
return _send->type() == Ui::SendButton::Type::Schedule;
|
return _send->type() == Ui::SendButton::Type::Schedule;
|
||||||
|
@ -1027,4 +1036,8 @@ rpl::producer<Data::MessagePosition> ComposeControls::scrollRequests() const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ComposeControls::isEditingMessage() const {
|
||||||
|
return _header->isEditingMessage();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -88,6 +88,7 @@ public:
|
||||||
[[nodiscard]] rpl::producer<not_null<DocumentData*>> fileChosen() const;
|
[[nodiscard]] rpl::producer<not_null<DocumentData*>> fileChosen() const;
|
||||||
[[nodiscard]] rpl::producer<not_null<PhotoData*>> photoChosen() const;
|
[[nodiscard]] rpl::producer<not_null<PhotoData*>> photoChosen() const;
|
||||||
[[nodiscard]] rpl::producer<Data::MessagePosition> scrollRequests() const;
|
[[nodiscard]] rpl::producer<Data::MessagePosition> scrollRequests() const;
|
||||||
|
[[nodiscard]] rpl::producer<not_null<QKeyEvent*>> keyEvents() const;
|
||||||
[[nodiscard]] auto inlineResultChosen() const
|
[[nodiscard]] auto inlineResultChosen() const
|
||||||
-> rpl::producer<ChatHelpers::TabbedSelector::InlineChosen>;
|
-> rpl::producer<ChatHelpers::TabbedSelector::InlineChosen>;
|
||||||
|
|
||||||
|
@ -101,6 +102,8 @@ public:
|
||||||
const Window::SectionShow ¶ms);
|
const Window::SectionShow ¶ms);
|
||||||
bool returnTabbedSelector();
|
bool returnTabbedSelector();
|
||||||
|
|
||||||
|
bool isEditingMessage() const;
|
||||||
|
|
||||||
void showForGrab();
|
void showForGrab();
|
||||||
void showStarted();
|
void showStarted();
|
||||||
void showFinished();
|
void showFinished();
|
||||||
|
|
|
@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
#include "chat_helpers/message_field.h"
|
#include "chat_helpers/message_field.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
#include "boxes/edit_caption_box.h"
|
|
||||||
#include "boxes/sticker_set_box.h"
|
#include "boxes/sticker_set_box.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_photo_media.h"
|
#include "data/data_photo_media.h"
|
||||||
|
@ -477,16 +476,7 @@ bool AddEditMessageAction(
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto media = item->media();
|
list->editMessageRequestNotify(item->fullId());
|
||||||
if (media && !media->webpage()) {
|
|
||||||
if (media->allowsEditCaption()) {
|
|
||||||
Ui::show(Box<EditCaptionBox>(
|
|
||||||
App::wnd()->sessionController(),
|
|
||||||
item));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
list->editMessageRequestNotify(item->fullId());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_sending.h"
|
#include "api/api_sending.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
|
#include "boxes/edit_caption_box.h"
|
||||||
#include "boxes/send_files_box.h"
|
#include "boxes/send_files_box.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
|
@ -134,8 +135,17 @@ ScheduledWidget::ScheduledWidget(
|
||||||
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
connect(_scroll, &Ui::ScrollArea::scrolled, [=] { onScroll(); });
|
||||||
|
|
||||||
_inner->editMessageRequested(
|
_inner->editMessageRequested(
|
||||||
) | rpl::start_with_next([=](auto id) {
|
) | rpl::start_with_next([=](auto fullId) {
|
||||||
_composeControls->editMessage(id);
|
if (const auto item = session().data().message(fullId)) {
|
||||||
|
const auto media = item->media();
|
||||||
|
if (media && !media->webpage()) {
|
||||||
|
if (media->allowsEditCaption()) {
|
||||||
|
Ui::show(Box<EditCaptionBox>(controller, item));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_composeControls->editMessage(fullId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, _inner->lifetime());
|
}, _inner->lifetime());
|
||||||
|
|
||||||
setupScrollDownButton();
|
setupScrollDownButton();
|
||||||
|
@ -207,6 +217,26 @@ void ScheduledWidget::setupComposeControls() {
|
||||||
showAtPosition(pos);
|
showAtPosition(pos);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
_composeControls->keyEvents(
|
||||||
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||||
|
if (e->key() == Qt::Key_Up) {
|
||||||
|
if (!_composeControls->isEditingMessage()) {
|
||||||
|
auto &messages = session().data().scheduledMessages();
|
||||||
|
if (const auto item = messages.lastSentMessage(_history)) {
|
||||||
|
_inner->editMessageRequestNotify(item->fullId());
|
||||||
|
} else {
|
||||||
|
_scroll->keyPressEvent(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_scroll->keyPressEvent(e);
|
||||||
|
}
|
||||||
|
e->accept();
|
||||||
|
} else if (e->key() == Qt::Key_Down) {
|
||||||
|
_scroll->keyPressEvent(e);
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
_composeControls->setMimeDataHook([=](
|
_composeControls->setMimeDataHook([=](
|
||||||
not_null<const QMimeData*> data,
|
not_null<const QMimeData*> data,
|
||||||
Ui::InputField::MimeAction action) {
|
Ui::InputField::MimeAction action) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue