|
@@ -141,7 +141,7 @@ void YoutubeAuth::LoadUI()
|
|
|
QSize size = main->frameSize();
|
|
|
QPoint pos = main->pos();
|
|
|
|
|
|
- chat.reset(new BrowserDock());
|
|
|
+ chat.reset(new YoutubeChatDock());
|
|
|
chat->setObjectName("ytChat");
|
|
|
chat->resize(300, 600);
|
|
|
chat->setMinimumSize(200, 300);
|
|
@@ -173,16 +173,18 @@ void YoutubeAuth::LoadUI()
|
|
|
uiLoaded = true;
|
|
|
}
|
|
|
|
|
|
-void YoutubeAuth::SetChatId(QString &chat_id)
|
|
|
+void YoutubeAuth::SetChatId(const QString &chat_id,
|
|
|
+ const std::string &api_chat_id)
|
|
|
{
|
|
|
#ifdef BROWSER_AVAILABLE
|
|
|
QString chat_url = QString(YOUTUBE_CHAT_POPOUT_URL).arg(chat_id);
|
|
|
|
|
|
if (chat && chat->cefWidget) {
|
|
|
chat->cefWidget->setURL(chat_url.toStdString());
|
|
|
+ chat->SetApiChatId(api_chat_id);
|
|
|
}
|
|
|
#else
|
|
|
- UNUSED_PARAMETER(chat_id);
|
|
|
+ UNUSED_PARAMETER(chat_id, api_chat_id);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
@@ -322,3 +324,83 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
|
|
|
config_save_safe(config, "tmp", nullptr);
|
|
|
return auth;
|
|
|
}
|
|
|
+
|
|
|
+#ifdef BROWSER_AVAILABLE
|
|
|
+void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
|
|
+{
|
|
|
+ lineEdit = new LineEditAutoResize();
|
|
|
+ lineEdit->setVisible(false);
|
|
|
+ lineEdit->setMaxLength(200);
|
|
|
+ lineEdit->setPlaceholderText(QTStr("YouTube.Chat.Input.Placeholder"));
|
|
|
+ sendButton = new QPushButton(QTStr("YouTube.Chat.Input.Send"));
|
|
|
+ sendButton->setVisible(false);
|
|
|
+
|
|
|
+ chatLayout = new QHBoxLayout();
|
|
|
+ chatLayout->setMargin(0);
|
|
|
+ chatLayout->addWidget(lineEdit, 1);
|
|
|
+ chatLayout->addWidget(sendButton);
|
|
|
+
|
|
|
+ QVBoxLayout *layout = new QVBoxLayout();
|
|
|
+ layout->setMargin(0);
|
|
|
+ layout->addWidget(widget_, 1);
|
|
|
+ layout->addLayout(chatLayout);
|
|
|
+
|
|
|
+ QWidget *widget = new QWidget();
|
|
|
+ widget->setLayout(layout);
|
|
|
+ setWidget(widget);
|
|
|
+
|
|
|
+ QWidget::connect(lineEdit, SIGNAL(returnPressed()), this,
|
|
|
+ SLOT(SendChatMessage()));
|
|
|
+ QWidget::connect(sendButton, SIGNAL(pressed()), this,
|
|
|
+ SLOT(SendChatMessage()));
|
|
|
+
|
|
|
+ cefWidget.reset(widget_);
|
|
|
+}
|
|
|
+
|
|
|
+void YoutubeChatDock::SetApiChatId(const std::string &id)
|
|
|
+{
|
|
|
+ this->apiChatId = id;
|
|
|
+ QMetaObject::invokeMethod(this, "EnableChatInput",
|
|
|
+ Qt::QueuedConnection);
|
|
|
+}
|
|
|
+
|
|
|
+void YoutubeChatDock::SendChatMessage()
|
|
|
+{
|
|
|
+ const QString message = lineEdit->text();
|
|
|
+ if (message == "")
|
|
|
+ return;
|
|
|
+
|
|
|
+ OBSBasic *main = OBSBasic::Get();
|
|
|
+ YoutubeApiWrappers *apiYouTube(
|
|
|
+ dynamic_cast<YoutubeApiWrappers *>(main->GetAuth()));
|
|
|
+
|
|
|
+ ExecuteFuncSafeBlock([&]() {
|
|
|
+ lineEdit->setText("");
|
|
|
+ lineEdit->setPlaceholderText(
|
|
|
+ QTStr("YouTube.Chat.Input.Sending"));
|
|
|
+ if (apiYouTube->SendChatMessage(apiChatId, message)) {
|
|
|
+ os_sleep_ms(3000);
|
|
|
+ } else {
|
|
|
+ QString error = apiYouTube->GetLastError();
|
|
|
+ apiYouTube->GetTranslatedError(error);
|
|
|
+ QMetaObject::invokeMethod(
|
|
|
+ this, "ShowErrorMessage", Qt::QueuedConnection,
|
|
|
+ Q_ARG(const QString &, error));
|
|
|
+ }
|
|
|
+ lineEdit->setPlaceholderText(
|
|
|
+ QTStr("YouTube.Chat.Input.Placeholder"));
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+void YoutubeChatDock::ShowErrorMessage(const QString &error)
|
|
|
+{
|
|
|
+ QMessageBox::warning(this, QTStr("YouTube.Chat.Error.Title"),
|
|
|
+ QTStr("YouTube.Chat.Error.Text").arg(error));
|
|
|
+}
|
|
|
+
|
|
|
+void YoutubeChatDock::EnableChatInput()
|
|
|
+{
|
|
|
+ lineEdit->setVisible(true);
|
|
|
+ sendButton->setVisible(true);
|
|
|
+}
|
|
|
+#endif
|