2016-05-24 16:13:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-05-24 16:13:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/observer.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
|
|
|
|
|
|
|
enum class Flag {
|
2016-06-20 15:40:36 +00:00
|
|
|
// Common flags
|
2016-10-23 21:03:10 +00:00
|
|
|
NameChanged = 0x00000001U,
|
|
|
|
UsernameChanged = 0x00000002U,
|
|
|
|
PhotoChanged = 0x00000004U,
|
|
|
|
AboutChanged = 0x00000008U,
|
|
|
|
NotificationsEnabled = 0x00000010U,
|
|
|
|
SharedMediaChanged = 0x00000020U,
|
|
|
|
MigrationChanged = 0x00000040U,
|
2016-12-13 07:59:57 +00:00
|
|
|
PinnedChanged = 0x00000080U,
|
2016-06-02 13:02:55 +00:00
|
|
|
|
|
|
|
// For chats and channels
|
2016-12-13 07:59:57 +00:00
|
|
|
InviteLinkChanged = 0x00000100U,
|
|
|
|
MembersChanged = 0x00000200U,
|
|
|
|
AdminsChanged = 0x00000400U,
|
2017-04-07 15:07:26 +00:00
|
|
|
BlockedUsersChanged = 0x00000800U,
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// For users
|
2016-10-23 21:03:10 +00:00
|
|
|
UserCanShareContact = 0x00010000U,
|
|
|
|
UserIsContact = 0x00020000U,
|
|
|
|
UserPhoneChanged = 0x00040000U,
|
|
|
|
UserIsBlocked = 0x00080000U,
|
|
|
|
BotCommandsChanged = 0x00100000U,
|
|
|
|
UserOnlineChanged = 0x00200000U,
|
|
|
|
BotCanAddToGroups = 0x00400000U,
|
|
|
|
UserCommonChatsChanged = 0x00800000U,
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// For chats
|
2016-10-23 21:03:10 +00:00
|
|
|
ChatCanEdit = 0x00010000U,
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
// For channels
|
2016-10-23 21:03:10 +00:00
|
|
|
ChannelAmIn = 0x00010000U,
|
|
|
|
ChannelAmEditor = 0x00020000U,
|
|
|
|
ChannelCanEditPhoto = 0x00040000U,
|
|
|
|
ChannelCanAddMembers = 0x00080000U,
|
|
|
|
ChannelCanViewAdmins = 0x00100000U,
|
|
|
|
ChannelCanViewMembers = 0x00200000U,
|
2016-06-01 20:05:37 +00:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(Flags, Flag);
|
|
|
|
Flags flags = 0;
|
2016-05-25 12:09:05 +00:00
|
|
|
|
|
|
|
// NameChanged data
|
|
|
|
PeerData::Names oldNames;
|
|
|
|
PeerData::NameFirstChars oldNameFirstChars;
|
2016-06-02 13:02:55 +00:00
|
|
|
|
|
|
|
// SharedMediaChanged data
|
|
|
|
int32 mediaTypesMask = 0;
|
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
};
|
2016-06-01 20:05:37 +00:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PeerUpdate::Flags);
|
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();
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
inline void mediaOverviewUpdated(PeerData *peer, MediaOverviewType type) {
|
|
|
|
PeerUpdate update(peer);
|
|
|
|
update.flags |= PeerUpdate::Flag::SharedMediaChanged;
|
|
|
|
update.mediaTypesMask |= (1 << type);
|
|
|
|
peerUpdatedDelayed(update);
|
|
|
|
}
|
|
|
|
|
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;
|
2016-11-20 12:54:07 +00:00
|
|
|
base::lambda<void(const PeerUpdate&)> _handler;
|
2016-09-26 14:50:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
base::Observable<PeerUpdate, PeerUpdatedHandler> &PeerUpdated();
|
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
} // namespace Notify
|