Improve async distant chat, fix chat msg receiving

DistantChatService::initiateDistantChatConnexion(...) made notification
  message optional (enabled by default)
p3ChatService removed duplicion avoidance as it is not necessary
p3ChatService::sendStatusString(...) send status only if peer is online
protect p3ChatService::mDistantGxsMap with mutex as operation on it may
  be done by different threads
p3ChatService::receiveGxsMai(...) set chat message item peer id with
  distant tunnel id, so it is recognized as a distant message later
made p3GxsTunnelService::makeGxsTunnelId(...) static as it need no
  access to this, now it can be used easier by other components
rename RsGxsMailItem::recipientsHint to recipientHint as for now only
  one recipient is possible (TODO: update documentation too)
GxsMailsClient::receiveGxsMail(...) changed paramethers for better
  abstracion, now destination id is passed too because it is usually a
  very useful information
ChatWidget some adaptation to async chat, a couple of method have been
  deprecated too
PopupDistantChatDialog::updateDisplay(...) adapt message shown to the
  user to the new async chat paradigm (TODO: need review)
This commit is contained in:
Gioacchino Mazzurco 2017-03-01 23:07:53 +01:00
parent 0f1106fd8f
commit 953b70fbe4
14 changed files with 212 additions and 212 deletions

View file

@ -70,7 +70,7 @@
*****/
ChatWidget::ChatWidget(QWidget *parent) :
QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget)
QWidget(parent), ui(new Ui::ChatWidget)
{
ui->setupUi(this);
@ -413,18 +413,9 @@ ChatWidget::ChatType ChatWidget::chatType()
return CHATTYPE_UNKNOWN;
}
void ChatWidget::blockSending(QString msg)
{
sendingBlocked = true;
ui->sendButton->setEnabled(false);
ui->sendButton->setToolTip(msg);
}
void ChatWidget::blockSending(QString msg) { ui->sendButton->setToolTip(msg); }
void ChatWidget::unblockSending()
{
sendingBlocked = false;
updateLenOfChatTextEdit();
}
void ChatWidget::unblockSending() { updateLenOfChatTextEdit(); }
void ChatWidget::processSettings(bool load)
{
@ -1096,8 +1087,6 @@ void ChatWidget::updateStatusTyping()
void ChatWidget::updateLenOfChatTextEdit()
{
if(sendingBlocked) return;
QTextEdit *chatWidget = ui->chatTextEdit;
QString text;
RsHtml::optimizeHtml(chatWidget, text);

View file

@ -36,6 +36,7 @@
#include <retroshare/rsmsgs.h>
#include <retroshare/rsfiles.h>
#include <util/rsdeprecate.h>
class QAction;
class QTextEdit;
@ -78,9 +79,8 @@ public:
ChatId getChatId();
ChatType chatType();
// allow/disallow sendng of messages
void blockSending(QString msg);
void unblockSending();
RS_DEPRECATED void blockSending(QString msg);
RS_DEPRECATED void unblockSending();
bool hasNewMessages() { return newMessages; }
bool isTyping() { return typing; }
@ -216,8 +216,6 @@ private:
bool typing;
int peerStatus;
bool sendingBlocked;
time_t lastStatusSendTime;
ChatStyle chatStyle;

View file

@ -104,41 +104,52 @@ void PopupDistantChatDialog::updateDisplay()
QString msg;
switch(tinfo.status)
{
case RS_DISTANT_CHAT_STATUS_UNKNOWN: //std::cerr << "Unknown hash. Error!" << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRY_LED)) ;
msg = tr("Chat remotely closed. Please close this window.");
_status_label->setToolTip(msg) ;
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(tr("Can't send message, because there is no tunnel."));
setPeerStatus(RS_STATUS_OFFLINE) ;
break ;
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED: std::cerr << "Chat remotely closed. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_RED_LED)) ;
_status_label->setToolTip(QObject::tr("Distant peer has closed the chat")) ;
getChatWidget()->updateStatusString("%1", tr("The person you're talking to has deleted the secured chat tunnel. You may remove the chat window now."), true);
getChatWidget()->blockSending(tr("Can't send message, because the chat partner deleted the secure tunnel."));
setPeerStatus(RS_STATUS_OFFLINE) ;
break ;
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: //std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_RED_LED)) ;
msg = QObject::tr("Tunnel is pending...");
_status_label->setToolTip(msg) ;
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(msg);
setPeerStatus(RS_STATUS_OFFLINE) ;
break ;
case RS_DISTANT_CHAT_STATUS_CAN_TALK: //std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRN_LED)) ;
msg = QObject::tr("Secured tunnel is working. You can talk!");
_status_label->setToolTip(msg) ;
getChatWidget()->unblockSending();
setPeerStatus(RS_STATUS_ONLINE) ;
break ;
}
switch(tinfo.status)
{
case RS_DISTANT_CHAT_STATUS_UNKNOWN:
//std::cerr << "Unknown hash. Error!" << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRY_LED));
msg = tr("Remote status unknown.");
_status_label->setToolTip(msg);
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(tr( "Can't send message immediately, "
"because there is no tunnel "
"available." ));
setPeerStatus(RS_STATUS_OFFLINE);
break ;
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED:
std::cerr << "Chat remotely closed. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_RED_LED));
_status_label->setToolTip(
QObject::tr("Distant peer has closed the chat") );
getChatWidget()->updateStatusString(
"%1", tr( "The person you're talking to has deleted the"
"secured chat tunnel." ), true );
getChatWidget()->blockSending(tr( "The chat partner deleted the secure"
" tunnel, messages will be delivered"
" as soon as possible"));
setPeerStatus(RS_STATUS_OFFLINE) ;
break ;
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN:
//std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_RED_LED));
msg = QObject::tr( "Tunnel is pending... Messages will be delivered as"
" soon as possible" );
_status_label->setToolTip(msg);
getChatWidget()->updateStatusString("%1", msg, true);
getChatWidget()->blockSending(msg);
setPeerStatus(RS_STATUS_OFFLINE);
break;
case RS_DISTANT_CHAT_STATUS_CAN_TALK:
//std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRN_LED));
msg = QObject::tr( "Secured tunnel is working."
"Messages are delivered immediately!" );
_status_label->setToolTip(msg);
getChatWidget()->unblockSending();
setPeerStatus(RS_STATUS_ONLINE);
break;
}
}
void PopupDistantChatDialog::closeEvent(QCloseEvent *e)