summary refs log tree commit diff
path: root/src/ChatPage.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-08-17 20:40:33 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-08-17 20:40:33 +0200
commitde7ec4d2b38888ee88d0a45b05d5a4a7cc730a4d (patch)
tree7d65f5bcbe6996c24f0f5103160e0d4d23bb0983 /src/ChatPage.cpp
parentAdd /clear-timeline command (diff)
parentMerge pull request #237 from trilene/voip (diff)
downloadnheko-de7ec4d2b38888ee88d0a45b05d5a4a7cc730a4d.tar.xz
Merge remote-tracking branch 'origin/master' into new-event-store
Conflicts:
	CMakeLists.txt
	io.github.NhekoReborn.Nheko.json
	src/Cache.cpp
	src/timeline/TimelineModel.cpp
	src/timeline/TimelineModel.h
	src/timeline/TimelineViewManager.cpp
Diffstat (limited to 'src/ChatPage.cpp')
-rw-r--r--src/ChatPage.cpp114
1 files changed, 101 insertions, 13 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 63d13fb9..e55b3eca 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -22,6 +22,7 @@
 #include <QShortcut>
 #include <QtConcurrent>
 
+#include "ActiveCallBar.h"
 #include "AvatarProvider.h"
 #include "Cache.h"
 #include "Cache_p.h"
@@ -40,11 +41,13 @@
 #include "UserInfoWidget.h"
 #include "UserSettingsPage.h"
 #include "Utils.h"
+#include "WebRTCSession.h"
 #include "ui/OverlayModal.h"
 #include "ui/Theme.h"
 
 #include "notifications/Manager.h"
 
+#include "dialogs/PlaceCall.h"
 #include "dialogs/ReadReceipts.h"
 #include "popups/UserMentions.h"
 #include "timeline/TimelineViewManager.h"
@@ -68,6 +71,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
   , isConnected_(true)
   , userSettings_{userSettings}
   , notificationsManager(this)
+  , callManager_(userSettings)
 {
         setObjectName("chatPage");
 
@@ -123,11 +127,17 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
         contentLayout_->setMargin(0);
 
         top_bar_      = new TopRoomBar(this);
-        view_manager_ = new TimelineViewManager(userSettings_, this);
+        view_manager_ = new TimelineViewManager(userSettings_, &callManager_, this);
 
         contentLayout_->addWidget(top_bar_);
         contentLayout_->addWidget(view_manager_->getWidget());
 
+        activeCallBar_ = new ActiveCallBar(this);
+        contentLayout_->addWidget(activeCallBar_);
+        activeCallBar_->hide();
+        connect(
+          &callManager_, &CallManager::newCallParty, activeCallBar_, &ActiveCallBar::setCallParty);
+
         // Splitter
         splitter->addWidget(sideBar_);
         splitter->addWidget(content_);
@@ -448,6 +458,35 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
                                   roomid, filename, encryptedFile, url, mime, dsize);
                 });
 
+        connect(text_input_, &TextInputWidget::callButtonPress, this, [this]() {
+                if (callManager_.onActiveCall()) {
+                        callManager_.hangUp();
+                } else {
+                        if (auto roomInfo = cache::singleRoomInfo(current_room_.toStdString());
+                            roomInfo.member_count != 2) {
+                                showNotification("Voice calls are limited to 1:1 rooms.");
+                        } else {
+                                std::vector<RoomMember> members(
+                                  cache::getMembers(current_room_.toStdString()));
+                                const RoomMember &callee =
+                                  members.front().user_id == utils::localUser() ? members.back()
+                                                                                : members.front();
+                                auto dialog = new dialogs::PlaceCall(
+                                  callee.user_id,
+                                  callee.display_name,
+                                  QString::fromStdString(roomInfo.name),
+                                  QString::fromStdString(roomInfo.avatar_url),
+                                  userSettings_,
+                                  MainWindow::instance());
+                                connect(dialog, &dialogs::PlaceCall::voice, this, [this]() {
+                                        callManager_.sendInvite(current_room_);
+                                });
+                                utils::centerWidget(dialog, MainWindow::instance());
+                                dialog->show();
+                        }
+                }
+        });
+
         connect(room_list_, &RoomList::roomAvatarChanged, this, &ChatPage::updateTopBarAvatar);
 
         connect(
@@ -581,6 +620,11 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
 
         connect(this, &ChatPage::dropToLoginPageCb, this, &ChatPage::dropToLoginPage);
 
+        connectCallMessage<mtx::events::msg::CallInvite>();
+        connectCallMessage<mtx::events::msg::CallCandidates>();
+        connectCallMessage<mtx::events::msg::CallAnswer>();
+        connectCallMessage<mtx::events::msg::CallHangUp>();
+
         instance_ = this;
 }
 
@@ -683,6 +727,8 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
                 const bool isInitialized = cache::isInitialized();
                 const auto cacheVersion  = cache::formatVersion();
 
+                callManager_.refreshTurnServer();
+
                 if (!isInitialized) {
                         cache::setCurrentFormat();
                 } else {
@@ -1165,11 +1211,19 @@ ChatPage::leaveRoom(const QString &room_id)
 void
 ChatPage::inviteUser(QString userid, QString reason)
 {
+        auto room = current_room_;
+
+        if (QMessageBox::question(this,
+                                  tr("Confirm invite"),
+                                  tr("Do you really want to invite %1 (%2)?")
+                                    .arg(cache::displayName(current_room_, userid))
+                                    .arg(userid)) != QMessageBox::Yes)
+                return;
+
         http::client()->invite_user(
-          current_room_.toStdString(),
+          room.toStdString(),
           userid.toStdString(),
-          [this, userid, room = current_room_](const mtx::responses::Empty &,
-                                               mtx::http::RequestErr err) {
+          [this, userid, room](const mtx::responses::Empty &, mtx::http::RequestErr err) {
                   if (err) {
                           emit showNotification(
                             tr("Failed to invite %1 to %2: %3")
@@ -1184,11 +1238,19 @@ ChatPage::inviteUser(QString userid, QString reason)
 void
 ChatPage::kickUser(QString userid, QString reason)
 {
+        auto room = current_room_;
+
+        if (QMessageBox::question(this,
+                                  tr("Confirm kick"),
+                                  tr("Do you really want to kick %1 (%2)?")
+                                    .arg(cache::displayName(current_room_, userid))
+                                    .arg(userid)) != QMessageBox::Yes)
+                return;
+
         http::client()->kick_user(
-          current_room_.toStdString(),
+          room.toStdString(),
           userid.toStdString(),
-          [this, userid, room = current_room_](const mtx::responses::Empty &,
-                                               mtx::http::RequestErr err) {
+          [this, userid, room](const mtx::responses::Empty &, mtx::http::RequestErr err) {
                   if (err) {
                           emit showNotification(
                             tr("Failed to kick %1 to %2: %3")
@@ -1203,11 +1265,19 @@ ChatPage::kickUser(QString userid, QString reason)
 void
 ChatPage::banUser(QString userid, QString reason)
 {
+        auto room = current_room_;
+
+        if (QMessageBox::question(this,
+                                  tr("Confirm ban"),
+                                  tr("Do you really want to ban %1 (%2)?")
+                                    .arg(cache::displayName(current_room_, userid))
+                                    .arg(userid)) != QMessageBox::Yes)
+                return;
+
         http::client()->ban_user(
-          current_room_.toStdString(),
+          room.toStdString(),
           userid.toStdString(),
-          [this, userid, room = current_room_](const mtx::responses::Empty &,
-                                               mtx::http::RequestErr err) {
+          [this, userid, room](const mtx::responses::Empty &, mtx::http::RequestErr err) {
                   if (err) {
                           emit showNotification(
                             tr("Failed to ban %1 in %2: %3")
@@ -1222,11 +1292,19 @@ ChatPage::banUser(QString userid, QString reason)
 void
 ChatPage::unbanUser(QString userid, QString reason)
 {
+        auto room = current_room_;
+
+        if (QMessageBox::question(this,
+                                  tr("Confirm unban"),
+                                  tr("Do you really want to unban %1 (%2)?")
+                                    .arg(cache::displayName(current_room_, userid))
+                                    .arg(userid)) != QMessageBox::Yes)
+                return;
+
         http::client()->unban_user(
-          current_room_.toStdString(),
+          room.toStdString(),
           userid.toStdString(),
-          [this, userid, room = current_room_](const mtx::responses::Empty &,
-                                               mtx::http::RequestErr err) {
+          [this, userid, room](const mtx::responses::Empty &, mtx::http::RequestErr err) {
                   if (err) {
                           emit showNotification(
                             tr("Failed to unban %1 in %2: %3")
@@ -1451,3 +1529,13 @@ ChatPage::initiateLogout()
 
         emit showOverlayProgressBar();
 }
+
+template<typename T>
+void
+ChatPage::connectCallMessage()
+{
+        connect(&callManager_,
+                qOverload<const QString &, const T &>(&CallManager::newMessage),
+                view_manager_,
+                qOverload<const QString &, const T &>(&TimelineViewManager::queueCallMessage));
+}