From 2a935868a8f276d31512dc88642c339ef80cc1e9 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 3 Mar 2019 12:32:01 +0300 Subject: [PATCH] Added grouping of album files into a single notification. - Added display of "Album" in inDialogsText(). --- .../SourceFiles/data/data_media_types.cpp | 2 - Telegram/SourceFiles/history/history_item.cpp | 3 ++ .../window/notifications_manager.cpp | 47 +++++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 1c092044c..8eb98d2df 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -301,14 +301,12 @@ QString MediaPhoto::notificationText() const { return WithCaptionNotificationText( lang(lng_in_dlg_photo), parent()->originalText().text); - //return WithCaptionNotificationText(lang(lng_in_dlg_album), _caption); } QString MediaPhoto::chatListText() const { return WithCaptionDialogsText( lang(lng_in_dlg_photo), parent()->originalText().text); - //return WithCaptionDialogsText(lang(lng_in_dlg_album), _caption); } QString MediaPhoto::pinnedTextSubstring() const { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index f4c9d33d2..4da1682c0 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -706,6 +706,9 @@ QString HistoryItem::notificationText() const { QString HistoryItem::inDialogsText(DrawInDialog way) const { auto getText = [this]() { if (_media) { + if (_groupId) { + return textcmdLink(1, TextUtilities::Clean(lang(lng_in_dlg_album))); + } return _media->chatListText(); } else if (!emptyText()) { return TextUtilities::Clean(_text.originalText()); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index cb46f2e23..c23248b2a 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -307,12 +307,14 @@ void System::showNext() { _waitTimer.callOnce(next - ms); break; } else { - auto forwardedItem = notifyItem->Has() ? notifyItem : nullptr; // forwarded notify grouping - auto forwardedCount = 1; + const auto isForwarded = notifyItem->Has(); + const auto isAlbum = notifyItem->groupId(); - auto ms = crl::now(); - auto history = notifyItem->history(); - auto j = _whenMaps.find(history); + auto groupedItem = (isForwarded || isAlbum) ? notifyItem : nullptr; // forwarded and album notify grouping + auto forwardedCount = isForwarded ? 1 : 0; + + const auto history = notifyItem->history(); + const auto j = _whenMaps.find(history); if (j == _whenMaps.cend()) { history->clearNotifications(); } else { @@ -323,9 +325,9 @@ void System::showNext() { break; } - j.value().remove((forwardedItem ? forwardedItem : notifyItem)->id); + j.value().remove((groupedItem ? groupedItem : notifyItem)->id); do { - auto k = j.value().constFind(history->currentNotification()->id); + const auto k = j.value().constFind(history->currentNotification()->id); if (k != j.value().cend()) { nextNotify = history->currentNotification(); _waiters.insert(notifyHistory, Waiter(k.key(), k.value(), 0)); @@ -334,19 +336,26 @@ void System::showNext() { history->skipNotification(); } while (history->hasNotification()); if (nextNotify) { - if (forwardedItem) { - auto nextForwarded = nextNotify->Has() ? nextNotify : nullptr; - if (nextForwarded - && forwardedItem->author() == nextForwarded->author() - && qAbs(int64(nextForwarded->date()) - int64(forwardedItem->date())) < 2) { - forwardedItem = nextForwarded; - ++forwardedCount; - } else { - nextNotify = nullptr; + if (groupedItem) { + const auto canNextBeGrouped = (isForwarded && nextNotify->Has()) + || (isAlbum && nextNotify->groupId()); + const auto nextItem = canNextBeGrouped ? nextNotify : nullptr; + if (nextItem + && qAbs(int64(nextItem->date()) - int64(groupedItem->date())) < 2) { + if (isForwarded + && groupedItem->author() == nextItem->author()) { + ++forwardedCount; + groupedItem = nextItem; + continue; + } + if (isAlbum + && groupedItem->groupId() == nextItem->groupId()) { + groupedItem = nextItem; + continue; + } } - } else { - nextNotify = nullptr; } + nextNotify = nullptr; } } while (nextNotify); } @@ -464,7 +473,7 @@ void NativeManager::doShowNotification(HistoryItem *item, int forwardedCount) { const auto text = options.hideMessageText ? lang(lng_notification_preview) : (forwardedCount < 2 - ? item->notificationText() + ? (item->groupId() ? lang(lng_in_dlg_album) : item->notificationText()) : lng_forward_messages(lt_count, forwardedCount)); doShowNativeNotification(