mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +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
|
height: collapsedNotificationBubbleText.height + Nheko.paddingMedium
|
||||||
width: Math.max(collapsedNotificationBubbleText.width, height)
|
width: Math.max(collapsedNotificationBubbleText.width, height)
|
||||||
radius: height / 2
|
radius: height / 2
|
||||||
color: /*hasLoudNotification ? Nheko.theme.red :*/ communityItem.bubbleBackground
|
color: model.hasLoudNotification ? Nheko.theme.red : communityItem.bubbleBackground
|
||||||
ToolTip.text: model.unreadMessages
|
ToolTip.text: model.unreadMessages
|
||||||
ToolTip.delay: Nheko.tooltipDelay
|
ToolTip.delay: Nheko.tooltipDelay
|
||||||
ToolTip.visible: collapsedNotificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
ToolTip.visible: collapsedNotificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
||||||
|
@ -178,7 +178,7 @@ Page {
|
||||||
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
||||||
font.bold: true
|
font.bold: true
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.6
|
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
|
text: model.unreadMessages > 9999 ? "9999+" : model.unreadMessages
|
||||||
|
|
||||||
HoverHandler {
|
HoverHandler {
|
||||||
|
@ -214,7 +214,7 @@ Page {
|
||||||
height: notificationBubbleText.height + Nheko.paddingMedium
|
height: notificationBubbleText.height + Nheko.paddingMedium
|
||||||
Layout.preferredWidth: Math.max(notificationBubbleText.width, height)
|
Layout.preferredWidth: Math.max(notificationBubbleText.width, height)
|
||||||
radius: height / 2
|
radius: height / 2
|
||||||
color: /*hasLoudNotification ? Nheko.theme.red :*/ communityItem.bubbleBackground
|
color: model.hasLoudNotification ? Nheko.theme.red : communityItem.bubbleBackground
|
||||||
ToolTip.text: model.unreadMessages
|
ToolTip.text: model.unreadMessages
|
||||||
ToolTip.delay: Nheko.tooltipDelay
|
ToolTip.delay: Nheko.tooltipDelay
|
||||||
ToolTip.visible: notificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
ToolTip.visible: notificationBubbleHover.hovered && (model.unreadMessages > 9999)
|
||||||
|
@ -228,7 +228,7 @@ Page {
|
||||||
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
width: Math.max(implicitWidth + Nheko.paddingMedium, parent.height)
|
||||||
font.bold: true
|
font.bold: true
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 0.8
|
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
|
text: model.unreadMessages > 9999 ? "9999+" : model.unreadMessages
|
||||||
|
|
||||||
HoverHandler {
|
HoverHandler {
|
||||||
|
|
|
@ -882,16 +882,20 @@ utils::markRoomAsDirect(QString roomid, std::vector<RoomMember> members)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
QPair<int, int>
|
||||||
utils::getChildNotificationsForSpace(const QString &spaceId)
|
utils::getChildNotificationsForSpace(const QString &spaceId)
|
||||||
{
|
{
|
||||||
auto children = cache::getRoomInfo(cache::client()->getChildRoomIds(spaceId.toStdString()));
|
auto children = cache::getRoomInfo(cache::client()->getChildRoomIds(spaceId.toStdString()));
|
||||||
int total{0};
|
QPair<int, int> retVal;
|
||||||
for (const auto &[childId, child] : children) {
|
for (const auto &[childId, child] : children) {
|
||||||
if (child.is_space)
|
if (child.is_space) {
|
||||||
total += utils::getChildNotificationsForSpace(childId);
|
auto temp{utils::getChildNotificationsForSpace(childId)};
|
||||||
else
|
retVal.first += temp.first;
|
||||||
total += child.notification_count;
|
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
|
void
|
||||||
markRoomAsDirect(QString roomid, std::vector<RoomMember> members);
|
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);
|
getChildNotificationsForSpace(const QString &spaceId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ CommunitiesModel::roleNames() const
|
||||||
{Depth, "depth"},
|
{Depth, "depth"},
|
||||||
{Id, "id"},
|
{Id, "id"},
|
||||||
{UnreadMessages, "unreadMessages"},
|
{UnreadMessages, "unreadMessages"},
|
||||||
|
{HasLoudNotification, "hasLoudNotification"},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
||||||
case CommunitiesModel::Roles::Id:
|
case CommunitiesModel::Roles::Id:
|
||||||
return "";
|
return "";
|
||||||
case CommunitiesModel::Roles::UnreadMessages:
|
case CommunitiesModel::Roles::UnreadMessages:
|
||||||
|
case CommunitiesModel::Roles::HasLoudNotification:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (index.row() == 1) {
|
} else if (index.row() == 1) {
|
||||||
|
@ -103,6 +105,7 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
||||||
case CommunitiesModel::Roles::Id:
|
case CommunitiesModel::Roles::Id:
|
||||||
return "dm";
|
return "dm";
|
||||||
case CommunitiesModel::Roles::UnreadMessages:
|
case CommunitiesModel::Roles::UnreadMessages:
|
||||||
|
case CommunitiesModel::Roles::HasLoudNotification:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (index.row() - 2 < spaceOrder_.size()) {
|
} else if (index.row() - 2 < spaceOrder_.size()) {
|
||||||
|
@ -132,7 +135,9 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
||||||
case CommunitiesModel::Roles::Id:
|
case CommunitiesModel::Roles::Id:
|
||||||
return "space:" + id;
|
return "space:" + id;
|
||||||
case CommunitiesModel::Roles::UnreadMessages:
|
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()) {
|
} else if (index.row() - 2 < tags_.size() + spaceOrder_.size()) {
|
||||||
auto tag = tags_.at(index.row() - 2 - 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:
|
case CommunitiesModel::Roles::Id:
|
||||||
return "tag:" + tag;
|
return "tag:" + tag;
|
||||||
case CommunitiesModel::Roles::UnreadMessages:
|
case CommunitiesModel::Roles::UnreadMessages:
|
||||||
|
case CommunitiesModel::Roles::HasLoudNotification:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
Depth,
|
Depth,
|
||||||
Id,
|
Id,
|
||||||
UnreadMessages,
|
UnreadMessages,
|
||||||
|
HasLoudNotification,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FlatTree
|
struct FlatTree
|
||||||
|
|
|
@ -355,8 +355,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
|
||||||
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
|
auto roomInfo = cache::singleRoomInfo(room_id_.toStdString());
|
||||||
this->isSpace_ = roomInfo.is_space;
|
this->isSpace_ = roomInfo.is_space;
|
||||||
this->notification_count =
|
this->notification_count =
|
||||||
isSpace_ ? utils::getChildNotificationsForSpace(room_id_) : roomInfo.notification_count;
|
isSpace_ ? utils::getChildNotificationsForSpace(room_id_).first : roomInfo.notification_count;
|
||||||
this->highlight_count = roomInfo.highlight_count;
|
this->highlight_count =
|
||||||
|
isSpace_ ? utils::getChildNotificationsForSpace(room_id_).second : roomInfo.highlight_count;
|
||||||
lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
|
lastMessage_.timestamp = roomInfo.approximate_last_modification_ts;
|
||||||
|
|
||||||
// this connection will simplify adding the plainRoomNameChanged() signal everywhere that it
|
// 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_)
|
if (isSpace_)
|
||||||
connect(ChatPage::instance(), &ChatPage::unreadMessages, this, [this](int) {
|
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();
|
emit notificationsChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue