2016-10-02 09:30:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-02 09:30:28 +00:00
|
|
|
*/
|
|
|
|
#include "platform/mac/notifications_manager_mac.h"
|
|
|
|
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2019-09-26 10:20:34 +00:00
|
|
|
#include "base/platform/mac/base_utilities_mac.h"
|
2021-01-23 22:34:40 +00:00
|
|
|
#include "base/openssl_help.h"
|
2018-01-25 14:19:14 +00:00
|
|
|
#include "history/history.h"
|
2019-08-28 18:20:49 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2020-06-19 17:13:43 +00:00
|
|
|
#include "main/main_session.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "mainwindow.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2018-01-25 14:19:14 +00:00
|
|
|
#include "styles/style_window.h"
|
2016-10-02 15:44:54 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
#include <thread>
|
2016-10-02 15:44:54 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-03-08 07:31:29 +00:00
|
|
|
static constexpr auto kQuerySettingsEachMs = 1000;
|
|
|
|
auto DoNotDisturbEnabled = false;
|
|
|
|
auto LastSettingsQueryMs = 0;
|
|
|
|
|
|
|
|
void queryDoNotDisturbState() {
|
2019-02-19 06:57:53 +00:00
|
|
|
auto ms = crl::now();
|
2017-03-08 07:31:29 +00:00
|
|
|
if (LastSettingsQueryMs > 0 && ms <= LastSettingsQueryMs + kQuerySettingsEachMs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LastSettingsQueryMs = ms;
|
|
|
|
|
2020-07-12 09:01:44 +00:00
|
|
|
Boolean isKeyValid;
|
|
|
|
const auto doNotDisturb = CFPreferencesGetAppBooleanValue(
|
|
|
|
CFSTR("doNotDisturb"),
|
|
|
|
CFSTR("com.apple.notificationcenterui"),
|
|
|
|
&isKeyValid);
|
|
|
|
DoNotDisturbEnabled = isKeyValid
|
|
|
|
? doNotDisturb
|
|
|
|
: false;
|
2017-03-08 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using Manager = Platform::Notifications::Manager;
|
2016-10-02 15:44:54 +00:00
|
|
|
|
|
|
|
} // namespace
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-02 17:06:34 +00:00
|
|
|
@interface NotificationDelegate : NSObject<NSUserNotificationCenterDelegate> {
|
|
|
|
}
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
- (id) initWithManager:(base::weak_ptr<Manager>)manager managerId:(uint64)managerId;
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) userNotificationCenter:(NSUserNotificationCenter*)center didActivateNotification:(NSUserNotification*)notification;
|
|
|
|
- (BOOL) userNotificationCenter:(NSUserNotificationCenter*)center shouldPresentNotification:(NSUserNotification*)notification;
|
2016-10-02 17:06:34 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
@end // @interface NotificationDelegate
|
2016-10-02 17:06:34 +00:00
|
|
|
|
|
|
|
@implementation NotificationDelegate {
|
2017-11-30 17:33:27 +00:00
|
|
|
base::weak_ptr<Manager> _manager;
|
2017-04-12 12:50:35 +00:00
|
|
|
uint64 _managerId;
|
2017-03-08 07:31:05 +00:00
|
|
|
|
2016-10-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
- (id) initWithManager:(base::weak_ptr<Manager>)manager managerId:(uint64)managerId {
|
2016-10-02 17:06:34 +00:00
|
|
|
if (self = [super init]) {
|
2017-03-08 07:31:05 +00:00
|
|
|
_manager = manager;
|
2017-04-12 12:50:35 +00:00
|
|
|
_managerId = managerId;
|
2016-10-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
|
|
|
|
NSDictionary *notificationUserInfo = [notification userInfo];
|
2017-04-12 12:50:35 +00:00
|
|
|
NSNumber *managerIdObject = [notificationUserInfo objectForKey:@"manager"];
|
|
|
|
auto notificationManagerId = managerIdObject ? [managerIdObject unsignedLongLongValue] : 0ULL;
|
|
|
|
DEBUG_LOG(("Received notification with instance %1, mine: %2").arg(notificationManagerId).arg(_managerId));
|
|
|
|
if (notificationManagerId != _managerId) { // other app instance notification
|
2017-12-30 21:28:38 +00:00
|
|
|
crl::on_main([] {
|
2017-04-12 11:58:37 +00:00
|
|
|
// Usually we show and activate main window when the application
|
|
|
|
// is activated (receives applicationDidBecomeActive: notification).
|
|
|
|
//
|
|
|
|
// This is used for window show in Cmd+Tab switching to the application.
|
|
|
|
//
|
|
|
|
// But when a notification arrives sometimes macOS still activates the app
|
|
|
|
// and we receive applicationDidBecomeActive: notification even if the
|
|
|
|
// notification was sent by another instance of the application. In that case
|
|
|
|
// we set a flag for a couple of seconds to ignore this app activation.
|
|
|
|
objc_ignoreApplicationActivationRightNow();
|
|
|
|
});
|
2016-10-02 17:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-24 09:05:56 +00:00
|
|
|
NSNumber *sessionObject = [notificationUserInfo objectForKey:@"session"];
|
|
|
|
const auto notificationSessionId = sessionObject ? [sessionObject unsignedLongLongValue] : 0;
|
|
|
|
if (!notificationSessionId) {
|
|
|
|
LOG(("App Error: A notification with unknown session was received"));
|
2020-06-19 17:13:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-02 17:06:34 +00:00
|
|
|
NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"];
|
2020-06-19 17:13:43 +00:00
|
|
|
const auto notificationPeerId = peerObject ? [peerObject unsignedLongLongValue] : 0ULL;
|
2016-10-02 17:06:34 +00:00
|
|
|
if (!notificationPeerId) {
|
2017-04-12 11:58:37 +00:00
|
|
|
LOG(("App Error: A notification with unknown peer was received"));
|
2016-10-02 17:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSNumber *msgObject = [notificationUserInfo objectForKey:@"msgid"];
|
2020-06-19 17:13:43 +00:00
|
|
|
const auto notificationMsgId = msgObject ? [msgObject intValue] : 0;
|
|
|
|
|
|
|
|
const auto my = Window::Notifications::Manager::NotificationId{
|
2020-06-25 15:13:02 +00:00
|
|
|
.full = Manager::FullPeer{
|
2020-06-24 09:05:56 +00:00
|
|
|
.sessionId = notificationSessionId,
|
2021-04-09 15:17:47 +00:00
|
|
|
.peerId = PeerId(notificationPeerId)
|
2020-06-24 09:05:56 +00:00
|
|
|
},
|
|
|
|
.msgId = notificationMsgId
|
2020-06-19 17:13:43 +00:00
|
|
|
};
|
2016-10-02 17:06:34 +00:00
|
|
|
if (notification.activationType == NSUserNotificationActivationTypeReplied) {
|
2017-12-30 21:28:38 +00:00
|
|
|
const auto notificationReply = QString::fromUtf8([[[notification response] string] UTF8String]);
|
|
|
|
const auto manager = _manager;
|
|
|
|
crl::on_main(manager, [=] {
|
2020-06-19 17:13:43 +00:00
|
|
|
manager->notificationReplied(my, { notificationReply, {} });
|
2017-04-12 11:58:37 +00:00
|
|
|
});
|
2016-10-02 17:06:34 +00:00
|
|
|
} else if (notification.activationType == NSUserNotificationActivationTypeContentsClicked) {
|
2017-12-30 21:28:38 +00:00
|
|
|
const auto manager = _manager;
|
|
|
|
crl::on_main(manager, [=] {
|
2020-06-19 17:13:43 +00:00
|
|
|
manager->notificationActivated(my);
|
2017-04-12 11:58:37 +00:00
|
|
|
});
|
2016-10-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[center removeDeliveredNotification: notification];
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
2016-10-02 17:06:34 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
@end // @implementation NotificationDelegate
|
2016-10-02 17:06:34 +00:00
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
namespace Notifications {
|
|
|
|
|
2021-04-28 07:20:39 +00:00
|
|
|
bool SkipAudioForCustom() {
|
|
|
|
return false;
|
2017-03-08 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 07:20:39 +00:00
|
|
|
bool SkipToastForCustom() {
|
|
|
|
return false;
|
2017-03-08 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 07:20:39 +00:00
|
|
|
bool SkipFlashBounceForCustom() {
|
|
|
|
return false;
|
2020-05-12 10:04:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
bool Supported() {
|
2019-06-03 14:41:23 +00:00
|
|
|
return Platform::IsMac10_8OrGreater();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 09:56:49 +00:00
|
|
|
bool Enforced() {
|
|
|
|
return Supported();
|
|
|
|
}
|
|
|
|
|
2021-01-24 23:16:32 +00:00
|
|
|
bool ByDefault() {
|
|
|
|
return Supported();
|
|
|
|
}
|
|
|
|
|
2021-01-21 10:18:40 +00:00
|
|
|
void Create(Window::Notifications::System *system) {
|
2017-03-04 19:36:59 +00:00
|
|
|
if (Supported()) {
|
2021-01-21 10:18:40 +00:00
|
|
|
system->setManager(std::make_unique<Manager>(system));
|
|
|
|
} else {
|
|
|
|
system->setManager(nullptr);
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
2017-03-02 14:00:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class Manager::Private : public QObject, private base::Subscriber {
|
2016-10-02 13:54:27 +00:00
|
|
|
public:
|
2017-03-08 07:31:05 +00:00
|
|
|
Private(Manager *manager);
|
2017-04-12 11:58:37 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void showNotification(
|
|
|
|
not_null<PeerData*> peer,
|
2020-05-29 16:55:01 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> &userpicView,
|
2019-08-28 14:24:12 +00:00
|
|
|
MsgId msgId,
|
|
|
|
const QString &title,
|
|
|
|
const QString &subtitle,
|
|
|
|
const QString &msg,
|
|
|
|
bool hideNameAndPhoto,
|
|
|
|
bool hideReplyButton);
|
2016-10-02 13:54:27 +00:00
|
|
|
void clearAll();
|
2019-08-30 14:06:21 +00:00
|
|
|
void clearFromHistory(not_null<History*> history);
|
2020-06-19 12:59:31 +00:00
|
|
|
void clearFromSession(not_null<Main::Session*> session);
|
2016-10-02 17:06:34 +00:00
|
|
|
void updateDelegate();
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
~Private();
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-12 12:50:35 +00:00
|
|
|
template <typename Task>
|
|
|
|
void putClearTask(Task task);
|
|
|
|
|
|
|
|
void clearingThreadLoop();
|
|
|
|
|
|
|
|
const uint64 _managerId = 0;
|
|
|
|
QString _managerIdString;
|
|
|
|
|
2017-03-08 07:31:05 +00:00
|
|
|
NotificationDelegate *_delegate = nullptr;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2017-04-12 12:50:35 +00:00
|
|
|
std::thread _clearingThread;
|
|
|
|
std::mutex _clearingMutex;
|
|
|
|
std::condition_variable _clearingCondition;
|
|
|
|
|
|
|
|
struct ClearFromHistory {
|
2020-06-19 17:13:43 +00:00
|
|
|
FullPeer fullPeer;
|
|
|
|
};
|
|
|
|
struct ClearFromSession {
|
2020-06-24 09:05:56 +00:00
|
|
|
uint64 sessionId = 0;
|
2017-04-12 12:50:35 +00:00
|
|
|
};
|
|
|
|
struct ClearAll {
|
|
|
|
};
|
|
|
|
struct ClearFinish {
|
|
|
|
};
|
2020-08-31 08:14:53 +00:00
|
|
|
using ClearTask = std::variant<
|
|
|
|
ClearFromHistory,
|
|
|
|
ClearFromSession,
|
|
|
|
ClearAll,
|
|
|
|
ClearFinish>;
|
2017-04-12 12:50:35 +00:00
|
|
|
std::vector<ClearTask> _clearingTasks;
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
};
|
|
|
|
|
2017-03-08 07:31:05 +00:00
|
|
|
Manager::Private::Private(Manager *manager)
|
2021-01-23 22:34:40 +00:00
|
|
|
: _managerId(openssl::RandomValue<uint64>())
|
2017-04-12 12:50:35 +00:00
|
|
|
, _managerIdString(QString::number(_managerId))
|
2017-04-15 17:33:46 +00:00
|
|
|
, _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId]) {
|
2017-03-04 19:36:59 +00:00
|
|
|
updateDelegate();
|
|
|
|
subscribe(Global::RefWorkMode(), [this](DBIWorkMode mode) {
|
|
|
|
// We need to update the delegate _after_ the tray icon change was done in Qt.
|
|
|
|
// Because Qt resets the delegate.
|
2017-12-30 21:28:38 +00:00
|
|
|
crl::on_main(this, [=] {
|
2017-03-04 19:36:59 +00:00
|
|
|
updateDelegate();
|
2017-12-30 21:28:38 +00:00
|
|
|
});
|
2017-03-04 19:36:59 +00:00
|
|
|
});
|
2016-10-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void Manager::Private::showNotification(
|
|
|
|
not_null<PeerData*> peer,
|
2020-05-29 16:55:01 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> &userpicView,
|
2019-08-28 14:24:12 +00:00
|
|
|
MsgId msgId,
|
|
|
|
const QString &title,
|
|
|
|
const QString &subtitle,
|
|
|
|
const QString &msg,
|
|
|
|
bool hideNameAndPhoto,
|
|
|
|
bool hideReplyButton) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
NSUserNotification *notification = [[[NSUserNotification alloc] init] autorelease];
|
|
|
|
if ([notification respondsToSelector:@selector(setIdentifier:)]) {
|
2021-04-09 15:17:47 +00:00
|
|
|
auto identifier = _managerIdString + '_' + QString::number(peer->id.value) + '_' + QString::number(msgId);
|
2016-10-02 15:44:54 +00:00
|
|
|
auto identifierValue = Q2NSString(identifier);
|
|
|
|
[notification setIdentifier:identifierValue];
|
|
|
|
}
|
2021-04-09 15:17:47 +00:00
|
|
|
[notification setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedLongLong:peer->session().uniqueId()],@"session",[NSNumber numberWithUnsignedLongLong:peer->id.value],@"peer",[NSNumber numberWithInt:msgId],@"msgid",[NSNumber numberWithUnsignedLongLong:_managerId],@"manager",nil]];
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
[notification setTitle:Q2NSString(title)];
|
|
|
|
[notification setSubtitle:Q2NSString(subtitle)];
|
|
|
|
[notification setInformativeText:Q2NSString(msg)];
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!hideNameAndPhoto && [notification respondsToSelector:@selector(setContentImage:)]) {
|
2019-08-28 18:20:49 +00:00
|
|
|
auto userpic = peer->isSelf()
|
|
|
|
? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize)
|
2020-09-11 15:33:26 +00:00
|
|
|
: peer->isRepliesChat()
|
|
|
|
? Ui::EmptyUserpic::GenerateRepliesMessages(st::notifyMacPhotoSize)
|
2020-05-29 16:55:01 +00:00
|
|
|
: peer->genUserpic(userpicView, st::notifyMacPhotoSize);
|
2020-10-27 10:32:09 +00:00
|
|
|
NSImage *img = Q2NSImage(userpic.toImage());
|
2016-10-02 13:54:27 +00:00
|
|
|
[notification setContentImage:img];
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!hideReplyButton && [notification respondsToSelector:@selector(setHasReplyButton:)]) {
|
2016-10-02 13:54:27 +00:00
|
|
|
[notification setHasReplyButton:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
[notification setSoundName:nil];
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
2016-10-02 13:54:27 +00:00
|
|
|
[center deliverNotification:notification];
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 12:50:35 +00:00
|
|
|
void Manager::Private::clearingThreadLoop() {
|
|
|
|
auto finished = false;
|
|
|
|
while (!finished) {
|
|
|
|
auto clearAll = false;
|
2020-06-19 17:13:43 +00:00
|
|
|
auto clearFromPeers = base::flat_set<FullPeer>();
|
2020-06-24 09:05:56 +00:00
|
|
|
auto clearFromSessions = base::flat_set<uint64>();
|
2017-04-12 12:50:35 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_clearingMutex);
|
|
|
|
while (_clearingTasks.empty()) {
|
|
|
|
_clearingCondition.wait(lock);
|
|
|
|
}
|
|
|
|
for (auto &task : _clearingTasks) {
|
2020-08-31 08:14:53 +00:00
|
|
|
v::match(task, [&](ClearFinish) {
|
2017-04-12 12:50:35 +00:00
|
|
|
finished = true;
|
|
|
|
clearAll = true;
|
2020-08-31 08:14:53 +00:00
|
|
|
}, [&](ClearAll) {
|
2017-04-12 12:50:35 +00:00
|
|
|
clearAll = true;
|
2020-08-31 08:14:53 +00:00
|
|
|
}, [&](const ClearFromHistory &value) {
|
|
|
|
clearFromPeers.emplace(value.fullPeer);
|
|
|
|
}, [&](const ClearFromSession &value) {
|
|
|
|
clearFromSessions.emplace(value.sessionId);
|
|
|
|
});
|
2017-04-12 12:50:35 +00:00
|
|
|
}
|
|
|
|
_clearingTasks.clear();
|
|
|
|
}
|
|
|
|
|
2020-07-01 15:35:25 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
2020-06-19 17:13:43 +00:00
|
|
|
auto clearBySpecial = [&](NSDictionary *notificationUserInfo) {
|
2020-06-24 09:05:56 +00:00
|
|
|
NSNumber *sessionObject = [notificationUserInfo objectForKey:@"session"];
|
|
|
|
const auto notificationSessionId = sessionObject ? [sessionObject unsignedLongLongValue] : 0;
|
|
|
|
if (!notificationSessionId) {
|
2020-06-19 17:13:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-12 12:50:35 +00:00
|
|
|
if (NSNumber *peerObject = [notificationUserInfo objectForKey:@"peer"]) {
|
2020-06-19 17:13:43 +00:00
|
|
|
const auto notificationPeerId = [peerObject unsignedLongLongValue];
|
2017-04-12 12:50:35 +00:00
|
|
|
if (notificationPeerId) {
|
2020-06-24 09:05:56 +00:00
|
|
|
return clearFromSessions.contains(notificationSessionId)
|
|
|
|
|| clearFromPeers.contains(FullPeer{
|
|
|
|
.sessionId = notificationSessionId,
|
2021-04-09 15:17:47 +00:00
|
|
|
.peerId = PeerId(notificationPeerId)
|
2020-06-24 09:05:56 +00:00
|
|
|
});
|
2017-04-12 12:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
|
|
NSArray *notificationsList = [center deliveredNotifications];
|
|
|
|
for (id notification in notificationsList) {
|
|
|
|
NSDictionary *notificationUserInfo = [notification userInfo];
|
|
|
|
NSNumber *managerIdObject = [notificationUserInfo objectForKey:@"manager"];
|
|
|
|
auto notificationManagerId = managerIdObject ? [managerIdObject unsignedLongLongValue] : 0ULL;
|
|
|
|
if (notificationManagerId == _managerId) {
|
2020-06-19 17:13:43 +00:00
|
|
|
if (clearAll || clearBySpecial(notificationUserInfo)) {
|
2017-04-12 12:50:35 +00:00
|
|
|
[center removeDeliveredNotification:notification];
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
2020-07-01 15:35:25 +00:00
|
|
|
|
|
|
|
}
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 12:50:35 +00:00
|
|
|
template <typename Task>
|
|
|
|
void Manager::Private::putClearTask(Task task) {
|
2017-04-15 17:33:46 +00:00
|
|
|
if (!_clearingThread.joinable()) {
|
|
|
|
_clearingThread = std::thread([this] { clearingThreadLoop(); });
|
|
|
|
}
|
|
|
|
|
2017-04-12 12:50:35 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_clearingMutex);
|
|
|
|
_clearingTasks.push_back(task);
|
|
|
|
_clearingCondition.notify_one();
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2017-04-12 12:50:35 +00:00
|
|
|
void Manager::Private::clearAll() {
|
|
|
|
putClearTask(ClearAll());
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:06:21 +00:00
|
|
|
void Manager::Private::clearFromHistory(not_null<History*> history) {
|
2020-06-24 09:05:56 +00:00
|
|
|
putClearTask(ClearFromHistory { FullPeer{
|
|
|
|
.sessionId = history->session().uniqueId(),
|
|
|
|
.peerId = history->peer->id
|
|
|
|
} });
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
|
2020-06-24 09:05:56 +00:00
|
|
|
putClearTask(ClearFromSession { session->uniqueId() });
|
2020-06-19 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void Manager::Private::updateDelegate() {
|
2016-10-02 17:06:34 +00:00
|
|
|
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
|
|
[center setDelegate:_delegate];
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager::Private::~Private() {
|
2017-04-15 17:33:46 +00:00
|
|
|
if (_clearingThread.joinable()) {
|
|
|
|
putClearTask(ClearFinish());
|
|
|
|
_clearingThread.join();
|
|
|
|
}
|
2018-10-10 05:29:31 +00:00
|
|
|
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
|
|
|
[center setDelegate:nil];
|
2016-10-02 17:06:34 +00:00
|
|
|
[_delegate release];
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager::Manager(Window::Notifications::System *system) : NativeManager(system)
|
2017-03-08 07:31:05 +00:00
|
|
|
, _private(std::make_unique<Private>(this)) {
|
2016-10-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
Manager::~Manager() = default;
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void Manager::doShowNativeNotification(
|
|
|
|
not_null<PeerData*> peer,
|
2020-05-29 16:55:01 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> &userpicView,
|
2019-08-28 14:24:12 +00:00
|
|
|
MsgId msgId,
|
|
|
|
const QString &title,
|
|
|
|
const QString &subtitle,
|
|
|
|
const QString &msg,
|
|
|
|
bool hideNameAndPhoto,
|
|
|
|
bool hideReplyButton) {
|
|
|
|
_private->showNotification(
|
|
|
|
peer,
|
2020-05-29 16:55:01 +00:00
|
|
|
userpicView,
|
2019-08-28 14:24:12 +00:00
|
|
|
msgId,
|
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
msg,
|
|
|
|
hideNameAndPhoto,
|
|
|
|
hideReplyButton);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doClearAllFast() {
|
2017-03-04 19:36:59 +00:00
|
|
|
_private->clearAll();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 14:06:21 +00:00
|
|
|
void Manager::doClearFromHistory(not_null<History*> history) {
|
2017-03-04 19:36:59 +00:00
|
|
|
_private->clearFromHistory(history);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
void Manager::doClearFromSession(not_null<Main::Session*> session) {
|
|
|
|
_private->clearFromSession(session);
|
|
|
|
}
|
|
|
|
|
2020-06-19 13:34:43 +00:00
|
|
|
QString Manager::accountNameSeparator() {
|
|
|
|
return QString::fromUtf8(" \xE2\x86\x92 ");
|
|
|
|
}
|
|
|
|
|
2021-04-28 07:20:39 +00:00
|
|
|
bool Manager::doSkipAudio() const {
|
|
|
|
queryDoNotDisturbState();
|
|
|
|
return DoNotDisturbEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Manager::doSkipToast() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Manager::doSkipFlashBounce() const {
|
|
|
|
return doSkipAudio();
|
|
|
|
}
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Platform
|