Changeset - d7ffa366e13b
[Not reviewed]
0 1 0
Thomas Riccardi - 7 years ago 2018-08-26 08:25:24
riccardi.thomas@gmail.com
libcommuni IRC backend: support multi-lines messages

... by splitting them into one PRIVMSG command per line.
1 file changed with 10 insertions and 1 deletions:
0 comments (0 inline, 0 general)
backends/libcommuni/ircnetworkplugin.cpp
Show inline comments
 
@@ -187,49 +187,58 @@ void IRCNetworkPlugin::handleMessageSendRequest(const std::string &user, const s
 
	if (m_sessions[session] == NULL) {
 
		LOG4CXX_WARN(logger, user << ": Session name: " << session << ", No session for user");
 
		return;
 
	}
 

	
 
	std::string target = getTargetName(legacyName);
 
	// We are sending PM message. On XMPP side, user is sending PM using the particular channel,
 
	// for example #room@irc.freenode.org/hanzz. On IRC side, we are forwarding this message
 
	// just to "hanzz". Therefore we have to somewhere store, that message from "hanzz" should
 
	// be mapped to #room@irc.freenode.org/hanzz.
 
	if (legacyName.find("/") != std::string::npos) {
 
		m_sessions[session]->addPM(target, legacyName.substr(0, legacyName.find("@")));
 
	}
 

	
 
	LOG4CXX_INFO(logger, user << ": Session name: " << session << ", message to " << target);
 

	
 
	if (message.find("/me") == 0) {
 
		m_sessions[session]->sendCommand(IrcCommand::createCtcpAction(FROM_UTF8(target), FROM_UTF8(message.substr(4))));
 
	}
 
	else if (message.find("/whois") == 0 || message.find(".whois") == 0) {
 
		m_sessions[session]->sendWhoisCommand(target, message.substr(7));
 
		return;
 
	}
 
	else {
 
		m_sessions[session]->sendCommand(IrcCommand::createMessage(FROM_UTF8(target), FROM_UTF8(message)));
 
		// IRC does not support newlines in messages, so we split the message into multiple Message commands
 
		std::size_t cur = 0;
 
		while (cur != std::string::npos) {
 
			if (message[cur] == '\n') {
 
				cur++;
 
			}
 
			std::size_t end = message.find('\n', cur);
 
			m_sessions[session]->sendCommand(IrcCommand::createMessage(FROM_UTF8(target), FROM_UTF8(message.substr(cur, end - cur))));
 
			cur = end;
 
		}
 
	}
 

	
 
	if (target.find("#") == 0) {
 
		handleMessage(user, legacyName, message, TO_UTF8(m_sessions[session]->nickName()));
 
	}
 
}
 

	
 
void IRCNetworkPlugin::handleRoomSubjectChangedRequest(const std::string &user, const std::string &room, const std::string &message) {
 
	std::string session = getSessionName(user, room);
 
	if (m_sessions[session] == NULL) {
 
		LOG4CXX_WARN(logger, user << ": Session name: " << session << ", No session for user");
 
		return;
 
	}
 

	
 
	std::string target = getTargetName(room);
 
	m_sessions[session]->sendCommand(IrcCommand::createTopic(FROM_UTF8(target), FROM_UTF8(message)));
 
}
 

	
 
void IRCNetworkPlugin::handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password) {
 
	std::string session = getSessionName(user, room);
 
	std::string target = getTargetName(room);
 

	
 
	LOG4CXX_INFO(logger, user << ": Session name: " << session << ", Joining room " << target);
 
	bool createdSession = false;
0 comments (0 inline, 0 general)