Fix typing / send action updates handling.

This commit is contained in:
John Preston 2019-04-05 15:17:34 +04:00
parent d3c5ed08ab
commit 60a991bcb0
2 changed files with 44 additions and 2 deletions

View File

@ -686,6 +686,40 @@ public:
}
return { where, false };
}
std::pair<iterator, bool> 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<iterator, bool> 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 <typename... Args>
std::pair<iterator, bool> emplace(
const Key &key,
@ -695,6 +729,14 @@ public:
Type(std::forward<Args>(args)...)));
}
template <typename... Args>
std::pair<iterator, bool> emplace_or_assign(
const Key &key,
Args&&... args) {
return this->insert_or_assign(
key,
Type(std::forward<Args>(args)...));
}
template <typename... Args>
std::pair<iterator, bool> try_emplace(
const Key &key,
Args&&... args) {

View File

@ -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 &) {