From c7a86f8abed3218b6b904159b67ed235b5ef43f2 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 30 Mar 2018 12:16:12 +0200 Subject: [PATCH] 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 --- src/channel.cpp | 21 ++------------------- src/channel.hpp | 17 +---------------- src/providers/twitch/twitchchannel.cpp | 11 +++++++++++ src/providers/twitch/twitchchannel.hpp | 11 +++++++++++ src/providers/twitch/twitchserver.cpp | 3 --- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 08265f395..3e214bb34 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -79,25 +79,7 @@ void Channel::replaceMessage(messages::MessagePtr message, messages::MessagePtr void Channel::addRecentChatter(const std::shared_ptr &message) { - assert(!message->loginName.isEmpty()); - - std::lock_guard lock(this->recentChattersMutex); - - this->recentChatters[message->loginName] = {message->displayName, message->localizedName}; -} - -std::vector Channel::getUsernamesForCompletions() -{ - std::vector 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::getEmpty() void Channel::onConnected() { } + } // namespace chatterino diff --git a/src/channel.hpp b/src/channel.hpp index bd653aee6..940f0d907 100644 --- a/src/channel.hpp +++ b/src/channel.hpp @@ -6,14 +6,10 @@ #include "util/completionmodel.hpp" #include "util/concurrentmap.hpp" -#include -#include #include -#include #include #include -#include namespace chatterino { namespace messages { @@ -40,22 +36,11 @@ public: void addMessage(messages::MessagePtr message); void addMessagesAtStart(std::vector &messages); void replaceMessage(messages::MessagePtr message, messages::MessagePtr replacement); - void addRecentChatter(const std::shared_ptr &message); - - struct NameOptions { - QString displayName; - QString localizedName; - }; - - std::vector getUsernamesForCompletions(); + virtual void addRecentChatter(const std::shared_ptr &message); QString name; QStringList modList; - // Key = login name - std::map recentChatters; - std::mutex recentChattersMutex; - virtual bool canSendMessage() const; virtual void sendMessage(const QString &message); virtual bool isMod() const diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index adb7cfe32..049566a33 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -163,6 +163,17 @@ bool TwitchChannel::hasModRights() return this->isMod() || this->isBroadcaster(); } +void TwitchChannel::addRecentChatter(const std::shared_ptr &message) +{ + assert(!message->loginName.isEmpty()); + + std::lock_guard 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) { diff --git a/src/providers/twitch/twitchchannel.hpp b/src/providers/twitch/twitchchannel.hpp index c0aba110b..26763bb99 100644 --- a/src/providers/twitch/twitchchannel.hpp +++ b/src/providers/twitch/twitchchannel.hpp @@ -33,6 +33,8 @@ public: bool isBroadcaster(); bool hasModRights(); + void addRecentChatter(const std::shared_ptr &message) final; + const std::shared_ptr bttvChannelEmotes; const std::shared_ptr 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 recentChatters; + std::mutex recentChattersMutex; }; } // namespace twitch diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index 5dfbc9465..ddff5b554 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -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) {