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.
This commit is contained in:
John Preston 2018-12-26 14:28:24 +04:00
parent 874d76b16b
commit b00ca217b3
12 changed files with 43 additions and 21 deletions

View File

@ -1172,7 +1172,8 @@ void ApiWrap::markMediaRead(
QVector<MTPint>>();
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<HistoryItem*> 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<MsgId>();
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);

View File

@ -555,8 +555,7 @@ void RowPainter::paint(
if (displayMentionBadge
&& unreadCount == 1
&& item
&& item->isMediaUnread()
&& item->mentionsMe()) {
&& item->isUnreadMention()) {
return false;
}
return (unreadCount > 0);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -4127,7 +4127,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
auto possiblyReadMentions = base::flat_set<MsgId>();
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);
}

View File

@ -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);