Send much more less presences when connecting to legacy network
This commit is contained in:
parent
1595f7e448
commit
eeda354422
10 changed files with 51 additions and 42 deletions
|
@ -122,10 +122,7 @@ class Buddy {
|
|||
/// so it can be used in JIDs.
|
||||
std::string getSafeName();
|
||||
|
||||
/// This method should be called whenever some information returned by virtual functions changes.
|
||||
|
||||
/// This method sends presence to XMPP user.
|
||||
void handleBuddyChanged();
|
||||
void sendPresence();
|
||||
|
||||
/// Handles VCard from legacy network and forwards it to XMPP user.
|
||||
|
||||
|
|
|
@ -45,18 +45,10 @@ class LocalBuddy : public Buddy {
|
|||
return true;
|
||||
}
|
||||
|
||||
void setStatus(const Swift::StatusShow &status, const std::string &statusMessage) {
|
||||
m_status = status;
|
||||
m_statusMessage = statusMessage;
|
||||
}
|
||||
void setStatus(const Swift::StatusShow &status, const std::string &statusMessage);
|
||||
|
||||
std::string getIconHash() { return m_iconHash; }
|
||||
void setIconHash(const std::string &iconHash) {
|
||||
bool changed = m_iconHash != iconHash;
|
||||
m_iconHash = iconHash;
|
||||
if (changed)
|
||||
getRosterManager()->storeBuddy(this);
|
||||
}
|
||||
void setIconHash(const std::string &iconHash);
|
||||
|
||||
std::vector<std::string> getGroups() { return m_groups; }
|
||||
void setGroups(const std::vector<std::string> &groups);
|
||||
|
|
|
@ -37,6 +37,13 @@ Buddy::~Buddy() {
|
|||
// m_rosterManager->unsetBuddy(this);
|
||||
}
|
||||
|
||||
void Buddy::sendPresence() {
|
||||
Swift::Presence::ref presence = generatePresenceStanza(255);
|
||||
if (presence) {
|
||||
m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
|
||||
}
|
||||
}
|
||||
|
||||
void Buddy::generateJID() {
|
||||
m_jid = Swift::JID();
|
||||
m_jid = Swift::JID(getSafeName(), m_rosterManager->getUser()->getComponent()->getJID().toString(), "bot");
|
||||
|
@ -150,13 +157,6 @@ std::string Buddy::getSafeName() {
|
|||
return name;
|
||||
}
|
||||
|
||||
void Buddy::handleBuddyChanged() {
|
||||
Swift::Presence::ref presence = generatePresenceStanza(255);
|
||||
if (presence) {
|
||||
m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
|
||||
}
|
||||
}
|
||||
|
||||
void Buddy::handleVCardReceived(const std::string &id, Swift::VCard::ref vcard) {
|
||||
boost::shared_ptr<Swift::GenericRequest<Swift::VCard> > request(new Swift::GenericRequest<Swift::VCard>(Swift::IQ::Result, m_rosterManager->getUser()->getJID(), vcard, m_rosterManager->getUser()->getComponent()->getIQRouter()));
|
||||
request->send();
|
||||
|
|
|
@ -37,6 +37,24 @@ LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id, const std::string
|
|||
LocalBuddy::~LocalBuddy() {
|
||||
}
|
||||
|
||||
void LocalBuddy::setStatus(const Swift::StatusShow &status, const std::string &statusMessage) {
|
||||
bool changed = ((m_status.getType() != status.getType()) || (m_statusMessage != statusMessage));
|
||||
if (changed) {
|
||||
m_status = status;
|
||||
m_statusMessage = statusMessage;
|
||||
sendPresence();
|
||||
}
|
||||
}
|
||||
|
||||
void LocalBuddy::setIconHash(const std::string &iconHash) {
|
||||
bool changed = m_iconHash != iconHash;
|
||||
m_iconHash = iconHash;
|
||||
if (changed) {
|
||||
getRosterManager()->storeBuddy(this);
|
||||
sendPresence();
|
||||
}
|
||||
}
|
||||
|
||||
bool LocalBuddy::setName(const std::string &name) {
|
||||
if (name == m_name) {
|
||||
return true;
|
||||
|
|
|
@ -561,7 +561,6 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) {
|
|||
LocalBuddy *buddy = (LocalBuddy *) user->getRosterManager()->getBuddy(payload.buddyname());
|
||||
if (buddy) {
|
||||
handleBuddyPayload(buddy, payload);
|
||||
buddy->handleBuddyChanged();
|
||||
}
|
||||
else {
|
||||
if (payload.buddyname() == user->getUserInfo().uin) {
|
||||
|
@ -583,10 +582,10 @@ void NetworkPluginServer::handleBuddyChangedPayload(const std::string &data) {
|
|||
return;
|
||||
}
|
||||
|
||||
buddy->setStatus(Swift::StatusShow((Swift::StatusShow::Type) payload.status()), payload.statusmessage());
|
||||
buddy->setIconHash(payload.iconhash());
|
||||
buddy->setBlocked(payload.blocked());
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
buddy->setStatus(Swift::StatusShow((Swift::StatusShow::Type) payload.status()), payload.statusmessage());
|
||||
buddy->setIconHash(payload.iconhash());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ void RosterManager::storeBuddy(Buddy *buddy) {
|
|||
void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error, Swift::SetRosterRequest::ref request, const std::string &key) {
|
||||
LOG4CXX_INFO(logger, "handleBuddyRosterPushResponse called for buddy " << key);
|
||||
if (m_buddies[key] != NULL) {
|
||||
m_buddies[key]->handleBuddyChanged();
|
||||
m_buddies[key]->sendPresence();
|
||||
}
|
||||
else {
|
||||
LOG4CXX_WARN(logger, "handleBuddyRosterPushResponse called for unknown buddy " << key);
|
||||
|
@ -577,7 +577,7 @@ void RosterManager::sendCurrentPresences(const Swift::JID &to) {
|
|||
continue;
|
||||
}
|
||||
Swift::Presence::ref presence = buddy->generatePresenceStanza(255);
|
||||
if (presence) {
|
||||
if (presence && presence->getType() == Swift::Presence::Available) {
|
||||
presence->setTo(to);
|
||||
m_component->getStanzaChannel()->sendPresence(presence);
|
||||
}
|
||||
|
|
|
@ -258,13 +258,13 @@ void BasicTest::add2Buddies() {
|
|||
std::vector<std::string> grp;
|
||||
grp.push_back("group1");
|
||||
LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1", "Buddy 1", grp, BUDDY_JID_ESCAPING);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1");
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1");
|
||||
|
||||
std::vector<std::string> grp2;
|
||||
grp2.push_back("group2");
|
||||
buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy2", "Buddy 2", grp2, BUDDY_JID_ESCAPING);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status2");
|
||||
user->getRosterManager()->setBuddy(buddy);
|
||||
buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status2");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
CPPUNIT_TEST(buddyFlagsFromJID);
|
||||
CPPUNIT_TEST(JIDToLegacyName);
|
||||
CPPUNIT_TEST(getSafeName);
|
||||
CPPUNIT_TEST(handleBuddyChanged);
|
||||
CPPUNIT_TEST(sendPresence);
|
||||
CPPUNIT_TEST(setAlias);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
|
@ -90,7 +90,7 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
CPPUNIT_ASSERT_EQUAL(BUDDY_NO_FLAG, Buddy::buddyFlagsFromJID("hanzz%test@localhost/bot"));
|
||||
}
|
||||
|
||||
void handleBuddyChanged() {
|
||||
void sendPresence() {
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
CPPUNIT_ASSERT(user);
|
||||
|
||||
|
@ -101,7 +101,7 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
user->getRosterManager()->setBuddy(buddy);
|
||||
received.clear();
|
||||
|
||||
buddy->handleBuddyChanged();
|
||||
buddy->sendPresence();
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
|
||||
|
|
|
@ -107,6 +107,7 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
pbnetwork::Buddy buddy;
|
||||
buddy.set_username("user@localhost");
|
||||
buddy.set_buddyname("buddy" + boost::lexical_cast<std::string>(i) + "@test");
|
||||
buddy.set_status((pbnetwork::StatusType) 5);
|
||||
|
||||
std::string message;
|
||||
buddy.SerializeToString(&message);
|
||||
|
@ -144,6 +145,7 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
pbnetwork::Buddy buddy;
|
||||
buddy.set_username("user@localhost");
|
||||
buddy.set_buddyname("buddy1@test");
|
||||
buddy.set_status(pbnetwork::STATUS_NONE);
|
||||
|
||||
std::string message;
|
||||
buddy.SerializeToString(&message);
|
||||
|
@ -164,6 +166,7 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
pbnetwork::Buddy buddy;
|
||||
buddy.set_username("user@localhost");
|
||||
buddy.set_buddyname("buddy1@test");
|
||||
buddy.set_status(pbnetwork::STATUS_NONE);
|
||||
|
||||
std::string message;
|
||||
buddy.SerializeToString(&message);
|
||||
|
|
|
@ -73,7 +73,7 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
void setBuddy() {
|
||||
add2Buddies();
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
|
||||
CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
|
||||
|
||||
Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
|
||||
CPPUNIT_ASSERT(payload1);
|
||||
|
@ -82,7 +82,7 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Buddy 1"), item.getName());
|
||||
|
||||
Swift::RosterPayload::ref payload2 = getStanza(received[1])->getPayload<Swift::RosterPayload>();
|
||||
Swift::RosterPayload::ref payload2 = getStanza(received[2])->getPayload<Swift::RosterPayload>();
|
||||
CPPUNIT_ASSERT(payload2);
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) payload2->getItems().size());
|
||||
item = payload2->getItems()[0];
|
||||
|
@ -91,17 +91,17 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
// send responses back
|
||||
injectIQ(Swift::IQ::createResult(getStanza(received[0])->getFrom(), getStanza(received[0])->getTo(), getStanza(received[0])->getID()));
|
||||
injectIQ(Swift::IQ::createResult(getStanza(received[1])->getFrom(), getStanza(received[1])->getTo(), getStanza(received[1])->getID()));
|
||||
injectIQ(Swift::IQ::createResult(getStanza(received[2])->getFrom(), getStanza(received[2])->getTo(), getStanza(received[2])->getID()));
|
||||
|
||||
// we should get presences
|
||||
CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[2])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[2]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("status1"), dynamic_cast<Swift::Presence *>(getStanza(received[2]))->getStatus());
|
||||
CPPUNIT_ASSERT_EQUAL(6, (int) received.size());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[4])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[4]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("status1"), dynamic_cast<Swift::Presence *>(getStanza(received[4]))->getStatus());
|
||||
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[3])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[3]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("status2"), dynamic_cast<Swift::Presence *>(getStanza(received[3]))->getStatus());
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[5])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast<Swift::Presence *>(getStanza(received[5]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("status2"), dynamic_cast<Swift::Presence *>(getStanza(received[5]))->getStatus());
|
||||
}
|
||||
|
||||
void sendCurrentPresences() {
|
||||
|
@ -142,7 +142,7 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
|||
|
||||
void removeBuddy() {
|
||||
add2Buddies();
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
|
||||
CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
|
||||
|
||||
received.clear();
|
||||
User *user = userManager->getUser("user@localhost");
|
||||
|
|
Loading…
Add table
Reference in a new issue