From bfcc9cdc7462c515c308592735bc661103fb92b5 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Thu, 21 Nov 2013 00:58:14 +0100 Subject: Send XMPP multi-line messages as multiple IRC messages --- src/bridge/bridge.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index e39cdd3..e24ab88 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -73,6 +73,10 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& username) void Bridge::send_channel_message(const Iid& iid, const std::string& body) { + std::vector lines = utils::split(body, '\n', true); + if (lines.empty()) + return ; + const std::string first_line = lines[0]; if (iid.chan.empty() || iid.server.empty()) { std::cout << "Cannot send message to channel: [" << iid.chan << "] on server [" << iid.server << "]" << std::endl; @@ -84,16 +88,19 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) std::cout << "Cannot send message: no client exist for server " << iid.server << std::endl; return; } - if (body.substr(0, 6) == "/mode ") + if (first_line.substr(0, 6) == "/mode ") { - std::vector args = utils::split(body.substr(6), ' ', false); + std::vector args = utils::split(first_line.substr(6), ' ', false); irc->send_mode_command(iid.chan, args); return; } - if (body.substr(0, 4) == "/me ") - irc->send_channel_message(iid.chan, action_prefix + body.substr(4) + "\01"); + if (first_line.substr(0, 4) == "/me ") + irc->send_channel_message(iid.chan, action_prefix + first_line.substr(4) + "\01"); else - irc->send_channel_message(iid.chan, body); + irc->send_channel_message(iid.chan, first_line); + // Send each of the other lines of the message as a separate IRC message + for (std::vector::const_iterator it = lines.begin() + 1; it != lines.end(); ++it) + irc->send_channel_message(iid.chan, *it); // We do not need to convert body to utf-8: it comes from our XMPP server, // so it's ok to send it back this->xmpp->send_muc_message(iid.chan + "%" + iid.server, irc->get_own_nick(), body, this->user_jid); -- cgit v1.2.3