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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2019-04-01 17:44:54 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-01-18 11:26:43 +00:00
|
|
|
#include "base/timer.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "base/binary_guard.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
|
|
|
|
#include <QtCore/QTimer>
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
namespace Data {
|
|
|
|
class CloudImageView;
|
|
|
|
} // namespace Data
|
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
namespace Ui {
|
|
|
|
class IconButton;
|
2016-11-11 13:46:04 +00:00
|
|
|
class RoundButton;
|
2018-05-20 17:42:30 +00:00
|
|
|
class InputField;
|
2016-10-04 18:18:08 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
2016-10-02 13:54:27 +00:00
|
|
|
namespace Default {
|
2016-10-05 16:56:27 +00:00
|
|
|
namespace internal {
|
2016-10-06 16:41:09 +00:00
|
|
|
class Widget;
|
2016-10-05 16:56:27 +00:00
|
|
|
class Notification;
|
|
|
|
class HideAllButton;
|
|
|
|
} // namespace internal
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
class Manager;
|
2017-03-04 19:36:59 +00:00
|
|
|
std::unique_ptr<Manager> Create(System *system);
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2021-05-25 13:51:59 +00:00
|
|
|
class Manager final : public Notifications::Manager {
|
2016-10-02 09:30:28 +00:00
|
|
|
public:
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager(System *system);
|
2020-06-19 12:59:31 +00:00
|
|
|
~Manager();
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2021-01-21 10:18:40 +00:00
|
|
|
[[nodiscard]] ManagerType type() const override {
|
|
|
|
return ManagerType::Default;
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
template <typename Method>
|
2016-10-05 16:56:27 +00:00
|
|
|
void enumerateNotifications(Method method) {
|
2020-06-19 12:59:31 +00:00
|
|
|
for (const auto ¬ification : _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
method(notification);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
private:
|
2016-10-07 13:14:02 +00:00
|
|
|
friend class internal::Notification;
|
|
|
|
friend class internal::HideAllButton;
|
|
|
|
friend class internal::Widget;
|
2016-10-05 16:56:27 +00:00
|
|
|
using Notification = internal::Notification;
|
|
|
|
using HideAllButton = internal::HideAllButton;
|
2020-07-01 08:03:34 +00:00
|
|
|
struct SessionSubscription {
|
|
|
|
rpl::lifetime subscription;
|
|
|
|
rpl::lifetime lifetime;
|
|
|
|
};
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
[[nodiscard]] QPixmap hiddenUserpicPlaceholder() const;
|
2017-05-12 15:27:19 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void doUpdateAll() override;
|
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
|
|
|
void doClearAll() override;
|
|
|
|
void doClearAllFast() override;
|
2019-08-30 14:06:21 +00:00
|
|
|
void doClearFromHistory(not_null<History*> history) override;
|
2020-06-19 12:59:31 +00:00
|
|
|
void doClearFromSession(not_null<Main::Session*> session) override;
|
2019-08-30 14:06:21 +00:00
|
|
|
void doClearFromItem(not_null<HistoryItem*> item) override;
|
2021-04-28 10:08:02 +00:00
|
|
|
bool doSkipAudio() const override;
|
|
|
|
bool doSkipToast() const override;
|
|
|
|
bool doSkipFlashBounce() const override;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void showNextFromQueue();
|
|
|
|
void unlinkFromShown(Notification *remove);
|
|
|
|
void startAllHiding();
|
|
|
|
void stopAllHiding();
|
|
|
|
void checkLastInput();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void removeWidget(internal::Widget *remove);
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
float64 demoMasterOpacity() const;
|
|
|
|
void demoMasterOpacityCallback();
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void moveWidgets();
|
|
|
|
void changeNotificationHeight(Notification *widget, int newHeight);
|
2017-03-04 19:36:59 +00:00
|
|
|
void settingsChanged(ChangeType change);
|
2016-10-06 16:41:09 +00:00
|
|
|
|
|
|
|
bool hasReplyingNotification() const;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
void subscribeToSession(not_null<Main::Session*> session);
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
std::vector<std::unique_ptr<Notification>> _notifications;
|
2020-06-19 12:59:31 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<Main::Session*>,
|
2020-07-01 08:03:34 +00:00
|
|
|
SessionSubscription> _subscriptions;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
std::unique_ptr<HideAllButton> _hideAll;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
bool _positionsOutdated = false;
|
2019-01-18 11:26:43 +00:00
|
|
|
base::Timer _inputCheckTimer;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
struct QueuedNotification {
|
2018-01-11 19:33:26 +00:00
|
|
|
QueuedNotification(not_null<HistoryItem*> item, int forwardedCount);
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<History*> history;
|
|
|
|
not_null<PeerData*> peer;
|
2019-08-28 14:24:12 +00:00
|
|
|
QString author;
|
|
|
|
HistoryItem *item = nullptr;
|
|
|
|
int forwardedCount = 0;
|
|
|
|
bool fromScheduled = false;
|
2016-10-02 13:54:27 +00:00
|
|
|
};
|
2017-03-04 19:36:59 +00:00
|
|
|
std::deque<QueuedNotification> _queuedNotifications;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _demoMasterOpacity;
|
2021-05-25 22:22:55 +00:00
|
|
|
bool _demoIsShown = false;
|
2016-10-06 16:41:09 +00:00
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
mutable QPixmap _hiddenUserpicPlaceholder;
|
|
|
|
|
2021-06-24 06:08:57 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
};
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class Widget : public Ui::RpWidget {
|
2016-10-05 16:56:27 +00:00
|
|
|
public:
|
2016-10-06 16:41:09 +00:00
|
|
|
enum class Direction {
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
};
|
2019-08-28 14:24:12 +00:00
|
|
|
Widget(
|
|
|
|
not_null<Manager*> manager,
|
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
bool isShowing() const {
|
2016-10-06 16:41:09 +00:00
|
|
|
return _a_opacity.animating() && !_hiding;
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void updateOpacity();
|
|
|
|
void changeShift(int top);
|
|
|
|
int currentShift() const {
|
2019-04-01 17:44:54 +00:00
|
|
|
return _shift.current();
|
2016-10-06 16:41:09 +00:00
|
|
|
}
|
|
|
|
void updatePosition(QPoint startPosition, Direction shiftDirection);
|
|
|
|
void addToHeight(int add);
|
|
|
|
void addToShift(int add);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void hideSlow();
|
|
|
|
void hideFast();
|
|
|
|
void hideStop();
|
2016-10-06 16:41:09 +00:00
|
|
|
QPoint computePosition(int height) const;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
virtual void updateGeometry(int x, int y, int width, int height);
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
protected:
|
2020-06-19 13:34:43 +00:00
|
|
|
[[nodiscard]] not_null<Manager*> manager() const {
|
2017-03-04 19:36:59 +00:00
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void opacityAnimationCallback();
|
2016-10-07 13:24:19 +00:00
|
|
|
void destroyDelayed();
|
2016-10-06 16:41:09 +00:00
|
|
|
void moveByShift();
|
2016-11-20 12:54:07 +00:00
|
|
|
void hideAnimated(float64 duration, const anim::transition &func);
|
2019-04-01 17:44:54 +00:00
|
|
|
bool shiftAnimationCallback(crl::time now);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
const not_null<Manager*> _manager;
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _hiding = false;
|
2016-10-07 13:24:19 +00:00
|
|
|
bool _deleted = false;
|
2018-09-21 18:14:48 +00:00
|
|
|
base::binary_guard _hidingDelayed;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _a_opacity;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
QPoint _startPosition;
|
|
|
|
Direction _direction;
|
2019-04-01 17:44:54 +00:00
|
|
|
anim::value _shift;
|
|
|
|
Ui::Animations::Basic _shiftAnimation;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Background : public TWidget {
|
|
|
|
public:
|
|
|
|
Background(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
class Notification final : public Widget {
|
2016-10-02 09:30:28 +00:00
|
|
|
public:
|
2019-08-02 10:40:35 +00:00
|
|
|
Notification(
|
2019-08-28 14:24:12 +00:00
|
|
|
not_null<Manager*> manager,
|
|
|
|
not_null<History*> history,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &author,
|
2019-08-02 10:40:35 +00:00
|
|
|
HistoryItem *item,
|
|
|
|
int forwardedCount,
|
2019-08-28 14:24:12 +00:00
|
|
|
bool fromScheduled,
|
2019-08-02 10:40:35 +00:00
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
void startHiding();
|
|
|
|
void stopHiding();
|
|
|
|
|
|
|
|
void updateNotifyDisplay();
|
|
|
|
void updatePeerPhoto();
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool isUnlinked() const {
|
2016-10-04 18:18:08 +00:00
|
|
|
return !_history;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
bool isReplying() const {
|
2016-12-13 17:07:56 +00:00
|
|
|
return _replyArea && !isUnlinked();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2020-06-19 12:59:31 +00:00
|
|
|
[[nodiscard]] History *maybeHistory() const {
|
|
|
|
return _history;
|
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
// Called only by Manager.
|
2017-03-08 20:51:40 +00:00
|
|
|
bool unlinkItem(HistoryItem *del);
|
2016-10-05 16:56:27 +00:00
|
|
|
bool unlinkHistory(History *history = nullptr);
|
2020-06-19 12:59:31 +00:00
|
|
|
bool unlinkSession(not_null<Main::Session*> session);
|
2021-06-18 15:22:36 +00:00
|
|
|
bool checkLastInput(
|
|
|
|
bool hasReplyingNotifications,
|
|
|
|
std::optional<crl::time> lastInputTime);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
protected:
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-02 09:30:28 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2016-10-05 16:56:27 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
2016-10-19 13:31:18 +00:00
|
|
|
bool eventFilter(QObject *o, QEvent *e) override;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-30 15:21:05 +00:00
|
|
|
void refreshLang();
|
|
|
|
void updateReplyGeometry();
|
2016-10-07 17:02:13 +00:00
|
|
|
bool canReply() const;
|
2018-05-31 12:20:28 +00:00
|
|
|
void replyResized();
|
|
|
|
void replyCancel();
|
2016-10-07 17:02:13 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void unlinkHistoryInManager();
|
2016-10-04 18:18:08 +00:00
|
|
|
void toggleActionButtons(bool visible);
|
|
|
|
void prepareActionsCache();
|
|
|
|
void showReplyField();
|
|
|
|
void sendReply();
|
2016-10-05 16:56:27 +00:00
|
|
|
void changeHeight(int newHeight);
|
|
|
|
void updateGeometry(int x, int y, int width, int height) override;
|
|
|
|
void actionsOpacityCallback();
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
[[nodiscard]] Notifications::Manager::NotificationId myId() const;
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
const not_null<PeerData*> _peer;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
QPixmap _cache;
|
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
bool _hideReplyButton = false;
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _actionsVisible = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple a_actionsOpacity;
|
2016-10-05 16:56:27 +00:00
|
|
|
QPixmap _buttonsCache;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _started;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
History *_history = nullptr;
|
2020-05-28 14:32:10 +00:00
|
|
|
std::shared_ptr<Data::CloudImageView> _userpicView;
|
2019-08-28 14:24:12 +00:00
|
|
|
QString _author;
|
|
|
|
HistoryItem *_item = nullptr;
|
|
|
|
int _forwardedCount = 0;
|
|
|
|
bool _fromScheduled = false;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::IconButton> _close;
|
|
|
|
object_ptr<Ui::RoundButton> _reply;
|
|
|
|
object_ptr<Background> _background = { nullptr };
|
2018-05-20 17:42:30 +00:00
|
|
|
object_ptr<Ui::InputField> _replyArea = { nullptr };
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::IconButton> _replySend = { nullptr };
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _waitingForInput = true;
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
QTimer _hideTimer;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
int _replyPadding = 0;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _userpicLoaded = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class HideAllButton : public Widget {
|
|
|
|
public:
|
2019-08-28 14:24:12 +00:00
|
|
|
HideAllButton(
|
|
|
|
not_null<Manager*> manager,
|
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
void startHiding();
|
|
|
|
void startHidingFast();
|
|
|
|
void stopHiding();
|
|
|
|
|
|
|
|
protected:
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-05 16:56:27 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _mouseOver = false;
|
|
|
|
bool _mouseDown = false;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
} // namespace internal
|
2016-10-02 13:54:27 +00:00
|
|
|
} // namespace Default
|
2016-10-02 09:30:28 +00:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|