diff --git a/src/widgets/dialogs/showlistmessagebasedialog.cpp b/src/widgets/dialogs/showlistmessagebasedialog.cpp index 8d5915e8..1259ef76 100644 --- a/src/widgets/dialogs/showlistmessagebasedialog.cpp +++ b/src/widgets/dialogs/showlistmessagebasedialog.cpp @@ -1,77 +1,82 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "showlistmessagebasedialog.h" #include "showlistmessagebasewidget.h" #include "ruqolawidgets_debug.h" #include "ruqola.h" #include "rocketchataccount.h" #include "room/messagelistview.h" #include #include ShowListMessageBaseDialog::ShowListMessageBaseDialog(QWidget *parent) : QDialog(parent) { auto *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mShowListMessage = new ShowListMessageBaseWidget(this); mShowListMessage->setObjectName(QStringLiteral("mShowListMessage")); mainLayout->addWidget(mShowListMessage); QDialogButtonBox *button = new QDialogButtonBox(QDialogButtonBox::Close, this); button->setObjectName(QStringLiteral("button")); mainLayout->addWidget(button); connect(button, &QDialogButtonBox::rejected, this, &ShowListMessageBaseDialog::reject); connect(mShowListMessage, &ShowListMessageBaseWidget::loadMoreElements, this, &ShowListMessageBaseDialog::slotLoadMoreMessages); connect(mShowListMessage->messageListView(), &MessageListView::goToMessageRequested, this, &ShowListMessageBaseDialog::goToMessageRequested); } ShowListMessageBaseDialog::~ShowListMessageBaseDialog() { } void ShowListMessageBaseDialog::slotLoadMoreMessages() { if (mRoomId.isEmpty()) { qCWarning(RUQOLAWIDGETS_LOG) << "RoomId is empty. It's a bug"; return; } Ruqola::self()->rocketChatAccount()->loadMoreListMessages(roomId()); } void ShowListMessageBaseDialog::setModel(ListMessagesModelFilterProxyModel *model) { mShowListMessage->setModel(model); } void ShowListMessageBaseDialog::setRoomId(const QString &roomId) { mRoomId = roomId; } QString ShowListMessageBaseDialog::roomId() const { return mRoomId; } + +void ShowListMessageBaseDialog::setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount) +{ + mShowListMessage->setCurrentRocketChatAccount(currentRocketChatAccount); +} diff --git a/src/widgets/dialogs/showlistmessagebasedialog.h b/src/widgets/dialogs/showlistmessagebasedialog.h index df80c57e..4cdaaeda 100644 --- a/src/widgets/dialogs/showlistmessagebasedialog.h +++ b/src/widgets/dialogs/showlistmessagebasedialog.h @@ -1,50 +1,52 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SHOWLISTMESSAGEBASEDIALOG_H #define SHOWLISTMESSAGEBASEDIALOG_H #include #include "libruqolawidgets_export.h" class ShowListMessageBaseWidget; class ListMessagesModelFilterProxyModel; +class RocketChatAccount; class LIBRUQOLAWIDGETS_EXPORT ShowListMessageBaseDialog : public QDialog { Q_OBJECT public: explicit ShowListMessageBaseDialog(QWidget *parent = nullptr); ~ShowListMessageBaseDialog() override; void setModel(ListMessagesModelFilterProxyModel *model); void setRoomId(const QString &roomId); Q_REQUIRED_RESULT QString roomId() const; + void setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount); Q_SIGNALS: void goToMessageRequested(const QString &messageId); private: void slotLoadMoreMessages(); QString mRoomId; ShowListMessageBaseWidget *mShowListMessage = nullptr; }; #endif // SHOWLISTMESSAGEBASEDIALOG_H diff --git a/src/widgets/dialogs/showlistmessagebasewidget.cpp b/src/widgets/dialogs/showlistmessagebasewidget.cpp index fb7d7d5f..e94f2636 100644 --- a/src/widgets/dialogs/showlistmessagebasewidget.cpp +++ b/src/widgets/dialogs/showlistmessagebasewidget.cpp @@ -1,97 +1,107 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "showlistmessagebasewidget.h" #include "room/messagelistview.h" #include "model/listmessagesmodelfilterproxymodel.h" #include #include #include #include ShowListMessageBaseWidget::ShowListMessageBaseWidget(QWidget *parent) : QWidget(parent) { auto *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mSearchMessageLineEdit = new KLineEdit(this); mSearchMessageLineEdit->setObjectName(QStringLiteral("mSearchMessageLineEdit")); mSearchMessageLineEdit->setClearButtonEnabled(true); mSearchMessageLineEdit->setTrapReturnKey(true); mSearchMessageLineEdit->setPlaceholderText(i18n("Search Messages...")); connect(mSearchMessageLineEdit, &KLineEdit::textChanged, this, &ShowListMessageBaseWidget::slotSearchMessageTextChanged); mainLayout->addWidget(mSearchMessageLineEdit); mMessageListInfo = new QLabel(this); mMessageListInfo->setObjectName(QStringLiteral("mMessageListInfo")); mMessageListInfo->setTextFormat(Qt::RichText); mMessageListInfo->setContextMenuPolicy(Qt::NoContextMenu); QFont labFont = mMessageListInfo->font(); labFont.setBold(true); mMessageListInfo->setFont(labFont); connect(mMessageListInfo, &QLabel::linkActivated, this, &ShowListMessageBaseWidget::loadMoreElements); mainLayout->addWidget(mMessageListInfo); mMessageListView = new MessageListView(MessageListView::Mode::Viewing, this); mMessageListView->setObjectName(QStringLiteral("mMessageListView")); mainLayout->addWidget(mMessageListView); connect(mMessageListView, &MessageListView::modelChanged, this, &ShowListMessageBaseWidget::updateLabel); } ShowListMessageBaseWidget::~ShowListMessageBaseWidget() { } void ShowListMessageBaseWidget::setModel(ListMessagesModelFilterProxyModel *model) { mModel = model; mMessageListView->setModel(model); connect(mModel, &ListMessagesModelFilterProxyModel::hasFullListChanged, this, &ShowListMessageBaseWidget::updateLabel); connect(mModel, &ListMessagesModelFilterProxyModel::loadingInProgressChanged, this, &ShowListMessageBaseWidget::updateLabel); updateLabel(); } +MessageListView *ShowListMessageBaseWidget::messageListView() const +{ + return mMessageListView; +} + +void ShowListMessageBaseWidget::setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount) +{ + mMessageListView->setCurrentRocketChatAccount(currentRocketChatAccount); +} + void ShowListMessageBaseWidget::updateLabel() { if (mModel->loadMoreListMessagesInProgress()) { mMessageListInfo->setText(i18n("Loading...")); } else { mMessageListInfo->setText(mModel->rowCount() == 0 ? i18n("No Message found") : displayShowMessageInRoom()); } } QString ShowListMessageBaseWidget::displayShowMessageInRoom() const { QString displayMessageStr; displayMessageStr = i18np("%1 Message in room (Total: %2)", "%1 Messages in room (Total: %2)", mModel->rowCount(), mModel->total()); if (!mModel->hasFullList()) { displayMessageStr += QStringLiteral(" %1").arg(i18n("(Click here for Loading more...)")); } return displayMessageStr; } void ShowListMessageBaseWidget::slotSearchMessageTextChanged(const QString &str) { mModel->setFilterString(str); } diff --git a/src/widgets/dialogs/showlistmessagebasewidget.h b/src/widgets/dialogs/showlistmessagebasewidget.h index de27e174..c6339cc3 100644 --- a/src/widgets/dialogs/showlistmessagebasewidget.h +++ b/src/widgets/dialogs/showlistmessagebasewidget.h @@ -1,57 +1,57 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SHOWLISTMESSAGEBASEWIDGET_H #define SHOWLISTMESSAGEBASEWIDGET_H #include #include "libruqolawidgets_private_export.h" class KLineEdit; class MessageListView; class QLabel; class ListMessagesModelFilterProxyModel; +class RocketChatAccount; class LIBRUQOLAWIDGETS_TESTS_EXPORT ShowListMessageBaseWidget : public QWidget { Q_OBJECT public: explicit ShowListMessageBaseWidget(QWidget *parent = nullptr); ~ShowListMessageBaseWidget() override; void setModel(ListMessagesModelFilterProxyModel *model); - MessageListView *messageListView() const - { - return mMessageListView; - } + Q_REQUIRED_RESULT MessageListView *messageListView() const; + + void setCurrentRocketChatAccount(RocketChatAccount *currentRocketChatAccount); Q_SIGNALS: void loadMoreElements(); private: void updateLabel(); void slotSearchMessageTextChanged(const QString &str); Q_REQUIRED_RESULT QString displayShowMessageInRoom() const; KLineEdit *mSearchMessageLineEdit = nullptr; MessageListView *mMessageListView = nullptr; QLabel *mMessageListInfo = nullptr; ListMessagesModelFilterProxyModel *mModel = nullptr; }; #endif // SHOWLISTMESSAGEBASEWIDGET_H diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index e0fb8b99..82a28527 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,523 +1,528 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "roomwidget.h" #include "roomheaderwidget.h" #include "messagelistview.h" #include "messagelinewidget.h" #include "ruqola.h" #include "rocketchataccount.h" #include "roomwrapper.h" #include "readonlylineeditwidget.h" #include "messagetextedit.h" #include "roomutil.h" #include "ruqolawidgets_debug.h" #include "usersinroomflowwidget.h" #include "dialogs/createnewdiscussiondialog.h" #include "dialogs/searchmessagedialog.h" #include "dialogs/configurenotificationdialog.h" #include "dialogs/showattachmentdialog.h" #include "dialogs/showdiscussionsdialog.h" #include "dialogs/showmentionsmessagesdialog.h" #include "dialogs/showpinnedmessagesdialog.h" #include "dialogs/showsnipperedmessagesdialog.h" #include "dialogs/showstarredmessagesdialog.h" #include "dialogs/showthreadsdialog.h" #include "dialogs/autotranslateconfiguredialog.h" #include "dialogs/channelinfodialog.h" #include "dialogs/directchannelinfodialog.h" #include "dialogs/inviteusersdialog.h" #include "dialogs/addusersinroomdialog.h" #include "threadwidget/threadmessagedialog.h" #include #include #include #include #include #include #include #include #include #include RoomWidget::RoomWidget(QWidget *parent) : QWidget(parent) { auto *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mRoomHeaderWidget = new RoomHeaderWidget(this); mRoomHeaderWidget->setObjectName(QStringLiteral("mRoomHeaderWidget")); mainLayout->addWidget(mRoomHeaderWidget); mUsersInRoomFlowWidget = new UsersInRoomFlowWidget(this); mUsersInRoomFlowWidget->setObjectName(QStringLiteral("mUsersInRoomFlowWidget")); mainLayout->addWidget(mUsersInRoomFlowWidget); mUsersInRoomFlowWidget->setVisible(false); mMessageListView = new MessageListView(MessageListView::Mode::Editing, this); mMessageListView->setObjectName(QStringLiteral("mMessageListView")); mainLayout->addWidget(mMessageListView, 1); mStackedWidget = new QStackedWidget(this); mStackedWidget->setObjectName(QStringLiteral("mStackedWidget")); mainLayout->addWidget(mStackedWidget); mMessageLineWidget = new MessageLineWidget(this); mMessageLineWidget->setObjectName(QStringLiteral("mMessageLineWidget")); mStackedWidget->addWidget(mMessageLineWidget); mReadOnlyLineEditWidget = new ReadOnlyLineEditWidget(this); mReadOnlyLineEditWidget->setObjectName(QStringLiteral("mReadOnlyLineEditWidget")); mStackedWidget->addWidget(mReadOnlyLineEditWidget); mStackedWidget->setCurrentWidget(mMessageLineWidget); connect(mMessageLineWidget, &MessageLineWidget::keyPressed, this, &RoomWidget::keyPressedInLineEdit); connect(mRoomHeaderWidget, &RoomHeaderWidget::favoriteChanged, this, &RoomWidget::slotChangeFavorite); connect(mRoomHeaderWidget, &RoomHeaderWidget::encryptedChanged, this, &RoomWidget::slotEncryptedChanged); connect(mRoomHeaderWidget, &RoomHeaderWidget::goBackToRoom, this, &RoomWidget::slotGoBackToRoom); connect(mRoomHeaderWidget, &RoomHeaderWidget::listOfUsersChanged, this, &RoomWidget::slotShowListOfUsersInRoom); connect(mRoomHeaderWidget, &RoomHeaderWidget::searchMessageRequested, this, &RoomWidget::slotSearchMessages); connect(mRoomHeaderWidget, &RoomHeaderWidget::actionRequested, this, &RoomWidget::slotActionRequested); connect(mRoomHeaderWidget, &RoomHeaderWidget::channelInfoRequested, this, &RoomWidget::slotChannelInfoRequested); connect(mMessageListView, &MessageListView::editMessageRequested, mMessageLineWidget, &MessageLineWidget::setEditMessage); connect(mMessageListView, &MessageListView::createNewDiscussion, this, &RoomWidget::slotCreateNewDiscussion); connect(mMessageListView, &MessageListView::createPrivateConversation, this, &RoomWidget::slotCreatePrivateDiscussion); connect(mMessageListView, &MessageListView::loadHistoryRequested, this, &RoomWidget::slotLoadHistory); connect(mMessageListView, &MessageListView::replyInThreadRequested, mMessageLineWidget, &MessageLineWidget::setReplyInThread); setAcceptDrops(true); } RoomWidget::~RoomWidget() { delete mRoomWrapper; } void RoomWidget::slotLoadHistory() { mCurrentRocketChatAccount->loadHistory(mRoomId, mRoomType); } void RoomWidget::slotChannelInfoRequested() { if (mRoomType == QLatin1String("d")) { QPointer dlg = new DirectChannelInfoDialog(this); dlg->setUserName(mRoomWrapper->name()); dlg->exec(); delete dlg; } else { QPointer dlg = new ChannelInfoDialog(this); dlg->setRoomWrapper(mRoomWrapper); dlg->exec(); delete dlg; } } void RoomWidget::slotActionRequested(RoomHeaderWidget::ChannelActionType type) { switch (type) { case RoomHeaderWidget::ShowMentions: slotShowMentions(); break; case RoomHeaderWidget::ShowPinned: slotPinnedMessages(); break; case RoomHeaderWidget::ShowStarred: slotStarredMessages(); break; case RoomHeaderWidget::ShowSnippered: slotSnipperedMessages(); break; case RoomHeaderWidget::ShowDiscussions: slotShowDiscussions(); break; case RoomHeaderWidget::ShowThreads: slotShowThreads(); break; case RoomHeaderWidget::ShowAttachment: slotShowFileAttachments(); break; case RoomHeaderWidget::Notification: slotConfigureNotification(); break; case RoomHeaderWidget::AutoTranslate: slotConfigureAutoTranslate(); break; case RoomHeaderWidget::InviteUsers: slotInviteUsers(); break; case RoomHeaderWidget::AddUsersInRoom: slotAddUsersInRoom(); break; case RoomHeaderWidget::VideoChat: slotVideoChat(); break; } } void RoomWidget::slotVideoChat() { mCurrentRocketChatAccount->createJitsiConfCall(mRoomId); } void RoomWidget::slotAddUsersInRoom() { QPointer dlg = new AddUsersInRoomDialog(this); if (dlg->exec()) { const QStringList users = dlg->users(); for (const QString &user : users) { mCurrentRocketChatAccount->addUserToRoom(user, mRoomId, mRoomType); } } delete dlg; } void RoomWidget::slotInviteUsers() { QPointer dlg = new InviteUsersDialog(this); dlg->setRoomId(mRoomId); dlg->generateLink(); dlg->exec(); delete dlg; } void RoomWidget::updateListView() { mMessageListView->viewport()->update(); } void RoomWidget::slotConfigureAutoTranslate() { QPointer dlg = new AutoTranslateConfigureDialog(this); dlg->setRoomWrapper(mRoomWrapper); dlg->exec(); delete dlg; } void RoomWidget::slotConfigureNotification() { QPointer dlg = new ConfigureNotificationDialog(this); dlg->setRoomWrapper(mRoomWrapper); dlg->exec(); delete dlg; } void RoomWidget::slotStarredMessages() { QPointer dlg = new ShowStarredMessagesDialog(this); dlg->setRoomId(mRoomId); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); + dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); mCurrentRocketChatAccount->getListMessages(mRoomId, ListMessagesModel::StarredMessages); connect(dlg, &ShowListMessageBaseDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotPinnedMessages() { QPointer dlg = new ShowPinnedMessagesDialog(this); dlg->setRoomId(mRoomId); + dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mRoomId, ListMessagesModel::PinnedMessages); connect(dlg, &ShowListMessageBaseDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotShowMentions() { QPointer dlg = new ShowMentionsMessagesDialog(this); dlg->setRoomId(mRoomId); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); + dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); mCurrentRocketChatAccount->getListMessages(mRoomId, ListMessagesModel::MentionsMessages); connect(dlg, &ShowListMessageBaseDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotSnipperedMessages() { QPointer dlg = new ShowSnipperedMessagesDialog(this); dlg->setRoomId(mRoomId); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); + dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); mCurrentRocketChatAccount->getListMessages(mRoomId, ListMessagesModel::SnipperedMessages); connect(dlg, &ShowListMessageBaseDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotShowThreads() { QPointer dlg = new ShowThreadsDialog(this); + dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); dlg->setRoomId(mRoomId); mCurrentRocketChatAccount->getListMessages(mRoomId, ListMessagesModel::ThreadsMessages); connect(dlg, &ShowListMessageBaseDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotShowDiscussions() { QPointer dlg = new ShowDiscussionsDialog(this); dlg->setModel(mCurrentRocketChatAccount->discussionsFilterProxyModel()); dlg->setRoomId(mRoomId); mCurrentRocketChatAccount->discussionsInRoom(mRoomId); dlg->exec(); delete dlg; } void RoomWidget::slotShowFileAttachments() { QPointer dlg = new ShowAttachmentDialog(this); mCurrentRocketChatAccount->roomFiles(mRoomId, mRoomType); dlg->setModel(mCurrentRocketChatAccount->filesForRoomFilterProxyModel()); dlg->setRoomId(mRoomId); dlg->setRoomType(mRoomType); dlg->exec(); delete dlg; } void RoomWidget::slotSearchMessages() { QPointer dlg = new SearchMessageDialog(this); dlg->setRoomId(mRoomId); dlg->setModel(mCurrentRocketChatAccount->searchMessageFilterProxyModel()); connect(dlg, &SearchMessageDialog::goToMessageRequested, mMessageListView, &MessageListView::goToMessage); dlg->exec(); delete dlg; } void RoomWidget::slotCreateNewDiscussion(const QString &messageId, const QString &originalMessage) { QPointer dlg = new CreateNewDiscussionDialog(this); dlg->setDiscussionName(originalMessage); dlg->setChannelName(mRoomHeaderWidget->roomName()); if (dlg->exec()) { const CreateNewDiscussionDialog::NewDiscussionInfo info = dlg->newDiscussionInfo(); mCurrentRocketChatAccount->createDiscussion(mRoomId, info.discussionName, info.message, messageId, info.users); } delete dlg; } void RoomWidget::slotCreatePrivateDiscussion(const QString &userName) { Q_EMIT mCurrentRocketChatAccount->openLinkRequested(RoomUtil::generateUserLink(userName)); } void RoomWidget::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { event->accept(); } } void RoomWidget::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { mMessageLineWidget->handleMimeData(mimeData); } } void RoomWidget::setChannelSelected(const QString &roomId, const QString &roomType) { if (mMessageLineWidget->text().isEmpty()) { auto *vbar = mMessageListView->verticalScrollBar(); if (vbar->value() != vbar->maximum()) { AccountRoomSettings::PendingTypedInfo info; info.scrollbarPosition = mMessageListView->verticalScrollBar()->value(); mCurrentRocketChatAccount->accountRoomSettings()->add(mRoomId, info); } else { mCurrentRocketChatAccount->accountRoomSettings()->remove(mRoomId); } } else { AccountRoomSettings::PendingTypedInfo info; info.text = mMessageLineWidget->text(); info.messageIdBeingEdited = mMessageLineWidget->messageIdBeingEdited(); info.scrollbarPosition = mMessageListView->verticalScrollBar()->value(); mCurrentRocketChatAccount->accountRoomSettings()->add(mRoomId, info); } setRoomId(roomId); setRoomType(roomType); const AccountRoomSettings::PendingTypedInfo currentPendingInfo = mCurrentRocketChatAccount->accountRoomSettings()->value(roomId); if (currentPendingInfo.isValid()) { mMessageLineWidget->setText(currentPendingInfo.text); mMessageLineWidget->setMessageIdBeingEdited(currentPendingInfo.messageIdBeingEdited); if (currentPendingInfo.scrollbarPosition != -1) { mMessageListView->verticalScrollBar()->setValue(currentPendingInfo.scrollbarPosition); } } else { mMessageLineWidget->setText(QString()); } mMessageLineWidget->setMode(mMessageLineWidget->messageIdBeingEdited().isEmpty() ? MessageLineWidget::EditingMode::NewMessage : MessageLineWidget::EditingMode::EditMessage); mMessageLineWidget->setFocus(); } void RoomWidget::updateRoomHeader() { if (mRoomWrapper) { mRoomHeaderWidget->setRoomName(mRoomWrapper->displayRoomName()); mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); mRoomHeaderWidget->setFavoriteStatus(mRoomWrapper->favorite()); mRoomHeaderWidget->setEncypted(mRoomWrapper->encrypted()); mRoomHeaderWidget->setIsDiscussion(mRoomWrapper->isDiscussionRoom()); //TODO Description ? if (mRoomWrapper->roomMessageInfo().isEmpty()) { mStackedWidget->setCurrentWidget(mMessageLineWidget); } else { mStackedWidget->setCurrentWidget(mReadOnlyLineEditWidget); mReadOnlyLineEditWidget->setMessage(mRoomWrapper->roomMessageInfo()); } } } QString RoomWidget::roomId() const { return mRoomId; } void RoomWidget::setRoomType(const QString &roomType) { mRoomType = roomType; } RoomWrapper *RoomWidget::roomWrapper() const { return mRoomWrapper; } void RoomWidget::slotShowListOfUsersInRoom(bool checked) { mUsersInRoomFlowWidget->setVisible(checked); } void RoomWidget::setRoomId(const QString &roomId) { mRoomId = roomId; delete mRoomWrapper; mRoomWrapper = mCurrentRocketChatAccount->roomWrapper(mRoomId); connectRoomWrapper(); mMessageLineWidget->setRoomId(roomId); mMessageListView->setChannelSelected(roomId); mUsersInRoomFlowWidget->setRoomWrapper(mRoomWrapper); mRoomHeaderWidget->setRoomWrapper(mRoomWrapper); } void RoomWidget::connectRoomWrapper() { if (mRoomWrapper) { connect(mRoomWrapper, &RoomWrapper::announcementChanged, this, [this]() { mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); }); connect(mRoomWrapper, &RoomWrapper::topicChanged, this, [this]() { mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); }); connect(mRoomWrapper, &RoomWrapper::nameChanged, this, [this]() { mRoomHeaderWidget->setRoomName(mRoomWrapper->displayRoomName()); }); connect(mRoomWrapper, &RoomWrapper::favoriteChanged, this, [this]() { mRoomHeaderWidget->setFavoriteStatus(mRoomWrapper->favorite()); }); connect(mRoomWrapper, &RoomWrapper::encryptedChanged, this, [this]() { mRoomHeaderWidget->setEncypted(mRoomWrapper->encrypted()); }); connect(mRoomWrapper, &RoomWrapper::autoTranslateLanguageChanged, this, &RoomWidget::updateListView); connect(mRoomWrapper, &RoomWrapper::autoTranslateChanged, this, &RoomWidget::updateListView); connect(mRoomWrapper, &RoomWrapper::ignoredUsersChanged, this, &RoomWidget::updateListView); } updateRoomHeader(); } void RoomWidget::slotClearNotification() { mCurrentRocketChatAccount->clearUnreadMessages(mRoomId); } void RoomWidget::slotEncryptedChanged(bool b) { qCWarning(RUQOLAWIDGETS_LOG) << "change encrypted not supported yet"; //TODO mCurrentRocketChatAccount->slot } void RoomWidget::slotChangeFavorite(bool b) { mCurrentRocketChatAccount->changeFavorite(mRoomId, b); } void RoomWidget::keyPressedInLineEdit(QKeyEvent *ev) { const int key = ev->key(); if (key == Qt::Key_Escape) { slotClearNotification(); ev->accept(); } else { mMessageListView->handleKeyPressEvent(ev); } } QString RoomWidget::roomType() const { return mRoomType; } void RoomWidget::setCurrentRocketChatAccount(RocketChatAccount *account) { if (mCurrentRocketChatAccount) { disconnect(mCurrentRocketChatAccount, &RocketChatAccount::openThreadRequested, this, &RoomWidget::slotOpenThreadRequested); } mCurrentRocketChatAccount = account; connect(mCurrentRocketChatAccount, &RocketChatAccount::openThreadRequested, this, &RoomWidget::slotOpenThreadRequested); mMessageListView->setCurrentRocketChatAccount(account); mMessageLineWidget->setCurrentRocketChatAccount(account); mRoomHeaderWidget->setCurrentRocketChatAccount(account); mRoomId.clear(); //Clear it otherwise if we switch between two account with same roomId (as "GENERAL") we will see incorrect room. } void RoomWidget::slotGoBackToRoom() { Q_EMIT selectChannelRequested(mRoomWrapper->parentRid()); } void RoomWidget::slotOpenThreadRequested(const QString &threadMessageId, const QString &threadMessagePreview) { QPointer dlg = new ThreadMessageDialog(this); dlg->setThreadMessageId(threadMessageId); dlg->setCurrentRocketChatAccount(mCurrentRocketChatAccount); dlg->setThreadPreview(threadMessagePreview); dlg->setRoomId(mRoomId); dlg->exec(); delete dlg; }