mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Merge branch 'dont-send-notifications-on-first-sync' of github.com:LcsTen/nheko into notif-test
This commit is contained in:
commit
3f4d384220
3 changed files with 60 additions and 27 deletions
|
@ -215,6 +215,12 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
|
||||||
if (pushrules) {
|
if (pushrules) {
|
||||||
const auto local_user = utils::localUser().toStdString();
|
const auto local_user = utils::localUser().toStdString();
|
||||||
|
|
||||||
|
// Desktop notifications to be sent
|
||||||
|
std::vector<std::tuple<QSharedPointer<TimelineModel>,
|
||||||
|
mtx::events::collections::TimelineEvents,
|
||||||
|
std::string,
|
||||||
|
std::vector<mtx::pushrules::actions::Action>>>
|
||||||
|
notifications;
|
||||||
for (const auto &[room_id, room] : sync.rooms.join) {
|
for (const auto &[room_id, room] : sync.rooms.join) {
|
||||||
// clear old notifications
|
// clear old notifications
|
||||||
for (const auto &e : room.ephemeral.events) {
|
for (const auto &e : room.ephemeral.events) {
|
||||||
|
@ -334,30 +340,46 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (userSettings_->hasDesktopNotifications()) {
|
if (userSettings_->hasDesktopNotifications()) {
|
||||||
auto info = cache::singleRoomInfo(room_id);
|
notifications.emplace_back(roomModel, te, room_id, actions);
|
||||||
|
|
||||||
AvatarProvider::resolve(
|
|
||||||
roomModel->roomAvatarUrl(),
|
|
||||||
96,
|
|
||||||
this,
|
|
||||||
[this, te, room_id = room_id, actions](QPixmap image) {
|
|
||||||
notificationsManager->postNotification(
|
|
||||||
mtx::responses::Notification{
|
|
||||||
.actions = actions,
|
|
||||||
.event = std::move(te),
|
|
||||||
.read = false,
|
|
||||||
.profile_tag = "",
|
|
||||||
.room_id = room_id,
|
|
||||||
.ts = 0,
|
|
||||||
},
|
|
||||||
image.toImage());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (notifications.size() <= 5) {
|
||||||
|
for (const auto &[roomModel, te, room_id, actions] : notifications) {
|
||||||
|
AvatarProvider::resolve(
|
||||||
|
roomModel->roomAvatarUrl(),
|
||||||
|
96,
|
||||||
|
this,
|
||||||
|
[this, te = te, room_id = room_id, actions = actions](QPixmap image) {
|
||||||
|
notificationsManager->postNotification(
|
||||||
|
mtx::responses::Notification{
|
||||||
|
.actions = actions,
|
||||||
|
.event = std::move(te),
|
||||||
|
.read = false,
|
||||||
|
.profile_tag = "",
|
||||||
|
.room_id = room_id,
|
||||||
|
.ts = 0,
|
||||||
|
},
|
||||||
|
image.toImage());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (!notifications.empty()) {
|
||||||
|
std::map<QSharedPointer<TimelineModel>, std::size_t> missedEvents;
|
||||||
|
for (const auto &[roomModel, te, room_id, actions] : notifications) {
|
||||||
|
missedEvents[roomModel]++;
|
||||||
|
}
|
||||||
|
QString body;
|
||||||
|
for (const auto &[roomModel, nbNotifs] : missedEvents) {
|
||||||
|
body += tr("%1 unread messages in room %2\n")
|
||||||
|
.arg(nbNotifs)
|
||||||
|
.arg(roomModel->roomName());
|
||||||
|
}
|
||||||
|
emit notificationsManager->systemPostNotificationCb(
|
||||||
|
"", "", "New messages while away", body, QImage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -187,11 +187,14 @@ NotificationsManager::systemPostNotification(const QString &room_id,
|
||||||
// The list of actions has always the action name and then a localized version of that
|
// The list of actions has always the action name and then a localized version of that
|
||||||
// action. Currently we just use an empty string for that.
|
// action. Currently we just use an empty string for that.
|
||||||
// TODO(Nico): Look into what to actually put there.
|
// TODO(Nico): Look into what to actually put there.
|
||||||
argumentList << (QStringList(QStringLiteral("default"))
|
QStringList actions;
|
||||||
<< QLatin1String("") << QStringLiteral("inline-reply")
|
actions << QStringList(QStringLiteral("default")) << QLatin1String("");
|
||||||
<< QLatin1String("")); // actions
|
if (!room_id.isEmpty()) {
|
||||||
argumentList << hints; // hints
|
actions << QStringLiteral("inline-reply") << QLatin1String("");
|
||||||
argumentList << (int)-1; // timeout in ms
|
}
|
||||||
|
argumentList << actions; // actions
|
||||||
|
argumentList << hints; // hints
|
||||||
|
argumentList << (int)-1; // timeout in ms
|
||||||
|
|
||||||
QDBusPendingCall call = dbus.asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList);
|
QDBusPendingCall call = dbus.asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList);
|
||||||
auto watcher = new QDBusPendingCallWatcher{call, this};
|
auto watcher = new QDBusPendingCallWatcher{call, this};
|
||||||
|
|
|
@ -106,10 +106,18 @@ void NotificationsManager::objCxxPostNotification(
|
||||||
textInputButtonTitle:sendStr.toNSString()
|
textInputButtonTitle:sendStr.toNSString()
|
||||||
textInputPlaceholder:placeholder.toNSString()];
|
textInputPlaceholder:placeholder.toNSString()];
|
||||||
|
|
||||||
UNNotificationCategory* category = [UNNotificationCategory categoryWithIdentifier:@"ReplyCategory"
|
UNNotificationCategory* category;
|
||||||
actions:@[ replyAction ]
|
if(!room_id.isEmpty()){
|
||||||
intentIdentifiers:@[]
|
category = [UNNotificationCategory categoryWithIdentifier:@"ReplyCategory"
|
||||||
options:UNNotificationCategoryOptionNone];
|
actions:@[ replyAction ]
|
||||||
|
intentIdentifiers:@[]
|
||||||
|
options:UNNotificationCategoryOptionNone];
|
||||||
|
}else{
|
||||||
|
category = [UNNotificationCategory categoryWithIdentifier:@"ReplyCategory"
|
||||||
|
actions:@[]
|
||||||
|
intentIdentifiers:@[]
|
||||||
|
options:UNNotificationCategoryOptionNone];
|
||||||
|
}
|
||||||
|
|
||||||
NSString* title = room_name.toNSString();
|
NSString* title = room_name.toNSString();
|
||||||
NSString* sub = subtitle.toNSString();
|
NSString* sub = subtitle.toNSString();
|
||||||
|
|
Loading…
Reference in a new issue