mirror of https://github.com/procxx/kepka.git
Beta 10008001: moved all Notify::Observer-s to base::Subscriber-s.
This commit is contained in:
parent
18f3e45657
commit
da49d8440a
|
@ -34,8 +34,8 @@ IDI_ICON1 ICON "..\\art\\icon256.ico"
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 0,10,8,0
|
FILEVERSION 0,10,8,1
|
||||||
PRODUCTVERSION 0,10,8,0
|
PRODUCTVERSION 0,10,8,1
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -51,10 +51,10 @@ BEGIN
|
||||||
BLOCK "040904b0"
|
BLOCK "040904b0"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Telegram Messenger LLP"
|
VALUE "CompanyName", "Telegram Messenger LLP"
|
||||||
VALUE "FileVersion", "0.10.8.0"
|
VALUE "FileVersion", "0.10.8.1"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
|
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
|
||||||
VALUE "ProductName", "Telegram Desktop"
|
VALUE "ProductName", "Telegram Desktop"
|
||||||
VALUE "ProductVersion", "0.10.8.0"
|
VALUE "ProductVersion", "0.10.8.1"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 0,10,8,0
|
FILEVERSION 0,10,8,1
|
||||||
PRODUCTVERSION 0,10,8,0
|
PRODUCTVERSION 0,10,8,1
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -43,10 +43,10 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Telegram Messenger LLP"
|
VALUE "CompanyName", "Telegram Messenger LLP"
|
||||||
VALUE "FileDescription", "Telegram Updater"
|
VALUE "FileDescription", "Telegram Updater"
|
||||||
VALUE "FileVersion", "0.10.8.0"
|
VALUE "FileVersion", "0.10.8.1"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
|
VALUE "LegalCopyright", "Copyright (C) 2014-2016"
|
||||||
VALUE "ProductName", "Telegram Desktop"
|
VALUE "ProductName", "Telegram Desktop"
|
||||||
VALUE "ProductVersion", "0.10.8.0"
|
VALUE "ProductVersion", "0.10.8.1"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -217,7 +217,6 @@ void Application::singleInstanceChecked() {
|
||||||
Logs::multipleInstances();
|
Logs::multipleInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
Notify::startObservers();
|
|
||||||
Sandbox::start();
|
Sandbox::start();
|
||||||
|
|
||||||
if (!Logs::started() || (!cManyInstance() && !Logs::instanceChecked())) {
|
if (!Logs::started() || (!cManyInstance() && !Logs::instanceChecked())) {
|
||||||
|
@ -356,8 +355,6 @@ void Application::closeApplication() {
|
||||||
}
|
}
|
||||||
_updateThread = 0;
|
_updateThread = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Notify::finishObservers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||||
|
|
|
@ -262,11 +262,9 @@ ShareInner::ShareInner(QWidget *parent) : ScrolledWidget(parent)
|
||||||
|
|
||||||
using UpdateFlag = Notify::PeerUpdate::Flag;
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
||||||
auto observeEvents = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged;
|
auto observeEvents = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged;
|
||||||
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ private:
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class ShareInner : public ScrolledWidget, public RPCSender, public Notify::Observer, private base::Subscriber {
|
class ShareInner : public ScrolledWidget, public RPCSender, private base::Subscriber {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -21,99 +21,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "core/observer.h"
|
#include "core/observer.h"
|
||||||
|
|
||||||
namespace Notify {
|
|
||||||
namespace internal {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct StartCallbackData {
|
|
||||||
void *that;
|
|
||||||
StartCallback call;
|
|
||||||
};
|
|
||||||
struct FinishCallbackData {
|
|
||||||
void *that;
|
|
||||||
FinishCallback call;
|
|
||||||
};
|
|
||||||
struct UnregisterCallbackData {
|
|
||||||
void *that;
|
|
||||||
UnregisterCallback call;
|
|
||||||
};
|
|
||||||
using StartCallbacksList = QVector<StartCallbackData>;
|
|
||||||
using FinishCallbacksList = QVector<FinishCallbackData>;
|
|
||||||
NeverFreedPointer<StartCallbacksList> StartCallbacks;
|
|
||||||
NeverFreedPointer<FinishCallbacksList> FinishCallbacks;
|
|
||||||
UnregisterCallbackData UnregisterCallbacks[256]/* = { nullptr }*/;
|
|
||||||
|
|
||||||
ObservedEvent LastRegisteredEvent/* = 0*/;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
void startObservers() {
|
|
||||||
if (!internal::StartCallbacks) return;
|
|
||||||
|
|
||||||
for (auto &callback : *internal::StartCallbacks) {
|
|
||||||
callback.call(callback.that);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void finishObservers() {
|
|
||||||
if (!internal::FinishCallbacks) return;
|
|
||||||
|
|
||||||
for (auto &callback : *internal::FinishCallbacks) {
|
|
||||||
callback.call(callback.that);
|
|
||||||
}
|
|
||||||
internal::StartCallbacks.clear();
|
|
||||||
internal::FinishCallbacks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
BaseObservedEventRegistrator::BaseObservedEventRegistrator(void *that
|
|
||||||
, StartCallback startCallback
|
|
||||||
, FinishCallback finishCallback
|
|
||||||
, UnregisterCallback unregisterCallback) {
|
|
||||||
_event = LastRegisteredEvent++;
|
|
||||||
|
|
||||||
StartCallbacks.makeIfNull();
|
|
||||||
StartCallbacks->push_back({ that, startCallback });
|
|
||||||
|
|
||||||
FinishCallbacks.makeIfNull();
|
|
||||||
FinishCallbacks->push_back({ that, finishCallback });
|
|
||||||
|
|
||||||
UnregisterCallbacks[_event] = { that, unregisterCallback };
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
// Observer base interface.
|
|
||||||
Observer::~Observer() {
|
|
||||||
for_const (auto connection, _connections) {
|
|
||||||
unregisterObserver(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Observer::observerRegistered(ConnectionId connection) {
|
|
||||||
_connections.push_back(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unregisterObserver(ConnectionId connection) {
|
|
||||||
auto event = static_cast<internal::ObservedEvent>(connection >> 24);
|
|
||||||
auto connectionIndex = int(connection & 0x00FFFFFFU) - 1;
|
|
||||||
auto &callback = internal::UnregisterCallbacks[event];
|
|
||||||
if (connectionIndex >= 0 && callback.call && callback.that) {
|
|
||||||
callback.call(callback.that, connectionIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
void observerRegisteredDefault(Observer *observer, ConnectionId connection) {
|
|
||||||
observer->observerRegistered(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
} // namespace Notify
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -22,230 +22,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
#include "core/vector_of_moveable.h"
|
#include "core/vector_of_moveable.h"
|
||||||
|
|
||||||
namespace Notify {
|
|
||||||
|
|
||||||
using ConnectionId = uint32;
|
|
||||||
|
|
||||||
// startObservers() must be called after main() started (not in a global variable constructor).
|
|
||||||
// finishObservers() must be called before main() finished (not in a global variable destructor).
|
|
||||||
void startObservers();
|
|
||||||
void finishObservers();
|
|
||||||
|
|
||||||
using StartObservedEventCallback = void(*)();
|
|
||||||
using FinishObservedEventCallback = void(*)();
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
using ObservedEvent = uchar;
|
|
||||||
using StartCallback = void(*)(void*);
|
|
||||||
using FinishCallback = void(*)(void*);
|
|
||||||
using UnregisterCallback = void(*)(void*,int connectionIndex);
|
|
||||||
|
|
||||||
class BaseObservedEventRegistrator {
|
|
||||||
public:
|
|
||||||
BaseObservedEventRegistrator(void *that
|
|
||||||
, StartCallback startCallback
|
|
||||||
, FinishCallback finishCallback
|
|
||||||
, UnregisterCallback unregisterCallback);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
inline ObservedEvent event() const {
|
|
||||||
return _event;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ObservedEvent _event;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handler is one of base::lambda_unique<> instantiations.
|
|
||||||
template <typename Flags, typename Handler>
|
|
||||||
struct ObserversList {
|
|
||||||
struct Entry {
|
|
||||||
Flags flags;
|
|
||||||
Handler handler;
|
|
||||||
};
|
|
||||||
std_::vector_of_moveable<Entry> entries;
|
|
||||||
QVector<int> freeIndices;
|
|
||||||
};
|
|
||||||
|
|
||||||
// If no filtering by flags is done, you can use Flags=int and this value.
|
|
||||||
constexpr int UniversalFlag = 0x01;
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
// Objects of this class should be constructed in global scope.
|
|
||||||
// startCallback will be called from Notify::startObservers().
|
|
||||||
// finishCallback will be called from Notify::finishObservers().
|
|
||||||
template <typename Flags, typename Handler>
|
|
||||||
class ObservedEventRegistrator : public internal::BaseObservedEventRegistrator {
|
|
||||||
public:
|
|
||||||
ObservedEventRegistrator(StartObservedEventCallback startCallback,
|
|
||||||
FinishObservedEventCallback finishCallback) : internal::BaseObservedEventRegistrator(static_cast<void*>(this),
|
|
||||||
ObservedEventRegistrator<Flags, Handler>::start,
|
|
||||||
ObservedEventRegistrator<Flags, Handler>::finish,
|
|
||||||
ObservedEventRegistrator<Flags, Handler>::unregister)
|
|
||||||
, _startCallback(startCallback), _finishCallback(finishCallback) {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool started() const {
|
|
||||||
return _list != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionId registerObserver(Flags flags, Handler &&handler) {
|
|
||||||
t_assert(started());
|
|
||||||
|
|
||||||
int connectionIndex = doRegisterObserver(flags, std_::forward<Handler>(handler));
|
|
||||||
return (static_cast<uint32>(event()) << 24) | static_cast<uint32>(connectionIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
void notify(Flags flags, Args&&... args) {
|
|
||||||
t_assert(started());
|
|
||||||
|
|
||||||
auto &entries = _list->entries;
|
|
||||||
// This way of iterating (i < entries.size() should be used
|
|
||||||
// because some entries can be removed from the end of the
|
|
||||||
// entries list while the loop is still running.
|
|
||||||
for (int i = 0; i < entries.size(); ++i) {
|
|
||||||
auto &entry = entries[i];
|
|
||||||
if (entry.handler && (flags & entry.flags)) {
|
|
||||||
entry.handler(std_::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using Self = ObservedEventRegistrator<Flags, Handler>;
|
|
||||||
static void start(void *vthat) {
|
|
||||||
Self *that = static_cast<Self*>(vthat);
|
|
||||||
|
|
||||||
t_assert(!that->started());
|
|
||||||
if (that->_startCallback) that->_startCallback();
|
|
||||||
that->_list = new internal::ObserversList<Flags, Handler>();
|
|
||||||
}
|
|
||||||
static void finish(void *vthat) {
|
|
||||||
Self *that = static_cast<Self*>(vthat);
|
|
||||||
|
|
||||||
if (that->_finishCallback) that->_finishCallback();
|
|
||||||
delete that->_list;
|
|
||||||
that->_list = nullptr;
|
|
||||||
}
|
|
||||||
static void unregister(void *vthat, int connectionIndex) {
|
|
||||||
Self *that = static_cast<Self*>(vthat);
|
|
||||||
|
|
||||||
t_assert(that->started());
|
|
||||||
|
|
||||||
auto &entries = that->_list->entries;
|
|
||||||
if (entries.size() <= connectionIndex) return;
|
|
||||||
|
|
||||||
if (entries.size() == connectionIndex + 1) {
|
|
||||||
for (entries.pop_back(); !entries.isEmpty() && !entries.back().handler;) {
|
|
||||||
entries.pop_back();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entries[connectionIndex].handler = Handler();
|
|
||||||
that->_list->freeIndices.push_back(connectionIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int doRegisterObserver(Flags flags, Handler &&handler) {
|
|
||||||
while (!_list->freeIndices.isEmpty()) {
|
|
||||||
auto freeIndex = _list->freeIndices.back();
|
|
||||||
_list->freeIndices.pop_back();
|
|
||||||
|
|
||||||
if (freeIndex < _list->entries.size()) {
|
|
||||||
_list->entries[freeIndex] = { flags, std_::move(handler) };
|
|
||||||
return freeIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_list->entries.push_back({ flags, std_::move(handler) });
|
|
||||||
return _list->entries.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
StartObservedEventCallback _startCallback;
|
|
||||||
FinishObservedEventCallback _finishCallback;
|
|
||||||
internal::ObserversList<Flags, Handler> *_list = nullptr;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// If no filtering of notifications by Flags is intended use this class.
|
|
||||||
template <typename Handler>
|
|
||||||
class SimpleObservedEventRegistrator {
|
|
||||||
public:
|
|
||||||
SimpleObservedEventRegistrator(StartObservedEventCallback startCallback,
|
|
||||||
FinishObservedEventCallback finishCallback) : _implementation(startCallback, finishCallback) {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool started() const {
|
|
||||||
return _implementation.started();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionId registerObserver(Handler &&handler) {
|
|
||||||
return _implementation.registerObserver(internal::UniversalFlag, std_::forward<Handler>(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
void notify(Args&&... args) {
|
|
||||||
return _implementation.notify(internal::UniversalFlag, std_::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ObservedEventRegistrator<int, Handler> _implementation;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Each observer type should have observerRegistered(Notify::ConnectionId connection) method.
|
|
||||||
// Usually it is done by deriving the type from the Notify::Observer base class.
|
|
||||||
// In destructor it should call Notify::unregisterObserver(connection) for all the connections.
|
|
||||||
|
|
||||||
class Observer;
|
|
||||||
namespace internal {
|
|
||||||
void observerRegisteredDefault(Observer *observer, ConnectionId connection);
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
void unregisterObserver(ConnectionId connection);
|
|
||||||
|
|
||||||
class Observer {
|
|
||||||
public:
|
|
||||||
virtual ~Observer() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void observerRegistered(ConnectionId connection);
|
|
||||||
friend void internal::observerRegisteredDefault(Observer *observer, ConnectionId connection);
|
|
||||||
|
|
||||||
QVector<ConnectionId> _connections;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
template <typename ObserverType, int>
|
|
||||||
struct ObserverRegisteredGeneric {
|
|
||||||
static inline void call(ObserverType *observer, ConnectionId connection) {
|
|
||||||
observer->observerRegistered(connection);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ObserverType>
|
|
||||||
struct ObserverRegisteredGeneric<ObserverType, true> {
|
|
||||||
static inline void call(ObserverType *observer, ConnectionId connection) {
|
|
||||||
observerRegisteredDefault(observer, connection);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
template <typename ObserverType>
|
|
||||||
inline void observerRegistered(ObserverType *observer, ConnectionId connection) {
|
|
||||||
// For derivatives of the Observer class we call special friend function observerRegistered().
|
|
||||||
// For all other classes we call just a member function observerRegistered().
|
|
||||||
using ObserverRegistered = internal::ObserverRegisteredGeneric<ObserverType, std_::is_base_of<Observer, ObserverType>::value>;
|
|
||||||
ObserverRegistered::call(observer, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Notify
|
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
#include "core/basic_types.h"
|
#include "core/basic_types.h"
|
||||||
|
|
||||||
#define BETA_VERSION_MACRO (0ULL)
|
#define BETA_VERSION_MACRO (10008001ULL)
|
||||||
|
|
||||||
constexpr int AppVersion = 10008;
|
constexpr int AppVersion = 10008;
|
||||||
constexpr str_const AppVersionStr = "0.10.8";
|
constexpr str_const AppVersionStr = "0.10.8";
|
||||||
|
|
|
@ -31,8 +31,6 @@ void emitPeerUpdated();
|
||||||
namespace Notify {
|
namespace Notify {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using internal::PeerUpdateHandler;
|
|
||||||
|
|
||||||
using SmallUpdatesList = QVector<PeerUpdate>;
|
using SmallUpdatesList = QVector<PeerUpdate>;
|
||||||
NeverFreedPointer<SmallUpdatesList> SmallUpdates;
|
NeverFreedPointer<SmallUpdatesList> SmallUpdates;
|
||||||
using AllUpdatesList = QMap<PeerData*, PeerUpdate>;
|
using AllUpdatesList = QMap<PeerData*, PeerUpdate>;
|
||||||
|
@ -46,21 +44,11 @@ void FinishCallback() {
|
||||||
SmallUpdates.clear();
|
SmallUpdates.clear();
|
||||||
AllUpdates.clear();
|
AllUpdates.clear();
|
||||||
}
|
}
|
||||||
ObservedEventRegistrator<PeerUpdate::Flags, PeerUpdateHandler> creator(StartCallback, FinishCallback);
|
|
||||||
|
|
||||||
base::Observable<PeerUpdate, PeerUpdatedHandler> PeerUpdatedObservable;
|
base::Observable<PeerUpdate, PeerUpdatedHandler> PeerUpdatedObservable;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
ConnectionId plainRegisterPeerObserver(PeerUpdate::Flags events, PeerUpdateHandler &&handler) {
|
|
||||||
constexpr auto tmp = sizeof(PeerUpdate);
|
|
||||||
return creator.registerObserver(events, std_::forward<PeerUpdateHandler>(handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) {
|
void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) {
|
||||||
if (!(mergeTo.flags & PeerUpdate::Flag::NameChanged)) {
|
if (!(mergeTo.flags & PeerUpdate::Flag::NameChanged)) {
|
||||||
if (mergeFrom.flags & PeerUpdate::Flag::NameChanged) {
|
if (mergeFrom.flags & PeerUpdate::Flag::NameChanged) {
|
||||||
|
@ -75,7 +63,8 @@ void mergePeerUpdate(PeerUpdate &mergeTo, const PeerUpdate &mergeFrom) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerUpdatedDelayed(const PeerUpdate &update) {
|
void peerUpdatedDelayed(const PeerUpdate &update) {
|
||||||
t_assert(creator.started());
|
SmallUpdates.makeIfNull();
|
||||||
|
AllUpdates.makeIfNull();
|
||||||
|
|
||||||
Global::RefHandleDelayedPeerUpdates().call();
|
Global::RefHandleDelayedPeerUpdates().call();
|
||||||
|
|
||||||
|
@ -87,6 +76,7 @@ void peerUpdatedDelayed(const PeerUpdate &update) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AllUpdates->isEmpty()) {
|
if (AllUpdates->isEmpty()) {
|
||||||
if (existingUpdatesCount < 5) {
|
if (existingUpdatesCount < 5) {
|
||||||
SmallUpdates->push_back(update);
|
SmallUpdates->push_back(update);
|
||||||
|
@ -104,26 +94,19 @@ void peerUpdatedDelayed(const PeerUpdate &update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerUpdatedSendDelayed() {
|
void peerUpdatedSendDelayed() {
|
||||||
if (!creator.started()) return;
|
|
||||||
|
|
||||||
App::emitPeerUpdated();
|
App::emitPeerUpdated();
|
||||||
|
|
||||||
if (SmallUpdates->isEmpty()) return;
|
if (!SmallUpdates || !AllUpdates || SmallUpdates->empty()) return;
|
||||||
|
|
||||||
auto smallList = createAndSwap(*SmallUpdates);
|
auto smallList = createAndSwap(*SmallUpdates);
|
||||||
auto allList = createAndSwap(*AllUpdates);
|
auto allList = createAndSwap(*AllUpdates);
|
||||||
for_const (auto &update, smallList) {
|
|
||||||
creator.notify(update.flags, update);
|
|
||||||
}
|
|
||||||
for_const (auto &update, allList) {
|
|
||||||
creator.notify(update.flags, update);
|
|
||||||
}
|
|
||||||
for (auto &update : smallList) {
|
for (auto &update : smallList) {
|
||||||
PeerUpdated().notify(std_::move(update), true);
|
PeerUpdated().notify(std_::move(update), true);
|
||||||
}
|
}
|
||||||
for (auto &update : allList) {
|
for (auto &update : allList) {
|
||||||
PeerUpdated().notify(std_::move(update), true);
|
PeerUpdated().notify(std_::move(update), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SmallUpdates->isEmpty()) {
|
if (SmallUpdates->isEmpty()) {
|
||||||
std::swap(smallList, *SmallUpdates);
|
std::swap(smallList, *SmallUpdates);
|
||||||
SmallUpdates->resize(0);
|
SmallUpdates->resize(0);
|
||||||
|
|
|
@ -89,19 +89,6 @@ inline void peerUpdatedDelayed(PeerData *peer, PeerUpdate::Flags events) {
|
||||||
}
|
}
|
||||||
void peerUpdatedSendDelayed();
|
void peerUpdatedSendDelayed();
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
using PeerUpdateHandler = base::lambda_unique<void(const PeerUpdate&)>;
|
|
||||||
ConnectionId plainRegisterPeerObserver(PeerUpdate::Flags events, PeerUpdateHandler &&handler);
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
template <typename ObserverType, typename Lambda>
|
|
||||||
void registerPeerObserver(PeerUpdate::Flags events, ObserverType *observer, Lambda &&other) {
|
|
||||||
auto connection = internal::plainRegisterPeerObserver(events, std_::move(other));
|
|
||||||
observerRegistered(observer, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
class PeerUpdatedHandler {
|
class PeerUpdatedHandler {
|
||||||
public:
|
public:
|
||||||
template <typename Lambda>
|
template <typename Lambda>
|
||||||
|
|
|
@ -39,9 +39,9 @@ ActionsWidget::ActionsWidget(QWidget *parent, PeerData *peer) : BlockWidget(pare
|
||||||
| UpdateFlag::UserIsBlocked
|
| UpdateFlag::UserIsBlocked
|
||||||
| UpdateFlag::BotCommandsChanged
|
| UpdateFlag::BotCommandsChanged
|
||||||
| UpdateFlag::MembersChanged;
|
| UpdateFlag::MembersChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
validateBlockStatus();
|
validateBlockStatus();
|
||||||
refreshButtons();
|
refreshButtons();
|
||||||
|
|
|
@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||||
|
|
||||||
namespace Profile {
|
namespace Profile {
|
||||||
|
|
||||||
class BlockWidget : public ScrolledWidget, public Notify::Observer, protected base::Subscriber {
|
class BlockWidget : public ScrolledWidget, protected base::Subscriber {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -68,9 +68,9 @@ CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent)
|
||||||
auto observeEvents = ButtonsUpdateFlags
|
auto observeEvents = ButtonsUpdateFlags
|
||||||
| UpdateFlag::NameChanged
|
| UpdateFlag::NameChanged
|
||||||
| UpdateFlag::UserOnlineChanged;
|
| UpdateFlag::UserOnlineChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||||
notifyFileQueryUpdated(update);
|
notifyFileQueryUpdated(update);
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@ class BackButton;
|
||||||
class UserpicButton;
|
class UserpicButton;
|
||||||
class CoverDropArea;
|
class CoverDropArea;
|
||||||
|
|
||||||
class CoverWidget final : public TWidget, public Notify::Observer, private base::Subscriber {
|
class CoverWidget final : public TWidget, private base::Subscriber {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -83,9 +83,9 @@ FixedBar::FixedBar(QWidget *parent, PeerData *peer) : TWidget(parent)
|
||||||
|
|
||||||
auto observeEvents = ButtonsUpdateFlags
|
auto observeEvents = ButtonsUpdateFlags
|
||||||
| UpdateFlag::MigrationChanged;
|
| UpdateFlag::MigrationChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdate(update);
|
notifyPeerUpdate(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshRightActions();
|
refreshRightActions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Profile {
|
||||||
|
|
||||||
class BackButton;
|
class BackButton;
|
||||||
|
|
||||||
class FixedBar final : public TWidget, public Notify::Observer {
|
class FixedBar final : public TWidget, private base::Subscriber {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -36,9 +36,9 @@ InfoWidget::InfoWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, pe
|
||||||
| UpdateFlag::UsernameChanged
|
| UpdateFlag::UsernameChanged
|
||||||
| UpdateFlag::UserPhoneChanged
|
| UpdateFlag::UserPhoneChanged
|
||||||
| UpdateFlag::UserCanShareContact;
|
| UpdateFlag::UserCanShareContact;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshLabels();
|
refreshLabels();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,9 @@ using UpdateFlag = Notify::PeerUpdate::Flag;
|
||||||
|
|
||||||
InviteLinkWidget::InviteLinkWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_invite_link_section)) {
|
InviteLinkWidget::InviteLinkWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_invite_link_section)) {
|
||||||
auto observeEvents = UpdateFlag::InviteLinkChanged | UpdateFlag::UsernameChanged;
|
auto observeEvents = UpdateFlag::InviteLinkChanged | UpdateFlag::UsernameChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshLink();
|
refreshLink();
|
||||||
refreshVisibility();
|
refreshVisibility();
|
||||||
|
|
|
@ -49,9 +49,9 @@ MembersWidget::MembersWidget(QWidget *parent, PeerData *peer, TitleVisibility ti
|
||||||
auto observeEvents = UpdateFlag::AdminsChanged
|
auto observeEvents = UpdateFlag::AdminsChanged
|
||||||
| UpdateFlag::MembersChanged
|
| UpdateFlag::MembersChanged
|
||||||
| UpdateFlag::UserOnlineChanged;
|
| UpdateFlag::UserOnlineChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
||||||
|
|
||||||
refreshMembers();
|
refreshMembers();
|
||||||
|
@ -604,9 +604,9 @@ ChannelMembersWidget::ChannelMembersWidget(QWidget *parent, PeerData *peer) : Bl
|
||||||
| UpdateFlag::ChannelCanViewMembers
|
| UpdateFlag::ChannelCanViewMembers
|
||||||
| UpdateFlag::AdminsChanged
|
| UpdateFlag::AdminsChanged
|
||||||
| UpdateFlag::MembersChanged;
|
| UpdateFlag::MembersChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshButtons();
|
refreshButtons();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,9 @@ SettingsWidget::SettingsWidget(QWidget *parent, PeerData *peer) : BlockWidget(pa
|
||||||
observeEvents |= UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged;
|
observeEvents |= UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
refreshButtons();
|
refreshButtons();
|
||||||
_enableNotifications->finishAnimations();
|
_enableNotifications->finishAnimations();
|
||||||
|
|
|
@ -51,9 +51,10 @@ QString getButtonText(MediaOverviewType type, int count) {
|
||||||
SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media))
|
SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media))
|
||||||
, _history(App::history(peer))
|
, _history(App::history(peer))
|
||||||
, _migrated(peer->migrateFrom() ? App::history(peer->migrateFrom()) : nullptr) {
|
, _migrated(peer->migrateFrom() ? App::history(peer->migrateFrom()) : nullptr) {
|
||||||
Notify::registerPeerObserver(Notify::PeerUpdate::Flag::SharedMediaChanged, this, [this](const Notify::PeerUpdate &update) {
|
auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged;
|
||||||
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
App::main()->preloadOverviews(peer);
|
App::main()->preloadOverviews(peer);
|
||||||
if (_migrated) {
|
if (_migrated) {
|
||||||
|
|
|
@ -36,9 +36,10 @@ UserpicButton::UserpicButton(QWidget *parent, PeerData *peer) : Button(parent),
|
||||||
_userpic = prepareUserpicPixmap();
|
_userpic = prepareUserpicPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Notify::registerPeerObserver(Notify::PeerUpdate::Flag::PhotoChanged, this, [this](const Notify::PeerUpdate &update) {
|
auto observeEvents = Notify::PeerUpdate::Flag::PhotoChanged;
|
||||||
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
subscribe(FileDownload::ImageLoaded(), [this] {
|
subscribe(FileDownload::ImageLoaded(), [this] {
|
||||||
if (_waiting && _peer->userpicLoaded()) {
|
if (_waiting && _peer->userpicLoaded()) {
|
||||||
_waiting = false;
|
_waiting = false;
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct PeerUpdate;
|
||||||
|
|
||||||
namespace Profile {
|
namespace Profile {
|
||||||
|
|
||||||
class UserpicButton final : public Button, public Notify::Observer, private base::Subscriber {
|
class UserpicButton final : public Button, private base::Subscriber {
|
||||||
public:
|
public:
|
||||||
UserpicButton(QWidget *parent, PeerData *peer);
|
UserpicButton(QWidget *parent, PeerData *peer);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class WidgetSlideWrap;
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
class BlockWidget : public ScrolledWidget, public Notify::Observer, protected base::Subscriber {
|
class BlockWidget : public ScrolledWidget, protected base::Subscriber {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -57,10 +57,9 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent,
|
||||||
connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName()));
|
connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName()));
|
||||||
|
|
||||||
auto observeEvents = Notify::PeerUpdate::Flag::NameChanged;
|
auto observeEvents = Notify::PeerUpdate::Flag::NameChanged;
|
||||||
Notify::registerPeerObserver(observeEvents, this, [this](const Notify::PeerUpdate &update) {
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
||||||
notifyPeerUpdated(update);
|
notifyPeerUpdated(update);
|
||||||
});
|
}));
|
||||||
|
|
||||||
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
||||||
notifyFileQueryUpdated(update);
|
notifyFileQueryUpdated(update);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,4 +3,4 @@ AppVersionStrMajor 0.10
|
||||||
AppVersionStrSmall 0.10.8
|
AppVersionStrSmall 0.10.8
|
||||||
AppVersionStr 0.10.8
|
AppVersionStr 0.10.8
|
||||||
AlphaChannel 0
|
AlphaChannel 0
|
||||||
BetaVersion 0
|
BetaVersion 10008001
|
||||||
|
|
Loading…
Reference in New Issue