mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
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:
parent
7664a82fd6
commit
cfa10c6f80
@ -128,6 +128,7 @@ class ChatInfo
|
||||
std::string rsid;
|
||||
unsigned int chatflags;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::wstring msg;
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -193,7 +193,7 @@ PeersDialog::PeersDialog(QWidget *parent)
|
||||
QList<IMHistoryItem> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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) ;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -64,6 +64,7 @@ bool IMHistoryWriter::write(QList<IMHistoryItem>& 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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user