mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Add loud notifications for spaces
This commit is contained in:
parent
169384f0fa
commit
e446e3d679
6 changed files with 32 additions and 16 deletions
|
@ -164,7 +164,7 @@ Page {
|
|||
height: collapsedNotificationBubbleText.height + Nheko.paddingMedium
|
||||
width: Math.max(collapsedNotificationBubbleText.width, height)
|
||||
radius: height / 2
|
||||
color: /*hasLoudNotification ? Nheko.theme.red :*/ communityItem.bubbleBackground
|
||||
color: model.hasLoudNotification ? Nheko.theme.red : communityItem.bubbleBackground
|
||||
ToolTip.text: model.unreadMessages
|
||||
ToolTip.delay: Nheko.tooltipDelay
|
||||
ToolTip.visible: collapsedNotificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
||||
|
@ -178,7 +178,7 @@ Page {
|
|||
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
||||
font.bold: true
|
||||
font.pixelSize: fontMetrics.font.pixelSize * 0.6
|
||||
color: /*hasLoudNotification ? "white" :*/ communityItem.bubbleText
|
||||
color: model.hasLoudNotification ? "white" : communityItem.bubbleText
|
||||
text: model.unreadMessages > 9999 ? "9999+" : model.unreadMessages
|
||||
|
||||
HoverHandler {
|
||||
|
@ -214,7 +214,7 @@ Page {
|
|||
height: notificationBubbleText.height + Nheko.paddingMedium
|
||||
Layout.preferredWidth: Math.max(notificationBubbleText.width, height)
|
||||
radius: height / 2
|
||||
color: /*hasLoudNotification ? Nheko.theme.red :*/ communityItem.bubbleBackground
|
||||
color: model.hasLoudNotification ? Nheko.theme.red : communityItem.bubbleBackground
|
||||
ToolTip.text: model.unreadMessages
|
||||
ToolTip.delay: Nheko.tooltipDelay
|
||||
ToolTip.visible: notificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
||||
|
@ -228,7 +228,7 @@ Page {
|
|||
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
||||
font.bold: true
|
||||
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
||||
color: /*hasLoudNotification ? "white" :*/ communityItem.bubbleText
|
||||
color: model.hasLoudNotification ? "white" : communityItem.bubbleText
|
||||
text: model.unreadMessages > 9999 ? "9999+" : model.unreadMessages
|
||||
|
||||
HoverHandler {
|
||||
|
|
|
@ -882,16 +882,20 @@ utils::markRoomAsDirect(QString roomid, std::vector<RoomMember> members)
|
|||
});
|
||||
}
|
||||
|
||||
int
|
||||
QPair<int, int>
|
||||
utils::getChildNotificationsForSpace(const QString &spaceId)
|
||||
{
|
||||
auto children = cache::getRoomInfo(cache::client()->getChildRoomIds(spaceId.toStdString()));
|
||||
int total{0};
|
||||
QPair<int, int> retVal;
|
||||
for (const auto &[childId, child] : children) {
|
||||
if (child.is_space)
|
||||
total += utils::getChildNotificationsForSpace(childId);
|
||||
else
|
||||
total += child.notification_count;
|
||||
if (child.is_space) {
|
||||
auto temp{utils::getChildNotificationsForSpace(childId)};
|
||||
retVal.first += temp.first;
|
||||
retVal.second += temp.second;
|
||||
} else {
|
||||
retVal.first += child.notification_count;
|
||||
retVal.second += child.highlight_count;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -312,6 +312,8 @@ removeDirectFromRoom(QString roomid);
|
|||
void
|
||||
markRoomAsDirect(QString roomid, std::vector<RoomMember> members);
|
||||
|
||||
int
|
||||
//! Returns a pair of integers representing the unread notifications in a space and how many of them
|
||||
//! are loud notifications, respectively.
|
||||
QPair<int, int>
|
||||
getChildNotificationsForSpace(const QString &spaceId);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ CommunitiesModel::roleNames() const
|
|||
{Depth, "depth"},
|
||||
{Id, "id"},
|
||||
{UnreadMessages, "unreadMessages"},
|
||||
{HasLoudNotification, "hasLoudNotification"},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -80,6 +81,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
case CommunitiesModel::Roles::Id:
|
||||
return "";
|
||||
case CommunitiesModel::Roles::UnreadMessages:
|
||||
case CommunitiesModel::Roles::HasLoudNotification:
|
||||
return 0;
|
||||
}
|
||||
} else if (index.row() == 1) {
|
||||
|
@ -103,6 +105,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
case CommunitiesModel::Roles::Id:
|
||||
return "dm";
|
||||
case CommunitiesModel::Roles::UnreadMessages:
|
||||
case CommunitiesModel::Roles::HasLoudNotification:
|
||||
return 0;
|
||||
}
|
||||
} else if (index.row() - 2 < spaceOrder_.size()) {
|
||||
|
@ -132,7 +135,9 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
case CommunitiesModel::Roles::Id:
|
||||
return "space:" + id;
|
||||
case CommunitiesModel::Roles::UnreadMessages:
|
||||
return utils::getChildNotificationsForSpace(id);
|
||||
return utils::getChildNotificationsForSpace(id).first;
|
||||
case CommunitiesModel::Roles::HasLoudNotification:
|
||||
return utils::getChildNotificationsForSpace(id).second > 0;
|
||||
}
|
||||
} else if (index.row() - 2 < tags_.size() + spaceOrder_.size()) {
|
||||
auto tag = tags_.at(index.row() - 2 - spaceOrder_.size());
|
||||
|
@ -187,6 +192,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
case CommunitiesModel::Roles::Id:
|
||||
return "tag:" + tag;
|
||||
case CommunitiesModel::Roles::UnreadMessages:
|
||||
case CommunitiesModel::Roles::HasLoudNotification:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
Depth,
|
||||
Id,
|
||||
UnreadMessages,
|
||||
HasLoudNotification,
|
||||
};
|
||||
|
||||
struct FlatTree
|
||||
|
|
|
@ -355,8 +355,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
|||
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;
|
||||
isSpace_ ? utils::getChildNotificationsForSpace(room_id_).first : roomInfo.notification_count;
|
||||
this->highlight_count =
|
||||
isSpace_ ? utils::getChildNotificationsForSpace(room_id_).second : roomInfo.highlight_count;
|
||||
lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
|
||||
|
||||
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
|
||||
|
@ -365,7 +366,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
|||
|
||||
if (isSpace_)
|
||||
connect(ChatPage::instance(), &ChatPage::unreadMessages, this, [this](int) {
|
||||
notification_count = utils::getChildNotificationsForSpace(room_id_);
|
||||
auto temp{utils::getChildNotificationsForSpace(room_id_)};
|
||||
notification_count = temp.first;
|
||||
highlight_count = temp.second;
|
||||
emit notificationsChanged();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue