No longer add username to the completion model in privateMessageReceived

The username is added to the completion model with the
"addRecentChatter" method instead

Moved "NameOptions" stuff from base class Channel to TwitchChannel where
it belongs

Remove unused Channel::getUsernamesForCompletions method
This commit is contained in:
Rasmus Karlsson 2018-03-30 12:16:12 +02:00
parent f567f10d10
commit 95878dc7db
5 changed files with 25 additions and 38 deletions

View file

@ -79,25 +79,7 @@ void Channel::replaceMessage(messages::MessagePtr message, messages::MessagePtr
void Channel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
{
assert(!message->loginName.isEmpty());
std::lock_guard<std::mutex> lock(this->recentChattersMutex);
this->recentChatters[message->loginName] = {message->displayName, message->localizedName};
}
std::vector<Channel::NameOptions> Channel::getUsernamesForCompletions()
{
std::vector<NameOptions> names;
this->recentChattersMutex.lock();
for (const auto &p : this->recentChatters) {
names.push_back(p.second);
}
// usernames.insert(this->recentChatters.begin(), this->recentChatters.end());
this->recentChattersMutex.unlock();
return names;
// Do nothing by default
}
bool Channel::canSendMessage() const
@ -118,4 +100,5 @@ std::shared_ptr<Channel> Channel::getEmpty()
void Channel::onConnected()
{
}
} // namespace chatterino

View file

@ -6,14 +6,10 @@
#include "util/completionmodel.hpp"
#include "util/concurrentmap.hpp"
#include <QMap>
#include <QMutex>
#include <QString>
#include <QVector>
#include <boost/signals2.hpp>
#include <memory>
#include <set>
namespace chatterino {
namespace messages {
@ -40,22 +36,11 @@ public:
void addMessage(messages::MessagePtr message);
void addMessagesAtStart(std::vector<messages::MessagePtr> &messages);
void replaceMessage(messages::MessagePtr message, messages::MessagePtr replacement);
void addRecentChatter(const std::shared_ptr<messages::Message> &message);
struct NameOptions {
QString displayName;
QString localizedName;
};
std::vector<NameOptions> getUsernamesForCompletions();
virtual void addRecentChatter(const std::shared_ptr<messages::Message> &message);
QString name;
QStringList modList;
// Key = login name
std::map<QString, NameOptions> recentChatters;
std::mutex recentChattersMutex;
virtual bool canSendMessage() const;
virtual void sendMessage(const QString &message);
virtual bool isMod() const

View file

@ -163,6 +163,17 @@ bool TwitchChannel::hasModRights()
return this->isMod() || this->isBroadcaster();
}
void TwitchChannel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
{
assert(!message->loginName.isEmpty());
std::lock_guard<std::mutex> lock(this->recentChattersMutex);
this->recentChatters[message->loginName] = {message->displayName, message->localizedName};
this->completionModel.addUser(message->displayName);
}
void TwitchChannel::setLive(bool newLiveStatus)
{
if (this->isLive == newLiveStatus) {

View file

@ -33,6 +33,8 @@ public:
bool isBroadcaster();
bool hasModRights();
void addRecentChatter(const std::shared_ptr<messages::Message> &message) final;
const std::shared_ptr<chatterino::util::EmoteMap> bttvChannelEmotes;
const std::shared_ptr<chatterino::util::EmoteMap> ffzChannelEmotes;
@ -54,6 +56,11 @@ public:
QString streamGame;
QString streamUptime;
struct NameOptions {
QString displayName;
QString localizedName;
};
private:
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
@ -71,6 +78,10 @@ private:
Communi::IrcConnection *readConnecetion;
friend class TwitchServer;
// Key = login name
std::map<QString, NameOptions> recentChatters;
std::mutex recentChattersMutex;
};
} // namespace twitch

View file

@ -90,9 +90,6 @@ void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
TwitchMessageBuilder builder(chan.get(), message, args);
// XXX: Thread-safety
chan->completionModel.addUser(message->nick());
if (!builder.isIgnored()) {
messages::MessagePtr _message = builder.build();
if (_message->flags & messages::Message::Highlighted) {