+void CoreSession::processMessages()
+{
+ if (_messageQueue.count() == 1) {
+ const RawMessage &rawMsg = _messageQueue.first();
+ bool createBuffer = !(rawMsg.flags & Message::Redirected);
+ BufferInfo bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, rawMsg.bufferType, rawMsg.target, createBuffer);
+ if (!bufferInfo.isValid()) {
+ Q_ASSERT(!createBuffer);
+ bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, BufferInfo::StatusBuffer, "");
+ }
+ Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, rawMsg.flags);
+ if(Core::storeMessage(msg))
+ emit displayMsg(msg);
+ }
+ else {
+ QHash<NetworkId, QHash<QString, BufferInfo> > bufferInfoCache;
+ MessageList messages;
+ QList<RawMessage> redirectedMessages; // list of Messages which don't enforce a buffer creation
+ BufferInfo bufferInfo;
+ for (int i = 0; i < _messageQueue.count(); i++) {
+ const RawMessage &rawMsg = _messageQueue.at(i);
+ if (bufferInfoCache.contains(rawMsg.networkId) && bufferInfoCache[rawMsg.networkId].contains(rawMsg.target)) {
+ bufferInfo = bufferInfoCache[rawMsg.networkId][rawMsg.target];
+ }
+ else {
+ bool createBuffer = !(rawMsg.flags & Message::Redirected);
+ bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, rawMsg.bufferType, rawMsg.target, createBuffer);
+ if (!bufferInfo.isValid()) {
+ Q_ASSERT(!createBuffer);
+ redirectedMessages << rawMsg;
+ continue;
+ }
+ bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo;
+ }
+ Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, rawMsg.flags);
+ messages << msg;
+ }