+ // Check if any available capabilities have been disabled
+ QStringList capsSkipped;
+ if (!skipCaps().isEmpty() && !caps().isEmpty()) {
+ // Find the entries that are common to skipCaps() and caps(). This represents any
+ // capabilities supported by the server that were skipped.
+
+ // Both skipCaps() and caps() are already lowercase
+ // std::set_intersection requires sorted lists, and we can't modify the original lists.
+ //
+ // skipCaps() should already be sorted. caps() is intentionally not sorted elsewhere so
+ // Quassel can show the capabilities in the order transmitted by the network.
+ auto sortedCaps = caps();
+ sortedCaps.sort();
+
+ // Find the intersection between skipped caps and server-supplied caps
+ std::set_intersection(skipCaps().cbegin(), skipCaps().cend(),
+ sortedCaps.cbegin(), sortedCaps.cend(),
+ std::back_inserter(capsSkipped));
+ }
+
+ if (!capsPendingNegotiation()) {
+ // No capabilities are queued for request, determine the reason why
+ QString capStatusMsg;
+ if (caps().empty()) {
+ // The server doesn't provide any capabilities, but supports CAP LS
+ capStatusMsg = tr("No capabilities available");
+ }
+ else if (capsEnabled().empty()) {
+ // The server supports capabilities (caps() is not empty) but Quassel doesn't support
+ // anything offered. This should be uncommon.
+ capStatusMsg =
+ tr("None of the capabilities provided by the server are supported (found: %1)")
+ .arg(caps().join(", "));
+ }
+ else {
+ // Quassel has enabled some capabilities, but there are no further capabilities that can
+ // be negotiated.
+ // (E.g. the user has manually run "/cap ls 302" after initial negotiation.)
+ capStatusMsg =
+ tr("No additional capabilities are supported (found: %1; currently enabled: %2)")
+ .arg(caps().join(", "), capsEnabled().join(", "));
+ }
+ // Inform the user of the situation
+ showMessage(NetworkInternalMessage(
+ Message::Server,
+ BufferInfo::StatusBuffer,
+ "",
+ capStatusMsg
+ ));
+
+ if (!capsSkipped.isEmpty()) {
+ // Mention that some capabilities are skipped
+ showMessage(NetworkInternalMessage(
+ Message::Server,
+ BufferInfo::StatusBuffer,
+ "",
+ tr("Quassel is configured to ignore some capabilities (skipped: %1)").arg(capsSkipped.join(", "))
+ ));
+ }
+
+ // End any ongoing capability negotiation, allowing connection to continue