From 446416c72300feb2e607df59c4db5e1d9be839a6 Mon Sep 17 00:00:00 2001 From: faumaray Date: Fri, 26 Jun 2026 03:15:40 +0300 Subject: [PATCH] Plugin: keep
blocks intact when chunking replies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A reply is split into <=900-byte TeamSpeak messages; never split inside a
…
block (each top-level block starts a fresh message and is kept whole), otherwise a collapsible section spanning two messages would not render. Co-Authored-By: Claude Opus 4.8 --- src/PluginInterface.cpp | 52 +++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/PluginInterface.cpp b/src/PluginInterface.cpp index c7e33b1..2ab1a51 100644 --- a/src/PluginInterface.cpp +++ b/src/PluginInterface.cpp @@ -14,6 +14,8 @@ namespace Echoion::Plugin // TeamSpeak rejects over-long text messages (long replies such as // search results or the queue silently never arrive). Split into // UTF-8-safe chunks on line boundaries so every line is delivered. + // A
…
block is kept whole in its own message — + // splitting it across messages would break the collapsible. constexpr std::size_t kMaxMessageBytes = 900; std::vector chunkMessage(const std::string& message, @@ -26,6 +28,7 @@ namespace Echoion::Plugin } std::string current; + int detailsDepth = 0; auto flush = [&] { if (!current.empty()) { chunks.push_back(current); @@ -41,26 +44,45 @@ namespace Echoion::Plugin : message.substr(pos, nl - pos + 1); pos = (nl == std::string::npos) ? message.size() : nl + 1; - // Hard-split a single over-long line on a UTF-8 boundary. - while (line.size() > limit) { - std::size_t cut = limit; - while (cut > 0 && - (static_cast(line[cut]) & 0xC0) == - 0x80) { - --cut; + const bool opens = + line.find("
") != std::string::npos; + const bool closes = + line.find("
") != std::string::npos; + + if (detailsDepth == 0 && !current.empty()) { + // Start each top-level
block in a fresh message, + // and otherwise split when adding the line would overflow. + if (opens || current.size() + line.size() > limit) { + flush(); } - if (cut == 0) { - cut = limit; // pathological line; avoid an infinite loop - } - flush(); - chunks.push_back(line.substr(0, cut)); - line.erase(0, cut); } - if (current.size() + line.size() > limit) { - flush(); + // Hard-split an over-long line on a UTF-8 boundary, but never + // inside a
block (it stays whole even if oversized). + if (detailsDepth == 0 && !opens) { + while (line.size() > limit) { + std::size_t cut = limit; + while (cut > 0 && (static_cast( + line[cut]) & + 0xC0) == 0x80) { + --cut; + } + if (cut == 0) { + cut = limit; // pathological line; avoid infinite loop + } + flush(); + chunks.push_back(line.substr(0, cut)); + line.erase(0, cut); + } } + current += line; + if (opens) { + ++detailsDepth; + } + if (closes && detailsDepth > 0) { + --detailsDepth; + } } flush(); return chunks;