mirror of https://github.com/procxx/kepka.git
Fixed infrequent separation of grouped notifications.
This commit is contained in:
parent
2a935868a8
commit
dc95756ec9
|
@ -30,12 +30,14 @@ namespace {
|
||||||
|
|
||||||
// not more than one sound in 500ms from one peer - grouping
|
// not more than one sound in 500ms from one peer - grouping
|
||||||
constexpr auto kMinimalAlertDelay = crl::time(500);
|
constexpr auto kMinimalAlertDelay = crl::time(500);
|
||||||
|
constexpr auto kWaitingForAllGroupedDelay = crl::time(1000);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
System::System(AuthSession *session)
|
System::System(AuthSession *session)
|
||||||
: _authSession(session)
|
: _authSession(session)
|
||||||
, _waitTimer([=] { showNext(); }) {
|
, _waitTimer([=] { showNext(); })
|
||||||
|
, _waitForAllGroupedTimer([=] { showGrouped(); }) {
|
||||||
createManager();
|
createManager();
|
||||||
|
|
||||||
subscribe(settingsChanged(), [=](ChangeType type) {
|
subscribe(settingsChanged(), [=](ChangeType type) {
|
||||||
|
@ -211,9 +213,28 @@ void System::checkDelayed() {
|
||||||
showNext();
|
showNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void System::showGrouped() {
|
||||||
|
if (const auto lastItem = App::histItemById(_lastHistoryItemId)) {
|
||||||
|
_waitForAllGroupedTimer.cancel();
|
||||||
|
_manager->showNotification(lastItem, _lastForwardedCount);
|
||||||
|
_lastForwardedCount = 0;
|
||||||
|
_lastHistoryItemId = FullMsgId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void System::showNext() {
|
void System::showNext() {
|
||||||
if (App::quitting()) return;
|
if (App::quitting()) return;
|
||||||
|
|
||||||
|
const auto isSameGroup = [=](HistoryItem *item) {
|
||||||
|
if (!_lastHistoryItemId || !item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (const auto lastItem = App::histItemById(_lastHistoryItemId)) {
|
||||||
|
return (lastItem->groupId() == item->groupId() || lastItem->author() == item->author());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
auto ms = crl::now(), nextAlert = 0LL;
|
auto ms = crl::now(), nextAlert = 0LL;
|
||||||
bool alert = false;
|
bool alert = false;
|
||||||
int32 now = unixtime();
|
int32 now = unixtime();
|
||||||
|
@ -360,7 +381,33 @@ void System::showNext() {
|
||||||
} while (nextNotify);
|
} while (nextNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
_manager->showNotification(notifyItem, forwardedCount);
|
if (!_lastHistoryItemId && groupedItem) {
|
||||||
|
_lastHistoryItemId = groupedItem->fullId();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the current notification is grouped.
|
||||||
|
if (isAlbum || isForwarded) {
|
||||||
|
// If the previous notification is grouped
|
||||||
|
// then reset the timer.
|
||||||
|
if (_waitForAllGroupedTimer.isActive()) {
|
||||||
|
_waitForAllGroupedTimer.cancel();
|
||||||
|
// If this is not the same group
|
||||||
|
// then show the previous group immediately.
|
||||||
|
if (!isSameGroup(groupedItem)) {
|
||||||
|
showGrouped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// We have to wait until all the messages in this group are loaded.
|
||||||
|
_lastForwardedCount += forwardedCount;
|
||||||
|
_lastHistoryItemId = groupedItem->fullId();
|
||||||
|
_waitForAllGroupedTimer.callOnce(kWaitingForAllGroupedDelay);
|
||||||
|
} else {
|
||||||
|
// If the current notification is not grouped
|
||||||
|
// then there is no reason to wait for the timer
|
||||||
|
// to show the previous notification.
|
||||||
|
showGrouped();
|
||||||
|
_manager->showNotification(notifyItem, forwardedCount);
|
||||||
|
}
|
||||||
|
|
||||||
if (!history->hasNotification()) {
|
if (!history->hasNotification()) {
|
||||||
_waiters.remove(history);
|
_waiters.remove(history);
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showNext();
|
void showNext();
|
||||||
|
void showGrouped();
|
||||||
void ensureSoundCreated();
|
void ensureSoundCreated();
|
||||||
|
|
||||||
AuthSession *_authSession = nullptr;
|
AuthSession *_authSession = nullptr;
|
||||||
|
@ -99,6 +100,7 @@ private:
|
||||||
Waiters _waiters;
|
Waiters _waiters;
|
||||||
Waiters _settingWaiters;
|
Waiters _settingWaiters;
|
||||||
base::Timer _waitTimer;
|
base::Timer _waitTimer;
|
||||||
|
base::Timer _waitForAllGroupedTimer;
|
||||||
|
|
||||||
QMap<History*, QMap<crl::time, PeerData*>> _whenAlerts;
|
QMap<History*, QMap<crl::time, PeerData*>> _whenAlerts;
|
||||||
|
|
||||||
|
@ -108,6 +110,9 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
||||||
|
|
||||||
|
int _lastForwardedCount = 0;
|
||||||
|
FullMsgId _lastHistoryItemId;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
Loading…
Reference in New Issue