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
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
#include "base/timer.h"
|
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
class History;
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
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,
|
2018-12-04 10:32:06 +00:00
|
|
|
CountMessages,
|
2017-03-04 19:36:59 +00:00
|
|
|
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:
|
2019-07-24 11:45:24 +00:00
|
|
|
explicit System(not_null<Main::Session*> session);
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
void createManager();
|
|
|
|
|
|
|
|
void checkDelayed();
|
2019-08-28 14:24:12 +00:00
|
|
|
void schedule(not_null<HistoryItem*> item);
|
2019-08-30 14:06:21 +00:00
|
|
|
void clearFromHistory(not_null<History*> history);
|
|
|
|
void clearIncomingFromHistory(not_null<History*> history);
|
|
|
|
void clearFromItem(not_null<HistoryItem*> item);
|
2017-03-04 19:36:59 +00:00
|
|
|
void clearAll();
|
|
|
|
void clearAllFast();
|
|
|
|
void updateAll();
|
|
|
|
|
|
|
|
base::Observable<ChangeType> &settingsChanged() {
|
|
|
|
return _settingsChanged;
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &session() const {
|
2019-06-05 20:41:51 +00:00
|
|
|
return *_session;
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 13:01:15 +00:00
|
|
|
~System();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
private:
|
2019-08-28 14:24:12 +00:00
|
|
|
struct SkipState {
|
|
|
|
enum Value {
|
|
|
|
Unknown,
|
|
|
|
Skip,
|
|
|
|
DontSkip
|
|
|
|
};
|
|
|
|
Value value = Value::Unknown;
|
|
|
|
bool silent = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkipState skipNotification(not_null<HistoryItem*> item) const;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void showNext();
|
2019-03-10 07:42:25 +00:00
|
|
|
void showGrouped();
|
2017-05-03 13:01:15 +00:00
|
|
|
void ensureSoundCreated();
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
not_null<Main::Session*> _session;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
QMap<History*, QMap<MsgId, crl::time>> _whenMaps;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
struct Waiter {
|
2019-02-19 06:57:53 +00:00
|
|
|
Waiter(MsgId msg, crl::time when, PeerData *notifyBy)
|
2018-04-09 17:48:29 +00:00
|
|
|
: msg(msg)
|
|
|
|
, when(when)
|
|
|
|
, notifyBy(notifyBy) {
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
MsgId msg;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time 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;
|
2019-01-18 11:26:43 +00:00
|
|
|
base::Timer _waitTimer;
|
2019-03-10 07:42:25 +00:00
|
|
|
base::Timer _waitForAllGroupedTimer;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
QMap<History*, QMap<crl::time, PeerData*>> _whenAlerts;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Manager> _manager;
|
|
|
|
|
|
|
|
base::Observable<ChangeType> _settingsChanged;
|
|
|
|
|
2017-05-03 13:01:15 +00:00
|
|
|
std::unique_ptr<Media::Audio::Track> _soundTrack;
|
|
|
|
|
2019-03-10 07:42:25 +00:00
|
|
|
int _lastForwardedCount = 0;
|
|
|
|
FullMsgId _lastHistoryItemId;
|
2019-06-05 20:41:51 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
};
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
class Manager {
|
|
|
|
public:
|
2019-07-24 11:13:51 +00:00
|
|
|
explicit Manager(not_null<System*> system) : _system(system) {
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void showNotification(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int forwardedCount) {
|
2016-10-02 13:54:27 +00:00
|
|
|
doShowNotification(item, forwardedCount);
|
|
|
|
}
|
|
|
|
void updateAll() {
|
|
|
|
doUpdateAll();
|
|
|
|
}
|
|
|
|
void clearAll() {
|
|
|
|
doClearAll();
|
|
|
|
}
|
|
|
|
void clearAllFast() {
|
|
|
|
doClearAllFast();
|
|
|
|
}
|
2019-08-30 14:06:21 +00:00
|
|
|
void clearFromItem(not_null<HistoryItem*> item) {
|
2016-10-02 13:54:27 +00:00
|
|
|
doClearFromItem(item);
|
|
|
|
}
|
2019-08-30 14:06:21 +00:00
|
|
|
void clearFromHistory(not_null<History*> history) {
|
2016-10-02 13:54:27 +00:00
|
|
|
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:
|
2019-07-24 11:13:51 +00:00
|
|
|
not_null<System*> system() const {
|
2017-03-04 19:36:59 +00:00
|
|
|
return _system;
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
virtual void doUpdateAll() = 0;
|
2019-08-28 14:24:12 +00:00
|
|
|
virtual void doShowNotification(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int forwardedCount) = 0;
|
2016-10-02 13:54:27 +00:00
|
|
|
virtual void doClearAll() = 0;
|
|
|
|
virtual void doClearAllFast() = 0;
|
2019-08-30 14:06:21 +00:00
|
|
|
virtual void doClearFromItem(not_null<HistoryItem*> item) = 0;
|
|
|
|
virtual void doClearFromHistory(not_null<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);
|
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
const not_null<System*> _system;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
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();
|
|
|
|
}
|
2019-08-30 14:06:21 +00:00
|
|
|
void doClearFromItem(not_null<HistoryItem*> item) override {
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
2019-08-28 14:24:12 +00:00
|
|
|
void doShowNotification(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int forwardedCount) override;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
virtual void doShowNativeNotification(
|
|
|
|
not_null<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
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
QString WrapFromScheduled(const QString &text);
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|