Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve Participant List, Send Message to Channel and Real JID lookup of participants proxy JID #89

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated based on feedback
Change-Id: Ie4a349c6b9ef35f08f367885755446c316f1e20e
  • Loading branch information
tarun018 committed Aug 23, 2017
commit 00bcfc19cc2442dc0cfd2013ef784d213b9d5f89
33 changes: 15 additions & 18 deletions Swiften/MIX/MIXRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,25 @@
namespace Swift {

MIXRegistry::MIXRegistry(const JID& ownJID, IQRouter* iqRouter, XMPPRoster* xmppRoster) : ownJID_(ownJID), iqRouter_(iqRouter), xmppRoster_(xmppRoster) {
scopedConnection_ = xmppRoster_->onInitialRosterPopulated.connect(boost::bind(&MIXRegistry::syncRegistryWithRoster, this));
}

MIXRegistry::~MIXRegistry() {

}

void MIXRegistry::syncRegistryWithRoster() {
SWIFT_LOG(debug) << "Syncing with roster items. " << std::endl;
for (auto item : xmppRoster_->getItems()) {
if (item.isMIXChannel()) {
SWIFT_LOG(debug) << item.getJID() << std::endl;
auto i = entries_.find(item.getJID());
if (i == entries_.end()) {
SWIFT_LOG(debug) << "Adding " << item.getJID() << std::endl;
entries_.insert(std::make_pair(item.getJID(), std::make_shared<MIXImpl>(ownJID_, item.getJID(), iqRouter_)));
initialRosterPopulationConnection_ = xmppRoster_->onInitialRosterPopulated.connect([=] {
SWIFT_LOG(debug) << "Syncing with roster items. " << std::endl;
for (auto item : xmppRoster_->getItems()) {
if (item.isMIXChannel()) {
auto i = entries_.find(item.getJID());
if (i == entries_.end()) {
entries_.insert(std::make_pair(item.getJID(), std::make_shared<MIXImpl>(ownJID_, item.getJID(), iqRouter_)));
}
}
}
}
onSyncSuccess();
});
xmppRoster_->onJIDAdded.connect(boost::bind(&MIXRegistry::handleJIDAdded, this, _1));
xmppRoster_->onJIDRemoved.connect(boost::bind(&MIXRegistry::handleJIDRemoved, this, _1));
onSyncSuccess();
}

MIXRegistry::~MIXRegistry() {
xmppRoster_->onJIDAdded.disconnect(boost::bind(&MIXRegistry::handleJIDAdded, this, _1));
xmppRoster_->onJIDRemoved.disconnect(boost::bind(&MIXRegistry::handleJIDRemoved, this, _1));
}

void MIXRegistry::joinChannel(const JID& channelJID, const std::unordered_set<std::string>& nodes) {
Expand Down
19 changes: 7 additions & 12 deletions Swiften/MIX/MIXRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ namespace Swift {

~MIXRegistry();

/**
* Sync based on initially populated roster.
*/
void syncRegistryWithRoster();

/**
* Join a MIX Channel with subscriptions.
*/
Expand All @@ -61,23 +56,23 @@ namespace Swift {
*/
MIXImpl::ref getMIXInstance(const JID& jid);

private:
void handleJIDAdded(const JID& jid);
void handleJIDRemoved(const JID& jid);
void handleJoinResponse(MIXJoin::ref, ErrorPayload::ref);
void handleLeaveResponse(MIXLeave::ref, ErrorPayload::ref);

public:
boost::signals2::signal<void (const JID& /* joinedChannel */)> onChannelJoined;
boost::signals2::signal<void (ErrorPayload::ref /* joinResponse */)> onChannelJoinFailed;
boost::signals2::signal<void (const JID& /* leavedChannel */)> onChannelLeft;
boost::signals2::signal<void ()> onSyncSuccess;

private:
void handleJIDAdded(const JID& jid);
void handleJIDRemoved(const JID& jid);
void handleJoinResponse(MIXJoin::ref, ErrorPayload::ref);
void handleLeaveResponse(MIXLeave::ref, ErrorPayload::ref);

private:
JID ownJID_;
IQRouter* iqRouter_;
XMPPRoster* xmppRoster_;
MIXInstanceMap entries_;
boost::signals2::scoped_connection scopedConnection_;
boost::signals2::scoped_connection initialRosterPopulationConnection_;
};
}
2 changes: 0 additions & 2 deletions Swiften/MIX/UnitTest/MIXRegistryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class MIXRegistryTest : public ::testing::Test {

TEST_F(MIXRegistryTest, testJoinAndLeaveChannel) {
auto testling = getMIXRegistry();
testling->syncRegistryWithRoster();

std::unordered_set<std::string> nodes;
nodes.insert(std::string("urn:xmpp:mix:nodes:messages"));
Expand Down Expand Up @@ -123,7 +122,6 @@ TEST_F(MIXRegistryTest, testJoinAndLeaveChannel) {

TEST_F(MIXRegistryTest, testFailedJoin) {
auto testling = getMIXRegistry();
testling->syncRegistryWithRoster();

std::unordered_set<std::string> nodes;
nodes.insert(std::string("urn:xmpp:mix:nodes:messages"));
Expand Down