2016-10-02 13:54:27 +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 13:54:27 +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 13:54:27 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class AuthSession;
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
namespace Notifications {
|
|
|
|
class Manager;
|
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Platform
|
|
|
|
|
2017-05-03 13:01:15 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Audio {
|
|
|
|
class Track;
|
|
|
|
} // namespace Audio
|
|
|
|
} // namespace Media
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
|
|
|
|
|
|
|
enum class ChangeType {
|
|
|
|
SoundEnabled,
|
|
|
|
IncludeMuted,
|
|
|
|
DesktopEnabled,
|
|
|
|
ViewParams,
|
|
|
|
MaxCount,
|
|
|
|
Corner,
|
|
|
|
DemoIsShown,
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct custom_is_fast_copy_type<Window::Notifications::ChangeType> : public std::true_type {
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace base
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
|
|
|
|
|
|
|
class Manager;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class System final : private base::Subscriber {
|
|
|
|
public:
|
|
|
|
System(AuthSession *session);
|
|
|
|
|
|
|
|
void createManager();
|
|
|
|
|
|
|
|
void checkDelayed();
|
|
|
|
void schedule(History *history, HistoryItem *item);
|
|
|
|
void clearFromHistory(History *history);
|
|
|
|
void clearFromItem(HistoryItem *item);
|
|
|
|
void clearAll();
|
|
|
|
void clearAllFast();
|
|
|
|
void updateAll();
|
|
|
|
|
|
|
|
base::Observable<ChangeType> &settingsChanged() {
|
|
|
|
return _settingsChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuthSession *authSession() {
|
|
|
|
return _authSession;
|
|
|
|
}
|
|
|
|
|
2017-05-03 13:01:15 +00:00
|
|
|
~System();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
private:
|
|
|
|
void showNext();
|
2017-05-03 13:01:15 +00:00
|
|
|
void ensureSoundCreated();
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
AuthSession *_authSession = nullptr;
|
|
|
|
|
|
|
|
QMap<History*, QMap<MsgId, TimeMs>> _whenMaps;
|
|
|
|
|
|
|
|
struct Waiter {
|
2018-04-09 17:48:29 +00:00
|
|
|
Waiter(MsgId msg, TimeMs when, PeerData *notifyBy)
|
|
|
|
: msg(msg)
|
|
|
|
, when(when)
|
|
|
|
, notifyBy(notifyBy) {
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
MsgId msg;
|
|
|
|
TimeMs when;
|
2018-04-09 17:48:29 +00:00
|
|
|
PeerData *notifyBy;
|
2017-03-04 19:36:59 +00:00
|
|
|
};
|
|
|
|
using Waiters = QMap<History*, Waiter>;
|
|
|
|
Waiters _waiters;
|
|
|
|
Waiters _settingWaiters;
|
|
|
|
SingleTimer _waitTimer;
|
|
|
|
|
|
|
|
QMap<History*, QMap<TimeMs, PeerData*>> _whenAlerts;
|
|
|
|
|
|
|
|
std::unique_ptr<Manager> _manager;
|
|
|
|
|
|
|
|
base::Observable<ChangeType> _settingsChanged;
|
|
|
|
|
2017-05-03 13:01:15 +00:00
|
|
|
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
};
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
class Manager {
|
|
|
|
public:
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager(System *system) : _system(system) {
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void showNotification(HistoryItem *item, int forwardedCount) {
|
|
|
|
doShowNotification(item, forwardedCount);
|
|
|
|
}
|
|
|
|
void updateAll() {
|
|
|
|
doUpdateAll();
|
|
|
|
}
|
|
|
|
void clearAll() {
|
|
|
|
doClearAll();
|
|
|
|
}
|
|
|
|
void clearAllFast() {
|
|
|
|
doClearAllFast();
|
|
|
|
}
|
|
|
|
void clearFromItem(HistoryItem *item) {
|
|
|
|
doClearFromItem(item);
|
|
|
|
}
|
|
|
|
void clearFromHistory(History *history) {
|
|
|
|
doClearFromHistory(history);
|
|
|
|
}
|
2016-10-02 17:06:34 +00:00
|
|
|
|
2016-10-02 16:32:46 +00:00
|
|
|
void notificationActivated(PeerId peerId, MsgId msgId);
|
2018-05-24 13:03:21 +00:00
|
|
|
void notificationReplied(
|
|
|
|
PeerId peerId,
|
|
|
|
MsgId msgId,
|
|
|
|
const TextWithTags &reply);
|
2016-10-02 16:32:46 +00:00
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
struct DisplayOptions {
|
|
|
|
bool hideNameAndPhoto;
|
|
|
|
bool hideMessageText;
|
|
|
|
bool hideReplyButton;
|
|
|
|
};
|
|
|
|
static DisplayOptions getNotificationOptions(HistoryItem *item);
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
virtual ~Manager() = default;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
protected:
|
2017-03-04 19:36:59 +00:00
|
|
|
System *system() const {
|
|
|
|
return _system;
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
virtual void doUpdateAll() = 0;
|
|
|
|
virtual void doShowNotification(HistoryItem *item, int forwardedCount) = 0;
|
|
|
|
virtual void doClearAll() = 0;
|
|
|
|
virtual void doClearAllFast() = 0;
|
|
|
|
virtual void doClearFromItem(HistoryItem *item) = 0;
|
|
|
|
virtual void doClearFromHistory(History *history) = 0;
|
2016-10-02 16:32:46 +00:00
|
|
|
virtual void onBeforeNotificationActivated(PeerId peerId, MsgId msgId) {
|
|
|
|
}
|
|
|
|
virtual void onAfterNotificationActivated(PeerId peerId, MsgId msgId) {
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
private:
|
2018-02-12 11:10:40 +00:00
|
|
|
void openNotificationMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId messageId);
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
System *_system = nullptr;
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NativeManager : public Manager {
|
|
|
|
protected:
|
2017-03-04 19:36:59 +00:00
|
|
|
using Manager::Manager;
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void doUpdateAll() override {
|
|
|
|
doClearAllFast();
|
|
|
|
}
|
|
|
|
void doClearAll() override {
|
|
|
|
doClearAllFast();
|
|
|
|
}
|
|
|
|
void doClearFromItem(HistoryItem *item) override {
|
|
|
|
}
|
|
|
|
void doShowNotification(HistoryItem *item, int forwardedCount) override;
|
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
virtual void doShowNativeNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) = 0;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|