From 947963d5d16d40dc33f11268e02ece8bae674f46 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 23 Sep 2016 21:26:53 +0300 Subject: [PATCH] Version 0.10.8: editing of service message added. --- Telegram/SourceFiles/app.cpp | 15 +++++---- Telegram/SourceFiles/app.h | 3 +- Telegram/SourceFiles/history.cpp | 52 ++++++++++++++++++----------- Telegram/SourceFiles/history.h | 11 +++--- Telegram/SourceFiles/mainwidget.cpp | 15 +++------ 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index eedca3a782..4f50262d87 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1111,19 +1111,22 @@ namespace { return false; } - void updateEditedMessage(const MTPDmessage &m) { - PeerId peerId = peerFromMTP(m.vto_id); + template + void updateEditedMessage(const TMTPDclass &m) { + auto peerId = peerFromMTP(m.vto_id); if (m.has_from_id() && peerToUser(peerId) == MTP::authedId()) { peerId = peerFromUser(m.vfrom_id); } - if (HistoryItem *existing = App::histItemById(peerToChannel(peerId), m.vid.v)) { + if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) { existing->applyEdition(m); } } - void updateEditedMessageToEmpty(PeerId peerId, MsgId msgId) { - if (auto existing = App::histItemById(peerToChannel(peerId), msgId)) { - existing->applyEditionToEmpty(); + void updateEditedMessage(const MTPMessage &m) { + if (m.type() == mtpc_message) { // apply message edit + App::updateEditedMessage(m.c_message()); + } else if (m.type() == mtpc_messageService) { + App::updateEditedMessage(m.c_messageService()); } } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index ed87457cae..299caaf90a 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -72,8 +72,7 @@ namespace App { void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated = true); void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated = true); bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached - void updateEditedMessage(const MTPDmessage &m); - void updateEditedMessageToEmpty(PeerId peerId, MsgId msgId); + void updateEditedMessage(const MTPMessage &m); void addSavedGif(DocumentData *doc); void checkSavedGif(HistoryItem *item); void feedMsgs(const QVector &msgs, NewMessageType type); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 2095207dd0..810914726d 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -7103,6 +7103,12 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) { finishEdition(keyboardTop); } +void HistoryMessage::applyEdition(const MTPDmessageService &message) { + if (message.vaction.type() == mtpc_messageActionHistoryClear) { + applyEditionToEmpty(); + } +} + void HistoryMessage::applyEditionToEmpty() { setEmptyText(); setMedia(nullptr); @@ -8175,20 +8181,7 @@ bool HistoryService::prepareGameScoreText(const QString &from, QString *outText, HistoryService::HistoryService(History *history, const MTPDmessageService &msg) : HistoryItem(history, msg.vid.v, mtpCastFlags(msg.vflags.v), ::date(msg.vdate), msg.has_from_id() ? msg.vfrom_id.v : 0) { - if (msg.has_reply_to_msg_id()) { - if (msg.vaction.type() == mtpc_messageActionPinMessage) { - UpdateComponents(HistoryServicePinned::Bit()); - } else if (msg.vaction.type() == mtpc_messageActionGameScore) { - UpdateComponents(HistoryServiceGameScore::Bit()); - Get()->score = msg.vaction.c_messageActionGameScore().vscore.v; - } - if (auto dependent = GetDependentData()) { - dependent->msgId = msg.vreply_to_msg_id.v; - if (!updateDependent() && App::api()) { - App::api()->requestMessageData(history->peer->asChannel(), dependent->msgId, std_::make_unique(fullId())); - } - } - } + createFromMtp(msg); setMessageByAction(msg.vaction); } @@ -8375,15 +8368,36 @@ HistoryTextState HistoryService::getState(int x, int y, HistoryStateRequest requ return result; } -void HistoryService::applyEditionToEmpty() { - TextWithEntities textWithEntities = { QString(), EntitiesInText() }; - setServiceText(QString(), Links()); - removeMedia(); +void HistoryService::createFromMtp(const MTPDmessageService &message) { + if (message.has_reply_to_msg_id()) { + if (message.vaction.type() == mtpc_messageActionPinMessage) { + UpdateComponents(HistoryServicePinned::Bit()); + } else if (message.vaction.type() == mtpc_messageActionGameScore) { + UpdateComponents(HistoryServiceGameScore::Bit()); + Get()->score = message.vaction.c_messageActionGameScore().vscore.v; + } + if (auto dependent = GetDependentData()) { + dependent->msgId = message.vreply_to_msg_id.v; + if (!updateDependent() && App::api()) { + App::api()->requestMessageData(history()->peer->asChannel(), dependent->msgId, std_::make_unique(fullId())); + } + } + } + setMessageByAction(message.vaction); +} +void HistoryService::applyEdition(const MTPDmessageService &message) { clearDependency(); UpdateComponents(0); - finishEditionToEmpty(); + createFromMtp(message); + + if (message.vaction.type() == mtpc_messageActionHistoryClear) { + removeMedia(); + finishEditionToEmpty(); + } else { + finishEdition(-1); + } } void HistoryService::removeMedia() { diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index d8435ab2d6..72cc5f101e 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -1206,7 +1206,7 @@ public: } virtual void applyEdition(const MTPDmessage &message) { } - virtual void applyEditionToEmpty() { + virtual void applyEdition(const MTPDmessageService &message) { } virtual void updateMedia(const MTPMessageMedia *media) { } @@ -2626,7 +2626,7 @@ public: QString notificationHeader() const override; void applyEdition(const MTPDmessage &message) override; - void applyEditionToEmpty() override; + void applyEdition(const MTPDmessageService &message) override; void updateMedia(const MTPMessageMedia *media) override; int32 addToOverview(AddToOverviewMethod method) override; void eraseFromOverview() override; @@ -2693,7 +2693,6 @@ public: ~HistoryMessage(); private: - HistoryMessage(History *history, const MTPDmessage &msg); HistoryMessage(History *history, MsgId msgId, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *fwd); // local forwarded HistoryMessage(History *history, MsgId msgId, MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, QDateTime date, int32 from, const TextWithEntities &textWithEntities); // local message @@ -2706,6 +2705,7 @@ private: void initDimensions() override; int resizeGetHeight_(int width) override; int performResizeGetHeight(int width); + void applyEditionToEmpty(); bool displayForwardedFrom() const { if (const HistoryMessageForwarded *fwd = Get()) { @@ -2827,7 +2827,7 @@ public: HistoryItem::clickHandlerPressedChanged(p, pressed); } - void applyEditionToEmpty() override; + void applyEdition(const MTPDmessageService &message) override; int32 addToOverview(AddToOverviewMethod method) override; void eraseFromOverview() override; @@ -2875,6 +2875,7 @@ private: bool updateDependentText(); void clearDependency(); + void createFromMtp(const MTPDmessageService &message); void setMessageByAction(const MTPmessageAction &action); bool preparePinnedText(const QString &from, QString *outText, Links *outLinks); @@ -2884,7 +2885,6 @@ private: class HistoryJoined : public HistoryService, private HistoryItemInstantiated { public: - static HistoryJoined *create(History *history, const QDateTime &date, UserData *from, MTPDmessage::Flags flags) { return _create(history, date, from, flags); } @@ -2894,7 +2894,6 @@ public: } protected: - HistoryJoined(History *history, const QDateTime &date, UserData *from, MTPDmessage::Flags flags); using HistoryItemInstantiated::_create; friend class HistoryItemInstantiated; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index dfcfe94ab0..7252dfce4a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4579,9 +4579,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } // update before applying skipped - if (d.vmessage.type() == mtpc_message) { // apply message edit - App::updateEditedMessage(d.vmessage.c_message()); - } + App::updateEditedMessage(d.vmessage); + if (channel && !_handlingChannelDifference) { channel->ptsApplySkippedUpdates(); } @@ -4595,14 +4594,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } // update before applying skipped - if (d.vmessage.type() == mtpc_message) { // apply message edit - App::updateEditedMessage(d.vmessage.c_message()); - } else if (d.vmessage.type() == mtpc_messageService) { - auto &message = d.vmessage.c_messageService(); - if (message.vaction.type() == mtpc_messageActionHistoryClear) { - App::updateEditedMessageToEmpty(peerFromMessage(d.vmessage), message.vid.v); - } - } + App::updateEditedMessage(d.vmessage); + ptsApplySkippedUpdates(); } break;