diff --git a/callwidget.cpp b/callwidget.cpp index 0a5aa210e6629de4a7be6306e2cec01d2dc9acbf..8fe1e3fa78bd36683fddd49eb0a601573f343353 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -586,8 +586,8 @@ void CallWidget::slotShowIncomingCallView(const std::string& accountId, } ui->videoWidget->pushRenderer(convInfo.callId); - // TODO:(new lrc) in call chat - //ui->instantMessagingWidget->setMediaText(actualCall_); + + ui->instantMessagingWidget->setupCallMessaging(convInfo.callId, messageModel_.get()); disconnect(selectedCallChanged_); selectedCallChanged_ = connect( @@ -733,7 +733,9 @@ void CallWidget::on_sendIMButton_clicked() { auto msg = ui->imMessageEdit->text(); - if (msg.trimmed().isEmpty()) return; + if (msg.trimmed().isEmpty()) { + return; + } ui->imMessageEdit->clear(); try { LRCInstance::getCurrentConversationModel()->sendMessage(selectedConvUid(), msg.toStdString()); @@ -843,37 +845,32 @@ CallWidget::connectConversationModel() updateConversationsFilterWidget(); selectSmartlistItem(selectedConvUid()); ui->smartList->update(); - } - ); + }); modelUpdatedConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::conversationUpdated, [this](const std::string& convUid) { Q_UNUSED(convUid); ui->smartList->update(); - } - ); + }); filterChangedConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::filterChanged, [this]() { updateSmartList(); updateConversationsFilterWidget(); ui->smartList->update(); - } - ); + }); newConversationConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::newConversation, [this](const std::string& convUid) { updateSmartList(); updateConversationForNewContact(convUid); ui->conversationsFilterWidget->update(); - } - ); + }); conversationRemovedConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::conversationRemoved, [this]() { backToWelcomePage(); - } - ); + }); conversationClearedConnection = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::conversationCleared, [this](const std::string& convUid) { @@ -884,8 +881,7 @@ CallWidget::connectConversationModel() return; } backToWelcomePage(); - } - ); + }); interactionStatusUpdatedConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::interactionStatusUpdated, [this](const std::string& convUid) { @@ -893,14 +889,12 @@ CallWidget::connectConversationModel() return; } updateConversationView(convUid); - } - ); + }); newInteractionConnection_ = QObject::connect( currentConversationModel, &lrc::api::ConversationModel::newInteraction, [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) { onIncomingMessage(convUid, interactionId, interaction); - } - ); + }); currentConversationModel->setFilter(""); // clear search field ui->ringContactLineEdit->setText(""); diff --git a/callwidget.h b/callwidget.h index 7a403891b825ef96ed33dd8e4b0cc88b449415c7..2395b10e2aedda9d1b128ef3031bd4fdafbaba89 100644 --- a/callwidget.h +++ b/callwidget.h @@ -112,7 +112,6 @@ private: void setupSmartListContextMenu(const QPoint &pos); void setupQRCode(QString ringID); void backToWelcomePage(); - void triggerDeleteContactDialog(ContactMethod *cm, Account *ac); // lrc void selectConversation(const QModelIndex& index); diff --git a/instantmessagingwidget.cpp b/instantmessagingwidget.cpp index 94739506f33b61e12964536010c98922f08e2aae..add65b849254e6cb4278507f66d77c936b40c223 100644 --- a/instantmessagingwidget.cpp +++ b/instantmessagingwidget.cpp @@ -1,6 +1,7 @@ /*************************************************************************** - * Copyright (C) 2015-2017 by Savoir-faire Linux * + * Copyright (C) 2015-2018 by Savoir-faire Linux * * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* + * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -29,6 +30,8 @@ #include "imdelegate.h" #include "globalsystemtray.h" #include "settingskey.h" +#include "lrcinstance.h" +#include "utils.h" InstantMessagingWidget::InstantMessagingWidget(QWidget *parent) : QWidget(parent), @@ -55,57 +58,41 @@ InstantMessagingWidget::~InstantMessagingWidget() } void -InstantMessagingWidget::setMediaText(Call *call) +InstantMessagingWidget::setupCallMessaging(const std::string& callId, + MessageModel *messageModel) { ui->listMessageView->disconnect(); ui->messageEdit->disconnect(); - if (call != nullptr) { - connect(call, SIGNAL(mediaAdded(media::Media*)), - this, SLOT(mediaAdd(media::Media*))); - media::Text *textMedia = nullptr; - if (call->hasMedia(media::Media::Type::TEXT, media::Media::Direction::OUT)) { - textMedia = call->firstMedia<media::Text>(media::Media::Direction::OUT); - } else { - textMedia = call->addOutgoingMedia<media::Text>(); - } - if (textMedia) { - ui->listMessageView->setModel(textMedia->recording()->instantMessagingModel()); - ui->listMessageView->scrollToBottom(); - connect(ui->messageEdit, &QLineEdit::returnPressed, [=]() { - if (not ui->messageEdit->text().trimmed().isEmpty()) { - QMap<QString, QString> messages; - messages["text/plain"] = ui->messageEdit->text(); - textMedia->send(messages); - ui->messageEdit->clear(); - ui->listMessageView->scrollToBottom(); - } - }); - } + if (messageModel == nullptr) { + return; } -} -void -InstantMessagingWidget::mediaAdd(media::Media *media) -{ - switch(media->type()) { - case media::Media::Type::AUDIO: - break; - case media::Media::Type::VIDEO: - break; - case media::Media::Type::TEXT: - if (media->direction() == media::Text::Direction::IN) { - connect(static_cast<media::Text*>(media), - SIGNAL(messageReceived(QMap<QString,QString>)), - this, - SLOT(onMsgReceived(QMap<QString,QString>))); - this->show(); - } - break; - case media::Media::Type::FILE: - break; - default: - break; - } + using namespace lrc::api; + + ui->listMessageView->setModel(messageModel); + ui->listMessageView->scrollToBottom(); + connect(ui->messageEdit, &QLineEdit::returnPressed, + [=]() { + auto msg = ui->messageEdit->text(); + if (msg.trimmed().isEmpty()) { + return; + } + ui->messageEdit->clear(); + try { + auto selectedConvUid = LRCInstance::getSelectedConvUid(); + LRCInstance::getCurrentConversationModel()->sendMessage(selectedConvUid, msg.toStdString()); + } + catch (...) { + qDebug() << "exception when sending message"; + } + ui->listMessageView->scrollToBottom(); + }); + + QObject::disconnect(newInteractionConnection_); + newInteractionConnection_ = QObject::connect(LRCInstance::getCurrentConversationModel(), &ConversationModel::newInteraction, + [this](const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) { + onIncomingMessage(convUid, interactionId, interaction); + }); } void @@ -132,6 +119,22 @@ InstantMessagingWidget::copyToClipboard() QApplication::clipboard()->setText(text.value<QString>()); } +} + +void +InstantMessagingWidget::updateConversationView(const std::string & convUid) +{ + auto& currentAccountInfo = LRCInstance::getCurrentAccountInfo(); + auto currentConversationModel = currentAccountInfo.conversationModel.get(); + currentConversationModel->clearUnreadInteractions(convUid); + auto currentConversation = Utils::getConversationFromUid(convUid, *currentConversationModel); + if (currentConversation == currentConversationModel->allFilteredConversations().end()) { + return; + } + messageModel_.reset(new MessageModel(*currentConversation, currentAccountInfo, this->parent())); + ui->listMessageView->setModel(messageModel_.get()); + ui->listMessageView->scrollToBottom(); + this->show(); } void @@ -141,12 +144,11 @@ InstantMessagingWidget::on_sendButton_clicked() } void -InstantMessagingWidget::onMsgReceived(const QMap<QString,QString>& message) +InstantMessagingWidget::onIncomingMessage(const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction) { if (!QApplication::activeWindow() && settings_.value(SettingsKey::enableNotifications).toBool()) { - GlobalSystemTray::instance().showMessage("Ring: Message Received", message["text/plain"]); + GlobalSystemTray::instance().showMessage("Ring: Message Received", QString::fromStdString(interaction.body)); QApplication::alert(this, 5000); } - ui->listMessageView->scrollToBottom(); - this->show(); + updateConversationView(convUid); } diff --git a/instantmessagingwidget.h b/instantmessagingwidget.h index e67f7d7f1fed3a85558bb6900ded075bb9af041f..ed4a79acc745183561083d275a06268d12f1a84c 100644 --- a/instantmessagingwidget.h +++ b/instantmessagingwidget.h @@ -26,6 +26,7 @@ #include "media/media.h" #include "imdelegate.h" +#include "messagemodel.h" namespace Ui { class InstantMessagingWidget; @@ -38,7 +39,8 @@ class InstantMessagingWidget final : public QWidget public: explicit InstantMessagingWidget(QWidget *parent = 0); ~InstantMessagingWidget(); - void setMediaText(Call* call); + void setupCallMessaging(const std::string& callId, + MessageModel *messageModel); protected: virtual void keyPressEvent(QKeyEvent *event) override; @@ -49,13 +51,17 @@ private slots: void on_sendButton_clicked(); private slots: - void mediaAdd(media::Media *media); - void onMsgReceived(const QMap<QString, QString>& message); + void onIncomingMessage(const std::string& convUid, uint64_t interactionId, const lrc::api::interaction::Info& interaction); private: Ui::InstantMessagingWidget *ui; ImDelegate* imDelegate_; + std::unique_ptr<MessageModel> messageModel_; QSettings settings_; + QMetaObject::Connection newInteractionConnection_; + void copyToClipboard(); + void updateConversationView(const std::string& convUid); + }; diff --git a/lrcinstance.h b/lrcinstance.h index e92dd3450e241b352e072bbe9d3436d0f0c6d590..517eaae588b594c5386cfbac144861b68687b26b 100644 --- a/lrcinstance.h +++ b/lrcinstance.h @@ -32,6 +32,7 @@ #include "api/contactmodel.h" #include "api/contact.h" #include "api/datatransfermodel.h" +#include "api/conversationmodel.h" #include <settingskey.h>