gui: adjust display of sync tree

Change-Id: Ie6afc35aae2a6414d3660cbb8151c625c43c0f69
diff --git a/src/chat-dialog-backend.cpp b/src/chat-dialog-backend.cpp
index 216f465..6cd24ad 100644
--- a/src/chat-dialog-backend.cpp
+++ b/src/chat-dialog-backend.cpp
@@ -222,11 +222,6 @@
                         2);
     }
 
-    // prepare notification to frontend
-    NodeInfo nodeInfo;
-    nodeInfo.sessionPrefix = QString::fromStdString(updates[i].session.toUri());
-    nodeInfo.seqNo = updates[i].high;
-    nodeInfos.push_back(nodeInfo);
   }
 
   // reflect the changes on GUI
@@ -280,24 +275,7 @@
       BOOST_ASSERT(false);
     }
 
-    // If we haven't got any message from this session yet.
-    if (m_roster[remoteSessionPrefix].hasNick == false) {
-      m_roster[remoteSessionPrefix].userNick = msg.from();
-      m_roster[remoteSessionPrefix].hasNick = true;
-      emit sessionAdded(QString::fromStdString(remoteSessionPrefix.toUri()),
-                        QString::fromStdString(msg.from()),
-                        msg.timestamp());
-
-      emit addInRoster(remoteSessionPrefix.getPrefix(IDENTITY_OFFSET),
-                       Name::Component(m_chatroomName));
-    }
-
-    // If we get a new nick for an existing session, update it.
-    if (m_roster[remoteSessionPrefix].userNick != msg.from()) {
-      m_roster[remoteSessionPrefix].userNick = msg.from();
-      emit nickUpdated(QString::fromStdString(remoteSessionPrefix.toUri()),
-                       QString::fromStdString(msg.from()));
-    }
+    uint64_t seqNo = data->getName().get(-1).toNumber();
 
     // If a timeout event has been scheduled, cancel it.
     if (static_cast<bool>(it->second.timeoutEventId))
@@ -322,7 +300,27 @@
     }
 
     // Notify frontend to plot notification on DigestTree.
-    emit messageReceived(QString::fromStdString(remoteSessionPrefix.toUri()));
+
+    // If we haven't got any message from this session yet.
+    if (m_roster[remoteSessionPrefix].hasNick == false) {
+      m_roster[remoteSessionPrefix].userNick = msg.from();
+      m_roster[remoteSessionPrefix].hasNick = true;
+
+      emit messageReceived(QString::fromStdString(remoteSessionPrefix.toUri()),
+                           QString::fromStdString(msg.from()),
+                           seqNo,
+                           msg.timestamp(),
+                           true);
+
+      emit addInRoster(remoteSessionPrefix.getPrefix(IDENTITY_OFFSET),
+                       Name::Component(m_chatroomName));
+    }
+    else
+      emit messageReceived(QString::fromStdString(remoteSessionPrefix.toUri()),
+                           QString::fromStdString(msg.from()),
+                           seqNo,
+                           msg.timestamp(),
+                           false);
   }
 }
 
@@ -369,6 +367,12 @@
 
   emit syncTreeUpdated(nodeInfos,
                        QString::fromStdString(getHexEncodedDigest(m_sock->getRootDigest())));
+
+  emit messageReceived(QString::fromStdString(sessionName.toUri()),
+                       QString::fromStdString(msg.from()),
+                       nextSequence,
+                       msg.timestamp(),
+                       msg.type() == SyncDemo::ChatMessage::JOIN);
 }
 
 void
@@ -382,11 +386,6 @@
 
   m_helloEventId = m_scheduler->scheduleEvent(HELLO_INTERVAL,
                                               bind(&ChatDialogBackend::sendHello, this));
-
-  Name sessionName = m_sock->getLogic().getSessionName();
-  emit sessionAdded(QString::fromStdString(sessionName.toUri()),
-                    QString::fromStdString(msg.from()),
-                    msg.timestamp());
 }
 
 void