From 60a991bcb0ca258a8b2aaf8a610a304d6ca73f73 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 5 Apr 2019 15:17:34 +0400 Subject: [PATCH] Fix typing / send action updates handling. --- Telegram/SourceFiles/base/flat_map.h | 42 ++++++++++++++++++++++++ Telegram/SourceFiles/history/history.cpp | 4 +-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/base/flat_map.h b/Telegram/SourceFiles/base/flat_map.h index 8dec2225bf..2f80a72195 100644 --- a/Telegram/SourceFiles/base/flat_map.h +++ b/Telegram/SourceFiles/base/flat_map.h @@ -686,6 +686,40 @@ public: } return { where, false }; } + std::pair insert_or_assign( + const Key &key, + const Type &value) { + if (this->empty() || this->compare()(key, this->front().first)) { + this->impl().emplace_front(key, value); + return { this->begin(), true }; + } else if (this->compare()(this->back().first, key)) { + this->impl().emplace_back(key, value); + return { this->end() - 1, true }; + } + auto where = this->getLowerBound(key); + if (this->compare()(key, where->first)) { + return { this->impl().insert(where, value_type(key, value)), true }; + } + where->second = value; + return { where, false }; + } + std::pair insert_or_assign( + const Key &key, + Type &&value) { + if (this->empty() || this->compare()(key, this->front().first)) { + this->impl().emplace_front(key, std::move(value)); + return { this->begin(), true }; + } else if (this->compare()(this->back().first, key)) { + this->impl().emplace_back(key, std::move(value)); + return { this->end() - 1, true }; + } + auto where = this->getLowerBound(key); + if (this->compare()(key, where->first)) { + return { this->impl().insert(where, value_type(key, std::move(value))), true }; + } + where->second = std::move(value); + return { where, false }; + } template std::pair emplace( const Key &key, @@ -695,6 +729,14 @@ public: Type(std::forward(args)...))); } template + std::pair emplace_or_assign( + const Key &key, + Args&&... args) { + return this->insert_or_assign( + key, + Type(std::forward(args)...)); + } + template std::pair try_emplace( const Key &key, Args&&... args) { diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 98aeda2a28..ddec634d4a 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -358,10 +358,10 @@ bool History::updateSendActionNeedsAnimating( Type type, crl::time duration, int progress = 0) { - _sendActions.emplace(user, type, now + duration, progress); + _sendActions.emplace_or_assign(user, type, now + duration, progress); }; action.match([&](const MTPDsendMessageTypingAction &) { - _typing.emplace(user, now + kStatusShowClientsideTyping); + _typing.emplace_or_assign(user, now + kStatusShowClientsideTyping); }, [&](const MTPDsendMessageRecordVideoAction &) { emplaceAction(Type::RecordVideo, kStatusShowClientsideRecordVideo); }, [&](const MTPDsendMessageRecordAudioAction &) {