- if(_chatViews.contains(bufferId)) {
- chatView = _chatViews[bufferId];
- } else {
- chatView = createChatView(bufferId);
- _chatViews[bufferId] = chatView;
- }
- _currentBuffer = bufferId;
- showChatView(bufferId);
- buf->setVisible(true);
- setFocus();
+}
+*/
+
+void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
+{
+ Q_UNUSED(previous)
+
+ BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ // To be able to reset the selected buffer, we don't check if buffer/index is valid here
+ if (currentBuffer() != newBufferId) {
+ setCurrentBuffer(newBufferId);
+ emit currentChanged(newBufferId);
+ emit currentChanged(current);
+ }
+}
+
+
+void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId)
+{
+ BufferId prevBufferId = currentBuffer();
+ if (prevBufferId.isValid() && _chatViews.contains(prevBufferId)) {
+ MsgId msgId = _chatViews.value(prevBufferId)->lastMsgId();
+ Client::setBufferLastSeenMsg(prevBufferId, msgId);
+ }
+
+ if (!bufferId.isValid()) {
+ _currentBuffer = 0;
+ showChatView(0);
+ return;
+ }
+
+ if (!_chatViews.contains(bufferId))
+ _chatViews[bufferId] = createChatView(bufferId);
+
+ _currentBuffer = bufferId;
+ showChatView(bufferId);
+ Client::networkModel()->clearBufferActivity(bufferId);
+ Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId());
+ Client::backlogManager()->checkForBacklog(bufferId);
+ setFocus();