Add space notifications to room list

pull/1062/head
Loren Burkholder 3 years ago
parent e7c24b094f
commit 169384f0fa
  1. 80
      resources/qml/RoomList.qml
  2. 15
      src/Utils.cpp
  3. 3
      src/Utils.h
  4. 17
      src/timeline/CommunitiesModel.cpp
  5. 2
      src/timeline/CommunitiesModel.h
  6. 5
      src/timeline/RoomlistModel.cpp
  7. 17
      src/timeline/TimelineModel.cpp

@ -348,7 +348,45 @@ Page {
height: avatar.height
spacing: Nheko.paddingSmall
Component {
id: notificationBubble
Rectangle {
visible: notificationCount > 0
Layout.alignment: Qt.AlignRight
Layout.leftMargin: Nheko.paddingSmall
height: notificationBubbleText.height + Nheko.paddingMedium
width: Math.max(notificationBubbleText.width, height)
radius: height / 2
color: hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
ToolTip.text: notificationCount
ToolTip.delay: Nheko.tooltipDelay
ToolTip.visible: notificationBubbleHover.hovered && (notificationCount > 9999)
Label {
id: notificationBubbleText
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
font.bold: true
font.pixelSize: fontMetrics.font.pixelSize * 0.8
color: hasLoudNotification ? "white" : roomItem.bubbleText
text: notificationCount > 9999 ? "9999+" : notificationCount
HoverHandler {
id: notificationBubbleHover
}
}
}
}
RowLayout {
id: titleRow
Layout.alignment: Qt.AlignTop
Layout.fillWidth: true
spacing: Nheko.paddingSmall
@ -374,9 +412,16 @@ Page {
text: time
}
Loader {
sourceComponent: notificationBubble
active: isSpace
}
}
RowLayout {
id: subtextRow
Layout.fillWidth: true
spacing: 0
visible: !isSpace
@ -392,40 +437,11 @@ Page {
Layout.fillWidth: true
}
Rectangle {
id: notificationBubble
visible: notificationCount > 0
Layout.alignment: Qt.AlignRight
Layout.leftMargin: Nheko.paddingSmall
height: notificationBubbleText.height + Nheko.paddingMedium
Layout.preferredWidth: Math.max(notificationBubbleText.width, height)
radius: height / 2
color: hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground
ToolTip.text: notificationCount
ToolTip.delay: Nheko.tooltipDelay
ToolTip.visible: notificationBubbleHover.hovered && (notificationCount > 9999)
Label {
id: notificationBubbleText
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
font.bold: true
font.pixelSize: fontMetrics.font.pixelSize * 0.8
color: hasLoudNotification ? "white" : roomItem.bubbleText
text: notificationCount > 9999 ? "9999+" : notificationCount
HoverHandler {
id: notificationBubbleHover
}
}
Loader {
sourceComponent: notificationBubble
active: !isSpace
}
}
}

@ -27,6 +27,7 @@
#include <cmark.h>
#include "Cache.h"
#include "Cache_p.h"
#include "Config.h"
#include "EventAccessors.h"
#include "Logging.h"
@ -880,3 +881,17 @@ utils::markRoomAsDirect(QString roomid, std::vector<RoomMember> members)
});
});
}
int
utils::getChildNotificationsForSpace(const QString &spaceId)
{
auto children = cache::getRoomInfo(cache::client()->getChildRoomIds(spaceId.toStdString()));
int total{0};
for (const auto &[childId, child] : children) {
if (child.is_space)
total += utils::getChildNotificationsForSpace(childId);
else
total += child.notification_count;
}
return total;
}

@ -311,4 +311,7 @@ removeDirectFromRoom(QString roomid);
void
markRoomAsDirect(QString roomid, std::vector<RoomMember> members);
int
getChildNotificationsForSpace(const QString &spaceId);
}

@ -12,6 +12,7 @@
#include "ChatPage.h"
#include "Logging.h"
#include "UserSettingsPage.h"
#include "Utils.h"
CommunitiesModel::CommunitiesModel(QObject *parent)
: QAbstractListModel(parent)
@ -131,7 +132,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
case CommunitiesModel::Roles::Id:
return "space:" + id;
case CommunitiesModel::Roles::UnreadMessages:
return getChildNotifications(id);
return utils::getChildNotificationsForSpace(id);
}
} else if (index.row() - 2 < tags_.size() + spaceOrder_.size()) {
auto tag = tags_.at(index.row() - 2 - spaceOrder_.size());
@ -465,20 +466,6 @@ CommunitiesModel::toggleTagId(QString tagId)
emit hiddenTagsChanged();
}
int
CommunitiesModel::getChildNotifications(const QString &space_id) const
{
auto children = cache::getRoomInfo(cache::client()->getChildRoomIds(space_id.toStdString()));
int total{0};
for (const auto &[child_id, child] : children) {
if (child.is_space)
total += getChildNotifications(child_id);
else
total += child.notification_count;
}
return total;
}
FilteredCommunitiesModel::FilteredCommunitiesModel(CommunitiesModel *model, QObject *parent)
: QSortFilterProxyModel(parent)
{

@ -148,8 +148,6 @@ signals:
void containsSubspacesChanged();
private:
int getChildNotifications(const QString &space_id) const;
QStringList tags_;
QString currentTagId_;
QStringList hiddenTagIds_;

@ -330,10 +330,13 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification)
Qt::DisplayRole,
});
if (getRoomById(room_id)->isSpace())
return; // no need to update space notifications
int total_unread_msgs = 0;
for (const auto &room : qAsConst(models)) {
if (!room.isNull())
if (!room.isNull() && !room->isSpace())
total_unread_msgs += room->notificationCount();
}

@ -352,16 +352,23 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
{
this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString());
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
this->isSpace_ = roomInfo.is_space;
this->notification_count = roomInfo.notification_count;
this->highlight_count = roomInfo.highlight_count;
lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
this->isSpace_ = roomInfo.is_space;
this->notification_count =
isSpace_ ? utils::getChildNotificationsForSpace(room_id_) : roomInfo.notification_count;
this->highlight_count = roomInfo.highlight_count;
lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
// needs to be
connect(this, &TimelineModel::roomNameChanged, this, &TimelineModel::plainRoomNameChanged);
if (isSpace_)
connect(ChatPage::instance(), &ChatPage::unreadMessages, this, [this](int) {
notification_count = utils::getChildNotificationsForSpace(room_id_);
emit notificationsChanged();
});
connect(
this,
&TimelineModel::redactionFailed,

Loading…
Cancel
Save