@@ -125,38 +125,30 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
125125
126126void User::checkNotifiedNotifications ()
127127{
128- // after one hour, clear the gui log notification store
128+ // clear the gui log notification store after one hour has passed since the last received notification
129129 constexpr qint64 clearGuiLogInterval = 60 * 60 * 1000 ;
130130 if (_guiLogTimer.elapsed () > clearGuiLogInterval) {
131131 _notifiedNotifications.clear ();
132132 }
133133}
134134
135- bool User::notificationAlreadyShown (const long notificationId)
135+ bool User::notificationAlreadyShown (const qint64 notificationId)
136136{
137137 checkNotifiedNotifications ();
138138 return _notifiedNotifications.contains (notificationId);
139139}
140140
141- bool User::canShowNotification (const long notificationId)
141+ bool User::canShowNotification (const qint64 notificationId)
142142{
143143 ConfigFile cfg;
144144 return cfg.optionalServerNotifications () &&
145145 isDesktopNotificationsAllowed () &&
146146 !notificationAlreadyShown (notificationId);
147147}
148148
149- void User::checkAndRemoveSeenActivities (const ActivityList &list , const int numTalkNotificationsReceived )
149+ void User::showDesktopNotification (const QString &title , const QString &message, const qint64 notificationId )
150150{
151- if (numTalkNotificationsReceived < _lastTalkNotificationsReceivedCount) {
152- _activityModel->checkAndRemoveSeenActivities (list);
153- }
154- _lastTalkNotificationsReceivedCount = numTalkNotificationsReceived;
155- }
156-
157- void User::showDesktopNotification (const QString &title, const QString &message, const long notificationId)
158- {
159- if (!canShowNotification (notificationId)) {
151+ if (!canShowNotification (notificationId)) {
160152 return ;
161153 }
162154
@@ -200,7 +192,7 @@ void User::showDesktopNotification(const ActivityList &activityList)
200192
201193 Logger::instance ()->postGuiLog (subject, message);
202194
203- for (const auto &activity : activityList) {
195+ for (const auto &activity : activityList) {
204196 _notifiedNotifications.insert (activity._id );
205197 _activityModel->addNotificationToActivityList (activity);
206198 }
@@ -232,43 +224,41 @@ void User::showDesktopTalkNotification(const Activity &activity)
232224
233225void User::slotBuildNotificationDisplay (const ActivityList &list)
234226{
235- const auto talkNotificationsReceivedCount = std::count_if (std::cbegin (list), std::cend (list), [](const auto &activity) {
236- return activity._objectType == QStringLiteral (" chat" ) ||
237- activity._objectType == QStringLiteral (" call" );
238- });
239- checkAndRemoveSeenActivities (list, talkNotificationsReceivedCount);
240-
241227 ActivityList toNotifyList;
242228
243- std::copy_if (list. constBegin (), list. constEnd (), std::back_inserter (toNotifyList), [&]( const Activity &activity) {
229+ _activityModel-> removeOutdatedNotifications (list);
244230
245- if (_blacklistedNotifications.contains (activity)) {
246- qCInfo (lcActivity) << " Activity in blacklist, skip" ;
247- return false ;
248- } else if (_notifiedNotifications.contains (activity._id )) {
249- qCInfo (lcActivity) << " Activity already notified, skip" ;
231+ std::copy_if (list.constBegin (), list.constEnd (), std::back_inserter (toNotifyList), [&](const Activity &activity) -> bool {
232+ if (!activity._shouldNotify ) {
233+ qCDebug (lcActivity).nospace () << " No notification should be sent for activity with id=" << activity._id << " objectType=" << activity._objectType ;
250234 return false ;
251235 }
252- if (!activity._shouldNotify ) {
253- qCDebug (lcActivity) << " Activity should not be notified" ;
236+
237+ if (_notifiedNotifications.contains (activity._id )) {
238+ qCInfo (lcActivity).nospace () << " Ignoring already notified activity with id=" << activity._id << " objectType=" << activity._objectType ;
254239 return false ;
255240 }
256241
257242 return true ;
258243 });
259244
260- if (toNotifyList.count () > 2 ) {
261- showDesktopNotification (toNotifyList);
245+ if (toNotifyList.isEmpty ()) {
262246 return ;
263247 }
264248
265- for (const auto &activity : std::as_const (toNotifyList)) {
249+ if (toNotifyList.size () == 1 ) {
250+ const auto &activity = toNotifyList.constFirst ();
266251 if (activity._objectType == QStringLiteral (" chat" )) {
252+ // Talk's "call" type is handled in slotBuildIncomingCallDialogs
267253 showDesktopTalkNotification (activity);
268- } else {
269- showDesktopNotification (activity);
254+ return ;
270255 }
256+
257+ showDesktopNotification (activity);
258+ return ;
271259 }
260+
261+ showDesktopNotification (toNotifyList);
272262}
273263
274264void User::slotNotificationFetchFinished ()
@@ -288,16 +278,18 @@ void User::slotBuildIncomingCallDialogs(const ActivityList &list)
288278 }
289279
290280 const auto systray = Systray::instance ();
281+ if (!systray) {
282+ qCWarning (lcActivity) << " No systray instance available, can not notify about new calls" ;
283+ return ;
284+ }
291285
292- if (systray) {
293- for (const auto &activity : list) {
294- if (!activity._shouldNotify ) {
295- qCDebug (lcActivity) << " Activity should not be notified" ;
296- continue ;
297- }
298-
299- systray->createCallDialog (activity, _account);
286+ for (const auto &activity : list) {
287+ if (!activity._shouldNotify ) {
288+ qCDebug (lcActivity).nospace () << " No notification should be sent for activity with id=" << activity._id << " objectType=" << activity._objectType ;
289+ continue ;
300290 }
291+
292+ systray->createCallDialog (activity, _account);
301293 }
302294}
303295
0 commit comments