summary refs log tree commit diff
path: root/src/TimelineView.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-11-24 00:10:58 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-11-24 00:10:58 +0200
commit0f363b5f4424cc4cdf0e36d7aa5b62b8e8ea52bc (patch)
treeb216baa489755bbb3343f350aa6c6d3e17725fba /src/TimelineView.cc
parentFix qss formatting (diff)
downloadnheko-0f363b5f4424cc4cdf0e36d7aa5b62b8e8ea52bc.tar.xz
Send read receipts
Automatically dismiss unread notifications when the window regains
focus.

fixes #111
fixes #68
Diffstat (limited to 'src/TimelineView.cc')
-rw-r--r--src/TimelineView.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/TimelineView.cc b/src/TimelineView.cc

index 267fbbff..44f3b9d8 100644 --- a/src/TimelineView.cc +++ b/src/TimelineView.cc
@@ -379,6 +379,9 @@ TimelineView::addEvents(const Timeline &timeline) if (!timeline.events().isEmpty() && scroll_layout_->count() > 1) notifyForLastEvent(); + if (isActiveWindow() && isVisible() && timeline.events().size() > 0) + readLastEvent(); + return message_count; } @@ -648,3 +651,52 @@ TimelineView::paintEvent(QPaintEvent *) QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } + +void +TimelineView::readLastEvent() const +{ + const auto eventId = getLastEventId(); + + if (!eventId.isEmpty()) + client_->readEvent(room_id_, eventId); +} + +QString +TimelineView::getLastEventId() const +{ + auto index = scroll_layout_->count(); + + // Search backwards for the first event that has a valid event id. + while (index > 0) { + --index; + + auto lastItem = scroll_layout_->itemAt(index); + auto *lastTimelineItem = qobject_cast<TimelineItem *>(lastItem->widget()); + + if (lastTimelineItem && !lastTimelineItem->eventId().isEmpty()) + return lastTimelineItem->eventId(); + } + + return QString(""); +} + +void +TimelineView::showEvent(QShowEvent *event) +{ + readLastEvent(); + + QWidget::showEvent(event); +} + +bool +TimelineView::event(QEvent *event) +{ + if (event->type() == QEvent::WindowActivate) { + QTimer::singleShot(1000, this, [=]() { + emit clearUnreadMessageCount(room_id_); + readLastEvent(); + }); + } + + return QWidget::event(event); +}