We now also add localized names to the autocompletion

Changed the login name in autocompletion to the display name
Autocompletion model is now only updated on the "first completion"
This commit is contained in:
Rasmus Karlsson 2017-12-17 21:05:25 +01:00
parent 6f1509cb4f
commit 03958420be
9 changed files with 45 additions and 28 deletions

View file

@ -38,11 +38,11 @@ void Channel::addMessage(std::shared_ptr<Message> message)
{
std::shared_ptr<Message> deleted;
const QString &username = message->username;
const QString &username = message->loginName;
if (!username.isEmpty()) {
// TODO: Add recent chatters display name. This should maybe be a setting
this->addRecentChatter(username);
this->addRecentChatter(message);
}
// if (_loggingChannel.get() != nullptr) {
@ -56,22 +56,27 @@ void Channel::addMessage(std::shared_ptr<Message> message)
this->messageAppended(message);
}
void Channel::addRecentChatter(const QString &username)
void Channel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
{
assert(!message->loginName.isEmpty());
std::lock_guard<std::mutex> lock(this->recentChattersMutex);
this->recentChatters.insert(username);
this->recentChatters[message->loginName] = {message->displayName, message->localizedName};
}
std::set<QString> Channel::getUsernamesForCompletions()
std::vector<Channel::NameOptions> Channel::getUsernamesForCompletions()
{
std::set<QString> usernames;
std::vector<NameOptions> names;
this->recentChattersMutex.lock();
usernames.insert(this->recentChatters.begin(), this->recentChatters.end());
for (const auto &p : this->recentChatters) {
names.push_back(p.second);
}
// usernames.insert(this->recentChatters.begin(), this->recentChatters.end());
this->recentChattersMutex.unlock();
return usernames;
return names;
}
bool Channel::canSendMessage() const

View file

@ -32,15 +32,21 @@ public:
messages::LimitedQueueSnapshot<messages::SharedMessage> getMessageSnapshot();
void addMessage(messages::SharedMessage message);
void addRecentChatter(const QString &username);
void addRecentChatter(const std::shared_ptr<messages::Message> &message);
std::set<QString> getUsernamesForCompletions();
struct NameOptions {
QString displayName;
QString localizedName;
};
std::vector<NameOptions> getUsernamesForCompletions();
QString name;
QStringList modList;
// Key = login name
std::map<QString, NameOptions> recentChatters;
std::mutex recentChattersMutex;
std::set<QString> recentChatters;
virtual bool canSendMessage() const;
virtual void sendMessage(const QString &message);

View file

@ -65,9 +65,15 @@ void CompletionModel::refresh()
return;
}
auto usernames = c->getUsernamesForCompletions();
for (const auto &username : usernames) {
this->addString(username);
this->addString('@' + username);
for (const auto &name : usernames) {
assert(!name.displayName.isEmpty());
this->addString(name.displayName);
this->addString('@' + name.displayName);
if (!name.localizedName.isEmpty()) {
this->addString(name.localizedName);
this->addString('@' + name.localizedName);
}
}
}

View file

@ -13,18 +13,18 @@ class CompletionModel : public QAbstractListModel
public:
CompletionModel(const QString &_channelName);
virtual int columnCount(const QModelIndex & /*parent*/) const override
virtual int columnCount(const QModelIndex &) const override
{
return 1;
}
virtual QVariant data(const QModelIndex &index, int role) const override
virtual QVariant data(const QModelIndex &index, int) const override
{
// TODO: Implement more safely
return QVariant(this->emotes.at(index.row()));
}
virtual int rowCount(const QModelIndex &parent) const override
virtual int rowCount(const QModelIndex &) const override
{
return this->emotes.size();
}

View file

@ -37,7 +37,7 @@ void Channel::append(std::shared_ptr<messages::Message> message)
str.append('[');
str.append(now.toString("HH:mm:ss"));
str.append("] ");
str.append(message->username);
str.append(message->loginName);
str.append(": ");
str.append(message->getContent());
str.append('\n');

View file

@ -36,11 +36,6 @@ int Message::getTimeoutCount() const
return this->timeoutCount;
}
const QString &Message::getDisplayName() const
{
return this->displayName;
}
const QString &Message::getContent() const
{
return this->content;

View file

@ -22,14 +22,15 @@ public:
void setHighlight(bool value);
const QString &getTimeoutUser() const;
int getTimeoutCount() const;
const QString &getDisplayName() const;
const QString &getContent() const;
const std::chrono::time_point<std::chrono::system_clock> &getParseTime() const;
std::vector<Word> &getWords();
bool isDisabled() const;
const QString &getId() const;
QString username;
QString loginName;
QString displayName;
QString localizedName;
const QString text;
bool centered = false;
@ -58,7 +59,6 @@ private:
bool disabled = false;
std::chrono::time_point<std::chrono::system_clock> parseTime;
QString displayName = "";
QString content;
QString id = "";

View file

@ -288,7 +288,7 @@ void TwitchMessageBuilder::parseUsername()
this->userName = this->tags.value(QLatin1String("login")).toString();
}
this->message->username = this->userName;
this->message->loginName = this->userName;
}
void TwitchMessageBuilder::appendUsername()
@ -302,8 +302,13 @@ void TwitchMessageBuilder::appendUsername()
if (QString::compare(displayName, this->userName, Qt::CaseInsensitive) == 0) {
username = displayName;
this->message->displayName = displayName;
} else {
localizedName = displayName;
this->message->displayName = username;
this->message->localizedName = displayName;
}
}

View file

@ -89,9 +89,9 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
auto *completionModel =
static_cast<chatterino::CompletionModel *>(this->completer->model());
completionModel->refresh();
if (!this->nextCompletion) {
completionModel->refresh();
// first selection
this->completer->setCompletionPrefix(currentCompletionPrefix);
this->nextCompletion = true;