mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-17 20:54:11 +00:00
Use Main::Session::uniqueId in notifications.
This commit is contained in:
parent
e38d39656d
commit
d8a2b391a3
@ -165,6 +165,14 @@ base::Observable<void> &Session::downloaderTaskFinished() {
|
|||||||
return downloader().taskFinished();
|
return downloader().taskFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64 Session::uniqueId() const {
|
||||||
|
auto result = uint64(uint32(userId()));
|
||||||
|
if (mtp().isTestMode()) {
|
||||||
|
result |= 0x0100'0000'0000'0000ULL;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
UserId Session::userId() const {
|
UserId Session::userId() const {
|
||||||
return _user->bareId();
|
return _user->bareId();
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
[[nodiscard]] Domain &domain() const;
|
[[nodiscard]] Domain &domain() const;
|
||||||
[[nodiscard]] Storage::Domain &domainLocal() const;
|
[[nodiscard]] Storage::Domain &domainLocal() const;
|
||||||
|
|
||||||
|
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
||||||
[[nodiscard]] UserId userId() const;
|
[[nodiscard]] UserId userId() const;
|
||||||
[[nodiscard]] PeerId userPeerId() const;
|
[[nodiscard]] PeerId userPeerId() const;
|
||||||
[[nodiscard]] not_null<UserData*> user() const {
|
[[nodiscard]] not_null<UserData*> user() const {
|
||||||
|
@ -209,18 +209,14 @@ NotificationData::NotificationData(
|
|||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &subtitle,
|
const QString &subtitle,
|
||||||
const QString &msg,
|
const QString &msg,
|
||||||
PeerId peerId,
|
NotificationId id,
|
||||||
MsgId msgId,
|
|
||||||
UserId selfId,
|
|
||||||
bool hideReplyButton)
|
bool hideReplyButton)
|
||||||
: _dbusConnection(QDBusConnection::sessionBus())
|
: _dbusConnection(QDBusConnection::sessionBus())
|
||||||
, _manager(manager)
|
, _manager(manager)
|
||||||
, _title(title)
|
, _title(title)
|
||||||
, _imageKey(GetImageKey(ParseSpecificationVersion(
|
, _imageKey(GetImageKey(ParseSpecificationVersion(
|
||||||
GetServerInformation())))
|
GetServerInformation())))
|
||||||
, _peerId(peerId)
|
, _id(id) {
|
||||||
, _msgId(msgId)
|
|
||||||
, _selfId(selfId) {
|
|
||||||
const auto capabilities = GetCapabilities();
|
const auto capabilities = GetCapabilities();
|
||||||
|
|
||||||
if (capabilities.contains(qsl("body-markup"))) {
|
if (capabilities.contains(qsl("body-markup"))) {
|
||||||
@ -377,14 +373,10 @@ void NotificationData::setImage(const QString &imagePath) {
|
|||||||
_hints[_imageKey] = QVariant::fromValue(imageData);
|
_hints[_imageKey] = QVariant::fromValue(imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationData::NotificationId NotificationData::myId() const {
|
|
||||||
return { .peerId = _peerId, .msgId = _msgId, .selfId = _selfId };
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationData::notificationClosed(uint id) {
|
void NotificationData::notificationClosed(uint id) {
|
||||||
if (id == _notificationId) {
|
if (id == _notificationId) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->clearNotification(my);
|
manager->clearNotification(my);
|
||||||
});
|
});
|
||||||
@ -399,13 +391,13 @@ void NotificationData::actionInvoked(uint id, const QString &actionName) {
|
|||||||
if (actionName == qsl("default")
|
if (actionName == qsl("default")
|
||||||
|| actionName == qsl("mail-reply-sender")) {
|
|| actionName == qsl("mail-reply-sender")) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->notificationActivated(my);
|
manager->notificationActivated(my);
|
||||||
});
|
});
|
||||||
} else if (actionName == qsl("mail-mark-read")) {
|
} else if (actionName == qsl("mail-mark-read")) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->notificationReplied(my, {});
|
manager->notificationReplied(my, {});
|
||||||
});
|
});
|
||||||
@ -415,7 +407,7 @@ void NotificationData::actionInvoked(uint id, const QString &actionName) {
|
|||||||
void NotificationData::notificationReplied(uint id, const QString &text) {
|
void NotificationData::notificationReplied(uint id, const QString &text) {
|
||||||
if (id == _notificationId) {
|
if (id == _notificationId) {
|
||||||
const auto manager = _manager;
|
const auto manager = _manager;
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
crl::on_main(manager, [=] {
|
crl::on_main(manager, [=] {
|
||||||
manager->notificationReplied(my, { text, {} });
|
manager->notificationReplied(my, { text, {} });
|
||||||
});
|
});
|
||||||
@ -541,17 +533,16 @@ void Manager::Private::showNotification(
|
|||||||
bool hideReplyButton) {
|
bool hideReplyButton) {
|
||||||
if (!Supported()) return;
|
if (!Supported()) return;
|
||||||
|
|
||||||
const auto peerId = peer->id;
|
const auto key = FullPeer{
|
||||||
const auto selfId = peer->session().userId();
|
.sessionId = peer->session().uniqueId(),
|
||||||
const auto key = FullPeer{ peerId, selfId };
|
.peerId = peer->id
|
||||||
|
};
|
||||||
auto notification = std::make_shared<NotificationData>(
|
auto notification = std::make_shared<NotificationData>(
|
||||||
_manager,
|
_manager,
|
||||||
title,
|
title,
|
||||||
subtitle,
|
subtitle,
|
||||||
msg,
|
msg,
|
||||||
peer->id,
|
NotificationId{ .full = key, .msgId = msgId },
|
||||||
msgId,
|
|
||||||
peer->session().userId(),
|
|
||||||
hideReplyButton);
|
hideReplyButton);
|
||||||
|
|
||||||
if (!hideNameAndPhoto) {
|
if (!hideNameAndPhoto) {
|
||||||
@ -601,8 +592,8 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
|
|||||||
if (!Supported()) return;
|
if (!Supported()) return;
|
||||||
|
|
||||||
const auto key = FullPeer{
|
const auto key = FullPeer{
|
||||||
history->peer->id,
|
.sessionId = history->session().uniqueId(),
|
||||||
history->session().userId()
|
.peerId = history->peer->id
|
||||||
};
|
};
|
||||||
auto i = _notifications.find(key);
|
auto i = _notifications.find(key);
|
||||||
if (i != _notifications.cend()) {
|
if (i != _notifications.cend()) {
|
||||||
@ -618,9 +609,9 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
|
|||||||
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
||||||
if (!Supported()) return;
|
if (!Supported()) return;
|
||||||
|
|
||||||
const auto selfId = session->userId();
|
const auto sessionId = session->uniqueId();
|
||||||
for (auto i = _notifications.begin(); i != _notifications.end();) {
|
for (auto i = _notifications.begin(); i != _notifications.end();) {
|
||||||
if (i->first.second == selfId) {
|
if (i->first.sessionId == sessionId) {
|
||||||
const auto temp = base::take(i->second);
|
const auto temp = base::take(i->second);
|
||||||
i = _notifications.erase(i);
|
i = _notifications.erase(i);
|
||||||
|
|
||||||
@ -634,7 +625,7 @@ void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
|||||||
void Manager::Private::clearNotification(NotificationId id) {
|
void Manager::Private::clearNotification(NotificationId id) {
|
||||||
if (!Supported()) return;
|
if (!Supported()) return;
|
||||||
|
|
||||||
auto i = _notifications.find(FullPeer{ id.peerId, id.selfId });
|
auto i = _notifications.find(id.full);
|
||||||
if (i != _notifications.cend()) {
|
if (i != _notifications.cend()) {
|
||||||
if (i->second.remove(id.msgId) && i->second.empty()) {
|
if (i->second.remove(id.msgId) && i->second.empty()) {
|
||||||
_notifications.erase(i);
|
_notifications.erase(i);
|
||||||
|
@ -31,9 +31,7 @@ public:
|
|||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &subtitle,
|
const QString &subtitle,
|
||||||
const QString &msg,
|
const QString &msg,
|
||||||
PeerId peerId,
|
NotificationId id,
|
||||||
MsgId msgId,
|
|
||||||
UserId selfId,
|
|
||||||
bool hideReplyButton);
|
bool hideReplyButton);
|
||||||
|
|
||||||
NotificationData(const NotificationData &other) = delete;
|
NotificationData(const NotificationData &other) = delete;
|
||||||
@ -53,8 +51,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] NotificationId myId() const;
|
|
||||||
|
|
||||||
QDBusConnection _dbusConnection;
|
QDBusConnection _dbusConnection;
|
||||||
base::weak_ptr<Manager> _manager;
|
base::weak_ptr<Manager> _manager;
|
||||||
|
|
||||||
@ -65,14 +61,13 @@ private:
|
|||||||
QString _imageKey;
|
QString _imageKey;
|
||||||
|
|
||||||
uint _notificationId = 0;
|
uint _notificationId = 0;
|
||||||
PeerId _peerId = 0;
|
NotificationId _id;
|
||||||
MsgId _msgId = 0;
|
|
||||||
UserId _selfId = 0;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void notificationClosed(uint id);
|
void notificationClosed(uint id);
|
||||||
void actionInvoked(uint id, const QString &actionName);
|
void actionInvoked(uint id, const QString &actionName);
|
||||||
void notificationReplied(uint id, const QString &text);
|
void notificationReplied(uint id, const QString &text);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using Notification = std::shared_ptr<NotificationData>;
|
using Notification = std::shared_ptr<NotificationData>;
|
||||||
|
@ -92,10 +92,10 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSNumber *selfObject = [notificationUserInfo objectForKey:@"self"];
|
NSNumber *sessionObject = [notificationUserInfo objectForKey:@"session"];
|
||||||
const auto notificationSelfId = selfObject ? [selfObject intValue] : 0;
|
const auto notificationSessionId = sessionObject ? [sessionObject unsignedLongLongValue] : 0;
|
||||||
if (!notificationSelfId) {
|
if (!notificationSessionId) {
|
||||||
LOG(("App Error: A notification with unknown self was received"));
|
LOG(("App Error: A notification with unknown session was received"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"];
|
NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"];
|
||||||
@ -109,9 +109,11 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
|||||||
const auto notificationMsgId = msgObject ? [msgObject intValue] : 0;
|
const auto notificationMsgId = msgObject ? [msgObject intValue] : 0;
|
||||||
|
|
||||||
const auto my = Window::Notifications::Manager::NotificationId{
|
const auto my = Window::Notifications::Manager::NotificationId{
|
||||||
.peerId = notificationPeerId,
|
.full = FullPeer{
|
||||||
.msgId = notificationMsgId,
|
.sessionId = notificationSessionId,
|
||||||
.selfId = notificationSelfId
|
.peerId = notificationPeerId
|
||||||
|
},
|
||||||
|
.msgId = notificationMsgId
|
||||||
};
|
};
|
||||||
if (notification.activationType == NSUserNotificationActivationTypeReplied) {
|
if (notification.activationType == NSUserNotificationActivationTypeReplied) {
|
||||||
const auto notificationReply = QString::fromUtf8([[[notification response] string] UTF8String]);
|
const auto notificationReply = QString::fromUtf8([[[notification response] string] UTF8String]);
|
||||||
@ -207,7 +209,7 @@ private:
|
|||||||
FullPeer fullPeer;
|
FullPeer fullPeer;
|
||||||
};
|
};
|
||||||
struct ClearFromSession {
|
struct ClearFromSession {
|
||||||
UserId selfId = 0;
|
uint64 sessionId = 0;
|
||||||
};
|
};
|
||||||
struct ClearAll {
|
struct ClearAll {
|
||||||
};
|
};
|
||||||
@ -249,7 +251,7 @@ void Manager::Private::showNotification(
|
|||||||
auto identifierValue = Q2NSString(identifier);
|
auto identifierValue = Q2NSString(identifier);
|
||||||
[notification setIdentifier:identifierValue];
|
[notification setIdentifier:identifierValue];
|
||||||
}
|
}
|
||||||
[notification setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedLongLong:peer->session().userId()],@"self",[NSNumber numberWithUnsignedLongLong:peer->id],@"peer",[NSNumber numberWithInt:msgId],@"msgid",[NSNumber numberWithUnsignedLongLong:_managerId],@"manager",nil]];
|
[notification setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedLongLong:peer->session().uniqueId()],@"session",[NSNumber numberWithUnsignedLongLong:peer->id],@"peer",[NSNumber numberWithInt:msgId],@"msgid",[NSNumber numberWithUnsignedLongLong:_managerId],@"manager",nil]];
|
||||||
|
|
||||||
[notification setTitle:Q2NSString(title)];
|
[notification setTitle:Q2NSString(title)];
|
||||||
[notification setSubtitle:Q2NSString(subtitle)];
|
[notification setSubtitle:Q2NSString(subtitle)];
|
||||||
@ -279,7 +281,7 @@ void Manager::Private::clearingThreadLoop() {
|
|||||||
while (!finished) {
|
while (!finished) {
|
||||||
auto clearAll = false;
|
auto clearAll = false;
|
||||||
auto clearFromPeers = base::flat_set<FullPeer>();
|
auto clearFromPeers = base::flat_set<FullPeer>();
|
||||||
auto clearFromSessions = base::flat_set<UserId>();
|
auto clearFromSessions = base::flat_set<uint64>();
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(_clearingMutex);
|
std::unique_lock<std::mutex> lock(_clearingMutex);
|
||||||
|
|
||||||
@ -295,23 +297,26 @@ void Manager::Private::clearingThreadLoop() {
|
|||||||
} else if (auto fromHistory = base::get_if<ClearFromHistory>(&task)) {
|
} else if (auto fromHistory = base::get_if<ClearFromHistory>(&task)) {
|
||||||
clearFromPeers.emplace(fromHistory->fullPeer);
|
clearFromPeers.emplace(fromHistory->fullPeer);
|
||||||
} else if (auto fromSession = base::get_if<ClearFromSession>(&task)) {
|
} else if (auto fromSession = base::get_if<ClearFromSession>(&task)) {
|
||||||
clearFromSessions.emplace(fromSession->selfId);
|
clearFromSessions.emplace(fromSession->sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_clearingTasks.clear();
|
_clearingTasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clearBySpecial = [&](NSDictionary *notificationUserInfo) {
|
auto clearBySpecial = [&](NSDictionary *notificationUserInfo) {
|
||||||
NSNumber *selfObject = [notificationUserInfo objectForKey:@"self"];
|
NSNumber *sessionObject = [notificationUserInfo objectForKey:@"session"];
|
||||||
const auto notificationSelfId = selfObject ? [selfObject intValue] : 0;
|
const auto notificationSessionId = sessionObject ? [sessionObject unsignedLongLongValue] : 0;
|
||||||
if (!notificationSelfId) {
|
if (!notificationSessionId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"]) {
|
if (NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"]) {
|
||||||
const auto notificationPeerId = [peerObject unsignedLongLongValue];
|
const auto notificationPeerId = [peerObject unsignedLongLongValue];
|
||||||
if (notificationPeerId) {
|
if (notificationPeerId) {
|
||||||
return clearFromSessions.contains(notificationSelfId)
|
return clearFromSessions.contains(notificationSessionId)
|
||||||
|| clearFromPeers.contains(FullPeer{ notificationPeerId, notificationSelfId });
|
|| clearFromPeers.contains(FullPeer{
|
||||||
|
.sessionId = notificationSessionId,
|
||||||
|
.peerId = notificationPeerId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -348,11 +353,14 @@ void Manager::Private::clearAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Private::clearFromHistory(not_null<History*> history) {
|
void Manager::Private::clearFromHistory(not_null<History*> history) {
|
||||||
putClearTask(ClearFromHistory { FullPeer{ history->peer->id, history->session().userId() } });
|
putClearTask(ClearFromHistory { FullPeer{
|
||||||
|
.sessionId = history->session().uniqueId(),
|
||||||
|
.peerId = history->peer->id
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
||||||
putClearTask(ClearFromSession { session->userId() });
|
putClearTask(ClearFromSession { session->uniqueId() });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Private::updateDelegate() {
|
void Manager::Private::updateDelegate() {
|
||||||
|
@ -214,12 +214,8 @@ public:
|
|||||||
// We keep a weak pointer to a member field of native notifications manager.
|
// We keep a weak pointer to a member field of native notifications manager.
|
||||||
ToastEventHandler(
|
ToastEventHandler(
|
||||||
const std::shared_ptr<Manager*> &guarded,
|
const std::shared_ptr<Manager*> &guarded,
|
||||||
PeerId peer,
|
NotificationId id)
|
||||||
MsgId msg,
|
: _id(id)
|
||||||
UserId selfId)
|
|
||||||
: _peerId(peer)
|
|
||||||
, _msgId(msg)
|
|
||||||
, _selfId(selfId)
|
|
||||||
, _weak(guarded) {
|
, _weak(guarded) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +228,7 @@ public:
|
|||||||
|
|
||||||
// DesktopToastActivatedEventHandler
|
// DesktopToastActivatedEventHandler
|
||||||
IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IInspectable* args) {
|
IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IInspectable* args) {
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
performOnMainQueue([my](Manager *manager) {
|
performOnMainQueue([my](Manager *manager) {
|
||||||
manager->notificationActivated(my);
|
manager->notificationActivated(my);
|
||||||
});
|
});
|
||||||
@ -249,7 +245,7 @@ public:
|
|||||||
case ToastDismissalReason_UserCanceled:
|
case ToastDismissalReason_UserCanceled:
|
||||||
case ToastDismissalReason_TimedOut:
|
case ToastDismissalReason_TimedOut:
|
||||||
default:
|
default:
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
performOnMainQueue([my](Manager *manager) {
|
performOnMainQueue([my](Manager *manager) {
|
||||||
manager->clearNotification(my);
|
manager->clearNotification(my);
|
||||||
});
|
});
|
||||||
@ -261,7 +257,7 @@ public:
|
|||||||
|
|
||||||
// DesktopToastFailedEventHandler
|
// DesktopToastFailedEventHandler
|
||||||
IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastFailedEventArgs *e) {
|
IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastFailedEventArgs *e) {
|
||||||
const auto my = myId();
|
const auto my = _id;
|
||||||
performOnMainQueue([my](Manager *manager) {
|
performOnMainQueue([my](Manager *manager) {
|
||||||
manager->clearNotification(my);
|
manager->clearNotification(my);
|
||||||
});
|
});
|
||||||
@ -301,14 +297,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] NotificationId myId() const {
|
|
||||||
return { .peerId = _peerId, .msgId = _msgId, .selfId = _selfId };
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG _refCount = 0;
|
ULONG _refCount = 0;
|
||||||
PeerId _peerId = 0;
|
NotificationId _id;
|
||||||
MsgId _msgId = 0;
|
|
||||||
UserId _selfId = 0;
|
|
||||||
std::weak_ptr<Manager*> _weak;
|
std::weak_ptr<Manager*> _weak;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -439,8 +429,8 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
|
|||||||
if (!_notifier) return;
|
if (!_notifier) return;
|
||||||
|
|
||||||
auto i = _notifications.find(FullPeer{
|
auto i = _notifications.find(FullPeer{
|
||||||
history->peer->id,
|
.sessionId = history->session().uniqueId(),
|
||||||
history->session().userId()
|
.peerId = history->peer->id
|
||||||
});
|
});
|
||||||
if (i != _notifications.cend()) {
|
if (i != _notifications.cend()) {
|
||||||
auto temp = base::take(i->second);
|
auto temp = base::take(i->second);
|
||||||
@ -455,9 +445,9 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
|
|||||||
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
||||||
if (!_notifier) return;
|
if (!_notifier) return;
|
||||||
|
|
||||||
const auto selfId = session->userId();
|
const auto sessionId = session->uniqueId();
|
||||||
for (auto i = _notifications.begin(); i != _notifications.end();) {
|
for (auto i = _notifications.begin(); i != _notifications.end();) {
|
||||||
if (i->first.selfId == selfId) {
|
if (i->first.sessionId == sessionId) {
|
||||||
const auto temp = base::take(i->second);
|
const auto temp = base::take(i->second);
|
||||||
_notifications.erase(i);
|
_notifications.erase(i);
|
||||||
|
|
||||||
@ -479,7 +469,7 @@ void Manager::Private::afterNotificationActivated(NotificationId id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Private::clearNotification(NotificationId id) {
|
void Manager::Private::clearNotification(NotificationId id) {
|
||||||
auto i = _notifications.find(FullPeer{ id.peerId, id.selfId });
|
auto i = _notifications.find(id.full);
|
||||||
if (i != _notifications.cend()) {
|
if (i != _notifications.cend()) {
|
||||||
i->second.remove(id.msgId);
|
i->second.remove(id.msgId);
|
||||||
if (i->second.empty()) {
|
if (i->second.empty()) {
|
||||||
@ -565,12 +555,19 @@ bool Manager::Private::showNotification(
|
|||||||
hr = _notificationFactory->CreateToastNotification(toastXml.Get(), &toast);
|
hr = _notificationFactory->CreateToastNotification(toastXml.Get(), &toast);
|
||||||
if (!SUCCEEDED(hr)) return false;
|
if (!SUCCEEDED(hr)) return false;
|
||||||
|
|
||||||
|
const auto key = FullPeer{
|
||||||
|
.sessionId = peer->session().uniqueId(),
|
||||||
|
.peerId = peer->id,
|
||||||
|
};
|
||||||
|
const auto notificationId = NotificationId{
|
||||||
|
.full = key,
|
||||||
|
.msgId = msgId
|
||||||
|
};
|
||||||
|
|
||||||
EventRegistrationToken activatedToken, dismissedToken, failedToken;
|
EventRegistrationToken activatedToken, dismissedToken, failedToken;
|
||||||
ComPtr<ToastEventHandler> eventHandler(new ToastEventHandler(
|
ComPtr<ToastEventHandler> eventHandler(new ToastEventHandler(
|
||||||
_guarded,
|
_guarded,
|
||||||
peer->id,
|
notificationId));
|
||||||
msgId,
|
|
||||||
peer->session().userId()));
|
|
||||||
|
|
||||||
hr = toast->add_Activated(eventHandler.Get(), &activatedToken);
|
hr = toast->add_Activated(eventHandler.Get(), &activatedToken);
|
||||||
if (!SUCCEEDED(hr)) return false;
|
if (!SUCCEEDED(hr)) return false;
|
||||||
@ -581,10 +578,6 @@ bool Manager::Private::showNotification(
|
|||||||
hr = toast->add_Failed(eventHandler.Get(), &failedToken);
|
hr = toast->add_Failed(eventHandler.Get(), &failedToken);
|
||||||
if (!SUCCEEDED(hr)) return false;
|
if (!SUCCEEDED(hr)) return false;
|
||||||
|
|
||||||
const auto key = FullPeer{
|
|
||||||
peer->id,
|
|
||||||
peer->session().userId()
|
|
||||||
};
|
|
||||||
auto i = _notifications.find(key);
|
auto i = _notifications.find(key);
|
||||||
if (i != _notifications.cend()) {
|
if (i != _notifications.cend()) {
|
||||||
auto j = i->second.find(msgId);
|
auto j = i->second.find(msgId);
|
||||||
|
@ -74,10 +74,10 @@ void System::createManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::Session *System::findSession(UserId selfId) const {
|
Main::Session *System::findSession(uint64 sessionId) const {
|
||||||
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
||||||
if (const auto session = account->maybeSession()) {
|
if (const auto session = account->maybeSession()) {
|
||||||
if (session->userId() == selfId) {
|
if (session->uniqueId() == sessionId) {
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,12 +293,13 @@ void System::checkDelayed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void System::showGrouped() {
|
void System::showGrouped() {
|
||||||
if (const auto session = findSession(_lastHistorySelfId)) {
|
if (const auto session = findSession(_lastHistorySessionId)) {
|
||||||
if (const auto lastItem = session->data().message(_lastHistoryItemId)) {
|
if (const auto lastItem = session->data().message(_lastHistoryItemId)) {
|
||||||
_waitForAllGroupedTimer.cancel();
|
_waitForAllGroupedTimer.cancel();
|
||||||
_manager->showNotification(lastItem, _lastForwardedCount);
|
_manager->showNotification(lastItem, _lastForwardedCount);
|
||||||
_lastForwardedCount = 0;
|
_lastForwardedCount = 0;
|
||||||
_lastHistoryItemId = FullMsgId();
|
_lastHistoryItemId = FullMsgId();
|
||||||
|
_lastHistorySessionId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,13 +308,17 @@ void System::showNext() {
|
|||||||
if (App::quitting()) return;
|
if (App::quitting()) return;
|
||||||
|
|
||||||
const auto isSameGroup = [=](HistoryItem *item) {
|
const auto isSameGroup = [=](HistoryItem *item) {
|
||||||
if (!_lastHistoryItemId || !item) {
|
if (!_lastHistorySessionId || !_lastHistoryItemId || !item) {
|
||||||
|
return false;
|
||||||
|
} else if (item->history()->session().uniqueId()
|
||||||
|
!= _lastHistorySessionId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto lastItem = item->history()->owner().message(
|
const auto lastItem = item->history()->owner().message(
|
||||||
_lastHistoryItemId);
|
_lastHistoryItemId);
|
||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
return (lastItem->groupId() == item->groupId() || lastItem->author() == item->author());
|
return (lastItem->groupId() == item->groupId())
|
||||||
|
|| (lastItem->author() == item->author());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -476,6 +481,7 @@ void System::showNext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_lastHistoryItemId && groupedItem) {
|
if (!_lastHistoryItemId && groupedItem) {
|
||||||
|
_lastHistorySessionId = groupedItem->history()->session().uniqueId();
|
||||||
_lastHistoryItemId = groupedItem->fullId();
|
_lastHistoryItemId = groupedItem->fullId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,6 +499,7 @@ void System::showNext() {
|
|||||||
}
|
}
|
||||||
// We have to wait until all the messages in this group are loaded.
|
// We have to wait until all the messages in this group are loaded.
|
||||||
_lastForwardedCount += forwardedCount;
|
_lastForwardedCount += forwardedCount;
|
||||||
|
_lastHistorySessionId = groupedItem->history()->session().uniqueId();
|
||||||
_lastHistoryItemId = groupedItem->fullId();
|
_lastHistoryItemId = groupedItem->fullId();
|
||||||
_waitForAllGroupedTimer.callOnce(kWaitingForAllGroupedDelay);
|
_waitForAllGroupedTimer.callOnce(kWaitingForAllGroupedDelay);
|
||||||
} else {
|
} else {
|
||||||
@ -567,13 +574,13 @@ QString Manager::accountNameSeparator() {
|
|||||||
|
|
||||||
void Manager::notificationActivated(NotificationId id) {
|
void Manager::notificationActivated(NotificationId id) {
|
||||||
onBeforeNotificationActivated(id);
|
onBeforeNotificationActivated(id);
|
||||||
if (const auto session = system()->findSession(id.selfId)) {
|
if (const auto session = system()->findSession(id.full.sessionId)) {
|
||||||
if (session->windows().empty()) {
|
if (session->windows().empty()) {
|
||||||
Core::App().domain().activate(&session->account());
|
Core::App().domain().activate(&session->account());
|
||||||
}
|
}
|
||||||
if (!session->windows().empty()) {
|
if (!session->windows().empty()) {
|
||||||
const auto window = session->windows().front();
|
const auto window = session->windows().front();
|
||||||
const auto history = session->data().history(id.peerId);
|
const auto history = session->data().history(id.full.peerId);
|
||||||
window->widget()->showFromTray();
|
window->widget()->showFromTray();
|
||||||
window->widget()->reActivateWindow();
|
window->widget()->reActivateWindow();
|
||||||
if (Core::App().passcodeLocked()) {
|
if (Core::App().passcodeLocked()) {
|
||||||
@ -622,15 +629,15 @@ void Manager::openNotificationMessage(
|
|||||||
void Manager::notificationReplied(
|
void Manager::notificationReplied(
|
||||||
NotificationId id,
|
NotificationId id,
|
||||||
const TextWithTags &reply) {
|
const TextWithTags &reply) {
|
||||||
if (!id.selfId || !id.peerId) {
|
if (!id.full.sessionId || !id.full.peerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto session = system()->findSession(id.selfId);
|
const auto session = system()->findSession(id.full.sessionId);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto history = session->data().history(id.peerId);
|
const auto history = session->data().history(id.full.peerId);
|
||||||
|
|
||||||
auto message = Api::MessageToSend(history);
|
auto message = Api::MessageToSend(history);
|
||||||
message.textWithTags = reply;
|
message.textWithTags = reply;
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
System();
|
System();
|
||||||
~System();
|
~System();
|
||||||
|
|
||||||
[[nodiscard]] Main::Session *findSession(UserId selfId) const;
|
[[nodiscard]] Main::Session *findSession(uint64 sessionId) const;
|
||||||
|
|
||||||
void createManager();
|
void createManager();
|
||||||
|
|
||||||
@ -126,27 +126,26 @@ private:
|
|||||||
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
||||||
|
|
||||||
int _lastForwardedCount = 0;
|
int _lastForwardedCount = 0;
|
||||||
UserId _lastHistorySelfId = 0;
|
uint64 _lastHistorySessionId = 0;
|
||||||
FullMsgId _lastHistoryItemId;
|
FullMsgId _lastHistoryItemId;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
public:
|
public:
|
||||||
struct NotificationId {
|
|
||||||
PeerId peerId = 0;
|
|
||||||
MsgId msgId = 0;
|
|
||||||
UserId selfId = 0;
|
|
||||||
};
|
|
||||||
struct FullPeer {
|
struct FullPeer {
|
||||||
|
uint64 sessionId = 0;
|
||||||
PeerId peerId = 0;
|
PeerId peerId = 0;
|
||||||
UserId selfId = 0;
|
|
||||||
|
|
||||||
friend inline bool operator<(const FullPeer &a, const FullPeer &b) {
|
friend inline bool operator<(const FullPeer &a, const FullPeer &b) {
|
||||||
return std::tie(a.peerId, a.selfId)
|
return std::tie(a.sessionId, a.peerId)
|
||||||
< std::tie(b.peerId, b.selfId);
|
< std::tie(b.sessionId, b.peerId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
struct NotificationId {
|
||||||
|
FullPeer full;
|
||||||
|
MsgId msgId = 0;
|
||||||
|
};
|
||||||
|
|
||||||
explicit Manager(not_null<System*> system) : _system(system) {
|
explicit Manager(not_null<System*> system) : _system(system) {
|
||||||
}
|
}
|
||||||
|
@ -950,10 +950,10 @@ Notifications::Manager::NotificationId Notification::myId() const {
|
|||||||
if (!_history) {
|
if (!_history) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto selfId = _history->session().userId();
|
return { .full = {
|
||||||
const auto peerId = _history->peer->id;
|
.sessionId = _history->session().uniqueId(),
|
||||||
const auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
.peerId = _history->peer->id
|
||||||
return { .peerId = peerId, .msgId = msgId, .selfId = selfId };
|
}, .msgId = _item ? _item->id : ShowAtUnreadMsgId };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::changeHeight(int newHeight) {
|
void Notification::changeHeight(int newHeight) {
|
||||||
|
Loading…
Reference in New Issue
Block a user