mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 22:46:10 +00:00
One Window::Notifications system for all sessions.
This commit is contained in:
@@ -67,11 +67,6 @@ std::unique_ptr<Manager> Create(System *system) {
|
||||
Manager::Manager(System *system)
|
||||
: Notifications::Manager(system)
|
||||
, _inputCheckTimer([=] { checkLastInput(); }) {
|
||||
subscribe(system->session().downloaderTaskFinished(), [this] {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
notification->updatePeerPhoto();
|
||||
}
|
||||
});
|
||||
subscribe(system->settingsChanged(), [this](ChangeType change) {
|
||||
settingsChanged(change);
|
||||
});
|
||||
@@ -212,7 +207,8 @@ void Manager::showNextFromQueue() {
|
||||
auto queued = _queuedNotifications.front();
|
||||
_queuedNotifications.pop_front();
|
||||
|
||||
auto notification = std::make_unique<Notification>(
|
||||
subscribeToSession(&queued.history->session());
|
||||
_notifications.push_back(std::make_unique<Notification>(
|
||||
this,
|
||||
queued.history,
|
||||
queued.peer,
|
||||
@@ -222,8 +218,7 @@ void Manager::showNextFromQueue() {
|
||||
queued.fromScheduled,
|
||||
startPosition,
|
||||
startShift,
|
||||
shiftDirection);
|
||||
_notifications.push_back(std::move(notification));
|
||||
shiftDirection));
|
||||
--count;
|
||||
} while (count > 0 && !_queuedNotifications.empty());
|
||||
|
||||
@@ -231,6 +226,32 @@ void Manager::showNextFromQueue() {
|
||||
checkLastInput();
|
||||
}
|
||||
|
||||
void Manager::subscribeToSession(not_null<Main::Session*> session) {
|
||||
auto i = _subscriptions.find(session);
|
||||
if (i == _subscriptions.end()) {
|
||||
i = _subscriptions.emplace(session, base::Subscription()).first;
|
||||
session->lifetime().add([=] {
|
||||
_subscriptions.remove(session);
|
||||
});
|
||||
} else if (i->second) {
|
||||
return;
|
||||
}
|
||||
i->second = session->downloaderTaskFinished().add_subscription([=] {
|
||||
auto found = false;
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (const auto history = notification->maybeHistory()) {
|
||||
if (&history->session() == session) {
|
||||
notification->updatePeerPhoto();
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
_subscriptions[session].destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Manager::moveWidgets() {
|
||||
auto shift = st::notifyDeltaY;
|
||||
int lastShift = 0, lastShiftCurrent = 0, count = 0;
|
||||
@@ -334,7 +355,7 @@ void Manager::doClearFromHistory(not_null<History*> history) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (notification->unlinkHistory(history)) {
|
||||
_positionsOutdated = true;
|
||||
}
|
||||
@@ -342,6 +363,22 @@ void Manager::doClearFromHistory(not_null<History*> history) {
|
||||
showNextFromQueue();
|
||||
}
|
||||
|
||||
void Manager::doClearFromSession(not_null<Main::Session*> session) {
|
||||
for (auto i = _queuedNotifications.begin(); i != _queuedNotifications.cend();) {
|
||||
if (&i->history->session() == session) {
|
||||
i = _queuedNotifications.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (notification->unlinkSession(session)) {
|
||||
_positionsOutdated = true;
|
||||
}
|
||||
}
|
||||
showNextFromQueue();
|
||||
}
|
||||
|
||||
void Manager::doClearFromItem(not_null<HistoryItem*> item) {
|
||||
_queuedNotifications.erase(std::remove_if(_queuedNotifications.begin(), _queuedNotifications.end(), [&](auto &queued) {
|
||||
return (queued.item == item);
|
||||
@@ -678,7 +715,7 @@ void Notification::actionsOpacityCallback() {
|
||||
void Notification::updateNotifyDisplay() {
|
||||
if (!_history || (!_item && _forwardedCount < 2)) return;
|
||||
|
||||
const auto options = Manager::getNotificationOptions(_item);
|
||||
const auto options = Manager::GetNotificationOptions(_item);
|
||||
_hideReplyButton = options.hideReplyButton;
|
||||
|
||||
int32 w = width(), h = height();
|
||||
@@ -832,7 +869,7 @@ bool Notification::unlinkItem(HistoryItem *deleted) {
|
||||
bool Notification::canReply() const {
|
||||
return !_hideReplyButton
|
||||
&& (_item != nullptr)
|
||||
&& !Core::App().locked()
|
||||
&& !Core::App().passcodeLocked()
|
||||
&& (Core::App().settings().notifyView() <= dbinvShowPreview);
|
||||
}
|
||||
|
||||
@@ -901,16 +938,23 @@ void Notification::showReplyField() {
|
||||
void Notification::sendReply() {
|
||||
if (!_history) return;
|
||||
|
||||
auto peerId = _history->peer->id;
|
||||
auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
||||
manager()->notificationReplied(
|
||||
peerId,
|
||||
msgId,
|
||||
myId(),
|
||||
_replyArea->getTextWithAppliedMarkdown());
|
||||
|
||||
manager()->startAllHiding();
|
||||
}
|
||||
|
||||
Notifications::Manager::NotificationId Notification::myId() const {
|
||||
if (!_history) {
|
||||
return {};
|
||||
}
|
||||
const auto selfId = _history->session().userId();
|
||||
const auto peerId = _history->peer->id;
|
||||
const auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
||||
return { .peerId = peerId, .msgId = msgId, .selfId = selfId };
|
||||
}
|
||||
|
||||
void Notification::changeHeight(int newHeight) {
|
||||
manager()->changeNotificationHeight(this, newHeight);
|
||||
}
|
||||
@@ -925,6 +969,16 @@ bool Notification::unlinkHistory(History *history) {
|
||||
return unlink;
|
||||
}
|
||||
|
||||
bool Notification::unlinkSession(not_null<Main::Session*> session) {
|
||||
const auto unlink = _history && (&_history->session() == session);
|
||||
if (unlink) {
|
||||
hideFast();
|
||||
_history = nullptr;
|
||||
_item = nullptr;
|
||||
}
|
||||
return unlink;
|
||||
}
|
||||
|
||||
void Notification::enterEventHook(QEvent *e) {
|
||||
if (!_history) return;
|
||||
manager()->stopAllHiding();
|
||||
@@ -951,9 +1005,7 @@ void Notification::mousePressEvent(QMouseEvent *e) {
|
||||
unlinkHistoryInManager();
|
||||
} else {
|
||||
e->ignore();
|
||||
auto peerId = _history->peer->id;
|
||||
auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
||||
manager()->notificationActivated(peerId, msgId);
|
||||
manager()->notificationActivated(myId());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user