diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 773529167..6149a1f1c 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -128,6 +128,7 @@ class ChatInfo std::string rsid; unsigned int chatflags; uint32_t sendTime; + uint32_t recvTime; std::wstring msg; }; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 09fbd8a77..1010b6184 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -89,6 +89,7 @@ int p3ChatService::sendPublicChat(std::wstring &msg) ci->PeerId(*it); ci->chatFlags = 0; ci->sendTime = time(NULL); + ci->recvTime = ci->sendTime; ci->message = msg; #ifdef CHAT_DEBUG @@ -216,6 +217,7 @@ bool p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg) ci->PeerId(id); ci->chatFlags = RS_CHAT_FLAG_PRIVATE; ci->sendTime = time(NULL); + ci->recvTime = ci->sendTime; ci->message = msg; if (!mConnMgr->isOnline(id)) { @@ -599,7 +601,8 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i) { i.rsid = c->PeerId(); i.chatflags = 0; - i.sendTime =c->sendTime; + i.sendTime = c->sendTime; + i.recvTime = c->recvTime; i.msg = c->message; if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 4ae6cd626..fa2faa1fb 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -193,7 +193,7 @@ PeersDialog::PeersDialog(QWidget *parent) QList historyItems; historyKeeper.getMessages(historyItems, 20); foreach(IMHistoryItem item, historyItems) { - addChatMsg(item.incoming, true, item.name, item.sendTime, item.messageText); + addChatMsg(item.incoming, true, item.name, item.recvTime, item.messageText); } } @@ -1364,7 +1364,7 @@ void PeersDialog::publicChatChanged(int type) } } -void PeersDialog::addChatMsg(bool incoming, bool history, QString &name, QDateTime &sendTime, QString &message) +void PeersDialog::addChatMsg(bool incoming, bool history, QString &name, QDateTime &recvTime, QString &message) { unsigned int formatFlag = CHAT_FORMATMSG_EMBED_LINKS; @@ -1387,7 +1387,7 @@ void PeersDialog::addChatMsg(bool incoming, bool history, QString &name, QDateTi type = ChatStyle::FORMATMSG_OUTGOING; } } - QString formatMsg = style.formatMessage(type, name, sendTime, message, formatFlag); + QString formatMsg = style.formatMessage(type, name, recvTime, message, formatFlag); ui.msgText->append(formatMsg); } @@ -1418,6 +1418,7 @@ void PeersDialog::insertChat() } QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); + QDateTime recvTime = QDateTime::fromTime_t(it->recvTime); QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid)); QString msg = QString::fromStdWString(it->msg); @@ -1443,8 +1444,8 @@ void PeersDialog::insertChat() emit notifyGroupChat(QString("New group chat"), notifyMsg); } - historyKeeper.addMessage(incoming, it->rsid, name, sendTime, msg); - addChatMsg(incoming, false, name, sendTime, msg); + historyKeeper.addMessage(incoming, it->rsid, name, sendTime, recvTime, msg); + addChatMsg(incoming, false, name, recvTime, msg); } } diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 0a1d718ee..3cb02e571 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -173,7 +173,7 @@ signals: private: void processSettings(bool bLoad); - void addChatMsg(bool incoming, bool history, QString &name, QDateTime &sendTime, QString &message); + void addChatMsg(bool incoming, bool history, QString &name, QDateTime &recvTime, QString &message); class QLabel *iconLabel, *textLabel; class QWidget *widget; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index b1101b262..b89a5e65e 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -229,7 +229,7 @@ PopupChatDialog::PopupChatDialog(std::string id, const QString name, QWidget *pa } if (offineChatIt == offlineChat.end()) { - addChatMsg(item.incoming, item.id, item.name, item.sendTime, item.messageText, TYPE_HISTORY, false); + addChatMsg(item.incoming, item.id, item.name, item.sendTime, item.recvTime, item.messageText, TYPE_HISTORY, false); } } } @@ -576,6 +576,7 @@ void PopupChatDialog::onPrivateChatChanged(int list, int type, bool initial /*= QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid)); QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); + QDateTime recvTime = QDateTime::fromTime_t(it->recvTime); QString message = QString::fromStdWString(it->msg); bool existingMessage; @@ -591,7 +592,7 @@ void PopupChatDialog::onPrivateChatChanged(int list, int type, bool initial /*= } if (showMessage) { - addChatMsg(false, it->rsid, name, sendTime, message, TYPE_OFFLINE, !existingMessage); + addChatMsg(false, it->rsid, name, sendTime, recvTime, message, TYPE_OFFLINE, !existingMessage); } } } @@ -605,9 +606,10 @@ void PopupChatDialog::onPrivateChatChanged(int list, int type, bool initial /*= for(it = m_savedOfflineChat.begin(); it != m_savedOfflineChat.end(); it++) { QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid)); QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); + QDateTime recvTime = QDateTime::fromTime_t(it->recvTime); QString message = QString::fromStdWString(it->msg); - addChatMsg(false, it->rsid, name, sendTime, message, TYPE_NORMAL, false); + addChatMsg(false, it->rsid, name, sendTime, recvTime, message, TYPE_NORMAL, false); } } @@ -646,7 +648,7 @@ void PopupChatDialog::insertChatMsgs() continue; } - addChatMsg(true, it->rsid, QString::fromStdString(rsPeers->getPeerName(it->rsid)), QDateTime::fromTime_t(it->sendTime), QString::fromStdWString(it->msg), TYPE_NORMAL, true); + addChatMsg(true, it->rsid, QString::fromStdString(rsPeers->getPeerName(it->rsid)), QDateTime::fromTime_t(it->sendTime), QDateTime::fromTime_t(it->recvTime), QString::fromStdWString(it->msg), TYPE_NORMAL, true); } rsMsgs->clearPrivateChatQueue(true, dialogId); @@ -655,13 +657,10 @@ void PopupChatDialog::insertChatMsgs() QApplication::alert(this); } -void PopupChatDialog::addChatMsg(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QString &message, enumChatType chatType, bool addToHistory) +void PopupChatDialog::addChatMsg(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType, bool addToHistory) { std::string ownId = rsPeers->getOwnId(); -//... -// QString name = QString::fromStdString(rsPeers->getPeerName(offline ? ownId : id)); - #ifdef CHAT_DEBUG std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl; #endif @@ -682,14 +681,10 @@ void PopupChatDialog::addChatMsg(bool incoming, const std::string &id, const QSt type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING; } - QString formatMsg = style.formatMessage(type, name, sendTime, message, formatFlag); - -// if (offline) { -// ui.offlineTextBrowser->append(formatMsg); -// } + QString formatMsg = style.formatMessage(type, name, recvTime, message, formatFlag); if (addToHistory) { - historyKeeper.addMessage(incoming, id, name, sendTime, message); + historyKeeper.addMessage(incoming, id, name, sendTime, recvTime, message); } ui.textBrowser->append(formatMsg); @@ -761,7 +756,8 @@ void PopupChatDialog::sendChat() #endif if (rsMsgs->sendPrivateChat(dialogId, msg)) { - addChatMsg(false, ownId, QString::fromStdString(rsPeers->getPeerName(ownId)), QDateTime::currentDateTime(), QString::fromStdWString(msg), TYPE_NORMAL, true); + QDateTime currentTime = QDateTime::currentDateTime(); + addChatMsg(false, ownId, QString::fromStdString(rsPeers->getPeerName(ownId)), currentTime, currentTime, QString::fromStdWString(msg), TYPE_NORMAL, true); } chatWidget->clear(); @@ -1063,7 +1059,8 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) std::wstring msg = message.toStdWString(); if (rsMsgs->sendPrivateChat(dialogId, msg)) { - addChatMsg(false, ownId, QString::fromStdString(rsPeers->getPeerName(ownId)), QDateTime::currentDateTime(), QString::fromStdWString(msg), TYPE_NORMAL, true); + QDateTime currentTime = QDateTime::currentDateTime(); + addChatMsg(false, ownId, QString::fromStdString(rsPeers->getPeerName(ownId)), currentTime, currentTime, QString::fromStdWString(msg), TYPE_NORMAL, true); } } diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index d28011bdf..8fc94e0b4 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -86,7 +86,7 @@ protected: bool eventFilter(QObject *obj, QEvent *ev); void insertChatMsgs(); - void addChatMsg(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QString &message, enumChatType chatType, bool addToHistory); + void addChatMsg(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType, bool addToHistory); void updateAvatar(); diff --git a/retroshare-gui/src/gui/im_history/IMHistoryItem.cpp b/retroshare-gui/src/gui/im_history/IMHistoryItem.cpp index 935c58005..afd6ded2f 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryItem.cpp +++ b/retroshare-gui/src/gui/im_history/IMHistoryItem.cpp @@ -30,13 +30,14 @@ IMHistoryItem::IMHistoryItem() //============================================================================ -IMHistoryItem::IMHistoryItem(int hiidIn, bool incomingIn, const std::string &idIn, const QString &nameIn, const QDateTime &sendTimeIn, const QString &messageTextIn) +IMHistoryItem::IMHistoryItem(int hiidIn, bool incomingIn, const std::string &idIn, const QString &nameIn, const QDateTime &sendTimeIn, const QDateTime &recvTimeIn, const QString &messageTextIn) { hiid = hiidIn; incoming = incomingIn; id = idIn; name = nameIn; sendTime = sendTimeIn; + recvTime = recvTimeIn; messageText = messageTextIn; } @@ -46,5 +47,5 @@ IMHistoryItem::IMHistoryItem(int hiidIn, bool incomingIn, const std::string &idI bool IMHistoryItem::operator<(const IMHistoryItem& item) const { - return (sendTime < item.sendTime) ; + return (recvTime < item.recvTime) ; } diff --git a/retroshare-gui/src/gui/im_history/IMHistoryItem.h b/retroshare-gui/src/gui/im_history/IMHistoryItem.h index d8361bd45..85306c95a 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryItem.h +++ b/retroshare-gui/src/gui/im_history/IMHistoryItem.h @@ -30,13 +30,14 @@ class IMHistoryItem public: IMHistoryItem(); - IMHistoryItem(int hiid, bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QString &messageText); + IMHistoryItem(int hiid, bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &messageText); int hiid; bool incoming; std::string id; QString name; QDateTime sendTime; + QDateTime recvTime; QString messageText; bool operator<(const IMHistoryItem& item) const; diff --git a/retroshare-gui/src/gui/im_history/IMHistoryKeeper.cpp b/retroshare-gui/src/gui/im_history/IMHistoryKeeper.cpp index c1601211a..54d3efb22 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryKeeper.cpp +++ b/retroshare-gui/src/gui/im_history/IMHistoryKeeper.cpp @@ -67,9 +67,9 @@ void IMHistoryKeeper::init(QString historyFileName) //============================================================================= -void IMHistoryKeeper::addMessage(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QString &messageText) +void IMHistoryKeeper::addMessage(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &messageText) { - IMHistoryItem item(++lasthiid, incoming, id, name, sendTime, messageText); + IMHistoryItem item(++lasthiid, incoming, id, name, sendTime, recvTime, messageText); hitems.append(item); diff --git a/retroshare-gui/src/gui/im_history/IMHistoryKeeper.h b/retroshare-gui/src/gui/im_history/IMHistoryKeeper.h index c8fa46992..4349c9c09 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryKeeper.h +++ b/retroshare-gui/src/gui/im_history/IMHistoryKeeper.h @@ -78,7 +78,7 @@ public: //! Adds new message to the history, but the message will be saved to //! file only after destroing the object - void addMessage(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QString &messageText); + void addMessage(bool incoming, const std::string &id, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &messageText); //! Clear the history void clear(); diff --git a/retroshare-gui/src/gui/im_history/IMHistoryReader.cpp b/retroshare-gui/src/gui/im_history/IMHistoryReader.cpp index 6f6b4c3e5..601b56027 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryReader.cpp +++ b/retroshare-gui/src/gui/im_history/IMHistoryReader.cpp @@ -178,6 +178,13 @@ void IMHistoryReader::readMessage(IMHistoryItem &historyItem) int ti = attributes().value("sendTime").toString().toInt(); historyItem.sendTime = QDateTime::fromTime_t(ti); + ti = attributes().value("recvTime").toString().toInt(); + if (ti) { + historyItem.recvTime = QDateTime::fromTime_t(ti); + } else { + historyItem.recvTime = historyItem.sendTime; + } + //=== after processing attributes, read the message text QString tstr = readElementText(); diff --git a/retroshare-gui/src/gui/im_history/IMHistoryWriter.cpp b/retroshare-gui/src/gui/im_history/IMHistoryWriter.cpp index 6d4325243..60d445d4b 100644 --- a/retroshare-gui/src/gui/im_history/IMHistoryWriter.cpp +++ b/retroshare-gui/src/gui/im_history/IMHistoryWriter.cpp @@ -64,6 +64,7 @@ bool IMHistoryWriter::write(QList& itemList, const QString fileNa writeAttribute("id", QString::fromStdString(item.id)); writeAttribute("name", item.name); writeAttribute("sendTime", QString::number(item.sendTime.toTime_t())); + writeAttribute("recvTime", QString::number(item.recvTime.toTime_t())); writeCDATA(item.messageText); writeEndElement(); }