| 414 | } |
| 415 | |
| 416 | void System::schedule(Data::ItemNotification notification) { |
| 417 | Expects(_manager != nullptr); |
| 418 | |
| 419 | const auto item = notification.item; |
| 420 | const auto type = notification.type; |
| 421 | const auto thread = item->notificationThread(); |
| 422 | const auto skip = skipNotification(notification); |
| 423 | if (skip.value == SkipState::Skip) { |
| 424 | thread->popNotification(notification); |
| 425 | return; |
| 426 | } |
| 427 | const auto ready = (skip.value != SkipState::Unknown) |
| 428 | && item->notificationReady(); |
| 429 | |
| 430 | const auto minimalDelay = (type == Data::ItemNotificationType::Reaction |
| 431 | || type == Data::ItemNotificationType::PollVote) |
| 432 | ? kMinimalDelay |
| 433 | : item->Has<HistoryMessageForwarded>() |
| 434 | ? kMinimalForwardDelay |
| 435 | : kMinimalDelay; |
| 436 | const auto timing = countTiming(thread, minimalDelay); |
| 437 | const auto notifyBy = (type == Data::ItemNotificationType::Message) |
| 438 | ? item->specialNotificationPeer() |
| 439 | : notification.reactionOrVoteSender; |
| 440 | if (!skip.silent) { |
| 441 | registerThread(thread); |
| 442 | _whenAlerts[thread].emplace(timing.when, notifyBy); |
| 443 | } |
| 444 | if (const auto user = item->history()->peer->asUser()) { |
| 445 | if (user->hasStarsPerMessage() |
| 446 | && !user->messageMoneyRestrictionsKnown()) { |
| 447 | user->updateFull(); |
| 448 | } |
| 449 | } |
| 450 | if (Core::App().settings().desktopNotify() |
| 451 | && !_manager->skipToast()) { |
| 452 | registerThread(thread); |
| 453 | const auto key = NotificationInHistoryKey(notification); |
| 454 | auto &whenMap = _whenMaps[thread]; |
| 455 | if (whenMap.find(key) == whenMap.end()) { |
| 456 | whenMap.emplace(key, timing.when); |
| 457 | } |
| 458 | |
| 459 | auto &addTo = ready ? _waiters : _settingWaiters; |
| 460 | const auto it = addTo.find(thread); |
| 461 | if (it == addTo.end() || it->second.when > timing.when) { |
| 462 | addTo.emplace(thread, Waiter{ |
| 463 | .key = key, |
| 464 | .reactionOrVoteSender = notification.reactionOrVoteSender, |
| 465 | .type = notification.type, |
| 466 | .when = timing.when, |
| 467 | }); |
| 468 | } |
| 469 | } |
| 470 | if (ready) { |
| 471 | if (!_waitTimer.isActive() |
| 472 | || _waitTimer.remainingTime() > timing.delay) { |
| 473 | _waitTimer.callOnce(timing.delay); |
nothing calls this directly
no test coverage detected