Commit 43865373 authored by Andreas Traczyk's avatar Andreas Traczyk

message view: update message view when reacting to invites

Change-Id: Idc4d3b74b181aa8538e782fe1699d54d5b1b580a
Gitlab: #432
parent e9320371
......@@ -204,6 +204,11 @@ CallWidget::CallWidget(QWidget* parent) :
ui->btnInvites->setChecked(false);
});
connect(ui->messageView, &MessageWebView::conversationRemoved,
[this] {
backToWelcomePage();
});
// set first view to welcome view
ui->stackedWidget->setCurrentWidget(ui->welcomePage);
ui->btnConversations->setChecked(true);
......@@ -581,20 +586,27 @@ CallWidget::on_ringContactLineEdit_returnPressed()
void CallWidget::slotAcceptInviteClicked(const QModelIndex & index)
{
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>();
LRCInstance::getCurrentConversationModel()->makePermanent(convUid.toStdString());
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
LRCInstance::getCurrentConversationModel()->makePermanent(convUid);
ui->messageView->setInvitation(false);
}
void CallWidget::slotBlockInviteClicked(const QModelIndex & index)
{
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>();
LRCInstance::getCurrentConversationModel()->removeConversation(convUid.toStdString(), true);
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
backToWelcomePage();
}
LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
}
void CallWidget::slotIgnoreInviteClicked(const QModelIndex & index)
{
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>();
LRCInstance::getCurrentConversationModel()->removeConversation(convUid.toStdString(), false);
auto convUid = index.data(static_cast<int>(SmartListModel::Role::UID)).value<QString>().toStdString();
if (!convUid.empty() && convUid == LRCInstance::getSelectedConvUid()) {
backToWelcomePage();
}
LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
}
void CallWidget::slotCustomContextMenuRequested(const QPoint& pos)
......@@ -607,8 +619,20 @@ void CallWidget::slotAccountChanged(int index)
try {
auto accountList = LRCInstance::accountModel().getAccountList();
setSelectedAccount(accountList.at(index));
auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel;
disconnect(contactAddedConnection_);
contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded,
[this, &contactModel](const std::string & contactId) {
auto convModel = LRCInstance::getCurrentConversationModel();
auto currentConversation = Utils::getConversationFromUid(selectedConvUid(),
*convModel);
if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
ui->messageView->clear();
ui->messageView->printHistory(*convModel, currentConversation->interactions);
}
});
} catch (...) {
qWarning() << "exception changing account";
qWarning() << "CallWidget::slotAccountChanged exception";
}
}
......@@ -851,7 +875,7 @@ CallWidget::showIMOutOfCall(const QModelIndex& nodeIdx)
auto currentConversation = Utils::getConversationFromUid(selectedConvUid(),
*convModel);
ui->messageView->clear();
ui->messageView->printHistory(*convModel, currentConversation->interactions);
ui->messageView->printHistory(*convModel, currentConversation->interactions, true);
// Contact Avatars
auto accInfo = &LRCInstance::getCurrentAccountInfo();
......@@ -927,6 +951,7 @@ void
CallWidget::on_sendContactRequestButton_clicked()
{
LRCInstance::getCurrentConversationModel()->makePermanent(selectedConvUid());
ui->sendContactRequestButton->hide();
}
void
......
......@@ -165,4 +165,6 @@ private:
QMetaObject::Connection selectedCallChanged_;
QMetaObject::Connection smartlistSelectionConnection_;
QMetaObject::Connection interactionRemovedConnection_;
QMetaObject::Connection contactAddedConnection_;
};
......@@ -196,11 +196,12 @@ MessageWebView::removeInteraction(uint64_t interactionId)
void
MessageWebView::printHistory(lrc::api::ConversationModel& conversationModel,
const std::map<uint64_t,
lrc::api::interaction::Info> interactions)
lrc::api::interaction::Info> interactions,
bool fadeIn)
{
auto interactionsStr = interactionsToJsonArrayObject(conversationModel, interactions).toUtf8();
QString s = QString::fromLatin1("printHistory(%1);")
.arg(interactionsStr.constData());
QString s = QString::fromLatin1("printHistory(%1,%2);")
.arg(interactionsStr.constData()).arg(fadeIn);
page()->runJavaScript(s, QWebEngineScript::MainWorld);
}
......@@ -358,6 +359,7 @@ PrivateBridging::acceptInvitation()
try {
auto convUid = LRCInstance::getSelectedConvUid();
LRCInstance::getCurrentConversationModel()->makePermanent(convUid);
qobject_cast<MessageWebView*>(this->parent())->setInvitation(false);
} catch (...) {
qDebug() << "JS bridging - exception during acceptInvitation";
}
......@@ -370,6 +372,10 @@ PrivateBridging::refuseInvitation()
try {
auto convUid = LRCInstance::getSelectedConvUid();
LRCInstance::getCurrentConversationModel()->removeConversation(convUid, false);
if (auto messageView = qobject_cast<MessageWebView*>(this->parent())) {
messageView->setInvitation(false);
emit messageView->conversationRemoved();
}
} catch (...) {
qDebug() << "JS bridging - exception during refuseInvitation";
}
......@@ -382,6 +388,10 @@ PrivateBridging::blockConversation()
try {
auto convUid = LRCInstance::getSelectedConvUid();
LRCInstance::getCurrentConversationModel()->removeConversation(convUid, true);
if (auto messageView = qobject_cast<MessageWebView*>(this->parent())) {
messageView->setInvitation(false);
emit messageView->conversationRemoved();
}
} catch (...) {
qDebug() << "JS bridging - exception during blockConversation";
}
......
......@@ -67,12 +67,18 @@ public:
void removeInteraction(uint64_t interactionId);
void printHistory(lrc::api::ConversationModel& conversationModel,
const std::map<uint64_t,
lrc::api::interaction::Info> interactions);
lrc::api::interaction::Info> interactions,
bool fadeIn = false);
void setSenderImage(const std::string& sender,
const std::string& senderImage);
void setInvitation(bool show, const std::string& contactUri, const std::string& contactId);
void setInvitation(bool show,
const std::string& contactUri = "",
const std::string& contactId = "");
void hideMessages();
signals:
void conversationRemoved();
private slots:
void slotLoadFinished();
......
......@@ -1479,9 +1479,11 @@ function hideBody()
* @param messages_array should contain history to be printed
*/
/* exported printHistory */
function printHistory(messages_array)
function printHistory(messages_array, fadein = false)
{
hideBody()
if (fadein) {
hideBody()
}
historyBuffer = messages_array
historyBufferIndex = 0
......@@ -1490,7 +1492,9 @@ function printHistory(messages_array)
printHistoryPart(messages, 0)
isInitialLoading = false
document.body.classList.remove('fade');
if (fadein) {
document.body.classList.remove('fade');
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment