expire non-recent chatters

This commit is contained in:
Rasmus Karlsson
2018-03-30 13:50:43 +02:00
parent d4f37f786b
commit 89d7b7db87
4 changed files with 91 additions and 24 deletions
+21 -2
View File
@@ -81,12 +81,13 @@ void CompletionModel::refresh()
void CompletionModel::addString(const std::string &str, TaggedString::Type type)
{
// Always add a space at the end of completions
this->emotes.insert({qS(str + " "), type});
this->addString(qS(str), type);
}
void CompletionModel::addString(const QString &str, TaggedString::Type type)
{
std::lock_guard<std::mutex> lock(this->emotesMutex);
// Always add a space at the end of completions
this->emotes.insert({str + " ", type});
}
@@ -108,4 +109,22 @@ void CompletionModel::addUser(const QString &str)
}
}
void CompletionModel::ClearExpiredStrings()
{
std::lock_guard<std::mutex> lock(this->emotesMutex);
auto now = std::chrono::steady_clock::now();
for (auto it = this->emotes.begin(); it != this->emotes.end();) {
const auto &taggedString = *it;
if (taggedString.HasExpired(now)) {
// debug::Log("String {} expired", taggedString.str);
it = this->emotes.erase(it);
} else {
++it;
}
}
}
} // namespace chatterino