Added receive time to ChatInfo - recompile of gui needed.

Use receive time for chat information to have the right order in the history (problem of time zones and wrong clocks).

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3593 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-10-03 10:08:58 +00:00
parent 7664a82fd6
commit cfa10c6f80
12 changed files with 42 additions and 30 deletions

View File

@ -128,6 +128,7 @@ class ChatInfo
std::string rsid; std::string rsid;
unsigned int chatflags; unsigned int chatflags;
uint32_t sendTime; uint32_t sendTime;
uint32_t recvTime;
std::wstring msg; std::wstring msg;
}; };

View File

@ -89,6 +89,7 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
ci->PeerId(*it); ci->PeerId(*it);
ci->chatFlags = 0; ci->chatFlags = 0;
ci->sendTime = time(NULL); ci->sendTime = time(NULL);
ci->recvTime = ci->sendTime;
ci->message = msg; ci->message = msg;
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
@ -216,6 +217,7 @@ bool p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg)
ci->PeerId(id); ci->PeerId(id);
ci->chatFlags = RS_CHAT_FLAG_PRIVATE; ci->chatFlags = RS_CHAT_FLAG_PRIVATE;
ci->sendTime = time(NULL); ci->sendTime = time(NULL);
ci->recvTime = ci->sendTime;
ci->message = msg; ci->message = msg;
if (!mConnMgr->isOnline(id)) { if (!mConnMgr->isOnline(id)) {
@ -599,7 +601,8 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
{ {
i.rsid = c->PeerId(); i.rsid = c->PeerId();
i.chatflags = 0; i.chatflags = 0;
i.sendTime =c->sendTime; i.sendTime = c->sendTime;
i.recvTime = c->recvTime;
i.msg = c->message; i.msg = c->message;
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)

View File

@ -193,7 +193,7 @@ PeersDialog::PeersDialog(QWidget *parent)
QList<IMHistoryItem> historyItems; QList<IMHistoryItem> historyItems;
historyKeeper.getMessages(historyItems, 20); historyKeeper.getMessages(historyItems, 20);
foreach(IMHistoryItem item, historyItems) { 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; 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; 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); ui.msgText->append(formatMsg);
} }
@ -1418,6 +1418,7 @@ void PeersDialog::insertChat()
} }
QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); QDateTime sendTime = QDateTime::fromTime_t(it->sendTime);
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid)); QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid));
QString msg = QString::fromStdWString(it->msg); QString msg = QString::fromStdWString(it->msg);
@ -1443,8 +1444,8 @@ void PeersDialog::insertChat()
emit notifyGroupChat(QString("New group chat"), notifyMsg); emit notifyGroupChat(QString("New group chat"), notifyMsg);
} }
historyKeeper.addMessage(incoming, it->rsid, name, sendTime, msg); historyKeeper.addMessage(incoming, it->rsid, name, sendTime, recvTime, msg);
addChatMsg(incoming, false, name, sendTime, msg); addChatMsg(incoming, false, name, recvTime, msg);
} }
} }

View File

@ -173,7 +173,7 @@ signals:
private: private:
void processSettings(bool bLoad); 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 QLabel *iconLabel, *textLabel;
class QWidget *widget; class QWidget *widget;

View File

@ -229,7 +229,7 @@ PopupChatDialog::PopupChatDialog(std::string id, const QString name, QWidget *pa
} }
if (offineChatIt == offlineChat.end()) { 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)); QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid));
QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); QDateTime sendTime = QDateTime::fromTime_t(it->sendTime);
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
QString message = QString::fromStdWString(it->msg); QString message = QString::fromStdWString(it->msg);
bool existingMessage; bool existingMessage;
@ -591,7 +592,7 @@ void PopupChatDialog::onPrivateChatChanged(int list, int type, bool initial /*=
} }
if (showMessage) { 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++) { for(it = m_savedOfflineChat.begin(); it != m_savedOfflineChat.end(); it++) {
QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid)); QString name = QString::fromStdString(rsPeers->getPeerName(it->rsid));
QDateTime sendTime = QDateTime::fromTime_t(it->sendTime); QDateTime sendTime = QDateTime::fromTime_t(it->sendTime);
QDateTime recvTime = QDateTime::fromTime_t(it->recvTime);
QString message = QString::fromStdWString(it->msg); 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; 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); rsMsgs->clearPrivateChatQueue(true, dialogId);
@ -655,13 +657,10 @@ void PopupChatDialog::insertChatMsgs()
QApplication::alert(this); 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(); std::string ownId = rsPeers->getOwnId();
//...
// QString name = QString::fromStdString(rsPeers->getPeerName(offline ? ownId : id));
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl; std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl;
#endif #endif
@ -682,14 +681,10 @@ void PopupChatDialog::addChatMsg(bool incoming, const std::string &id, const QSt
type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING; type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING;
} }
QString formatMsg = style.formatMessage(type, name, sendTime, message, formatFlag); QString formatMsg = style.formatMessage(type, name, recvTime, message, formatFlag);
// if (offline) {
// ui.offlineTextBrowser->append(formatMsg);
// }
if (addToHistory) { if (addToHistory) {
historyKeeper.addMessage(incoming, id, name, sendTime, message); historyKeeper.addMessage(incoming, id, name, sendTime, recvTime, message);
} }
ui.textBrowser->append(formatMsg); ui.textBrowser->append(formatMsg);
@ -761,7 +756,8 @@ void PopupChatDialog::sendChat()
#endif #endif
if (rsMsgs->sendPrivateChat(dialogId, msg)) { 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(); chatWidget->clear();
@ -1063,7 +1059,8 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file)
std::wstring msg = message.toStdWString(); std::wstring msg = message.toStdWString();
if (rsMsgs->sendPrivateChat(dialogId, msg)) { 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);
} }
} }

View File

@ -86,7 +86,7 @@ protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
void insertChatMsgs(); 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(); void updateAvatar();

View File

@ -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; hiid = hiidIn;
incoming = incomingIn; incoming = incomingIn;
id = idIn; id = idIn;
name = nameIn; name = nameIn;
sendTime = sendTimeIn; sendTime = sendTimeIn;
recvTime = recvTimeIn;
messageText = messageTextIn; messageText = messageTextIn;
} }
@ -46,5 +47,5 @@ IMHistoryItem::IMHistoryItem(int hiidIn, bool incomingIn, const std::string &idI
bool bool
IMHistoryItem::operator<(const IMHistoryItem& item) const IMHistoryItem::operator<(const IMHistoryItem& item) const
{ {
return (sendTime < item.sendTime) ; return (recvTime < item.recvTime) ;
} }

View File

@ -30,13 +30,14 @@ class IMHistoryItem
public: public:
IMHistoryItem(); 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; int hiid;
bool incoming; bool incoming;
std::string id; std::string id;
QString name; QString name;
QDateTime sendTime; QDateTime sendTime;
QDateTime recvTime;
QString messageText; QString messageText;
bool operator<(const IMHistoryItem& item) const; bool operator<(const IMHistoryItem& item) const;

View File

@ -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); hitems.append(item);

View File

@ -78,7 +78,7 @@ public:
//! Adds new message to the history, but the message will be saved to //! Adds new message to the history, but the message will be saved to
//! file only after destroing the object //! 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 //! Clear the history
void clear(); void clear();

View File

@ -178,6 +178,13 @@ void IMHistoryReader::readMessage(IMHistoryItem &historyItem)
int ti = attributes().value("sendTime").toString().toInt(); int ti = attributes().value("sendTime").toString().toInt();
historyItem.sendTime = QDateTime::fromTime_t(ti); 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 //=== after processing attributes, read the message text
QString tstr = readElementText(); QString tstr = readElementText();

View File

@ -64,6 +64,7 @@ bool IMHistoryWriter::write(QList<IMHistoryItem>& itemList, const QString fileNa
writeAttribute("id", QString::fromStdString(item.id)); writeAttribute("id", QString::fromStdString(item.id));
writeAttribute("name", item.name); writeAttribute("name", item.name);
writeAttribute("sendTime", QString::number(item.sendTime.toTime_t())); writeAttribute("sendTime", QString::number(item.sendTime.toTime_t()));
writeAttribute("recvTime", QString::number(item.recvTime.toTime_t()));
writeCDATA(item.messageText); writeCDATA(item.messageText);
writeEndElement(); writeEndElement();
} }