mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
add simple username tabbing for recent chatters
This commit is contained in:
parent
5839b9f522
commit
e41c855545
6 changed files with 63 additions and 9 deletions
|
@ -38,6 +38,13 @@ void Channel::addMessage(std::shared_ptr<Message> message)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Message> deleted;
|
std::shared_ptr<Message> deleted;
|
||||||
|
|
||||||
|
const QString &username = message->username;
|
||||||
|
|
||||||
|
if (!username.isEmpty()) {
|
||||||
|
// TODO: Add recent chatters display name. This should maybe be a setting
|
||||||
|
this->addRecentChatter(username);
|
||||||
|
}
|
||||||
|
|
||||||
// if (_loggingChannel.get() != nullptr) {
|
// if (_loggingChannel.get() != nullptr) {
|
||||||
// _loggingChannel->append(message);
|
// _loggingChannel->append(message);
|
||||||
// }
|
// }
|
||||||
|
@ -49,6 +56,24 @@ void Channel::addMessage(std::shared_ptr<Message> message)
|
||||||
this->messageAppended(message);
|
this->messageAppended(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Channel::addRecentChatter(const QString &username)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->recentChattersMutex);
|
||||||
|
|
||||||
|
this->recentChatters.insert(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<QString> Channel::getUsernamesForCompletions()
|
||||||
|
{
|
||||||
|
std::set<QString> usernames;
|
||||||
|
|
||||||
|
this->recentChattersMutex.lock();
|
||||||
|
usernames.insert(this->recentChatters.begin(), this->recentChatters.end());
|
||||||
|
this->recentChattersMutex.unlock();
|
||||||
|
|
||||||
|
return usernames;
|
||||||
|
}
|
||||||
|
|
||||||
bool Channel::canSendMessage() const
|
bool Channel::canSendMessage() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <boost/signals2.hpp>
|
#include <boost/signals2.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace messages {
|
namespace messages {
|
||||||
|
@ -30,16 +31,21 @@ public:
|
||||||
virtual bool isEmpty() const;
|
virtual bool isEmpty() const;
|
||||||
messages::LimitedQueueSnapshot<messages::SharedMessage> getMessageSnapshot();
|
messages::LimitedQueueSnapshot<messages::SharedMessage> getMessageSnapshot();
|
||||||
|
|
||||||
// methods
|
|
||||||
void addMessage(messages::SharedMessage message);
|
void addMessage(messages::SharedMessage message);
|
||||||
|
void addRecentChatter(const QString &username);
|
||||||
|
|
||||||
|
std::set<QString> getUsernamesForCompletions();
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
QStringList modList;
|
QStringList modList;
|
||||||
|
|
||||||
|
std::mutex recentChattersMutex;
|
||||||
|
std::set<QString> recentChatters;
|
||||||
|
|
||||||
virtual bool canSendMessage() const;
|
virtual bool canSendMessage() const;
|
||||||
virtual void sendMessage(const QString &message);
|
virtual void sendMessage(const QString &message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// variables
|
|
||||||
messages::LimitedQueue<messages::SharedMessage> messages;
|
messages::LimitedQueue<messages::SharedMessage> messages;
|
||||||
|
|
||||||
// std::shared_ptr<logging::Channel> loggingChannel;
|
// std::shared_ptr<logging::Channel> loggingChannel;
|
||||||
|
|
|
@ -5,6 +5,8 @@ using namespace chatterino::twitch;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
ChannelManager *ChannelManager::instance = nullptr;
|
||||||
|
|
||||||
ChannelManager::ChannelManager(WindowManager &_windowManager, IrcManager &_ircManager)
|
ChannelManager::ChannelManager(WindowManager &_windowManager, IrcManager &_ircManager)
|
||||||
: windowManager(_windowManager)
|
: windowManager(_windowManager)
|
||||||
, ircManager(_ircManager)
|
, ircManager(_ircManager)
|
||||||
|
@ -12,6 +14,7 @@ ChannelManager::ChannelManager(WindowManager &_windowManager, IrcManager &_ircMa
|
||||||
, mentionsChannel(new TwitchChannel(_ircManager, "/mentions", true))
|
, mentionsChannel(new TwitchChannel(_ircManager, "/mentions", true))
|
||||||
, emptyChannel(new TwitchChannel(_ircManager, "", true))
|
, emptyChannel(new TwitchChannel(_ircManager, "", true))
|
||||||
{
|
{
|
||||||
|
ChannelManager::instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<Channel>> ChannelManager::getItems()
|
const std::vector<std::shared_ptr<Channel>> ChannelManager::getItems()
|
||||||
|
|
|
@ -16,6 +16,8 @@ class ChannelManager
|
||||||
public:
|
public:
|
||||||
explicit ChannelManager(WindowManager &_windowManager, IrcManager &_ircManager);
|
explicit ChannelManager(WindowManager &_windowManager, IrcManager &_ircManager);
|
||||||
|
|
||||||
|
static ChannelManager *instance;
|
||||||
|
|
||||||
WindowManager &windowManager;
|
WindowManager &windowManager;
|
||||||
IrcManager &ircManager;
|
IrcManager &ircManager;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "completionmanager.hpp"
|
#include "completionmanager.hpp"
|
||||||
|
#include "channelmanager.hpp"
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "debug/log.hpp"
|
#include "debug/log.hpp"
|
||||||
#include "emotemanager.hpp"
|
#include "emotemanager.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
CompletionModel::CompletionModel(const std::string &_channelName)
|
CompletionModel::CompletionModel(const QString &_channelName)
|
||||||
: channelName(_channelName)
|
: channelName(_channelName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -39,14 +40,14 @@ void CompletionModel::refresh()
|
||||||
|
|
||||||
// Channel-specific: BTTV Channel Emotes
|
// Channel-specific: BTTV Channel Emotes
|
||||||
std::vector<std::string> &bttvChannelEmoteCodes =
|
std::vector<std::string> &bttvChannelEmoteCodes =
|
||||||
emoteManager.bttvChannelEmoteCodes[this->channelName];
|
emoteManager.bttvChannelEmoteCodes[this->channelName.toStdString()];
|
||||||
for (const auto &m : bttvChannelEmoteCodes) {
|
for (const auto &m : bttvChannelEmoteCodes) {
|
||||||
this->addString(m);
|
this->addString(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Channel-specific: FFZ Channel Emotes
|
// Channel-specific: FFZ Channel Emotes
|
||||||
std::vector<std::string> &ffzChannelEmoteCodes =
|
std::vector<std::string> &ffzChannelEmoteCodes =
|
||||||
emoteManager.ffzChannelEmoteCodes[this->channelName];
|
emoteManager.ffzChannelEmoteCodes[this->channelName.toStdString()];
|
||||||
for (const auto &m : ffzChannelEmoteCodes) {
|
for (const auto &m : ffzChannelEmoteCodes) {
|
||||||
this->addString(m);
|
this->addString(m);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +58,17 @@ void CompletionModel::refresh()
|
||||||
this->addString(":" + m + ":");
|
this->addString(":" + m + ":");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add Channel-specific: Usernames
|
// Channel-specific: Usernames
|
||||||
|
auto *channelManager = ChannelManager::instance;
|
||||||
|
auto c = channelManager->getTwitchChannel(this->channelName);
|
||||||
|
if (!c) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto usernames = c->getUsernamesForCompletions();
|
||||||
|
for (const auto &username : usernames) {
|
||||||
|
this->addString(username);
|
||||||
|
this->addString('@' + username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompletionModel::addString(const std::string &str)
|
void CompletionModel::addString(const std::string &str)
|
||||||
|
@ -66,6 +77,12 @@ void CompletionModel::addString(const std::string &str)
|
||||||
this->emotes.push_back(qS(str) + " ");
|
this->emotes.push_back(qS(str) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompletionModel::addString(const QString &str)
|
||||||
|
{
|
||||||
|
// Always add a space at the end of completions
|
||||||
|
this->emotes.push_back(str + " ");
|
||||||
|
}
|
||||||
|
|
||||||
CompletionModel *CompletionManager::createModel(const std::string &channelName)
|
CompletionModel *CompletionManager::createModel(const std::string &channelName)
|
||||||
{
|
{
|
||||||
auto it = this->models.find(channelName);
|
auto it = this->models.find(channelName);
|
||||||
|
@ -73,7 +90,7 @@ CompletionModel *CompletionManager::createModel(const std::string &channelName)
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionModel *ret = new CompletionModel(channelName);
|
CompletionModel *ret = new CompletionModel(qS(channelName));
|
||||||
this->models[channelName] = ret;
|
this->models[channelName] = ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace chatterino {
|
||||||
class CompletionModel : public QAbstractListModel
|
class CompletionModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompletionModel(const std::string &_channelName);
|
CompletionModel(const QString &_channelName);
|
||||||
|
|
||||||
virtual int columnCount(const QModelIndex & /*parent*/) const override
|
virtual int columnCount(const QModelIndex & /*parent*/) const override
|
||||||
{
|
{
|
||||||
|
@ -33,10 +33,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addString(const std::string &str);
|
void addString(const std::string &str);
|
||||||
|
void addString(const QString &str);
|
||||||
|
|
||||||
QVector<QString> emotes;
|
QVector<QString> emotes;
|
||||||
|
|
||||||
std::string channelName;
|
QString channelName;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompletionManager
|
class CompletionManager
|
||||||
|
|
Loading…
Reference in a new issue