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) void Channel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
{ {
assert(!message->loginName.isEmpty()); // Do nothing by default
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;
} }
bool Channel::canSendMessage() const bool Channel::canSendMessage() const
@ -118,4 +100,5 @@ std::shared_ptr<Channel> Channel::getEmpty()
void Channel::onConnected() void Channel::onConnected()
{ {
} }
} // namespace chatterino } // namespace chatterino

View file

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

View file

@ -163,6 +163,17 @@ bool TwitchChannel::hasModRights()
return this->isMod() || this->isBroadcaster(); 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) void TwitchChannel::setLive(bool newLiveStatus)
{ {
if (this->isLive == newLiveStatus) { if (this->isLive == newLiveStatus) {

View file

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

View file

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