diff --git a/src/core/userinputhandler.cpp b/src/core/userinputhandler.cpp index 6167170..947f5ba 100644 --- a/src/core/userinputhandler.cpp +++ b/src/core/userinputhandler.cpp @@ -153,16 +153,34 @@ void UserInputHandler::handleInvite(const BufferInfo &bufferInfo, const QString void UserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &msg) { Q_UNUSED(bufferInfo) - QStringList params = msg.trimmed().split(" "); - QStringList chans = params[0].split(","); - QStringList keys; + // Sometimes channels can be prepended with whitespaces so the + // strategy is the following: + // First split msg after , and trim the results + // Secondly check if we can split the last element with ' '. If yes, + // we have our keys + + QStringList chans = msg.trimmed().split(","); int i; for(i = 0; i < chans.count(); i++) { + chans[i] = chans.at(i).trimmed(); + } + int lastElement = chans.count() - 1; + QStringList tempList = chans.at(lastElement).split(" "); + QStringList keys; + QStringList params; + if (tempList.count() > 1) { + keys = tempList.at(1).split(","); + // Strip the keys from the last channel + chans[lastElement] = tempList.at(0); + } + // Add missing # to the channel names + for(i = 0; i < chans.count(); i++) { if (chans.at(i)[0].isLetterOrNumber()) chans[i].prepend(QChar('#')); } - params[0] = chans.join(","); - if(params.count() > 1) keys = params[1].split(","); + params.append(chans.join(",")); + if (keys.count() > 0) + params.append(keys.join(",")); emit putCmd("JOIN", serverEncode(params)); // FIXME handle messages longer than 512 bytes! i = 0; for(; i < keys.count(); i++) {