Browse Source

libtransport, xmpp: attempt to reconnect to pg, fix presences

- Oops we forgot to run clang-format earlier, so now a bunch of unrelated
  stuff got clang-formatted into this change. :/
- Building on the already-super-hacky Postgres database backend, we now
  attempt to reconnect to the database every time there's an error.
  This is bad, but better than it just dropping connection and then
  failing all database operations afterwards...
  Ideally libpqxx would handle this, but of course it doesn't.
- The Buddy code did some super crazy crap around sending out multiple
  presences for each buddy???? I don't get it, so it's been replaced
  with something far saner.
- The RosterManager wouldn't send presence for contacts that weren't online.
  This is stupid, and it doesn't do that any more.
- Additionally, buddies would only send their photo hash when they were
  online, which is also stupid (and not spec-compliant). Fixing this
  means we actually have avatars for all of the buddies in the roster,
  which is nice!
master
eta 3 years ago
parent
commit
fd07c721c0
  1. 2
      include/transport/Buddy.h
  2. 4
      include/transport/PQXXBackend.h
  3. 4
      include/transport/SQLite3Backend.h
  4. 4
      include/transport/StorageBackend.h
  5. 1
      include/transport/UserManager.h
  6. 50
      libtransport/Buddy.cpp
  7. 4
      libtransport/NetworkPluginServer.cpp
  8. 102
      libtransport/PQXXBackend.cpp
  9. 37
      libtransport/RosterManager.cpp
  10. 16
      libtransport/SQLite3Backend.cpp
  11. 50
      libtransport/User.cpp
  12. 5
      src/frontends/xmpp/XMPPRosterManager.cpp
  13. 12
      src/frontends/xmpp/XMPPUser.cpp
  14. 6
      src/frontends/xmpp/XMPPUser.h
  15. 44
      src/frontends/xmpp/discoinforesponder.cpp

2
include/transport/Buddy.h

@ -85,7 +85,7 @@ class Buddy { @@ -85,7 +85,7 @@ class Buddy {
/// manually. \param features features used in returned stanza \param only_new
/// if True, this function returns Presence stanza only if it's different than
/// the previously generated one. \return Presence stanza or NULL.
std::vector<Swift::Presence::ref> &generatePresenceStanzas(int features, bool only_new = false);
Swift::Presence::ref generatePresence();
void setBlocked(bool block) {
if (block)

4
include/transport/PQXXBackend.h

@ -102,8 +102,8 @@ class PQXXBackend : public StorageBackend { @@ -102,8 +102,8 @@ class PQXXBackend : public StorageBackend {
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
void addMucName(long userId, const std::string &mucId, const std::string &mucName);
std::string getMucName(long userId, const std::string &mucId);
void addMucName(long userId, const std::string &mucId, const std::string &mucName);
std::string getMucName(long userId, const std::string &mucId);
void beginTransaction();
void commitTransaction();

4
include/transport/SQLite3Backend.h

@ -98,8 +98,8 @@ class SQLite3Backend : public StorageBackend { @@ -98,8 +98,8 @@ class SQLite3Backend : public StorageBackend {
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
void addMucName(long userId, const std::string &mucId, const std::string &mucName);
std::string getMucName(long userId, const std::string &mucId);
void addMucName(long userId, const std::string &mucId, const std::string &mucName);
std::string getMucName(long userId, const std::string &mucId);
void beginTransaction();
void commitTransaction();

4
include/transport/StorageBackend.h

@ -139,8 +139,8 @@ class StorageBackend { @@ -139,8 +139,8 @@ class StorageBackend {
virtual void beginTransaction() = 0;
virtual void commitTransaction() = 0;
virtual void addMucName(long userId, const std::string &mucId, const std::string &mucName) = 0;
virtual std::string getMucName(long userId, const std::string &mucId) = 0;
virtual void addMucName(long userId, const std::string &mucId, const std::string &mucName) = 0;
virtual std::string getMucName(long userId, const std::string &mucId) = 0;
/// onStorageError
// boost::signal<void (const std::string &statement, const

1
include/transport/UserManager.h

@ -139,6 +139,7 @@ class UserManager /*: public Swift::EntityCapsProvider*/ { @@ -139,6 +139,7 @@ class UserManager /*: public Swift::EntityCapsProvider*/ {
}
StorageBackend *m_storageBackend;
private:
void handlePresence(Swift::Presence::ref presence);
void handleMessageReceived(Swift::Message::ref message);

50
libtransport/Buddy.cpp

@ -41,10 +41,8 @@ Buddy::~Buddy() { @@ -41,10 +41,8 @@ Buddy::~Buddy() {
}
void Buddy::sendPresence() {
std::vector<Swift::Presence::ref> &presences = generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref presence, presences) {
m_rosterManager->getUser()->getComponent()->getFrontend()->sendPresence(presence);
}
Swift::Presence::ref presence = generatePresence();
m_rosterManager->getUser()->getComponent()->getFrontend()->sendPresence(presence);
}
void Buddy::generateJID() {
@ -103,22 +101,13 @@ void Buddy::handleRawPresence(Swift::Presence::ref presence) { @@ -103,22 +101,13 @@ void Buddy::handleRawPresence(Swift::Presence::ref presence) {
m_rosterManager->getUser()->getComponent()->getFrontend()->sendPresence(presence);
}
std::vector<Swift::Presence::ref> &Buddy::generatePresenceStanzas(int features, bool only_new) {
Swift::Presence::ref Buddy::generatePresence() {
if (m_jid.getNode().empty()) {
generateJID();
}
Swift::StatusShow s;
std::string statusMessage;
if (!getStatus(s, statusMessage)) {
for (std::vector<Swift::Presence::ref>::iterator it = m_presences.begin(); it != m_presences.end(); it++) {
if ((*it)->getFrom() == m_jid) {
m_presences.erase(it);
break;
}
}
return m_presences;
}
Swift::Presence::ref presence = Swift::Presence::create();
presence->setTo(m_rosterManager->getUser()->getJID().toBare());
@ -132,38 +121,9 @@ std::vector<Swift::Presence::ref> &Buddy::generatePresenceStanzas(int features, @@ -132,38 +121,9 @@ std::vector<Swift::Presence::ref> &Buddy::generatePresenceStanzas(int features,
presence->setType(Swift::Presence::Unavailable);
presence->setShow(s.getType());
presence->addPayload(std::shared_ptr<Swift::Payload>(new Swift::VCardUpdate(getIconHash())));
if (presence->getType() != Swift::Presence::Unavailable) {
// caps
// if (features & 0/*TRANSPORT_FEATURE_AVATARS*/) {
presence->addPayload(std::shared_ptr<Swift::Payload>(new Swift::VCardUpdate(getIconHash())));
// }
// if (isBlocked()) {
// presence->addPayload(std::shared_ptr<Swift::Payload>(new
// Transport::BlockPayload ()));
// }
}
BOOST_FOREACH (Swift::Presence::ref &p, m_presences) {
if (p->getFrom() == presence->getFrom()) {
p = presence;
return m_presences;
}
}
m_presences.push_back(presence);
// if (only_new) {
// if (m_lastPresence)
// m_lastPresence->setTo(Swift::JID(""));
// if (m_lastPresence == presence) {
// return Swift::Presence::ref();
// }
// m_lastPresence = presence;
// }
return m_presences;
return presence;
}
std::string Buddy::getSafeName() {

4
libtransport/NetworkPluginServer.cpp

@ -279,7 +279,7 @@ unsigned long NetworkPluginServer::spawnBackend() { @@ -279,7 +279,7 @@ unsigned long NetworkPluginServer::spawnBackend() {
LOG4CXX_INFO(logger, "Executing: " << debugBackendCommand);
binaryArgs.push_back(NULL); // indicate end of array
binaryArgs.push_back(NULL); // indicate end of array
const char **argv = binaryArgs.data();
// fork and exec
@ -290,7 +290,7 @@ unsigned long NetworkPluginServer::spawnBackend() { @@ -290,7 +290,7 @@ unsigned long NetworkPluginServer::spawnBackend() {
// child process
int ret = execvp(argv[0], (char *const *)argv);
if (ret == -1) {
perror("execvp");
perror("execvp");
exit(errno);
}
} else if (pid < 0) {

102
libtransport/PQXXBackend.cpp

@ -51,28 +51,7 @@ void PQXXBackend::disconnect() { @@ -51,28 +51,7 @@ void PQXXBackend::disconnect() {
bool PQXXBackend::connect() {
std::string connection_str;
connection_str = CONFIG_STRING_DEFAULTED(m_config, "database.connectionstring", "");
if (connection_str.empty()) {
LOG4CXX_INFO(logger, "Connecting PostgreSQL server " << CONFIG_STRING(m_config, "database.server") << ", user "
<< CONFIG_STRING(m_config, "database.user") << ", dbname "
<< CONFIG_STRING(m_config, "database.database")
<< ", port " << CONFIG_INT(m_config, "database.port"));
connection_str = "dbname=";
connection_str += CONFIG_STRING(m_config, "database.database");
if (!CONFIG_STRING(m_config, "database.server").empty()) {
connection_str += " host=" + CONFIG_STRING(m_config, "database.server");
}
if (!CONFIG_STRING(m_config, "database.user").empty()) {
connection_str += " user=" + CONFIG_STRING(m_config, "database.user");
}
if (!CONFIG_STRING(m_config, "database.password").empty()) {
connection_str += " password=" + CONFIG_STRING(m_config, "database.password");
}
if (CONFIG_INT(m_config, "database.port") != 0) {
connection_str += " port=" + boost::lexical_cast<std::string>(CONFIG_INT(m_config, "database.port"));
}
} else {
LOG4CXX_INFO(logger, "Connecting PostgreSQL server via provided connection string.");
}
LOG4CXX_INFO(logger, "Connecting PostgreSQL server: " << connection_str);
try {
m_conn = new pqxx::connection(connection_str);
@ -146,12 +125,13 @@ bool PQXXBackend::createDatabase() { @@ -146,12 +125,13 @@ bool PQXXBackend::createDatabase() {
exec("INSERT INTO " + m_prefix + "db_version (ver) VALUES ('1');");
}
exec("CREATE TABLE IF NOT EXISTS " + m_prefix + "muc_names ("
"user_id INTEGER NOT NULL,"
"muc_id VARCHAR NOT NULL,"
"name VARCHAR NOT NULL,"
"UNIQUE(user_id, muc_id)"
");");
exec("CREATE TABLE IF NOT EXISTS " + m_prefix +
"muc_names ("
"user_id INTEGER NOT NULL,"
"muc_id VARCHAR NOT NULL,"
"name VARCHAR NOT NULL,"
"UNIQUE(user_id, muc_id)"
");");
return true;
}
@ -172,6 +152,7 @@ bool PQXXBackend::exec(pqxx::nontransaction &txn, const std::string &query, bool @@ -172,6 +152,7 @@ bool PQXXBackend::exec(pqxx::nontransaction &txn, const std::string &query, bool
} catch (std::exception &e) {
if (show_error)
LOG4CXX_ERROR(logger, e.what());
connect();
return false;
}
return true;
@ -192,6 +173,7 @@ void PQXXBackend::setUser(const UserInfo &user) { @@ -192,6 +173,7 @@ void PQXXBackend::setUser(const UserInfo &user) {
(user.vip ? "'true'" : "'false'") + ")");
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
@ -215,6 +197,7 @@ bool PQXXBackend::getUser(const std::string &barejid, UserInfo &user) { @@ -215,6 +197,7 @@ bool PQXXBackend::getUser(const std::string &barejid, UserInfo &user) {
user.vip = r[0][6].as<bool>();
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
return false;
}
@ -228,6 +211,7 @@ void PQXXBackend::setUserOnline(long id, bool online) { @@ -228,6 +211,7 @@ void PQXXBackend::setUserOnline(long id, bool online) {
", last_login=NOW() WHERE id=" + pqxx::to_string(id));
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
@ -241,6 +225,7 @@ bool PQXXBackend::getOnlineUsers(std::vector<std::string> &users) { @@ -241,6 +225,7 @@ bool PQXXBackend::getOnlineUsers(std::vector<std::string> &users) {
}
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
return false;
}
@ -257,6 +242,7 @@ bool PQXXBackend::getUsers(std::vector<std::string> &users) { @@ -257,6 +242,7 @@ bool PQXXBackend::getUsers(std::vector<std::string> &users) {
}
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
return false;
}
@ -291,6 +277,7 @@ long PQXXBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) { @@ -291,6 +277,7 @@ long PQXXBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
return id;
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
return -1;
}
}
@ -305,6 +292,7 @@ void PQXXBackend::updateBuddy(long userId, const BuddyInfo &buddyInfo) { @@ -305,6 +292,7 @@ void PQXXBackend::updateBuddy(long userId, const BuddyInfo &buddyInfo) {
" AND uin=" + quote(txn, buddyInfo.legacyName));
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
@ -367,6 +355,7 @@ bool PQXXBackend::getBuddies(long id, std::list<BuddyInfo> &roster) { @@ -367,6 +355,7 @@ bool PQXXBackend::getBuddies(long id, std::list<BuddyInfo> &roster) {
return true;
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
return false;
@ -383,6 +372,7 @@ bool PQXXBackend::removeUser(long id) { @@ -383,6 +372,7 @@ bool PQXXBackend::removeUser(long id) {
return true;
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
return false;
}
@ -404,6 +394,7 @@ void PQXXBackend::getUserSetting(long id, const std::string &variable, int &type @@ -404,6 +394,7 @@ void PQXXBackend::getUserSetting(long id, const std::string &variable, int &type
}
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
@ -414,34 +405,39 @@ void PQXXBackend::updateUserSetting(long id, const std::string &variable, const @@ -414,34 +405,39 @@ void PQXXBackend::updateUserSetting(long id, const std::string &variable, const
" WHERE user_id=" + pqxx::to_string(id) + " AND var=" + quote(txn, variable));
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
void PQXXBackend::addMucName(long userId, const std::string &mucId, const std::string &mucName) {
try {
pqxx::nontransaction txn(*m_conn);
txn.exec_params("INSERT INTO " + m_prefix + "muc_names (user_id, muc_id, name) VALUES ($1, $2, $3) ON CONFLICT (user_id, muc_id) DO UPDATE SET name = EXCLUDED.name", userId, mucId, mucName);
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
}
}
std::string PQXXBackend::getMucName(long userId, const std::string &mucId) {
try {
pqxx::nontransaction txn(*m_conn);
pqxx::result r =
txn.exec_params("SELECT name FROM " + m_prefix + "muc_names WHERE user_id = $1 AND muc_id = $2", userId, mucId);
if (r.size() == 0) {
return "";
}
else {
return r[0][0].as<std::string>();
}
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
return "";
}
}
void PQXXBackend::addMucName(long userId, const std::string &mucId, const std::string &mucName) {
try {
pqxx::nontransaction txn(*m_conn);
txn.exec_params("INSERT INTO " + m_prefix +
"muc_names (user_id, muc_id, name) VALUES ($1, $2, $3) ON CONFLICT (user_id, muc_id) DO "
"UPDATE SET name = EXCLUDED.name",
userId, mucId, mucName);
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
}
}
std::string PQXXBackend::getMucName(long userId, const std::string &mucId) {
try {
pqxx::nontransaction txn(*m_conn);
pqxx::result r = txn.exec_params(
"SELECT name FROM " + m_prefix + "muc_names WHERE user_id = $1 AND muc_id = $2", userId, mucId);
if (r.size() == 0) {
return "";
} else {
return r[0][0].as<std::string>();
}
} catch (std::exception &e) {
LOG4CXX_ERROR(logger, e.what());
connect();
return "";
}
}
void PQXXBackend::beginTransaction() {
exec("BEGIN;");

37
libtransport/RosterManager.cpp

@ -122,11 +122,7 @@ void RosterManager::sendBuddySubscribePresence(Buddy *buddy) { @@ -122,11 +122,7 @@ void RosterManager::sendBuddySubscribePresence(Buddy *buddy) {
void RosterManager::sendBuddyPresences(Buddy *buddy, const Swift::JID &to) {
Swift::Presence::ref currentPresence;
std::vector<Swift::Presence::ref> presences = buddy->generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref &currentPresence, presences) {
currentPresence->setTo(to);
m_component->getFrontend()->sendPresence(currentPresence);
}
buddy->sendPresence();
}
void RosterManager::handleBuddyChanged(Buddy *buddy) {
@ -341,25 +337,14 @@ void RosterManager::sendCurrentPresences(const Swift::JID &to) { @@ -341,25 +337,14 @@ void RosterManager::sendCurrentPresences(const Swift::JID &to) {
if (!buddy) {
continue;
}
if (!buddy->isAvailable()) {
continue;
}
std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref &presence, presences) {
presence->setTo(to);
m_component->getFrontend()->sendPresence(presence);
}
buddy->sendPresence();
}
}
void RosterManager::sendCurrentPresence(const Swift::JID &from, const Swift::JID &to) {
Buddy *buddy = Buddy::JIDToBuddy(from, m_user);
if (buddy) {
std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref &presence, presences) {
presence->setTo(to);
m_component->getFrontend()->sendPresence(presence);
}
buddy->sendPresence();
} else {
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(to);
@ -378,18 +363,10 @@ void RosterManager::sendUnavailablePresences(const Swift::JID &to) { @@ -378,18 +363,10 @@ void RosterManager::sendUnavailablePresences(const Swift::JID &to) {
continue;
}
if (!buddy->isAvailable()) {
continue;
}
std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref &presence, presences) {
Swift::Presence::Type type = presence->getType();
presence->setTo(to);
presence->setType(Swift::Presence::Unavailable);
m_component->getFrontend()->sendPresence(presence);
presence->setType(type);
}
Swift::Presence::ref presence = buddy->generatePresence();
presence->setTo(to);
presence->setType(Swift::Presence::Unavailable);
m_component->getFrontend()->sendPresence(presence);
}
// in gateway mode, we have to send unavailable presence for transport

16
libtransport/SQLite3Backend.cpp

@ -588,14 +588,14 @@ void SQLite3Backend::updateBuddySetting(long userId, long buddyId, const std::st @@ -588,14 +588,14 @@ void SQLite3Backend::updateBuddySetting(long userId, long buddyId, const std::st
EXECUTE_STATEMENT(m_updateBuddySetting, "m_updateBuddySetting");
}
void SQLite3Backend::addMucName(long userId, const std::string &mucId, const std::string &mucName) {
LOG4CXX_ERROR(logger, "addMucName() not implemented in sqlite3 backend yet");
return;
}
std::string SQLite3Backend::getMucName(long userId, const std::string &mucId) {
LOG4CXX_ERROR(logger, "getMucName() not implemented in sqlite3 backend yet");
return "";
}
void SQLite3Backend::addMucName(long userId, const std::string &mucId, const std::string &mucName) {
LOG4CXX_ERROR(logger, "addMucName() not implemented in sqlite3 backend yet");
return;
}
std::string SQLite3Backend::getMucName(long userId, const std::string &mucId) {
LOG4CXX_ERROR(logger, "getMucName() not implemented in sqlite3 backend yet");
return "";
}
void SQLite3Backend::beginTransaction() {
exec("BEGIN TRANSACTION;");

50
libtransport/User.cpp

@ -87,35 +87,16 @@ const Swift::JID &User::getJID() { @@ -87,35 +87,16 @@ const Swift::JID &User::getJID() {
}
void User::sendCurrentPresence() {
std::vector<Swift::Presence::ref> presences = m_presenceOracle->getAllPresence(m_jid);
foreach (Swift::Presence::ref presence, presences) {
if (presence->getType() == Swift::Presence::Unavailable) {
continue;
}
if (m_connected) {
Swift::Presence::ref highest = m_presenceOracle->getHighestPriorityPresence(m_jid.toBare());
if (highest) {
Swift::Presence::ref response = Swift::Presence::create(highest);
response->setTo(presence->getFrom());
response->setFrom(m_component->getJID());
m_component->getFrontend()->sendPresence(response);
} else {
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(m_component->getJID());
response->setType(Swift::Presence::Unavailable);
m_component->getFrontend()->sendPresence(response);
}
} else {
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(m_component->getJID());
response->setType(Swift::Presence::Unavailable);
response->setStatus("Connecting");
m_component->getFrontend()->sendPresence(response);
}
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(m_jid);
response->setFrom(m_component->getJID());
if (m_connected) {
response->setShow(Swift::StatusShow::Online);
} else {
response->setShow(Swift::StatusShow::XA);
response->setStatus("Connecting...");
}
m_component->getFrontend()->sendPresence(response);
}
void User::setConnected(bool connected) {
@ -310,18 +291,7 @@ void User::handlePresence(Swift::Presence::ref presence, bool forceJoin) { @@ -310,18 +291,7 @@ void User::handlePresence(Swift::Presence::ref presence, bool forceJoin) {
}
}
// User wants to disconnect this resource
if (presence->getType() == Swift::Presence::Unavailable) {
// Send unavailable presences for online contacts
m_rosterManager->sendUnavailablePresences(presence->getFrom());
// Send unavailable presence for transport contact itself
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(m_component->getJID());
response->setType(Swift::Presence::Unavailable);
m_component->getFrontend()->sendPresence(response);
} else {
if (presence->getType() != Swift::Presence::Unavailable) {
sendCurrentPresence();
}

5
src/frontends/xmpp/XMPPRosterManager.cpp

@ -141,10 +141,7 @@ void XMPPRosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref e @@ -141,10 +141,7 @@ void XMPPRosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref e
Buddy *b = getBuddy(key);
if (b) {
if (b->isAvailable()) {
std::vector<Swift::Presence::ref> &presences = b->generatePresenceStanzas(255);
BOOST_FOREACH (Swift::Presence::ref &presence, presences) {
m_component->getFrontend()->sendPresence(presence);
}
b->sendPresence();
}
} else {
LOG4CXX_WARN(logger, "handleBuddyRosterPushResponse called for unknown buddy " << key);

12
src/frontends/xmpp/XMPPUser.cpp

@ -86,7 +86,7 @@ void XMPPUser::clearRoomList() { @@ -86,7 +86,7 @@ void XMPPUser::clearRoomList() {
void XMPPUser::addRoomToRoomList(const std::string &handle, const std::string &name) {
LOG4CXX_INFO(logger, m_jid.toString() << ": Adding room " << handle << " named " << name);
m_userManager->m_storageBackend->addMucName(getUserId(), handle, name);
m_userManager->m_storageBackend->addMucName(getUserId(), handle, name);
m_rooms->addItem(Swift::DiscoItems::Item(name, handle));
}
@ -94,11 +94,11 @@ void XMPPUser::handleRoomInformation(const std::string &room, const std::string @@ -94,11 +94,11 @@ void XMPPUser::handleRoomInformation(const std::string &room, const std::string
LOG4CXX_INFO(logger, m_jid.toString() << ": Room information received for " << room << ": name " << name);
struct RoomInformation room_info = {.room = room, .name = name};
m_room_info[room] = room_info;
m_userManager->m_storageBackend->beginTransaction();
if (m_userManager->m_storageBackend->getMucName(getUserId(), room) == "") {
m_userManager->m_storageBackend->addMucName(getUserId(), room, name);
}
m_userManager->m_storageBackend->commitTransaction();
m_userManager->m_storageBackend->beginTransaction();
if (m_userManager->m_storageBackend->getMucName(getUserId(), room) == "") {
m_userManager->m_storageBackend->addMucName(getUserId(), room, name);
}
m_userManager->m_storageBackend->commitTransaction();
}
} // namespace Transport

6
src/frontends/xmpp/XMPPUser.h

@ -84,9 +84,9 @@ class XMPPUser : public User { @@ -84,9 +84,9 @@ class XMPPUser : public User {
}
}
long getUserId() {
return m_userInfo.id;
}
long getUserId() {
return m_userInfo.id;
}
private:
void onConnectingTimeout();

44
src/frontends/xmpp/discoinforesponder.cpp

@ -188,34 +188,32 @@ bool DiscoInfoResponder::handleGetRequest(const Swift::JID &from, const Swift::J @@ -188,34 +188,32 @@ bool DiscoInfoResponder::handleGetRequest(const Swift::JID &from, const Swift::J
// disco#info for per-user rooms (like Skype/Facebook groupchats)
XMPPUser *user = static_cast<XMPPUser *>(m_userManager->getUser(from.toBare().toString()));
if (user) {
std::string room_name = "";
std::string muc_name = m_userManager->m_storageBackend->getMucName(user->getUserId(), to.toBare().toString());
auto room_info = user->getRoomInformation(to.toBare().toString());
if (muc_name != "") {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with DB name " << muc_name);
room_name = muc_name;
}
else if (room_info != nullptr) {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with room info name " << room_info->name);
room_name = room_info->name;
}
else {
BOOST_FOREACH (const DiscoItems::Item &item, user->getRoomList()->getItems()) {
if (item.getJID().toString() == to.toBare().toString()) {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with room list name " << item.getName());
room_name = item.getName();
}
}
}
if (room_name != "") {
std::string room_name = "";
std::string muc_name = m_userManager->m_storageBackend->getMucName(user->getUserId(), to.toBare().toString());
auto room_info = user->getRoomInformation(to.toBare().toString());
if (muc_name != "") {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with DB name " << muc_name);
room_name = muc_name;
} else if (room_info != nullptr) {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with room info name " << room_info->name);
room_name = room_info->name;
} else {
BOOST_FOREACH (const DiscoItems::Item &item, user->getRoomList()->getItems()) {
if (item.getJID().toString() == to.toBare().toString()) {
LOG4CXX_DEBUG(logger, "MUC disco#info handled with room list name " << item.getName());
room_name = item.getName();
}
}
}
if (room_name != "") {
std::shared_ptr<DiscoInfo> res(new DiscoInfo());
res->addIdentity(DiscoInfo::Identity(room_name, "conference", "text"));
res->addFeature("http://jabber.org/protocol/muc");
res->addFeature("muc_persistent");
res->addFeature("muc_persistent");
res->setNode(info->getNode());
sendResponse(from, to, id, res);
return true;
}
return true;
}
}
// disco#info for buddy

Loading…
Cancel
Save