no notifications for history messages
diff --git a/chatdialog.cpp b/chatdialog.cpp
index 1b0329c..fba460b 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -56,7 +56,7 @@
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
connect(treeButton, SIGNAL(pressed()), this, SLOT(treeButtonPressed()));
- connect(this, SIGNAL(dataReceived(QString, const char *, size_t, bool)), this, SLOT(processData(QString, const char *, size_t, bool)));
+ connect(this, SIGNAL(dataReceived(QString, const char *, size_t, bool, bool)), this, SLOT(processData(QString, const char *, size_t, bool, bool)));
connect(this, SIGNAL(treeUpdated(const std::vector<Sync::MissingDataInfo>)), this, SLOT(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(replot()));
connect(m_scene, SIGNAL(replot()), this, SLOT(replot()));
@@ -186,7 +186,7 @@
}
void
-ChatDialog::appendMessage(const SyncDemo::ChatMessage msg)
+ChatDialog::appendMessage(const SyncDemo::ChatMessage msg, bool isHistory)
{
boost::recursive_mutex::scoped_lock lock(m_msgMutex);
@@ -238,7 +238,10 @@
nextCursor.movePosition(QTextCursor::End);
table = nextCursor.insertTable(1, 1, tableFormat);
table->cellAt(0, 0).firstCursorPosition().insertText(msg.data().c_str());
- showMessage(from, msg.data().c_str());
+ if (!isHistory)
+ {
+ showMessage(from, msg.data().c_str());
+ }
}
if (msg.type() == SyncDemo::ChatMessage::JOIN || msg.type() == SyncDemo::ChatMessage::LEAVE)
@@ -375,7 +378,7 @@
{
char *tempBuf = new char[len];
memcpy(tempBuf, buf, len);
- emit dataReceived(name.c_str(), tempBuf, len, true);
+ emit dataReceived(name.c_str(), tempBuf, len, true, false);
#ifdef __DEBUG
std::cout <<"<<< " << name << " fetched" << std::endl;
#endif
@@ -386,7 +389,7 @@
{
char *tempBuf = new char[len];
memcpy(tempBuf, buf, len);
- emit dataReceived(name.c_str(), tempBuf, len, false);
+ emit dataReceived(name.c_str(), tempBuf, len, false, false);
if (!m_historyInitialized)
{
@@ -395,6 +398,14 @@
}
}
+void
+ChatDialog::processDataHistoryWrapper(std::string name, const char *buf, size_t len)
+{
+ char *tempBuf = new char[len];
+ memcpy(tempBuf, buf, len);
+ emit dataReceived(name.c_str(), tempBuf, len, true, true);
+}
+
void
ChatDialog::fetchHistory(std::string name)
{
@@ -406,7 +417,7 @@
for (int i = 0; i < MAX_HISTORY_ENTRY; i++)
{
QString interest = QString("%1/%2/%3").arg(prefix.c_str()).arg(randomString).arg(i);
- handle->sendInterest(interest.toStdString(), bind(&ChatDialog::processDataWrapper, this, _1, _2, _3));
+ handle->sendInterest(interest.toStdString(), bind(&ChatDialog::processDataHistoryWrapper, this, _1, _2, _3));
}
}
@@ -428,7 +439,7 @@
}
void
-ChatDialog::processData(QString name, const char *buf, size_t len, bool show)
+ChatDialog::processData(QString name, const char *buf, size_t len, bool show, bool isHistory)
{
SyncDemo::ChatMessage msg;
bool corrupted = false;
@@ -451,24 +462,27 @@
// the "cannonical" way to is use signal-slot
if (show && !corrupted)
{
- appendMessage(msg);
+ appendMessage(msg, isHistory);
}
- // update the tree view
- std::string stdStrName = name.toStdString();
- std::string stdStrNameWithoutSeq = stdStrName.substr(0, stdStrName.find_last_of('/'));
- std::string prefix = stdStrNameWithoutSeq.substr(0, stdStrNameWithoutSeq.find_last_of('/'));
+ if (!isHistory)
+ {
+ // update the tree view
+ std::string stdStrName = name.toStdString();
+ std::string stdStrNameWithoutSeq = stdStrName.substr(0, stdStrName.find_last_of('/'));
+ std::string prefix = stdStrNameWithoutSeq.substr(0, stdStrNameWithoutSeq.find_last_of('/'));
#ifdef __DEBUG
- std::cout <<"<<< updating scene for" << prefix << ": " << msg.from() << std::endl;
+ std::cout <<"<<< updating scene for" << prefix << ": " << msg.from() << std::endl;
#endif
- if (msg.type() == SyncDemo::ChatMessage::LEAVE)
- {
- processRemove(prefix.c_str());
- }
- else
- {
- boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
- m_scene->msgReceived(prefix.c_str(), msg.from().c_str());
+ if (msg.type() == SyncDemo::ChatMessage::LEAVE)
+ {
+ processRemove(prefix.c_str());
+ }
+ else
+ {
+ boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
+ m_scene->msgReceived(prefix.c_str(), msg.from().c_str());
+ }
}
fitView();
}
diff --git a/chatdialog.h b/chatdialog.h
index 5319f37..a801931 100644
--- a/chatdialog.h
+++ b/chatdialog.h
@@ -29,10 +29,11 @@
ChatDialog(QWidget *parent = 0);
~ChatDialog();
void setVisible(bool visible);
- void appendMessage(const SyncDemo::ChatMessage msg);
+ void appendMessage(const SyncDemo::ChatMessage msg, bool isHistory = false);
void processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncAppSocket *);
void processDataWrapper(std::string, const char *buf, size_t len);
void processDataNoShowWrapper(std::string, const char *buf, size_t len);
+ void processDataHistoryWrapper(std::string, const char *buf, size_t len);
void processRemoveWrapper(std::string);
void respondHistoryRequest(std::string interest);
@@ -42,7 +43,7 @@
public slots:
void processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
- void processData(QString name, const char *buf, size_t len, bool show);
+ void processData(QString name, const char *buf, size_t len, bool show, bool isHistory);
void processRemove(QString);
private:
@@ -84,7 +85,7 @@
void messageClicked();
signals:
- void dataReceived(QString name, const char *buf, size_t len, bool show);
+ void dataReceived(QString name, const char *buf, size_t len, bool show, bool isHistory);
void treeUpdated(const std::vector<Sync::MissingDataInfo>);
void removeReceived(QString prefix);