2016-05-24 16:13:07 +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-05-24 16:13:07 +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-05-24 16:13:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-10-24 17:11:35 +00:00
|
|
|
#include <rpl/producer.h>
|
|
|
|
#include <rpl/filter.h>
|
|
|
|
#include <rpl/then.h>
|
|
|
|
#include <rpl/range.h>
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/observer.h"
|
2017-08-31 16:28:58 +00:00
|
|
|
#include "base/flags.h"
|
2016-05-24 16:13:07 +00:00
|
|
|
|
|
|
|
namespace Notify {
|
|
|
|
|
|
|
|
// Generic notifications about updates of some PeerData.
|
|
|
|
// You can subscribe to them by Notify::registerPeerObserver().
|
2016-05-25 12:09:05 +00:00
|
|
|
// 0x0000FFFFU for general peer updates (valid for any peer).
|
|
|
|
// 0xFFFF0000U for specific peer updates (valid for user / chat / channel).
|
2016-05-24 16:13:07 +00:00
|
|
|
struct PeerUpdate {
|
2016-05-25 12:09:05 +00:00
|
|
|
PeerUpdate(PeerData *updated = nullptr) : peer(updated) {
|
|
|
|
}
|
|
|
|
PeerData *peer;
|
2016-06-01 20:05:37 +00:00
|
|
|
|
2017-08-03 12:52:56 +00:00
|
|
|
enum class Flag : uint32 {
|
2017-09-03 18:36:06 +00:00
|
|
|
None = 0,
|
2017-06-09 16:12:02 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// Common flags
|
2017-09-03 18:36:06 +00:00
|
|
|
NameChanged = (1 << 0),
|
|
|
|
UsernameChanged = (1 << 1),
|
|
|
|
PhotoChanged = (1 << 2),
|
|
|
|
AboutChanged = (1 << 3),
|
|
|
|
NotificationsEnabled = (1 << 4),
|
|
|
|
MigrationChanged = (1 << 6),
|
2018-10-31 11:29:14 +00:00
|
|
|
ChatPinnedChanged = (1 << 7),
|
2019-01-04 07:57:07 +00:00
|
|
|
UnavailableReasonChanged = (1 << 8),
|
2018-06-26 18:03:45 +00:00
|
|
|
UnreadViewChanged = (1 << 9),
|
2018-10-31 11:29:14 +00:00
|
|
|
PinnedMessageChanged = (1 << 10),
|
2016-06-02 13:02:55 +00:00
|
|
|
|
|
|
|
// For chats and channels
|
2018-11-20 15:36:36 +00:00
|
|
|
InviteLinkChanged = (1 << 11),
|
|
|
|
MembersChanged = (1 << 12),
|
|
|
|
AdminsChanged = (1 << 13),
|
|
|
|
BannedUsersChanged = (1 << 14),
|
|
|
|
UnreadMentionsChanged = (1 << 15),
|
2019-01-05 10:50:04 +00:00
|
|
|
RightsChanged = (1 << 16),
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// For users
|
2019-01-05 10:50:04 +00:00
|
|
|
UserCanShareContact = (1 << 17),
|
|
|
|
UserIsContact = (1 << 18),
|
|
|
|
UserPhoneChanged = (1 << 19),
|
|
|
|
UserIsBlocked = (1 << 20),
|
|
|
|
BotCommandsChanged = (1 << 21),
|
|
|
|
UserOnlineChanged = (1 << 22),
|
|
|
|
BotCanAddToGroups = (1 << 23),
|
|
|
|
UserCommonChatsChanged = (1 << 24),
|
|
|
|
UserHasCalls = (1 << 25),
|
|
|
|
UserOccupiedChanged = (1 << 26),
|
|
|
|
UserSupportInfoChanged = (1 << 27),
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// For channels
|
2019-01-05 10:50:04 +00:00
|
|
|
ChannelAmIn = (1 << 17),
|
2018-11-20 15:36:36 +00:00
|
|
|
ChannelStickersChanged = (1 << 18),
|
|
|
|
ChannelPromotedChanged = (1 << 19),
|
2019-05-23 21:38:49 +00:00
|
|
|
ChannelLinkedChat = (1 << 20),
|
2019-06-21 12:27:46 +00:00
|
|
|
ChannelLocation = (1 << 21),
|
2019-07-16 11:46:50 +00:00
|
|
|
ChannelSlowmode = (1 << 22),
|
2019-07-17 14:34:39 +00:00
|
|
|
ChannelLocalMessages = (1 << 23),
|
2016-06-01 20:05:37 +00:00
|
|
|
};
|
2017-08-31 16:28:58 +00:00
|
|
|
using Flags = base::flags<Flag>;
|
|
|
|
friend inline constexpr auto is_flag_type(Flag) { return true; }
|
|
|
|
|
2016-06-01 20:05:37 +00:00
|
|
|
Flags flags = 0;
|
2016-05-25 12:09:05 +00:00
|
|
|
|
|
|
|
// NameChanged data
|
2018-01-22 09:33:09 +00:00
|
|
|
base::flat_set<QChar> oldNameFirstLetters;
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void peerUpdatedDelayed(const PeerUpdate &update);
|
2016-06-01 20:05:37 +00:00
|
|
|
inline void peerUpdatedDelayed(PeerData *peer, PeerUpdate::Flags events) {
|
|
|
|
PeerUpdate update(peer);
|
|
|
|
update.flags = events;
|
|
|
|
peerUpdatedDelayed(update);
|
|
|
|
}
|
2016-05-24 16:13:07 +00:00
|
|
|
void peerUpdatedSendDelayed();
|
|
|
|
|
2016-09-26 14:50:24 +00:00
|
|
|
class PeerUpdatedHandler {
|
|
|
|
public:
|
|
|
|
template <typename Lambda>
|
2017-02-21 13:45:56 +00:00
|
|
|
PeerUpdatedHandler(PeerUpdate::Flags events, Lambda &&handler) : _events(events), _handler(std::move(handler)) {
|
2016-09-26 14:50:24 +00:00
|
|
|
}
|
|
|
|
void operator()(const PeerUpdate &update) const {
|
|
|
|
if (update.flags & _events) {
|
|
|
|
_handler(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PeerUpdate::Flags _events;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(const PeerUpdate&)> _handler;
|
2016-09-26 14:50:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
base::Observable<PeerUpdate, PeerUpdatedHandler> &PeerUpdated();
|
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<PeerUpdate> PeerUpdateViewer(
|
|
|
|
PeerUpdate::Flags flags);
|
2017-10-24 17:11:35 +00:00
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<PeerUpdate> PeerUpdateViewer(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
PeerUpdate::Flags flags);
|
2017-10-24 17:11:35 +00:00
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<PeerUpdate> PeerUpdateValue(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
PeerUpdate::Flags flags);
|
2017-10-24 17:11:35 +00:00
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
} // namespace Notify
|