From b00ca217b3d95a161030f20884abed09c58df5c8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 Dec 2018 14:28:24 +0400 Subject: [PATCH] Don't autoread mentions with voice/video messages. Voice/video message unread flag is the same that mention unread flag. If we mark such mentions as read together with all others we mark media as watched/listened instantly when they appear on the screen. So now we mark as read only simple mentions, without "unread" media. --- Telegram/SourceFiles/apiwrap.cpp | 8 ++++--- .../SourceFiles/dialogs/dialogs_layout.cpp | 3 +-- Telegram/SourceFiles/history/history.cpp | 2 +- .../history/history_inner_widget.cpp | 4 ++-- Telegram/SourceFiles/history/history_item.cpp | 23 ++++++++++++++++--- Telegram/SourceFiles/history/history_item.h | 4 +++- .../SourceFiles/history/history_message.cpp | 4 ++-- .../SourceFiles/history/history_widget.cpp | 2 +- .../history/media/history_media_document.cpp | 6 +++-- .../history/media/history_media_gif.cpp | 4 ++-- Telegram/SourceFiles/mainwidget.cpp | 2 +- .../SourceFiles/overview/overview_layout.cpp | 2 +- 12 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 2a6aef27fa..b9a686fab3 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1172,7 +1172,8 @@ void ApiWrap::markMediaRead( QVector>(); markedIds.reserve(items.size()); for (const auto item : items) { - if (!item->isMediaUnread() || (item->out() && !item->mentionsMe())) { + if ((!item->isUnreadMedia() || item->out()) + && !item->isUnreadMention()) { continue; } item->markMediaRead(); @@ -1201,7 +1202,8 @@ void ApiWrap::markMediaRead( } void ApiWrap::markMediaRead(not_null item) { - if (!item->isMediaUnread() || (item->out() && !item->mentionsMe())) { + if ((!item->isUnreadMedia() || item->out()) + && !item->isUnreadMention()) { return; } item->markMediaRead(); @@ -3290,7 +3292,7 @@ void ApiWrap::applyUpdateNoPtsCheck(const MTPUpdate &update) { auto possiblyReadMentions = base::flat_set(); for (const auto &msgId : d.vmessages.v) { if (auto item = App::histItemById(NoChannel, msgId.v)) { - if (item->isMediaUnread()) { + if (item->isUnreadMedia() || item->isUnreadMention()) { item->markMediaRead(); _session->data().requestItemRepaint(item); diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 2c8f323cb8..5ae1e9edb3 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -555,8 +555,7 @@ void RowPainter::paint( if (displayMentionBadge && unreadCount == 1 && item - && item->isMediaUnread() - && item->mentionsMe()) { + && item->isUnreadMention()) { return false; } return (unreadCount > 0); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 6b2648303d..0d96dda9f1 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1032,7 +1032,7 @@ void History::addUnreadMentionsSlice(const MTPmessages_Messages &result) { if (messages) { for (auto &message : *messages) { if (auto item = addToHistory(message)) { - if (item->mentionsMe() && item->isMediaUnread()) { + if (item->isUnreadMention()) { _unreadMentions.insert(item->id); added = true; } diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 4491f60095..e8c189fd42 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -595,7 +595,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { if (item->hasViews()) { App::main()->scheduleViewIncrement(item); } - if (item->mentionsMe() && item->isMediaUnread()) { + if (item->isUnreadMention() && !item->isUnreadMedia()) { readMentions.insert(item); _widget->enqueueMessageHighlight(view); } @@ -641,7 +641,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { if (item->hasViews()) { App::main()->scheduleViewIncrement(item); } - if (item->mentionsMe() && item->isMediaUnread()) { + if (item->isUnreadMention() && !item->isUnreadMedia()) { readMentions.insert(item); _widget->enqueueMessageHighlight(view); } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 6fe1659d56..c078b50f2a 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -236,9 +236,9 @@ void HistoryItem::finishEditionToEmpty() { _history->itemVanished(this); } -bool HistoryItem::isMediaUnread() const { - if (!mentionsMe() && _history->peer->isChannel()) { - auto passed = unixtime() - date(); +bool HistoryItem::hasUnreadMediaFlag() const { + if (_history->peer->isChannel()) { + const auto passed = unixtime() - date(); if (passed >= Global::ChannelsReadMediaPeriod()) { return false; } @@ -246,6 +246,23 @@ bool HistoryItem::isMediaUnread() const { return _flags & MTPDmessage::Flag::f_media_unread; } +bool HistoryItem::isUnreadMention() const { + return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread); +} + +bool HistoryItem::isUnreadMedia() const { + if (!hasUnreadMediaFlag()) { + return false; + } else if (const auto media = this->media()) { + if (const auto document = media->document()) { + if (document->isVoiceMessage() || document->isVideoMessage()) { + return (media->webpage() == nullptr); + } + } + } + return false; +} + void HistoryItem::markMediaRead() { _flags &= ~MTPDmessage::Flag::f_media_unread; diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index ac85ead6bd..4f4b8e2f3b 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -115,7 +115,9 @@ public: bool mentionsMe() const { return _flags & MTPDmessage::Flag::f_mentioned; } - bool isMediaUnread() const; + bool isUnreadMention() const; + bool isUnreadMedia() const; + bool hasUnreadMediaFlag() const; void markMediaRead(); // Zero result means this message is not self-destructing right now. diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index ca5cae4e51..4d35f71b7b 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -920,7 +920,7 @@ void HistoryMessage::updateSentMedia(const MTPMessageMedia *media) { } void HistoryMessage::addToUnreadMentions(UnreadMentionType type) { - if (IsServerMsgId(id) && mentionsMe() && isMediaUnread()) { + if (IsServerMsgId(id) && isUnreadMention()) { if (history()->addToUnreadMentions(id, type)) { Notify::peerUpdatedDelayed( history()->peer, @@ -930,7 +930,7 @@ void HistoryMessage::addToUnreadMentions(UnreadMentionType type) { } void HistoryMessage::eraseFromUnreadMentions() { - if (mentionsMe() && isMediaUnread()) { + if (isUnreadMention()) { history()->eraseFromUnreadMentions(id); } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 4a437e8df4..ca3afb8953 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2173,7 +2173,7 @@ void HistoryWidget::newUnreadMsg( destroyUnreadBar(); } if (App::wnd()->doWeReadServerHistory()) { - if (item->mentionsMe() && item->isMediaUnread()) { + if (item->isUnreadMention() && !item->isUnreadMedia()) { Auth().api().markMediaRead(item); } Auth().api().readServerHistoryForce(history); diff --git a/Telegram/SourceFiles/history/media/history_media_document.cpp b/Telegram/SourceFiles/history/media/history_media_document.cpp index 0631777e59..9a07e769c1 100644 --- a/Telegram/SourceFiles/history/media/history_media_document.cpp +++ b/Telegram/SourceFiles/history/media/history_media_document.cpp @@ -374,7 +374,9 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection, auto wf_size = wf ? wf->size() : Media::Player::kWaveformSamplesCount; auto availw = namewidth + st::msgWaveformSkip; auto activew = qRound(availw * progress); - if (!outbg && !voice->_playback && _parent->data()->isMediaUnread()) { + if (!outbg + && !voice->_playback + && _parent->data()->hasUnreadMediaFlag()) { activew = availw; } auto bar_count = qMin(availw / (st::msgWaveformBar + st::msgWaveformSkip), wf_size); @@ -428,7 +430,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection, p.setPen(status); p.drawTextLeft(nameleft, statustop, width(), statusText); - if (_parent->data()->isMediaUnread()) { + if (_parent->data()->hasUnreadMediaFlag()) { auto w = st::normalFont->width(statusText); if (w + st::mediaUnreadSkip + st::mediaUnreadSize <= statuswidth) { p.setPen(Qt::NoPen); diff --git a/Telegram/SourceFiles/history/media/history_media_gif.cpp b/Telegram/SourceFiles/history/media/history_media_gif.cpp index 0b5a011261..2cc546a395 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.cpp +++ b/Telegram/SourceFiles/history/media/history_media_gif.cpp @@ -417,12 +417,12 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM } if (!inWebPage && isRound) { - auto mediaUnread = item->isMediaUnread(); + auto mediaUnread = item->hasUnreadMediaFlag(); auto statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); auto statusX = usex + paintx + st::msgDateImgDelta + st::msgDateImgPadding.x(); auto statusY = painty + painth - st::msgDateImgDelta - statusH + st::msgDateImgPadding.y(); - if (item->isMediaUnread()) { + if (mediaUnread) { statusW += st::mediaUnreadSkip + st::mediaUnreadSize; } App::roundRect(p, rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index dc43080ff4..867b45ae70 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4127,7 +4127,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto possiblyReadMentions = base::flat_set(); for_const (auto &msgId, d.vmessages.v) { if (auto item = App::histItemById(channel, msgId.v)) { - if (item->isMediaUnread()) { + if (item->isUnreadMedia() || item->isUnreadMention()) { item->markMediaRead(); Auth().data().requestItemRepaint(item); } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 9026485421..9f657a6d43 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -706,7 +706,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const p.drawTextLeft(nameleft, statustop, _width, _status.text(), statusw); unreadx += statusw; } - if (parent()->isMediaUnread() && unreadx + st::mediaUnreadSkip + st::mediaUnreadSize <= _width) { + if (parent()->hasUnreadMediaFlag() && unreadx + st::mediaUnreadSkip + st::mediaUnreadSize <= _width) { p.setPen(Qt::NoPen); p.setBrush(selected ? st::msgFileInBgSelected : st::msgFileInBg);