mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-26 19:14:02 +02:00
Unified checking for editable message.
This commit is contained in:
parent
1607752cf9
commit
15254599e2
9 changed files with 19 additions and 36 deletions
|
@ -543,7 +543,8 @@ int32 ScheduledMessages::countListHash(const List &list) const {
|
||||||
return HashFinalize(hash);
|
return HashFinalize(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem *ScheduledMessages::lastSentMessage(not_null<History*> history) {
|
HistoryItem *ScheduledMessages::lastEditableMessage(
|
||||||
|
not_null<History*> history) {
|
||||||
const auto i = _data.find(history);
|
const auto i = _data.find(history);
|
||||||
if (i == end(_data)) {
|
if (i == end(_data)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -552,9 +553,12 @@ HistoryItem *ScheduledMessages::lastSentMessage(not_null<History*> history) {
|
||||||
|
|
||||||
sort(list);
|
sort(list);
|
||||||
const auto items = ranges::view::reverse(list.items);
|
const auto items = ranges::view::reverse(list.items);
|
||||||
const auto it = ranges::find_if(
|
|
||||||
items,
|
const auto now = base::unixtime::now();
|
||||||
&HistoryItem::canBeEditedFromHistory);
|
auto proj = [&](const OwnedItem &item) {
|
||||||
|
return item->allowsEdit(now);
|
||||||
|
};
|
||||||
|
const auto it = ranges::find_if(items, std::move(proj));
|
||||||
return (it == end(items)) ? nullptr : (*it).get();
|
return (it == end(items)) ? nullptr : (*it).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ 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);
|
[[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);
|
||||||
|
|
|
@ -2704,14 +2704,15 @@ MsgId History::msgIdForRead() const {
|
||||||
: result;
|
: result;
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem *History::lastSentMessage() const {
|
HistoryItem *History::lastEditableMessage() const {
|
||||||
if (!loadedAtBottom()) {
|
if (!loadedAtBottom()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const auto now = base::unixtime::now();
|
||||||
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();
|
||||||
if (item->canBeEditedFromHistory()) {
|
if (item->allowsEdit(now)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ public:
|
||||||
MsgId minMsgId() const;
|
MsgId minMsgId() const;
|
||||||
MsgId maxMsgId() const;
|
MsgId maxMsgId() const;
|
||||||
MsgId msgIdForRead() const;
|
MsgId msgIdForRead() const;
|
||||||
HistoryItem *lastSentMessage() const;
|
HistoryItem *lastEditableMessage() const;
|
||||||
|
|
||||||
void resizeToWidth(int newWidth);
|
void resizeToWidth(int newWidth);
|
||||||
void forceFullResize();
|
void forceFullResize();
|
||||||
|
|
|
@ -762,27 +762,6 @@ 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())
|
|
||||||
&& !Has<HistoryMessageForwarded>()) {
|
|
||||||
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));
|
||||||
|
|
|
@ -390,8 +390,6 @@ 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;
|
||||||
|
|
|
@ -5022,10 +5022,9 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
} else if (e->key() == Qt::Key_Up && !commonModifiers) {
|
} else if (e->key() == Qt::Key_Up && !commonModifiers) {
|
||||||
const auto item = _history
|
const auto item = _history
|
||||||
? _history->lastSentMessage()
|
? _history->lastEditableMessage()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
if (item
|
if (item
|
||||||
&& item->allowsEdit(base::unixtime::now())
|
|
||||||
&& _field->empty()
|
&& _field->empty()
|
||||||
&& !_editMsgId
|
&& !_editMsgId
|
||||||
&& !_replyToId) {
|
&& !_replyToId) {
|
||||||
|
|
|
@ -494,7 +494,7 @@ void RepliesWidget::setupComposeControls() {
|
||||||
if (!_composeControls->isEditingMessage()) {
|
if (!_composeControls->isEditingMessage()) {
|
||||||
// #TODO replies edit last sent message
|
// #TODO replies edit last sent message
|
||||||
//auto &messages = session().data().scheduledMessages();
|
//auto &messages = session().data().scheduledMessages();
|
||||||
//if (const auto item = messages.lastSentMessage(_history)) {
|
//if (const auto item = messages.lastEditableMessage(_history)) {
|
||||||
// _inner->editMessageRequestNotify(item->fullId());
|
// _inner->editMessageRequestNotify(item->fullId());
|
||||||
//} else {
|
//} else {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
|
|
|
@ -235,8 +235,9 @@ void ScheduledWidget::setupComposeControls() {
|
||||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||||
if (e->key() == Qt::Key_Up) {
|
if (e->key() == Qt::Key_Up) {
|
||||||
if (!_composeControls->isEditingMessage()) {
|
if (!_composeControls->isEditingMessage()) {
|
||||||
auto &messages = session().data().scheduledMessages();
|
const auto item = session().data().scheduledMessages()
|
||||||
if (const auto item = messages.lastSentMessage(_history)) {
|
.lastEditableMessage(_history);
|
||||||
|
if (item) {
|
||||||
_inner->editMessageRequestNotify(item->fullId());
|
_inner->editMessageRequestNotify(item->fullId());
|
||||||
} else {
|
} else {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue