mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-11 08:48:14 +00:00
OrderedSet class done using QMap as implementation,
instead of inheriting it, fixed replies delete code.
This commit is contained in:
parent
cbebf9ced7
commit
559a74847b
@ -1794,17 +1794,17 @@ namespace App {
|
||||
MsgsData *data = fetchMsgsData(item->channelId(), false);
|
||||
if (!data) return;
|
||||
|
||||
MsgsData::iterator i = data->find(item->id);
|
||||
auto i = data->find(item->id);
|
||||
if (i != data->cend()) {
|
||||
if (i.value() == item) {
|
||||
data->erase(i);
|
||||
}
|
||||
}
|
||||
historyItemDetached(item);
|
||||
DependentItems::iterator j = ::dependentItems.find(item);
|
||||
auto j = ::dependentItems.find(item);
|
||||
if (j != ::dependentItems.cend()) {
|
||||
for (OrderedSet<HistoryItem*>::const_iterator k = j.value().cbegin(), e = j.value().cend(); k != e; ++k) {
|
||||
k.key()->dependencyItemRemoved(item);
|
||||
for_const (HistoryItem *dependent, j.value()) {
|
||||
dependent->dependencyItemRemoved(item);
|
||||
}
|
||||
::dependentItems.erase(j);
|
||||
}
|
||||
@ -1816,8 +1816,8 @@ namespace App {
|
||||
void historyUpdateDependent(HistoryItem *item) {
|
||||
DependentItems::iterator j = ::dependentItems.find(item);
|
||||
if (j != ::dependentItems.cend()) {
|
||||
for (OrderedSet<HistoryItem*>::const_iterator k = j.value().cbegin(), e = j.value().cend(); k != e; ++k) {
|
||||
k.key()->updateDependencyItem();
|
||||
for_const (HistoryItem *dependent, j.value()) {
|
||||
dependent->updateDependencyItem();
|
||||
}
|
||||
}
|
||||
if (App::main()) {
|
||||
@ -1829,15 +1829,15 @@ namespace App {
|
||||
::dependentItems.clear();
|
||||
|
||||
QVector<HistoryItem*> toDelete;
|
||||
for (MsgsData::const_iterator i = msgsData.cbegin(), e = msgsData.cend(); i != e; ++i) {
|
||||
if ((*i)->detached()) {
|
||||
toDelete.push_back(*i);
|
||||
for_const (HistoryItem *item, msgsData) {
|
||||
if (item->detached()) {
|
||||
toDelete.push_back(item);
|
||||
}
|
||||
}
|
||||
for (ChannelMsgsData::const_iterator j = channelMsgsData.cbegin(), end = channelMsgsData.cend(); j != end; ++j) {
|
||||
for (MsgsData::const_iterator i = j->cbegin(), e = j->cend(); i != e; ++i) {
|
||||
if ((*i)->detached()) {
|
||||
toDelete.push_back(*i);
|
||||
for_const (const MsgsData &chMsgsData, channelMsgsData) {
|
||||
for_const (HistoryItem *item, chMsgsData) {
|
||||
if (item->detached()) {
|
||||
toDelete.push_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1670,12 +1670,15 @@ void ContactsBox::getAdminsDone(const MTPmessages_ChatFull &result) {
|
||||
}
|
||||
}
|
||||
_saveRequestId = 0;
|
||||
for (ChatData::Admins::const_iterator i = curadmins.cbegin(), e = curadmins.cend(); i != e; ++i) {
|
||||
MTP::send(MTPmessages_EditChatAdmin(_inner.chat()->inputChat, i.key()->inputUser, MTP_boolFalse()), rpcDone(&ContactsBox::removeAdminDone, i.key()), rpcFail(&ContactsBox::editAdminFail), 0, (appoint.isEmpty() && i + 1 == e) ? 0 : 10);
|
||||
|
||||
for_const (UserData *user, curadmins) {
|
||||
MTP::send(MTPmessages_EditChatAdmin(_inner.chat()->inputChat, user->inputUser, MTP_boolFalse()), rpcDone(&ContactsBox::removeAdminDone, user), rpcFail(&ContactsBox::editAdminFail), 0, 10);
|
||||
}
|
||||
for (int32 i = 0, l = appoint.size(); i < l; ++i) {
|
||||
MTP::send(MTPmessages_EditChatAdmin(_inner.chat()->inputChat, appoint.at(i)->inputUser, MTP_boolTrue()), rpcDone(&ContactsBox::setAdminDone, appoint.at(i)), rpcFail(&ContactsBox::editAdminFail), 0, (i + 1 == l) ? 0 : 10);
|
||||
for_const (UserData *user, appoint) {
|
||||
MTP::send(MTPmessages_EditChatAdmin(_inner.chat()->inputChat, user->inputUser, MTP_boolTrue()), rpcDone(&ContactsBox::setAdminDone, user), rpcFail(&ContactsBox::editAdminFail), 0, 10);
|
||||
}
|
||||
MTP::sendAnything();
|
||||
|
||||
_saveRequestId = curadmins.size() + appoint.size();
|
||||
if (!_saveRequestId) {
|
||||
onClose();
|
||||
|
@ -4501,8 +4501,7 @@ void MentionsDropdown::updateFiltered(bool resetScroll) {
|
||||
if (_channel->mgInfo->bots.isEmpty()) {
|
||||
if (!_channel->mgInfo->botStatus && App::api()) App::api()->requestBots(_channel);
|
||||
} else {
|
||||
for (MegagroupInfo::Bots::const_iterator i = _channel->mgInfo->bots.cbegin(), e = _channel->mgInfo->bots.cend(); i != e; ++i) {
|
||||
UserData *user = i.key();
|
||||
for_const (auto *user, _channel->mgInfo->bots) {
|
||||
if (!user->botInfo) continue;
|
||||
if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user);
|
||||
if (user->botInfo->commands.isEmpty()) continue;
|
||||
|
@ -216,8 +216,8 @@ namespace Notify {
|
||||
if (MainWidget *m = App::main()) {
|
||||
m->notify_handlePendingHistoryUpdate();
|
||||
}
|
||||
for (auto i = Global::PendingRepaintItems().cbegin(), e = Global::PendingRepaintItems().cend(); i != e; ++i) {
|
||||
Ui::repaintHistoryItem(i.key());
|
||||
for_const (HistoryItem *item, Global::PendingRepaintItems()) {
|
||||
Ui::repaintHistoryItem(item);
|
||||
}
|
||||
Global::RefPendingRepaintItems().clear();
|
||||
}
|
||||
|
@ -6090,7 +6090,11 @@ void HistoryMessageReply::resize(int width) const {
|
||||
|
||||
void HistoryMessageReply::itemRemoved(HistoryMessage *holder, HistoryItem *removed) {
|
||||
if (replyToMsg == removed) {
|
||||
clearData(holder);
|
||||
delete _replyToVia;
|
||||
_replyToVia = nullptr;
|
||||
|
||||
replyToMsg = nullptr;
|
||||
replyToMsgId = 0;
|
||||
holder->setPendingInitDimensions();
|
||||
}
|
||||
}
|
||||
|
@ -269,11 +269,11 @@ void ConfigLoader::enumDC() {
|
||||
dcs.insert(MTP::bareDcId(i.key()));
|
||||
}
|
||||
}
|
||||
OrderedSet<int32>::const_iterator i = dcs.constFind(_enumCurrent);
|
||||
auto i = dcs.constFind(_enumCurrent);
|
||||
if (i == dcs.cend() || (++i) == dcs.cend()) {
|
||||
_enumCurrent = dcs.cbegin().key();
|
||||
_enumCurrent = *dcs.cbegin();
|
||||
} else {
|
||||
_enumCurrent = i.key();
|
||||
_enumCurrent = *i;
|
||||
}
|
||||
_enumRequest = MTP::send(MTPhelp_GetConfig(), rpcDone(configLoaded), rpcFail(configFailed), MTP::cfgDcId(_enumCurrent));
|
||||
|
||||
|
@ -837,9 +837,9 @@ void finish() {
|
||||
sessions.clear();
|
||||
mainSession = nullptr;
|
||||
|
||||
for (MTPQuittingConnections::const_iterator i = quittingConnections.cbegin(), e = quittingConnections.cend(); i != e; ++i) {
|
||||
i.key()->waitTillFinish();
|
||||
delete i.key();
|
||||
for_const (internal::Connection *connection, quittingConnections) {
|
||||
connection->waitTillFinish();
|
||||
delete connection;
|
||||
}
|
||||
quittingConnections.clear();
|
||||
|
||||
|
@ -985,27 +985,27 @@ void WebLoadManager::process() {
|
||||
i.value() = 0;
|
||||
}
|
||||
}
|
||||
for (Loaders::iterator i = _loaders.begin(), e = _loaders.end(); i != e;) {
|
||||
LoaderPointers::iterator it = _loaderPointers.find(i.key()->_interface);
|
||||
if (it != _loaderPointers.cend() && it.key()->_private != i.key()) {
|
||||
for (auto i = _loaders.begin(), e = _loaders.end(); i != e;) {
|
||||
LoaderPointers::iterator it = _loaderPointers.find((*i)->_interface);
|
||||
if (it != _loaderPointers.cend() && it.key()->_private != (*i)) {
|
||||
it = _loaderPointers.end();
|
||||
}
|
||||
if (it == _loaderPointers.cend()) {
|
||||
if (QNetworkReply *reply = i.key()->reply()) {
|
||||
if (QNetworkReply *reply = (*i)->reply()) {
|
||||
_replies.remove(reply);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
delete i.key();
|
||||
delete (*i);
|
||||
i = _loaders.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Loaders::const_iterator i = newLoaders.cbegin(), e = newLoaders.cend(); i != e; ++i) {
|
||||
if (_loaders.contains(i.key())) {
|
||||
sendRequest(i.key());
|
||||
for_const (webFileLoaderPrivate *loader, newLoaders) {
|
||||
if (_loaders.contains(loader)) {
|
||||
sendRequest(loader);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1047,8 +1047,8 @@ void WebLoadManager::clear() {
|
||||
}
|
||||
_loaderPointers.clear();
|
||||
|
||||
for (Loaders::iterator i = _loaders.begin(), e = _loaders.end(); i != e; ++i) {
|
||||
delete i.key();
|
||||
for_const (webFileLoaderPrivate *loader, _loaders) {
|
||||
delete loader;
|
||||
}
|
||||
_loaders.clear();
|
||||
|
||||
|
@ -36,13 +36,126 @@ T *getPointerAndReset(T *&ptr) {
|
||||
struct NullType {
|
||||
};
|
||||
|
||||
// ordered set template based on QMap
|
||||
template <typename T>
|
||||
class OrderedSet : public QMap<T, NullType> {
|
||||
class OrderedSet {
|
||||
typedef OrderedSet<T> Self;
|
||||
typedef QMap<T, NullType> Impl;
|
||||
typedef typename Impl::iterator IteratorImpl;
|
||||
typedef typename Impl::const_iterator ConstIteratorImpl;
|
||||
Impl impl_;
|
||||
|
||||
public:
|
||||
|
||||
void insert(const T &v) {
|
||||
QMap<T, NullType>::insert(v, NullType());
|
||||
}
|
||||
inline bool operator==(const Self &other) const { return impl_ == other.impl_; }
|
||||
inline bool operator!=(const Self &other) const { return impl_ != other.impl_; }
|
||||
inline int size() const { return impl_.size(); }
|
||||
inline bool isEmpty() const { return impl_.isEmpty(); }
|
||||
inline void detach() { return impl_.detach(); }
|
||||
inline bool isDetached() const { return impl_.isDetached(); }
|
||||
inline void clear() { return impl_.clear(); }
|
||||
inline QList<T> values() const { return impl_.keys(); }
|
||||
inline const T &first() const { return impl_.firstKey(); }
|
||||
inline const T &last() const { return impl_.lastKey(); }
|
||||
|
||||
class const_iterator;
|
||||
class iterator {
|
||||
public:
|
||||
typedef typename IteratorImpl::iterator_category iterator_category;
|
||||
typedef typename IteratorImpl::difference_type difference_type;
|
||||
typedef T value_type;
|
||||
typedef T *pointer;
|
||||
typedef T &reference;
|
||||
|
||||
explicit iterator(const IteratorImpl &impl) : impl_(impl) {
|
||||
}
|
||||
inline const T &operator*() const { return impl_.key(); }
|
||||
inline const T *operator->() const { return &impl_.key(); }
|
||||
inline bool operator==(const iterator &other) const { return impl_ == other.impl_; }
|
||||
inline bool operator!=(const iterator &other) const { return impl_ != other.impl_; }
|
||||
inline iterator &operator++() { ++impl_; return *this; }
|
||||
inline iterator operator++(int) { return iterator(impl_++); }
|
||||
inline iterator &operator--() { --impl_; return *this; }
|
||||
inline iterator operator--(int) { return iterator(impl_--); }
|
||||
inline iterator operator+(int j) const { return iterator(impl_ + j); }
|
||||
inline iterator operator-(int j) const { return iterator(impl_ - j); }
|
||||
inline iterator &operator+=(int j) { impl_ += j; return *this; }
|
||||
inline iterator &operator-=(int j) { impl_ -= j; return *this; }
|
||||
|
||||
friend class const_iterator;
|
||||
inline bool operator==(const const_iterator &other) const { return impl_ == other.impl_; }
|
||||
inline bool operator!=(const const_iterator &other) const { return impl_ != other.impl_; }
|
||||
|
||||
private:
|
||||
IteratorImpl impl_;
|
||||
friend class Self;
|
||||
|
||||
};
|
||||
friend class iterator;
|
||||
|
||||
class const_iterator {
|
||||
public:
|
||||
typedef typename IteratorImpl::iterator_category iterator_category;
|
||||
typedef typename IteratorImpl::difference_type difference_type;
|
||||
typedef T value_type;
|
||||
typedef T *pointer;
|
||||
typedef T &reference;
|
||||
|
||||
explicit const_iterator(const ConstIteratorImpl &impl) : impl_(impl) {
|
||||
}
|
||||
inline const T &operator*() const { return impl_.key(); }
|
||||
inline const T *operator->() const { return &impl_.key(); }
|
||||
inline bool operator==(const const_iterator &other) const { return impl_ == other.impl_; }
|
||||
inline bool operator!=(const const_iterator &other) const { return impl_ != other.impl_; }
|
||||
inline const_iterator &operator++() { ++impl_; return *this; }
|
||||
inline const_iterator operator++(int) { return const_iterator(impl_++); }
|
||||
inline const_iterator &operator--() { --impl_; return *this; }
|
||||
inline const_iterator operator--(int) { return const_iterator(impl_--); }
|
||||
inline const_iterator operator+(int j) const { return const_iterator(impl_ + j); }
|
||||
inline const_iterator operator-(int j) const { return const_iterator(impl_ - j); }
|
||||
inline const_iterator &operator+=(int j) { impl_ += j; return *this; }
|
||||
inline const_iterator &operator-=(int j) { impl_ -= j; return *this; }
|
||||
|
||||
friend class iterator;
|
||||
inline bool operator==(const iterator &other) const { return impl_ == other.impl_; }
|
||||
inline bool operator!=(const iterator &o) const { return impl_ != other.impl_; }
|
||||
|
||||
private:
|
||||
ConstIteratorImpl impl_;
|
||||
friend class Self;
|
||||
|
||||
};
|
||||
friend class const_iterator;
|
||||
|
||||
// STL style
|
||||
inline iterator begin() { return iterator(impl_.begin()); }
|
||||
inline const_iterator begin() const { return const_iterator(impl_.cbegin()); }
|
||||
inline const_iterator constBegin() const { return const_iterator(impl_.cbegin()); }
|
||||
inline const_iterator cbegin() const { return const_iterator(impl_.cbegin()); }
|
||||
inline iterator end() { detach(); return iterator(impl_.end()); }
|
||||
inline const_iterator end() const { return const_iterator(impl_.cend()); }
|
||||
inline const_iterator constEnd() const { return const_iterator(impl_.cend()); }
|
||||
inline const_iterator cend() const { return const_iterator(impl_.cend()); }
|
||||
inline iterator erase(iterator it) { return iterator(impl_.erase(it.impl_)); }
|
||||
|
||||
inline iterator insert(const T &value) { return iterator(impl_.insert(value, NullType())); }
|
||||
inline iterator insert(const_iterator pos, const T &value) { return iterator(impl_.insert(pos.impl_, value, NullType())); }
|
||||
inline int remove(const T &value) { return impl_.remove(value); }
|
||||
inline bool contains(const T &value) const { return impl_.contains(value); }
|
||||
|
||||
// more Qt
|
||||
typedef iterator Iterator;
|
||||
typedef const_iterator ConstIterator;
|
||||
inline int count() const { return impl_.count(); }
|
||||
inline iterator find(const T &value) { return iterator(impl_.find(value)); }
|
||||
inline const_iterator find(const T &value) const { return const_iterator(impl_.constFind(value)); }
|
||||
inline const_iterator constFind(const T &value) const { return const_iterator(impl_.constFind(value)); }
|
||||
inline Self &unite(const Self &other) { impl_.unite(other.impl_); return *this; }
|
||||
|
||||
// STL compatibility
|
||||
typedef typename Impl::difference_type difference_type;
|
||||
typedef typename Impl::size_type size_type;
|
||||
inline bool empty() const { return impl_.empty(); }
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user