added username autocompletions with @

This commit is contained in:
fourtf 2018-05-14 17:28:00 +02:00
parent a0e33ef9e6
commit 454b6bcb70

View file

@ -92,23 +92,28 @@ void CompletionModel::addString(const QString &str, TaggedString::Type type)
this->emotes.insert({str + " ", type}); this->emotes.insert({str + " ", type});
} }
void CompletionModel::addUser(const QString &str) void CompletionModel::addUser(const QString &username)
{ {
auto ts = this->createUser(str + " "); auto add = [this](const QString &str) {
// Always add a space at the end of completions auto ts = this->createUser(str + " ");
std::pair<std::set<TaggedString>::iterator, bool> p = this->emotes.insert(ts); // Always add a space at the end of completions
if (!p.second) { std::pair<std::set<TaggedString>::iterator, bool> p = this->emotes.insert(ts);
// No inseration was made, figure out if we need to replace the username. if (!p.second) {
// No inseration was made, figure out if we need to replace the username.
if (p.first->str > ts.str) { if (p.first->str > ts.str) {
// Replace lowercase version of name with mixed-case version // Replace lowercase version of name with mixed-case version
this->emotes.erase(p.first); this->emotes.erase(p.first);
auto result2 = this->emotes.insert(ts); auto result2 = this->emotes.insert(ts);
assert(result2.second); assert(result2.second);
} else { } else {
p.first->timeAdded = std::chrono::steady_clock::now(); p.first->timeAdded = std::chrono::steady_clock::now();
}
} }
} };
add(username);
add("@" + username);
} }
void CompletionModel::ClearExpiredStrings() void CompletionModel::ClearExpiredStrings()