semi-working PMs in muc
This commit is contained in:
parent
8d72e074c0
commit
8c529dbabb
4 changed files with 44 additions and 18 deletions
|
@ -46,15 +46,26 @@ void IRCNetworkPlugin::handleLogoutRequest(const std::string &user, const std::s
|
|||
|
||||
void IRCNetworkPlugin::handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &/*xhtml*/) {
|
||||
std::string u = user;
|
||||
std::cout << "AAAAA " << legacyName << "\n";
|
||||
if (!CONFIG_BOOL(config, "service.server_mode")) {
|
||||
u = user + legacyName.substr(legacyName.find("@") + 1);
|
||||
if (u.find("/") != std::string::npos) {
|
||||
u = u.substr(0, u.find("/"));
|
||||
}
|
||||
}
|
||||
if (m_sessions[u] == NULL)
|
||||
if (m_sessions[u] == NULL) {
|
||||
std::cout << "No session for " << u << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string r = legacyName;
|
||||
if (!CONFIG_BOOL(config, "service.server_mode")) {
|
||||
r = legacyName.substr(0, r.find("@"));
|
||||
if (legacyName.find("/") == std::string::npos) {
|
||||
r = legacyName.substr(0, r.find("@"));
|
||||
}
|
||||
else {
|
||||
r = legacyName.substr(legacyName.find("/") + 1);
|
||||
}
|
||||
}
|
||||
std::cout << "MESSAGE " << u << " " << r << "\n";
|
||||
m_sessions[u]->message(QString::fromStdString(r), QString::fromStdString(message));
|
||||
|
@ -66,18 +77,18 @@ void IRCNetworkPlugin::handleJoinRoomRequest(const std::string &user, const std:
|
|||
std::string r = room;
|
||||
std::string u = user;
|
||||
if (!CONFIG_BOOL(config, "service.server_mode")) {
|
||||
u = user + room.substr(room.find("%") + 1);
|
||||
r = room.substr(0, room.find("%"));
|
||||
u = user + room.substr(room.find("@") + 1);
|
||||
r = room.substr(0, room.find("@"));
|
||||
}
|
||||
if (m_sessions[u] == NULL) {
|
||||
// in gateway mode we want to login this user to network according to legacyName
|
||||
if (room.find("%") != std::string::npos) {
|
||||
if (room.find("@") != std::string::npos) {
|
||||
// suffix is %irc.freenode.net to let MyIrcSession return #room%irc.freenode.net
|
||||
MyIrcSession *session = new MyIrcSession(user, this, room.substr(room.find("%")));
|
||||
MyIrcSession *session = new MyIrcSession(user, this, room.substr(room.find("@")));
|
||||
session->setNick(QString::fromStdString(nickname));
|
||||
session->connectToServer(QString::fromStdString(room.substr(room.find("%") + 1)), 6667);
|
||||
std::cout << "CONNECTING IRC NETWORK " << room.substr(room.find("%") + 1) << "\n";
|
||||
std::cout << "SUFFIX " << room.substr(room.find("%")) << "\n";
|
||||
session->connectToServer(QString::fromStdString(room.substr(room.find("@") + 1)), 6667);
|
||||
std::cout << "CONNECTING IRC NETWORK " << room.substr(room.find("@") + 1) << "\n";
|
||||
std::cout << "SUFFIX " << room.substr(room.find("@")) << "\n";
|
||||
m_sessions[u] = session;
|
||||
}
|
||||
else {
|
||||
|
@ -96,8 +107,8 @@ void IRCNetworkPlugin::handleLeaveRoomRequest(const std::string &user, const std
|
|||
std::string r = room;
|
||||
std::string u = user;
|
||||
if (!CONFIG_BOOL(config, "service.server_mode")) {
|
||||
r = room.substr(0, room.find("%"));
|
||||
u = user + room.substr(room.find("%") + 1);
|
||||
r = room.substr(0, room.find("@"));
|
||||
u = user + room.substr(room.find("@") + 1);
|
||||
}
|
||||
|
||||
if (m_sessions[u] == NULL)
|
||||
|
|
|
@ -97,9 +97,7 @@ class Conversation {
|
|||
|
||||
/// This is used to detect Private messages associated with particular room.
|
||||
/// \param room room name associated with this Conversation.
|
||||
void setRoom(const std::string &room) {
|
||||
m_room = room;
|
||||
}
|
||||
void setRoom(const std::string &room);
|
||||
|
||||
/// Returns room name associated with this Conversation.
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ Conversation::Conversation(ConversationManager *conversationManager, const std::
|
|||
Conversation::~Conversation() {
|
||||
}
|
||||
|
||||
void Conversation::setRoom(const std::string &room) {
|
||||
m_room = room;
|
||||
m_legacyName = m_room + "/" + m_legacyName;
|
||||
}
|
||||
|
||||
void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname) {
|
||||
if (m_muc) {
|
||||
message->setType(Swift::Message::Groupchat);
|
||||
|
@ -74,8 +79,12 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
|
|||
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
|
||||
}
|
||||
else {
|
||||
std::string legacyName = m_legacyName;
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
message->setTo(m_conversationManager->getUser()->getJID().toString());
|
||||
message->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
|
||||
message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
|
||||
m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +92,13 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
|
|||
void Conversation::handleParticipantChanged(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) {
|
||||
std::string nickname = nick;
|
||||
Swift::Presence::ref presence = Swift::Presence::create();
|
||||
presence->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
|
||||
std::string legacyName = m_legacyName;
|
||||
if (m_muc) {
|
||||
if (legacyName.find_last_of("@") != std::string::npos) {
|
||||
legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
|
||||
}
|
||||
}
|
||||
presence->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
|
||||
presence->setTo(m_conversationManager->getUser()->getJID().toString());
|
||||
presence->setType(Swift::Presence::Available);
|
||||
|
||||
|
|
|
@ -194,7 +194,8 @@ void User::handlePresence(Swift::Presence::ref presence) {
|
|||
if (isMUC) {
|
||||
if (presence->getType() == Swift::Presence::Unavailable) {
|
||||
LOG4CXX_INFO(logger, m_jid.toString() << ": Going to left room " << presence->getTo().getNode());
|
||||
onRoomLeft(presence->getTo().getNode());
|
||||
std::string room = Buddy::JIDToLegacyName(presence->getTo());
|
||||
onRoomLeft(room);
|
||||
}
|
||||
else {
|
||||
// force connection to legacy network to let backend to handle auto-join on connect.
|
||||
|
@ -204,7 +205,8 @@ void User::handlePresence(Swift::Presence::ref presence) {
|
|||
onReadyToConnect();
|
||||
}
|
||||
LOG4CXX_INFO(logger, m_jid.toString() << ": Going to join room " << presence->getTo().getNode() << " as " << presence->getTo().getResource());
|
||||
onRoomJoined(presence->getTo().getNode(), presence->getTo().getResource(), "");
|
||||
std::string room = Buddy::JIDToLegacyName(presence->getTo());
|
||||
onRoomJoined(room, presence->getTo().getResource(), "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue