Merge branch 'master' of https://github.com/fourtf/chatterino2
This commit is contained in:
@@ -97,20 +97,16 @@ void AbstractIrcServer::writeConnectionMessageReceived(Communi::IrcMessage *mess
|
||||
|
||||
std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &channelName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
// value exists
|
||||
auto it = this->channels.find(channelName);
|
||||
if (it != this->channels.end()) {
|
||||
std::shared_ptr<Channel> chan = it.value().lock();
|
||||
|
||||
if (chan) {
|
||||
return chan;
|
||||
}
|
||||
// try get channel
|
||||
ChannelPtr chan = this->getChannel(channelName);
|
||||
if (chan != Channel::getEmpty()) {
|
||||
return chan;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
// value doesn't exist
|
||||
std::shared_ptr<Channel> chan = this->createChannel(channelName);
|
||||
chan = this->createChannel(channelName);
|
||||
if (!chan) {
|
||||
return Channel::getEmpty();
|
||||
}
|
||||
@@ -119,7 +115,7 @@ std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &channelNam
|
||||
|
||||
this->channels.insert(channelName, chan);
|
||||
chan->destroyed.connect([this, clojuresInCppAreShit] {
|
||||
// fourtf: issues when the server itself in destroyed
|
||||
// fourtf: issues when the server itself is destroyed
|
||||
|
||||
debug::Log("[AbstractIrcServer::addChannel] {} was destroyed", clojuresInCppAreShit);
|
||||
this->channels.remove(clojuresInCppAreShit);
|
||||
@@ -128,6 +124,7 @@ std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &channelNam
|
||||
// join irc channel
|
||||
{
|
||||
std::lock_guard<std::mutex> lock2(this->connectionMutex);
|
||||
|
||||
if (this->readConnection) {
|
||||
this->readConnection->sendRaw("JOIN #" + channelName);
|
||||
}
|
||||
@@ -144,10 +141,16 @@ std::shared_ptr<Channel> AbstractIrcServer::getChannel(const QString &channelNam
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
// try get special channel
|
||||
ChannelPtr chan = this->getCustomChannel(channelName);
|
||||
if (chan) {
|
||||
return chan;
|
||||
}
|
||||
|
||||
// value exists
|
||||
auto it = this->channels.find(channelName);
|
||||
if (it != this->channels.end()) {
|
||||
std::shared_ptr<Channel> chan = it.value().lock();
|
||||
chan = it.value().lock();
|
||||
|
||||
if (chan) {
|
||||
return chan;
|
||||
@@ -221,6 +224,20 @@ void AbstractIrcServer::privateMessageReceived(Communi::IrcPrivateMessage *messa
|
||||
void AbstractIrcServer::messageReceived(Communi::IrcMessage *message)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractIrcServer::forEachChannel(std::function<void(ChannelPtr)> func)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
for (std::weak_ptr<Channel> &weak : this->channels.values()) {
|
||||
std::shared_ptr<Channel> chan = weak.lock();
|
||||
if (!chan) {
|
||||
continue;
|
||||
}
|
||||
|
||||
func(chan);
|
||||
}
|
||||
}
|
||||
} // namespace irc
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <IrcMessage>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
@@ -31,6 +32,9 @@ public:
|
||||
|
||||
void addFakeMessage(const QString &data);
|
||||
|
||||
// iteration
|
||||
void forEachChannel(std::function<void(ChannelPtr)> func);
|
||||
|
||||
protected:
|
||||
AbstractIrcServer();
|
||||
|
||||
@@ -47,16 +51,16 @@ protected:
|
||||
|
||||
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelName);
|
||||
|
||||
QMap<QString, std::weak_ptr<Channel>> channels;
|
||||
std::mutex channelMutex;
|
||||
|
||||
private:
|
||||
void initConnection();
|
||||
|
||||
QMap<QString, std::weak_ptr<Channel>> channels;
|
||||
|
||||
std::unique_ptr<Communi::IrcConnection> writeConnection = nullptr;
|
||||
std::unique_ptr<Communi::IrcConnection> readConnection = nullptr;
|
||||
|
||||
std::mutex connectionMutex;
|
||||
std::mutex channelMutex;
|
||||
};
|
||||
} // namespace irc
|
||||
} // namespace providers
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include "messages/limitedqueue.hpp"
|
||||
#include "messages/message.hpp"
|
||||
#include "providers/twitch/twitchchannel.hpp"
|
||||
//#include "singletons/channelmanager.hpp"
|
||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||
#include "providers/twitch/twitchserver.hpp"
|
||||
#include "singletons/resourcemanager.hpp"
|
||||
#include "singletons/windowmanager.hpp"
|
||||
#include "twitchserver.hpp"
|
||||
|
||||
using namespace chatterino::singletons;
|
||||
using namespace chatterino::messages;
|
||||
@@ -149,7 +149,29 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
||||
|
||||
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// TODO: Implement
|
||||
debug::Log("Received whisper!");
|
||||
messages::MessageParseArgs args;
|
||||
|
||||
args.isReceivedWhisper = true;
|
||||
|
||||
auto c = TwitchServer::getInstance().whispersChannel.get();
|
||||
|
||||
twitch::TwitchMessageBuilder builder(c, message, message->parameter(1), args);
|
||||
|
||||
if (!builder.isIgnored()) {
|
||||
messages::MessagePtr _message = builder.build();
|
||||
if (_message->flags & messages::Message::Highlighted) {
|
||||
TwitchServer::getInstance().mentionsChannel->addMessage(_message);
|
||||
}
|
||||
|
||||
c->addMessage(_message);
|
||||
|
||||
if (SettingManager::getInstance().inlineWhispers) {
|
||||
TwitchServer::getInstance().forEachChannel([_message](ChannelPtr channel) {
|
||||
channel->addMessage(_message); //
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message)
|
||||
@@ -177,9 +199,9 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||
|
||||
if (broadcast) {
|
||||
// fourtf: send to all twitch channels
|
||||
// this->channelManager.doOnAll([msg](const auto &c) {
|
||||
// c->addMessage(msg); //
|
||||
// });
|
||||
TwitchServer::getInstance().forEachChannelAndSpecialChannels([msg](const auto &c) {
|
||||
c->addMessage(msg); //
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -27,6 +28,8 @@ public:
|
||||
|
||||
bool isAnon() const;
|
||||
|
||||
QColor color;
|
||||
|
||||
private:
|
||||
QString oauthClient;
|
||||
QString oauthToken;
|
||||
|
||||
@@ -249,6 +249,7 @@ void TwitchChannel::fetchRecentMessages()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "providers/twitch/twitchchannel.hpp"
|
||||
#include "singletons/accountmanager.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
#include "singletons/ircmanager.hpp"
|
||||
#include "singletons/resourcemanager.hpp"
|
||||
@@ -27,8 +28,22 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||
, args(_args)
|
||||
, tags(this->ircMessage->tags())
|
||||
, usernameColor(singletons::ThemeManager::getInstance().messages.textColors.system)
|
||||
, originalMessage(_ircMessage->content())
|
||||
, action(_ircMessage->isAction())
|
||||
{
|
||||
}
|
||||
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||
const Communi::IrcMessage *_ircMessage, QString content,
|
||||
const messages::MessageParseArgs &_args)
|
||||
: channel(_channel)
|
||||
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
||||
, ircMessage(_ircMessage)
|
||||
, args(_args)
|
||||
, tags(this->ircMessage->tags())
|
||||
, usernameColor(singletons::ThemeManager::getInstance().messages.textColors.system)
|
||||
, originalMessage(content)
|
||||
{
|
||||
this->originalMessage = this->ircMessage->content();
|
||||
}
|
||||
|
||||
bool TwitchMessageBuilder::isIgnored() const
|
||||
@@ -125,8 +140,8 @@ MessagePtr TwitchMessageBuilder::build()
|
||||
long int i = 0;
|
||||
|
||||
for (QString split : splits) {
|
||||
MessageColor textColor = ircMessage->isAction() ? MessageColor(this->usernameColor)
|
||||
: MessageColor(MessageColor::Text);
|
||||
MessageColor textColor =
|
||||
this->action ? MessageColor(this->usernameColor) : MessageColor(MessageColor::Text);
|
||||
|
||||
// twitch emote
|
||||
if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) {
|
||||
@@ -244,7 +259,7 @@ void TwitchMessageBuilder::parseUsername()
|
||||
}
|
||||
|
||||
// username
|
||||
this->userName = ircMessage->nick();
|
||||
this->userName = this->ircMessage->nick();
|
||||
|
||||
if (this->userName.isEmpty()) {
|
||||
this->userName = this->tags.value(QLatin1String("login")).toString();
|
||||
@@ -309,20 +324,36 @@ void TwitchMessageBuilder::appendUsername()
|
||||
if (this->args.isSentWhisper) {
|
||||
// TODO(pajlada): Re-implement
|
||||
// userDisplayString += IrcManager::getInstance().getUser().getUserName();
|
||||
}
|
||||
} else if (this->args.isReceivedWhisper) {
|
||||
// Sender username
|
||||
this->emplace<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
||||
FontStyle::MediumBold)
|
||||
->setLink({Link::UserInfo, this->userName});
|
||||
|
||||
if (this->args.isReceivedWhisper) {
|
||||
// TODO(pajlada): Re-implement
|
||||
// userDisplayString += " -> " + IrcManager::getInstance().getUser().getUserName();
|
||||
}
|
||||
auto currentUser = singletons::AccountManager::getInstance().Twitch.getCurrent();
|
||||
|
||||
if (!ircMessage->isAction()) {
|
||||
usernameText += ":";
|
||||
}
|
||||
// Separator
|
||||
this->emplace<TextElement>(
|
||||
"->", MessageElement::Text,
|
||||
singletons::ThemeManager::getInstance().messages.textColors.system, FontStyle::Medium);
|
||||
|
||||
this->emplace<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
||||
FontStyle::MediumBold)
|
||||
->setLink({Link::UserInfo, this->userName});
|
||||
QColor selfColor = currentUser->color;
|
||||
if (!selfColor.isValid()) {
|
||||
selfColor = singletons::ThemeManager::getInstance().messages.textColors.system;
|
||||
}
|
||||
|
||||
// Your own username
|
||||
this->emplace<TextElement>(currentUser->getUserName() + ":", MessageElement::Text,
|
||||
selfColor, FontStyle::MediumBold);
|
||||
} else {
|
||||
if (!this->action) {
|
||||
usernameText += ":";
|
||||
}
|
||||
|
||||
this->emplace<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
||||
FontStyle::MediumBold)
|
||||
->setLink({Link::UserInfo, this->userName});
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::parseHighlights()
|
||||
@@ -330,11 +361,12 @@ void TwitchMessageBuilder::parseHighlights()
|
||||
static auto player = new QMediaPlayer;
|
||||
static QUrl currentPlayerUrl;
|
||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||
static pajlada::Settings::Setting<std::string> currentUser("/accounts/current");
|
||||
auto currentUser = singletons::AccountManager::getInstance().Twitch.getCurrent();
|
||||
|
||||
QString currentUsername = QString::fromStdString(currentUser.getValue());
|
||||
QString currentUsername = currentUser->getUserName();
|
||||
|
||||
if (this->ircMessage->nick() == currentUsername) {
|
||||
currentUser->color = this->usernameColor;
|
||||
// Do nothing. Highlights cannot be triggered by yourself
|
||||
return;
|
||||
}
|
||||
@@ -413,7 +445,7 @@ void TwitchMessageBuilder::parseHighlights()
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage,
|
||||
void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcMessage *ircMessage,
|
||||
const QString &emote,
|
||||
std::vector<std::pair<long int, util::EmoteData>> &vec)
|
||||
{
|
||||
@@ -442,11 +474,11 @@ void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcPrivateMessage *i
|
||||
long int start = std::stol(coords.at(0).toStdString(), nullptr, 10);
|
||||
long int end = std::stol(coords.at(1).toStdString(), nullptr, 10);
|
||||
|
||||
if (start >= end || start < 0 || end > ircMessage->content().length()) {
|
||||
if (start >= end || start < 0 || end > this->originalMessage.length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString name = ircMessage->content().mid(start, end - start + 1);
|
||||
QString name = this->originalMessage.mid(start, end - start + 1);
|
||||
|
||||
vec.push_back(
|
||||
std::pair<long int, util::EmoteData>(start, emoteManager.getTwitchEmoteById(id, name)));
|
||||
|
||||
@@ -29,10 +29,12 @@ public:
|
||||
|
||||
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
||||
const messages::MessageParseArgs &_args);
|
||||
explicit TwitchMessageBuilder(Channel *_channel, const Communi::IrcMessage *_ircMessage,
|
||||
QString content, const messages::MessageParseArgs &_args);
|
||||
|
||||
Channel *channel;
|
||||
TwitchChannel *twitchChannel;
|
||||
const Communi::IrcPrivateMessage *ircMessage;
|
||||
const Communi::IrcMessage *ircMessage;
|
||||
messages::MessageParseArgs args;
|
||||
const QVariantMap tags;
|
||||
|
||||
@@ -46,7 +48,9 @@ private:
|
||||
QString roomID;
|
||||
|
||||
QColor usernameColor;
|
||||
QString originalMessage;
|
||||
const QString originalMessage;
|
||||
|
||||
const bool action = false;
|
||||
|
||||
void parseMessageID();
|
||||
void parseRoomID();
|
||||
@@ -55,7 +59,7 @@ private:
|
||||
void appendUsername();
|
||||
void parseHighlights();
|
||||
|
||||
void appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage, const QString &emote,
|
||||
void appendTwitchEmote(const Communi::IrcMessage *ircMessage, const QString &emote,
|
||||
std::vector<std::pair<long, util::EmoteData>> &vec);
|
||||
bool tryAppendEmote(QString &emoteString);
|
||||
|
||||
|
||||
@@ -143,6 +143,23 @@ std::shared_ptr<Channel> TwitchServer::getCustomChannel(const QString &channelNa
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->channelMutex);
|
||||
|
||||
for (std::weak_ptr<Channel> &weak : this->channels) {
|
||||
std::shared_ptr<Channel> chan = weak.lock();
|
||||
if (!chan) {
|
||||
continue;
|
||||
}
|
||||
|
||||
func(chan);
|
||||
}
|
||||
|
||||
func(this->whispersChannel);
|
||||
func(this->mentionsChannel);
|
||||
}
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -16,6 +16,9 @@ class TwitchServer final : public irc::AbstractIrcServer
|
||||
public:
|
||||
static TwitchServer &getInstance();
|
||||
|
||||
// fourtf: ugh
|
||||
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
|
||||
|
||||
const ChannelPtr whispersChannel;
|
||||
const ChannelPtr mentionsChannel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user