diff options
author | 2022-05-10 10:52:48 +0530 | |
---|---|---|
committer | 2022-05-10 10:52:48 +0530 | |
commit | 1d950cd8bd6fbe3ad7dde1f78fd984dff6d7d25d (patch) | |
tree | b08e547c7f935a14e8051354cb32bf44d3b317ff /src/mainwindow.cpp | |
parent | 59abd9d951479ed417d8303e82818c2a34d5586e (diff) | |
download | whatsie-1d950cd8bd6fbe3ad7dde1f78fd984dff6d7d25d.tar.gz whatsie-1d950cd8bd6fbe3ad7dde1f78fd984dff6d7d25d.zip |
chore: use new chat trigger method to invoke new chats4.2.1
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f32d24b..23bfb44 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -146,27 +146,10 @@ void MainWindow::loadAppWithArgument(const QString &arg) { newArg = newArg.replace("?", "&"); QUrlQuery query(newArg); - static QString phone, phoneStr, text, textStr, urlStr; + QString phone, text; phone = query.queryItemValue("phone"); text = query.queryItemValue("text"); - - webEngine->page()->runJavaScript( - "openNewChatWhatsieDefined()", [this](const QVariant &result) { - if (result.toString().contains("true")) { - this->webEngine->page()->runJavaScript( - QString("openNewChatWhatsie(\"%1\",\"%2\")").arg(phone, text)); - this->notify(QApplication::applicationName(), - "New chat with " + phoneStr + - " is ready. Click to Open."); - } else { - // create send url equivalent - phoneStr = phone.isEmpty() ? "" : "phone=" + phone; - textStr = text.isEmpty() ? "" : "text=" + text; - urlStr = - "https://web.whatsapp.com/send?" + phoneStr + "&" + textStr; - this->webEngine->page()->load(QUrl(urlStr)); - } - }); + triggerNewChat(phone, text); } } @@ -1024,14 +1007,13 @@ void MainWindow::doAppReload() { void MainWindow::newChat() { bool ok; - QString text = QInputDialog::getText( + QString phoneNumber = QInputDialog::getText( this, tr("New Chat"), tr("Enter a valid WhatsApp number with country code (ex- +91XXXXXXXXXX)"), QLineEdit::Normal, "", &ok); if (ok) { - if (isPhoneNumber(text)) - this->webEngine->page()->load( - QUrl("https://web.whatsapp.com/send?phone=" + text)); + if (isPhoneNumber(phoneNumber)) + triggerNewChat(phoneNumber, ""); else QMessageBox::information(this, QApplication::applicationName() + "| Error", @@ -1039,6 +1021,27 @@ void MainWindow::newChat() { } } +void MainWindow::triggerNewChat(QString phone, QString text){ + static QString phoneStr, textStr; + webEngine->page()->runJavaScript( + "openNewChatWhatsieDefined()", [this, phone, text](const QVariant &result) { + if (result.toString().contains("true")) { + this->webEngine->page()->runJavaScript( + QString("openNewChatWhatsie(\"%1\",\"%2\")").arg(phone, text)); + this->notify(QApplication::applicationName(), + "New chat with " + phone + + " is ready. Click to Open."); + } else { + // create send url equivalent + phoneStr = phone.isEmpty() ? "" : "phone=" + phone; + textStr = text.isEmpty() ? "" : "text=" + text; + QString urlStr = + "https://web.whatsapp.com/send?" + phoneStr + "&" + textStr; + this->webEngine->page()->load(QUrl(urlStr)); + } + }); +} + bool MainWindow::isPhoneNumber(const QString &phoneNumber) { const QString phone = "^\\+(((\\d{2}))\\s?)?((\\d{2})|(\\((\\d{2})\\))\\s?)?(" "\\d{3,15})(\\-(\\d{3,15}))?$"; |