From ad089cb8da4053b478978b5f61d751098e6e8964 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 2 Sep 2015 00:33:44 +0300 Subject: [PATCH] fixed entities update, version 0.8.55 stable --- Telegram/SourceFiles/app.cpp | 22 +++++++++++++++++++++- Telegram/SourceFiles/app.h | 1 + Telegram/SourceFiles/history.cpp | 15 ++++----------- Telegram/SourceFiles/history.h | 4 ++++ Telegram/SourceFiles/mainwidget.cpp | 12 ++++++++---- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 07baf8abb..a4a79a426 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -699,13 +699,33 @@ namespace App { } } + void checkEntitiesUpdate(const MTPDmessage &m) { + if (HistoryItem *existing = App::histItemById(m.vid.v)) { + bool hasLinks = m.has_entities() && !m.ventities.c_vector().v.isEmpty(); + if ((hasLinks && !existing->hasTextLinks()) || (!hasLinks && existing->textHasLinks())) { + existing->setText(qs(m.vmessage), m.has_entities() ? linksFromMTP(m.ventities.c_vector().v) : LinksInText()); + existing->initDimensions(0); + if (App::main()) App::main()->itemResized(existing); + if (existing->hasTextLinks()) { + existing->history()->addToOverview(existing, OverviewLinks); + } + } + } + } + void feedMsgs(const MTPVector &msgs, int msgsState) { const QVector &v(msgs.c_vector().v); QMap msgsIds; for (int32 i = 0, l = v.size(); i < l; ++i) { const MTPMessage &msg(v.at(i)); switch (msg.type()) { - case mtpc_message: msgsIds.insert(msg.c_message().vid.v, i); break; + case mtpc_message: { + const MTPDmessage &d(msg.c_message()); + msgsIds.insert(d.vid.v, i); + if (msgsState == 1) { // new message, index my forwarded messages to links overview + checkEntitiesUpdate(d); + } + } break; case mtpc_messageEmpty: msgsIds.insert(msg.c_messageEmpty().vid.v, i); break; case mtpc_messageService: msgsIds.insert(msg.c_messageService().vid.v, i); break; } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 358622cf3..10465c71d 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -118,6 +118,7 @@ namespace App { void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated = true); void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated = true); void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated = true); + void checkEntitiesUpdate(const MTPDmessage &m); void feedMsgs(const MTPVector &msgs, int msgsState = 0); // 2 - new read message, 1 - new unread message, 0 - not new message, -1 - searched message void feedWereRead(const QVector &msgsIds); void feedInboxRead(const PeerId &peer, int32 upTo); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index ceaff4ed5..097d4e5dc 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -644,24 +644,14 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPmessage &msg, boo } const MTPMessageMedia *media = 0; - const QVector *entities = 0; switch (msg.type()) { case mtpc_message: media = msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0; - entities = msg.c_message().has_entities() ? (&msg.c_message().ventities.c_vector().v) : 0; break; } if (media) { existing->updateMedia(*media); } - if (entities && !existing->hasTextLinks()) { // index forwarded messages to links overview - existing->setText(qs(msg.c_message().vmessage), linksFromMTP(*entities)); - existing->initDimensions(0); - if (App::main()) App::main()->itemResized(existing); - if (existing->hasTextLinks()) { - existing->history()->addToOverview(existing, OverviewLinks); - } - } return (returnExisting || regged) ? existing : 0; } @@ -5249,7 +5239,6 @@ HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, const MTPD , _textHeight(0) , _media(0) { - //if (msg.has_entities()) msg.ventities.c_vector().v.size() QString text(textClean(qs(msg.vmessage))); initTime(); initMedia(msg.has_media() ? (&msg.vmedia) : 0, text); @@ -5494,6 +5483,10 @@ void HistoryMessage::getTextWithLinks(QString &text, LinksInText &links) { text = _text.original(); } +bool HistoryMessage::textHasLinks() { + return _text.hasLinks(); +} + void HistoryMessage::draw(QPainter &p, uint32 selection) const { textstyleSet(&(out() ? st::outTextStyle : st::inTextStyle)); diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 3795bb875..e696535a4 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -786,6 +786,9 @@ public: } virtual void getTextWithLinks(QString &text, LinksInText &links) { } + virtual bool textHasLinks() { + return false; + } virtual QString time() const { return QString(); } @@ -1339,6 +1342,7 @@ public: void setMedia(const MTPMessageMedia *media); void setText(const QString &text, const LinksInText &links); void getTextWithLinks(QString &text, LinksInText &links); + bool textHasLinks(); QString time() const { return _time; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e96f8806f..5f9de2fc6 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -3414,14 +3414,14 @@ void MainWidget::handleUpdates(const MTPUpdates &updates, uint64 randomId) { const MTPDupdateShortSentMessage &d(updates.c_updateShortSentMessage()); HistoryItem *item = 0; if (randomId) { - QString text = d.has_entities() ? App::histSentTextByItem(randomId) : QString(); + QString text = App::histSentTextByItem(randomId); feedUpdate(MTP_updateMessageID(d.vid, MTP_long(randomId))); // ignore real date if (!text.isEmpty()) { - LinksInText links(linksFromMTP(d.ventities.c_vector().v)); + bool hasLinks = d.has_entities() && !d.ventities.c_vector().v.isEmpty(); item = App::histItemById(d.vid.v); - if (item && !links.isEmpty()) { + if (item && ((hasLinks && !item->hasTextLinks()) || (!hasLinks && item->textHasLinks()))) { bool was = item->hasTextLinks(); - item->setText(text, links); + item->setText(text, d.has_entities() ? linksFromMTP(d.ventities.c_vector().v) : LinksInText()); item->initDimensions(0); itemResized(item); if (!was && item->hasTextLinks()) { @@ -3462,6 +3462,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { _byPtsUpdate.insert(ptsKey(SkippedUpdate), update); return; } + if (d.vmessage.type() == mtpc_message) { // index forwarded messages to links overview + App::checkEntitiesUpdate(d.vmessage.c_message()); + } + HistoryItem *item = App::histories().addToBack(d.vmessage); if (item) { history.peerMessagesUpdated(item->history()->peer->id);