diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index 0b7017a88..da31dbe3c 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -338,12 +338,7 @@ void ChatDialog::setPeerStatus(RsStatusValue status) // convert to virtual peer id // this is only required for private and distant chat, // because lobby and broadcast does not have a status - RsPeerId vpid; - if(mChatId.isPeerId()) - vpid = mChatId.toPeerId(); - if(mChatId.isDistantChatId()) - vpid = RsPeerId(mChatId.toDistantChatId()); - cw->updateStatus(QString::fromStdString(vpid.toStdString()), status); + cw->updateStatus(mChatId, status); } } RsStatusValue ChatDialog::getPeerStatus() diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 9f46fa1ce..8a842616d 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -176,7 +176,8 @@ ChatWidget::ChatWidget(QWidget *parent) //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int))); - mEventHandlerId = 0; + mEventHandlerId_friends = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr e) { RsQThreadUtils::postToObject([=](){ @@ -187,7 +188,7 @@ ChatWidget::ChatWidget(QWidget *parent) switch(fe->mEventCode) { - case RsFriendListEventCode::NODE_STATUS_CHANGED: updateStatus(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus); + case RsFriendListEventCode::NODE_STATUS_CHANGED: updateStatus(ChatId(fe->mSslId),fe->mStatus); break; case RsFriendListEventCode::NODE_STATE_STRING_CHANGED: updatePeersCustomStateString(ChatId(fe->mSslId),QString::fromUtf8(fe->mStateString.c_str())); @@ -198,7 +199,7 @@ ChatWidget::ChatWidget(QWidget *parent) } }, this ); - },mEventHandlerId,RsEventType::FRIEND_LIST); + },mEventHandlerId_friends,RsEventType::FRIEND_LIST); //connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&))); connect(NotifyQt::getInstance(), SIGNAL(chatFontChanged()), this, SLOT(resetFonts())); @@ -282,7 +283,7 @@ ChatWidget::ChatWidget(QWidget *parent) ChatWidget::~ChatWidget() { processSettings(false); - rsEvents->unregisterEventsHandler(mEventHandlerId); + rsEvents->unregisterEventsHandler(mEventHandlerId_friends); /* Cleanup plugin functions */ foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) { @@ -397,7 +398,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title) StatusInfo peerStatusInfo; // No check of return value. Non existing status info is handled as offline. rsStatus->getStatus(chatId.toPeerId(), peerStatusInfo); - updateStatus(QString::fromStdString(chatId.toPeerId().toStdString()), peerStatusInfo.status); + updateStatus(chatId, peerStatusInfo.status); // initialize first custom state string QString customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(chatId.toPeerId()).c_str()); @@ -1820,110 +1821,106 @@ void ChatWidget::setCurrentFileName(const QString &fileName) setWindowModified(false); } -void ChatWidget::updateStatus(const QString &peer_id, RsStatusValue status) +void ChatWidget::updateStatus(const ChatId& cid, RsStatusValue status) { if (! (chatType() == CHATTYPE_PRIVATE || chatType() == CHATTYPE_DISTANT)) { - // updateTitle is used - return; + // updateTitle is used + return; } - // make virtual peer id from gxs id in case of distant chat - RsPeerId vpid; + // // make virtual peer id from gxs id in case of distant chat + // RsPeerId vpid; + // if(chatId.isDistantChatId()) + // vpid = RsPeerId(chatId.toDistantChatId()); + // else + // vpid = chatId.toPeerId(); + + /* set font size for status */ + if (!(cid == chatId)) + return; + + // the peers status has changed + + QString tooltip_info ; + QString peerName ; + if(chatId.isDistantChatId()) - vpid = RsPeerId(chatId.toDistantChatId()); - else - vpid = chatId.toPeerId(); - - /* set font size for status */ - if (peer_id.toStdString() == vpid.toStdString()) { - // the peers status has changed + DistantChatPeerInfo dcpinfo ; + RsIdentityDetails details ; - QString tooltip_info ; - QString peerName ; + if(rsMsgs->getDistantChatStatus(chatId.toDistantChatId(),dcpinfo)) + { + if(rsIdentity->getIdDetails(dcpinfo.to_id,details)) + peerName = QString::fromUtf8( details.mNickname.c_str() ) ; + else + peerName = QString::fromStdString(dcpinfo.to_id.toStdString()) ; - if(chatId.isDistantChatId()) - { - DistantChatPeerInfo dcpinfo ; - RsIdentityDetails details ; - - if(rsMsgs->getDistantChatStatus(chatId.toDistantChatId(),dcpinfo)) - { - if(rsIdentity->getIdDetails(dcpinfo.to_id,details)) - peerName = QString::fromUtf8( details.mNickname.c_str() ) ; - else - peerName = QString::fromStdString(dcpinfo.to_id.toStdString()) ; - - tooltip_info = QString("Identity Id: ")+QString::fromStdString(dcpinfo.to_id.toStdString()); - } - else - { - peerName = QString::fromStdString(chatId.toDistantChatId().toStdString()) ; - tooltip_info = QString("Identity Id: unknown (bug?)"); - } - } - else - { - peerName = QString::fromUtf8(rsPeers->getPeerName(chatId.toPeerId()).c_str()); - tooltip_info = QString("Peer Id: ") + QString::fromStdString(chatId.toPeerId().toStdString()); - } - - // is scrollbar at the end? - QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar(); - bool atEnd = (scrollbar->value() == scrollbar->maximum()); - - switch (status) { - default: - case RsStatusValue::RS_STATUS_OFFLINE: - ui->info_Frame->setVisible(true); - ui->infoLabel->setText(peerName + " " + tr("appears to be Offline.") +"\n" + tr("Messages you send will be delivered after Friend is again Online.")); - break; - - case RsStatusValue::RS_STATUS_INACTIVE: - ui->info_Frame->setVisible(true); - ui->infoLabel->setText(peerName + " " + tr("is Idle and may not reply")); - break; - - case RsStatusValue::RS_STATUS_ONLINE: - ui->info_Frame->setVisible(false); - break; - - case RsStatusValue::RS_STATUS_AWAY: - ui->infoLabel->setText(peerName + " " + tr("is Away and may not reply")); - ui->info_Frame->setVisible(true); - break; - - case RsStatusValue::RS_STATUS_BUSY: - ui->infoLabel->setText(peerName + " " + tr("is Busy and may not reply")); - ui->info_Frame->setVisible(true); - break; - } - - ui->titleLabel->setText(peerName); - ui->titleLabel->setToolTip(tooltip_info); -#warning inconsistent conversion here - ui->statusLabel->setText(QString("(%1)").arg(StatusDefs::name((RsStatusValue)status))); - - peerStatus = status; - - if (atEnd) { - // scroll to the end - scrollbar->setValue(scrollbar->maximum()); - } - - emit infoChanged(this); - emit statusChanged(status); - - // Notify all ChatWidgetHolder - foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) { - chatWidgetHolder->updateStatus(status); - } - - return; + tooltip_info = QString("Identity Id: ")+QString::fromStdString(dcpinfo.to_id.toStdString()); + } + else + { + peerName = QString::fromStdString(chatId.toDistantChatId().toStdString()) ; + tooltip_info = QString("Identity Id: unknown (bug?)"); + } + } + else + { + peerName = QString::fromUtf8(rsPeers->getPeerName(chatId.toPeerId()).c_str()); + tooltip_info = QString("Peer Id: ") + QString::fromStdString(chatId.toPeerId().toStdString()); } - // ignore status change + // is scrollbar at the end? + QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar(); + bool atEnd = (scrollbar->value() == scrollbar->maximum()); + + switch (status) { + default: + case RsStatusValue::RS_STATUS_OFFLINE: + ui->info_Frame->setVisible(true); + ui->infoLabel->setText(peerName + " " + tr("appears to be Offline.") +"\n" + tr("Messages you send will be delivered after Friend is again Online.")); + break; + + case RsStatusValue::RS_STATUS_INACTIVE: + ui->info_Frame->setVisible(true); + ui->infoLabel->setText(peerName + " " + tr("is Idle and may not reply")); + break; + + case RsStatusValue::RS_STATUS_ONLINE: + ui->info_Frame->setVisible(false); + break; + + case RsStatusValue::RS_STATUS_AWAY: + ui->infoLabel->setText(peerName + " " + tr("is Away and may not reply")); + ui->info_Frame->setVisible(true); + break; + + case RsStatusValue::RS_STATUS_BUSY: + ui->infoLabel->setText(peerName + " " + tr("is Busy and may not reply")); + ui->info_Frame->setVisible(true); + break; + } + + ui->titleLabel->setText(peerName); + ui->titleLabel->setToolTip(tooltip_info); +#warning inconsistent conversion here + ui->statusLabel->setText(QString("(%1)").arg(StatusDefs::name((RsStatusValue)status))); + + peerStatus = status; + + if (atEnd) { + // scroll to the end + scrollbar->setValue(scrollbar->maximum()); + } + + emit infoChanged(this); + emit statusChanged(status); + + // Notify all ChatWidgetHolder + foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) { + chatWidgetHolder->updateStatus(status); + } } void ChatWidget::updateTitle() diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index b308bcc81..ed1645b14 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -131,7 +131,7 @@ public: const QList &chatWidgetHolderList() { return mChatWidgetHolder; } public slots: - void updateStatus(const QString &peer_id, RsStatusValue status); + void updateStatus(const ChatId &cid, RsStatusValue status); void setUseCMark(const bool bUseCMark); void updateCMPreview(); @@ -274,7 +274,8 @@ private: Ui::ChatWidget *ui; - RsEventsHandlerId_t mEventHandlerId ; +// RsEventsHandlerId_t mEventHandlerId_chat ; + RsEventsHandlerId_t mEventHandlerId_friends ; }; #endif // CHATWIDGET_H diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 09706990e..a440a2493 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -28,6 +28,7 @@ #include "gui/settings/RsharePeerSettings.h" #include "gui/notifyqt.h" #include "util/DateTime.h" +#include "util/qtthreadsutils.h" #include #include @@ -51,6 +52,25 @@ PopupChatDialog::PopupChatDialog(QWidget *parent, Qt::WindowFlags flags) connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool))); connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages())); //connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), this, SLOT(chatStatusChanged(ChatId,QString))); + + mEventHandlerId_chat =0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + auto fe = dynamic_cast(e.get()); if(!fe) return; + + switch(fe->mEventCode) + { + case RsChatServiceEventCode::CHAT_STATUS_CHANGED: chatStatusChanged(fe->mCid,QString::fromUtf8(fe->mStr.c_str())); break; + default: + break; + } + + } + , this ); + }, mEventHandlerId_chat, RsEventType::CHAT_SERVICE ); } void PopupChatDialog::init(const ChatId &chat_id, const QString &title) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index a88df7a2f..9708fbaae 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -65,6 +65,8 @@ protected: /** Qt Designer generated object */ Ui::PopupChatDialog ui; + + RsEventsHandlerId_t mEventHandlerId_chat; }; #endif diff --git a/retroshare-gui/src/gui/chat/PopupChatWindow.ui b/retroshare-gui/src/gui/chat/PopupChatWindow.ui index 0394a1c31..7f1dc2f24 100644 --- a/retroshare-gui/src/gui/chat/PopupChatWindow.ui +++ b/retroshare-gui/src/gui/chat/PopupChatWindow.ui @@ -85,7 +85,7 @@ - + :/images/tab-dock.png:/images/tab-dock.png @@ -97,7 +97,7 @@ - + :/images/tab-undock.png:/images/tab-undock.png