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

Add joining a MIX channel by invitation #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
63 changes: 63 additions & 0 deletions Swiften/Elements/MIXInvitation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#pragma once

#include <memory>

#include <Swiften/Base/API.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/JID/JID.h>

namespace Swift {
class SWIFTEN_API MIXInvitation : public Payload {

public:
using ref = std::shared_ptr<MIXInvitation>;

public:

MIXInvitation() {}

const JID& getInviter() const {
return inviter_;
}

void setInviter(JID inviter) {
inviter_ = inviter;
}

const JID& getInvitee() const {
return invitee_;
}

void setInvitee(JID invitee) {
invitee_ = invitee;
}

const JID& getChannel() const {
return channel_;
}

void setChannel(JID channel) {
channel_ = channel;
}

const std::string& getToken() const {
return token_;
}

void setToken(std::string token) {
token_ = token;
}

private:
JID inviter_;
JID invitee_;
JID channel_;
std::string token_;
};
}
47 changes: 47 additions & 0 deletions Swiften/Elements/MIXInvitationAck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#pragma once

#include <memory>

#include <Swiften/Base/API.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/MIXInvitation.h>

namespace Swift {
class SWIFTEN_API MIXInvitationAck : public Payload {

public:
using ref = std::shared_ptr<MIXInvitationAck>;

enum class InvitationStatus {Joined, Declined, Acknowledged};

public:

MIXInvitationAck() {}

const MIXInvitation::ref getInvitation() const {
return invitation_;
}

void setInvitation(MIXInvitation::ref invitation) {
invitation_ = invitation;
}

InvitationStatus getInvitationStatus() const {
return status_;
}

void setInvitationStatus(InvitationStatus status) {
status_ = status;
}

private:
InvitationStatus status_;
MIXInvitation::ref invitation_;
};
}
47 changes: 47 additions & 0 deletions Swiften/Elements/MIXInvite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#pragma once

#include <memory>

#include <boost/optional.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/MIXInvitation.h>

namespace Swift {
class SWIFTEN_API MIXInvite : public Payload {

public:
using ref = std::shared_ptr<MIXInvite>;

public:

MIXInvite() {}

const boost::optional<MIXInvitation::ref>& getInvitation() const {
return invitation_;
}

void setInvitation(MIXInvitation::ref invitation) {
invitation_ = invitation;
}

const boost::optional<JID>& getInvitee() const {
return invitee_;
}

void setInvitee(JID invitee) {
invitee_ = invitee;
}

private:
boost::optional<JID> invitee_;
boost::optional<MIXInvitation::ref> invitation_;
};
}
11 changes: 10 additions & 1 deletion Swiften/Elements/MIXJoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Swiften/Base/API.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/Form.h>
#include <Swiften/Elements/MIXInvitation.h>
#include <Swiften/JID/JID.h>

namespace Swift {
Expand Down Expand Up @@ -67,11 +68,19 @@ namespace Swift {
return form_;
}

const boost::optional<MIXInvitation::ref>& getInvitation() const {
return invitation_;
}

void setInvitation(MIXInvitation::ref invitation) {
invitation_ = invitation;
}

private:
boost::optional<JID> jid_;
boost::optional<JID> channel_;
std::unordered_set<std::string> subscribeItems_;
std::shared_ptr<Form> form_;
// FIXME: MIXInvitation to be implemented. boost::optional<MIXInvitation> invitation_;
boost::optional<MIXInvitation::ref> invitation_;
};
}
14 changes: 14 additions & 0 deletions Swiften/MIX/MIX.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#include <Swiften/MIX/MIX.h>

namespace Swift {

MIX::~MIX() {
}

}
99 changes: 99 additions & 0 deletions Swiften/MIX/MIX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2017 Tarun Gupta
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/

#pragma once

#include <memory>
#include <string>
#include <unordered_set>

#include <boost/signals2.hpp>

#include <Swiften/Base/API.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/Form.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Elements/MIXJoin.h>
#include <Swiften/Elements/MIXLeave.h>
#include <Swiften/Elements/MIXUpdateSubscription.h>
#include <Swiften/Elements/MIXUserPreference.h>
#include <Swiften/Elements/MIXInvite.h>
#include <Swiften/Elements/MIXInvitation.h>
#include <Swiften/Elements/MIXInvitationAck.h>
#include <Swiften/Elements/ErrorPayload.h>

namespace Swift {
class SWIFTEN_API MIX {
public:
using ref = std::shared_ptr<MIX>;

public:
virtual ~MIX();

/**
* Join Channel with preferences and subscriptions to node with invitation.
*/
virtual void joinChannel(const std::unordered_set<std::string>& nodes, Form::ref form, MIXInvitation::ref invitation) = 0;

/**
* Join a MIX channel and subscribe to nodes.
*/
virtual void joinChannelWithSubscriptions(const std::unordered_set<std::string>& nodes) = 0;

/**
* Join Channel with preferences and subscriptions to node with invitation.
*/
virtual void joinChannelWithPreferences(const std::unordered_set<std::string>& nodes, Form::ref form) = 0;

/**
* Join channel with invite and subscribe to nodes.
*/
virtual void joinChannelWithInvite(const std::unordered_set<std::string>& nodes, MIXInvitation::ref invitation) = 0;

/**
* Update subscription of nodes.
*/
virtual void updateSubscription(const std::unordered_set<std::string>& nodes) = 0;

/**
* Leave a MIX channel and unsubcribe nodes.
*/
virtual void leaveChannel() = 0;

/**
* Request a configuration form for updating preferences.
*/
virtual void requestPreferencesForm() = 0;

/**
* Update preferences after requesting preference form.
*/
virtual void updatePreferences(Form::ref form) = 0;

/**
* Request invitation payload along with token for invitee.
*/
virtual void requestInvitation(const JID& invitee) = 0;

/**
* Invite invitee based on received token from requestInvitation.
*/
virtual void sendInvitation(MIXInvitation::ref invitation, std::string invitationMessage) = 0;

public:
boost::signals2::signal<void (MIXJoin::ref /* joinResponse */)> onJoinComplete;
boost::signals2::signal<void (ErrorPayload::ref /* joinError */)> onJoinFailed;
boost::signals2::signal<void (MIXLeave::ref /* leaveResponse */)> onLeaveComplete;
boost::signals2::signal<void (ErrorPayload::ref /* leaveError */)> onLeaveFailed;
boost::signals2::signal<void (MIXUpdateSubscription::ref /* updateResponse */)> onSubscriptionUpdated;
boost::signals2::signal<void (ErrorPayload::ref /* updateError */)> onSubscriptionUpdateFailed;
boost::signals2::signal<void (Form::ref /* preferencesForm */)> onPreferencesFormReceived;
boost::signals2::signal<void (ErrorPayload::ref /* failedConfiguration */)> onPreferencesUpdateFailed;
boost::signals2::signal<void (MIXInvitation::ref /* inviteResponse */)> onInvitationReceived;
boost::signals2::signal<void (ErrorPayload::ref /* failedConfiguration */)> onInvitationRequestFailed;
boost::signals2::signal<void (Message::ref /* message */)> onMessageReceived;
};
}
Loading