mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Refactored handle of last editable message on Up arrow in sections.
This commit is contained in:
parent
b13e5ddce9
commit
062c451c27
10 changed files with 41 additions and 83 deletions
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "data/data_replies_list.h"
|
#include "data/data_replies_list.h"
|
||||||
|
|
||||||
#include "base/unixtime.h"
|
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/history_service.h"
|
#include "history/history_service.h"
|
||||||
|
@ -627,22 +626,4 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
|
||||||
return (list.size() == skipped);
|
return (list.size() == skipped);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem *RepliesList::lastEditableMessage() {
|
|
||||||
const auto message = [&](MsgId msgId) {
|
|
||||||
return _history->owner().message(_history->channelId(), msgId);
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto now = base::unixtime::now();
|
|
||||||
auto proj = [&](MsgId msgId) {
|
|
||||||
if (const auto item = message(msgId)) {
|
|
||||||
return item->allowsEdit(now);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
const auto it = ranges::find_if(_list, std::move(proj));
|
|
||||||
return (it == end(_list))
|
|
||||||
? nullptr
|
|
||||||
: _history->owner().groups().findItemToEdit(message(*it)).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -31,8 +31,6 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<int> fullCount() const;
|
[[nodiscard]] rpl::producer<int> fullCount() const;
|
||||||
|
|
||||||
[[nodiscard]] HistoryItem *lastEditableMessage();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Viewer;
|
struct Viewer;
|
||||||
|
|
||||||
|
|
|
@ -546,26 +546,4 @@ int32 ScheduledMessages::countListHash(const List &list) const {
|
||||||
return HashFinalize(hash);
|
return HashFinalize(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem *ScheduledMessages::lastEditableMessage(
|
|
||||||
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 now = base::unixtime::now();
|
|
||||||
auto proj = [&](const OwnedItem &item) {
|
|
||||||
return item->allowsEdit(now);
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto it = ranges::find_if(items, std::move(proj));
|
|
||||||
return (it == end(items))
|
|
||||||
? nullptr
|
|
||||||
: history->owner().groups().findItemToEdit((*it).get()).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -32,8 +32,6 @@ 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 *lastEditableMessage(
|
|
||||||
not_null<History*> history);
|
|
||||||
|
|
||||||
void checkEntitiesAndUpdate(const MTPDmessage &data);
|
void checkEntitiesAndUpdate(const MTPDmessage &data);
|
||||||
void apply(const MTPDupdateNewScheduledMessage &update);
|
void apply(const MTPDupdateNewScheduledMessage &update);
|
||||||
|
|
|
@ -712,20 +712,16 @@ 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ComposeControls::scrollKeyEvents() const
|
auto ComposeControls::scrollKeyEvents() const
|
||||||
-> rpl::producer<not_null<QKeyEvent*>> {
|
-> rpl::producer<not_null<QKeyEvent*>> {
|
||||||
return _scrollKeyEvents.events();
|
return _scrollKeyEvents.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ComposeControls::editLastMessageRequests() const
|
||||||
|
-> rpl::producer<not_null<QKeyEvent*>> {
|
||||||
|
return _editLastMessageRequests.events();
|
||||||
|
}
|
||||||
|
|
||||||
auto ComposeControls::sendContentRequests(SendRequestType requestType) const {
|
auto ComposeControls::sendContentRequests(SendRequestType requestType) const {
|
||||||
auto filter = rpl::filter([=] {
|
auto filter = rpl::filter([=] {
|
||||||
const auto type = (_mode == Mode::Normal)
|
const auto type = (_mode == Mode::Normal)
|
||||||
|
@ -1061,6 +1057,12 @@ void ComposeControls::initKeyHandler() {
|
||||||
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
auto keyEvent = static_cast<QKeyEvent*>(e.get());
|
auto keyEvent = static_cast<QKeyEvent*>(e.get());
|
||||||
const auto key = keyEvent->key();
|
const auto key = keyEvent->key();
|
||||||
|
if (key == Qt::Key_Up) {
|
||||||
|
if (!isEditingMessage()) {
|
||||||
|
_editLastMessageRequests.fire(std::move(keyEvent));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((key == Qt::Key_Up)
|
if ((key == Qt::Key_Up)
|
||||||
|| (key == Qt::Key_Down)
|
|| (key == Qt::Key_Down)
|
||||||
|| (key == Qt::Key_PageUp)
|
|| (key == Qt::Key_PageUp)
|
||||||
|
|
|
@ -118,12 +118,13 @@ public:
|
||||||
[[nodiscard]] rpl::producer<FileChosen> fileChosen() const;
|
[[nodiscard]] rpl::producer<FileChosen> fileChosen() const;
|
||||||
[[nodiscard]] rpl::producer<PhotoChosen> photoChosen() const;
|
[[nodiscard]] rpl::producer<PhotoChosen> 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]] rpl::producer<InlineChosen> inlineResultChosen() const;
|
[[nodiscard]] rpl::producer<InlineChosen> inlineResultChosen() const;
|
||||||
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
|
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
|
||||||
[[nodiscard]] rpl::producer<not_null<QEvent*>> viewportEvents() const;
|
[[nodiscard]] rpl::producer<not_null<QEvent*>> viewportEvents() const;
|
||||||
[[nodiscard]] auto scrollKeyEvents() const
|
[[nodiscard]] auto scrollKeyEvents() const
|
||||||
-> rpl::producer<not_null<QKeyEvent*>>;
|
-> rpl::producer<not_null<QKeyEvent*>>;
|
||||||
|
[[nodiscard]] auto editLastMessageRequests() const
|
||||||
|
-> rpl::producer<not_null<QKeyEvent*>>;
|
||||||
|
|
||||||
using MimeDataHook = Fn<bool(
|
using MimeDataHook = Fn<bool(
|
||||||
not_null<const QMimeData*> data,
|
not_null<const QMimeData*> data,
|
||||||
|
@ -294,6 +295,7 @@ private:
|
||||||
rpl::event_stream<SendActionUpdate> _sendActionUpdates;
|
rpl::event_stream<SendActionUpdate> _sendActionUpdates;
|
||||||
rpl::event_stream<QString> _sendCommandRequests;
|
rpl::event_stream<QString> _sendCommandRequests;
|
||||||
rpl::event_stream<not_null<QKeyEvent*>> _scrollKeyEvents;
|
rpl::event_stream<not_null<QKeyEvent*>> _scrollKeyEvents;
|
||||||
|
rpl::event_stream<not_null<QKeyEvent*>> _editLastMessageRequests;
|
||||||
|
|
||||||
TextUpdateEvents _textUpdateEvents = TextUpdateEvents()
|
TextUpdateEvents _textUpdateEvents = TextUpdateEvents()
|
||||||
| TextUpdateEvent::SaveDraft
|
| TextUpdateEvent::SaveDraft
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/history_view_list_widget.h"
|
#include "history/view/history_view_list_widget.h"
|
||||||
|
|
||||||
|
#include "base/unixtime.h"
|
||||||
#include "history/history_message.h"
|
#include "history/history_message.h"
|
||||||
#include "history/history_item_components.h"
|
#include "history/history_item_components.h"
|
||||||
#include "history/history_item_text.h"
|
#include "history/history_item_text.h"
|
||||||
|
@ -2725,10 +2726,27 @@ rpl::producer<FullMsgId> ListWidget::editMessageRequested() const {
|
||||||
return _requestedToEditMessage.events();
|
return _requestedToEditMessage.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWidget::editMessageRequestNotify(FullMsgId item) {
|
void ListWidget::editMessageRequestNotify(FullMsgId item) const {
|
||||||
_requestedToEditMessage.fire(std::move(item));
|
_requestedToEditMessage.fire(std::move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ListWidget::lastMessageEditRequestNotify() const {
|
||||||
|
const auto now = base::unixtime::now();
|
||||||
|
auto proj = [&](not_null<Element*> view) {
|
||||||
|
return view->data()->allowsEdit(now);
|
||||||
|
};
|
||||||
|
const auto &list = ranges::view::reverse(_items);
|
||||||
|
const auto it = ranges::find_if(list, std::move(proj));
|
||||||
|
if (it == end(list)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
const auto item =
|
||||||
|
session().data().groups().findItemToEdit((*it)->data()).get();
|
||||||
|
editMessageRequestNotify(item->fullId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<FullMsgId> ListWidget::replyToMessageRequested() const {
|
rpl::producer<FullMsgId> ListWidget::replyToMessageRequested() const {
|
||||||
return _requestedToReplyToMessage.events();
|
return _requestedToReplyToMessage.events();
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,8 @@ public:
|
||||||
bool tooltipWindowActive() const override;
|
bool tooltipWindowActive() const override;
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<FullMsgId> editMessageRequested() const;
|
[[nodiscard]] rpl::producer<FullMsgId> editMessageRequested() const;
|
||||||
void editMessageRequestNotify(FullMsgId item);
|
void editMessageRequestNotify(FullMsgId item) const;
|
||||||
|
[[nodiscard]] bool lastMessageEditRequestNotify() const;
|
||||||
[[nodiscard]] rpl::producer<FullMsgId> replyToMessageRequested() const;
|
[[nodiscard]] rpl::producer<FullMsgId> replyToMessageRequested() const;
|
||||||
void replyToMessageRequestNotify(FullMsgId item);
|
void replyToMessageRequestNotify(FullMsgId item);
|
||||||
[[nodiscard]] rpl::producer<FullMsgId> readMessageRequested() const;
|
[[nodiscard]] rpl::producer<FullMsgId> readMessageRequested() const;
|
||||||
|
|
|
@ -493,19 +493,10 @@ void RepliesWidget::setupComposeControls() {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_composeControls->keyEvents(
|
_composeControls->editLastMessageRequests(
|
||||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||||
if (e->key() == Qt::Key_Up) {
|
if (!_inner->lastMessageEditRequestNotify()) {
|
||||||
if (!_composeControls->isEditingMessage()) {
|
_scroll->keyPressEvent(e);
|
||||||
if (const auto item = _replies->lastEditableMessage()) {
|
|
||||||
_inner->editMessageRequestNotify(item->fullId());
|
|
||||||
} else {
|
|
||||||
_scroll->keyPressEvent(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_scroll->keyPressEvent(e);
|
|
||||||
}
|
|
||||||
e->accept();
|
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
|
|
@ -236,21 +236,10 @@ void ScheduledWidget::setupComposeControls() {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_composeControls->keyEvents(
|
_composeControls->editLastMessageRequests(
|
||||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||||
if (e->key() == Qt::Key_Up) {
|
if (!_inner->lastMessageEditRequestNotify()) {
|
||||||
if (!_composeControls->isEditingMessage()) {
|
_scroll->keyPressEvent(e);
|
||||||
const auto item = session().data().scheduledMessages()
|
|
||||||
.lastEditableMessage(_history);
|
|
||||||
if (item) {
|
|
||||||
_inner->editMessageRequestNotify(item->fullId());
|
|
||||||
} else {
|
|
||||||
_scroll->keyPressEvent(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_scroll->keyPressEvent(e);
|
|
||||||
}
|
|
||||||
e->accept();
|
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue