diff --git a/accountmanager.cpp b/accountmanager.cpp index 58f08ccaf..8ab216843 100644 --- a/accountmanager.cpp +++ b/accountmanager.cpp @@ -39,4 +39,5 @@ void AccountManager::addTwitchUser(const twitch::TwitchUser &user) _twitchUsers.push_back(user); } + } // namespace chatterino diff --git a/accountmanager.h b/accountmanager.h index b2019bf5f..f7b0b3ab9 100644 --- a/accountmanager.h +++ b/accountmanager.h @@ -24,13 +24,13 @@ public: void addTwitchUser(const twitch::TwitchUser &user); private: - AccountManager(); twitch::TwitchUser _twitchAnon; std::vector _twitchUsers; std::mutex _twitchUsersMutex; }; + } // namespace chatterino #endif // ACCOUNTMANAGER_H diff --git a/channel.cpp b/channel.cpp index 838ad4f69..211213782 100644 --- a/channel.cpp +++ b/channel.cpp @@ -1,10 +1,12 @@ #include "channel.h" #include "emotemanager.h" +#include "ircmanager.h" #include "logging/loggingmanager.h" #include "messages/message.h" #include "util/urlfetch.h" #include "windowmanager.h" +#include #include #include #include @@ -29,6 +31,8 @@ Channel::Channel(const QString &channel) , _popoutPlayerLink("https://player.twitch.tv/?channel=" + _name) // , _loggingChannel(logging::get(_name)) { + qDebug() << "Open channel:" << channel << ". Name: " << _name; + printf("Channel pointer: %p\n", this); reloadChannelEmotes(); } @@ -127,6 +131,13 @@ void Channel::reloadChannelEmotes() reloadFfzEmotes(); } +void Channel::sendMessage(const QString &message) +{ + qDebug() << "Channel send message: " << message; + IrcManager &instance = IrcManager::getInstance(); + instance.sendMessage(_name, message); +} + void Channel::reloadBttvEmotes() { util::urlJsonFetch( diff --git a/channel.h b/channel.h index b24991649..97c9d4fb2 100644 --- a/channel.h +++ b/channel.h @@ -50,6 +50,8 @@ public: void addMessage(messages::SharedMessage message); void reloadChannelEmotes(); + void sendMessage(const QString &message); + private: // variabeles messages::LimitedQueue _messages; diff --git a/ircmanager.cpp b/ircmanager.cpp index 5c1ff174d..87f93e475 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -66,12 +66,18 @@ void IrcManager::beginConnecting() QObject::connect(c, &Communi::IrcConnection::privateMessageReceived, this, &IrcManager::privateMessageReceived); - if (_account.isAnon()) { - // fetch ignored users - QString username = _account.getUserName(); - QString oauthClient = _account.getOAuthClient(); - QString oauthToken = _account.getOAuthToken(); + QString username = _account.getUserName(); + QString oauthClient = _account.getOAuthClient(); + QString oauthToken = _account.getOAuthToken(); + c->setUserName(username); + c->setNickName(username); + c->setRealName(username); + + if (!_account.isAnon()) { + c->setPassword(oauthToken); + + // fetch ignored users { QString nextLink = "https://api.twitch.tv/kraken/users/" + username + "/blocks?limit=" + 100 + "&client_id=" + oauthClient; @@ -105,42 +111,38 @@ void IrcManager::beginConnecting() manager->deleteLater(); }); } + } - // fetch available twitch emtoes - { - QNetworkRequest req(QUrl("https://api.twitch.tv/kraken/users/" + username + - "/emotes?oauth_token=" + oauthToken + - "&client_id=" + oauthClient)); - QNetworkReply *reply = _accessManager.get(req); + // fetch available twitch emtoes + { + QNetworkRequest req(QUrl("https://api.twitch.tv/kraken/users/" + username + + "/emotes?oauth_token=" + oauthToken + + "&client_id=" + oauthClient)); + QNetworkReply *reply = _accessManager.get(req); - QObject::connect(reply, &QNetworkReply::finished, [=] { - QByteArray data = reply->readAll(); - QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); - QJsonObject root = jsonDoc.object(); + QObject::connect(reply, &QNetworkReply::finished, [=] { + QByteArray data = reply->readAll(); + QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); + QJsonObject root = jsonDoc.object(); - // nextLink = - // root.value("_links").toObject().value("next").toString(); + // nextLink = + // root.value("_links").toObject().value("next").toString(); - auto blocks = root.value("blocks").toArray(); + auto blocks = root.value("blocks").toArray(); - _twitchBlockedUsersMutex.lock(); - for (QJsonValue block : blocks) { - QJsonObject user = block.toObject().value("user").toObject(); - // display_name - _twitchBlockedUsers.insert(user.value("name").toString().toLower(), true); - } - _twitchBlockedUsersMutex.unlock(); - }); - } + _twitchBlockedUsersMutex.lock(); + for (QJsonValue block : blocks) { + QJsonObject user = block.toObject().value("user").toObject(); + // display_name + _twitchBlockedUsers.insert(user.value("name").toString().toLower(), true); + } + _twitchBlockedUsersMutex.unlock(); + }); } c->setHost("irc.chat.twitch.tv"); c->setPort(6667); - c->setUserName("justinfan123"); - c->setNickName("justinfan123"); - c->setRealName("justinfan123"); - c->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands")); c->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags")); @@ -186,7 +188,21 @@ void IrcManager::sendJoin(const QString &channel) _connectionMutex.lock(); if (_connection.get() != NULL) { - _connection.get()->sendRaw("JOIN #" + channel); + _connection->sendRaw("JOIN #" + channel); + } + + _connectionMutex.unlock(); +} + +void IrcManager::sendMessage(const QString &channelName, const QString &message) +{ + _connectionMutex.lock(); + + if (_connection.get() != nullptr) { + qDebug() << "IRC Manager send message " << message << " to channel " << channelName; + QString xd = "PRIVMSG #" + channelName + " :" + message; + qDebug() << xd; + _connection->sendRaw(xd); } _connectionMutex.unlock(); diff --git a/ircmanager.h b/ircmanager.h index 49195d4ca..4e5d6ad7e 100644 --- a/ircmanager.h +++ b/ircmanager.h @@ -42,6 +42,7 @@ public: QNetworkAccessManager &getAccessManager(); void sendJoin(const QString &channel); + void sendMessage(const QString &channelName, const QString &message); void partChannel(const QString &channel); diff --git a/twitch/twitchaccount.h b/twitch/twitchaccount.h index f9920d9cc..29630ee8e 100644 --- a/twitch/twitchaccount.h +++ b/twitch/twitchaccount.h @@ -22,7 +22,8 @@ private: QString _oauthClient; QString _oauthToken; }; -} -} + +} // namespace twitch +} // namespace chatterino #endif // ACCOUNT_H diff --git a/widgets/accountpopup.cpp b/widgets/accountpopup.cpp index 9a71d5135..f724a706e 100644 --- a/widgets/accountpopup.cpp +++ b/widgets/accountpopup.cpp @@ -7,10 +7,10 @@ namespace chatterino { namespace widgets { -AccountPopupWidget::AccountPopupWidget(std::shared_ptr &&channel) +AccountPopupWidget::AccountPopupWidget(SharedChannel &channel) : QWidget(nullptr) , _ui(new Ui::AccountPopup) - , _channel(std::move(channel)) + , _channel(channel) { _ui->setupUi(this); @@ -25,10 +25,10 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr &&channel) connect(_ui->btnPurge, &QPushButton::clicked, [=]() { qDebug() << "xD: " << _channel->getName(); - /* - _channel->sendMessage( - QString(".timeout %1 0").arg(_ui->lblUsername->text())); - */ + printf("Channel pointer in dialog: %p\n", _channel.get()); + + //_channel->sendMessage(QString(".timeout %1 0").arg(_ui->lblUsername->text())); + _channel->sendMessage("xD"); }); } diff --git a/widgets/accountpopup.h b/widgets/accountpopup.h index cacf54bf8..7276c2455 100644 --- a/widgets/accountpopup.h +++ b/widgets/accountpopup.h @@ -19,14 +19,14 @@ class AccountPopupWidget : public QWidget { Q_OBJECT public: - AccountPopupWidget(std::shared_ptr &&_channel); + AccountPopupWidget(std::shared_ptr &channel); void setName(const QString &name); private: Ui::AccountPopup *_ui; - std::shared_ptr _channel; + std::shared_ptr &_channel; }; } // namespace widgets diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 3127f2eea..4b41998cf 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -43,6 +43,11 @@ std::shared_ptr ChatWidget::getChannel() const return _channel; } +std::shared_ptr &ChatWidget::getChannelRef() +{ + return _channel; +} + const QString &ChatWidget::getChannelName() const { return _channelName; @@ -50,11 +55,11 @@ const QString &ChatWidget::getChannelName() const void ChatWidget::setChannelName(const QString &name) { - QString channel = name.trimmed(); + QString channelName = name.trimmed(); // return if channel name is the same - if (QString::compare(channel, _channelName, Qt::CaseInsensitive) == 0) { - _channelName = channel; + if (QString::compare(channelName, _channelName, Qt::CaseInsensitive) == 0) { + _channelName = channelName; _header.updateChannelText(); return; @@ -68,15 +73,18 @@ void ChatWidget::setChannelName(const QString &name) } // update members - _channelName = channel; + _channelName = channelName; // update messages _messages.clear(); - if (channel.isEmpty()) { + printf("Set channel name xD %s\n", qPrintable(name)); + + if (channelName.isEmpty()) { _channel = NULL; } else { - _channel = ChannelManager::getInstance().addChannel(channel); + _channel = ChannelManager::getInstance().addChannel(channelName); + printf("Created channel FeelsGoodMan %p\n", _channel.get()); attachChannel(_channel); } diff --git a/widgets/chatwidget.h b/widgets/chatwidget.h index 0ae900400..9f34216ea 100644 --- a/widgets/chatwidget.h +++ b/widgets/chatwidget.h @@ -28,6 +28,7 @@ public: ~ChatWidget(); SharedChannel getChannel() const; + SharedChannel &getChannelRef(); const QString &getChannelName() const; void setChannelName(const QString &name); diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 3c85d28d7..030461465 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -22,7 +22,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent) : QWidget() , _chatWidget(parent) , _scrollbar(this) - , _userPopupWidget(_chatWidget->getChannel()) + , _userPopupWidget(_chatWidget->getChannelRef()) , _onlyUpdateEmotes(false) , _mouseDown(false) , _lastPressPosition()