Skip to content

Commit

Permalink
Simple MUC invites.
Browse files Browse the repository at this point in the history
Resolves: #152
  • Loading branch information
Kev committed Oct 3, 2011
1 parent 123502d commit 4ea336d
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 22 deletions.
8 changes: 2 additions & 6 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
<value>Swift</value>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
Expand All @@ -28,10 +28,6 @@
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>python</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>-c</value>
Expand All @@ -54,7 +50,7 @@
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
<value>Swift</value>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
Expand Down
3 changes: 0 additions & 3 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,8 @@ Swift contains some code contributed under the BSD License, under the following
--- START OF BSD LICENSE
Copyright (c) 2011, Arnt Gulbrandsen
Copyright (c) 2011, Thilo Cestonaro
<<<<<<< HEAD
Copyright (c) 2011, Vlad Voicu
=======
Copyright (c) 2011, Jan Kaluza
>>>>>>> swift-1.x
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
30 changes: 20 additions & 10 deletions Swift/Controllers/Chat/ChatControllerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

#include <Swift/Controllers/Intl.h>
#include <Swiften/Base/format.h>
#include "Swiften/Base/String.h"
#include "Swiften/Client/StanzaChannel.h"
#include "Swiften/Elements/Delay.h"
#include "Swiften/Base/foreach.h"
#include "Swift/Controllers/XMPPEvents/EventController.h"
#include "Swiften/Disco/EntityCapsProvider.h"
#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
#include "Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h"
#include "Swiften/Avatars/AvatarManager.h"
#include <Swiften/Base/String.h>
#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Elements/Delay.h>
#include <Swiften/Elements/MUCInvitationPayload.h>
#include <Swiften/Base/foreach.h>
#include <Swift/Controllers/XMPPEvents/EventController.h>
#include <Swiften/Disco/EntityCapsProvider.h>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h>
#include <Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h>
#include <Swiften/Avatars/AvatarManager.h>

namespace Swift {

Expand Down Expand Up @@ -176,6 +177,10 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
std::string errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't send message: %1%")) % getErrorMessage(message->getPayload<ErrorPayload>()));
chatWindow_->addErrorMessage(errorMessage);
}
else if (messageEvent->getStanza()->getPayload<MUCInvitationPayload>()) {
handleMUCInvitation(messageEvent->getStanza());
return;
}
else {
if (!messageEvent->isReadable()) {
return;
Expand Down Expand Up @@ -256,4 +261,9 @@ std::string ChatControllerBase::getErrorMessage(boost::shared_ptr<ErrorPayload>
return defaultMessage;
}

void ChatControllerBase::handleMUCInvitation(Message::ref message) {
MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>();
chatWindow_->addMUCInvitation(invite->getJID(), invite->getReason(), invite->getPassword());
}

}
1 change: 1 addition & 0 deletions Swift/Controllers/Chat/ChatControllerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace Swift {
void handleAllMessagesRead();
void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error);
void handleDayChangeTick();
void handleMUCInvitation(Message::ref message);

protected:
JID selfJID_;
Expand Down
7 changes: 4 additions & 3 deletions Swift/Controllers/Chat/ChatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Swift/Controllers/FileTransfer/FileTransferOverview.h>
#include <Swift/Controllers/ProfileSettingsProvider.h>
#include <Swiften/Avatars/AvatarManager.h>
#include <Swiften/Elements/MUCInvitationPayload.h>

namespace Swift {

Expand Down Expand Up @@ -516,12 +517,13 @@ void ChatsManager::handleSearchMUCRequest() {
void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {
JID jid = message->getFrom();
boost::shared_ptr<MessageEvent> event(new MessageEvent(message));
if (!event->isReadable() && !message->getPayload<ChatState>() && !message->hasSubject()) {
bool isInvite = message->getPayload<MUCInvitationPayload>();
if (!event->isReadable() && !message->getPayload<ChatState>() && !isInvite && !message->hasSubject()) {
return;
}

// Try to deliver it to a MUC
if (message->getType() == Message::Groupchat || message->getType() == Message::Error) {
if (message->getType() == Message::Groupchat || message->getType() == Message::Error || (isInvite && message->getType() == Message::Normal)) {
std::map<JID, MUCController*>::iterator i = mucControllers_.find(jid.toBare());
if (i != mucControllers_.end()) {
i->second->handleIncomingMessage(event);
Expand Down Expand Up @@ -562,5 +564,4 @@ void ChatsManager::handleRecentActivated(const ChatListWindow::Chat& chat) {
}
}


}
5 changes: 5 additions & 0 deletions Swift/Controllers/Chat/MUCController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ MUCController::MUCController (
chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1));
chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1));
chatWindow_->onDestroyRequest.connect(boost::bind(&MUCController::handleDestroyRoomRequest, this));
chatWindow_->onInvitePersonToThisMUCRequest.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1, _2));
muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1));
muc_->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1));
muc_->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
Expand Down Expand Up @@ -603,4 +604,8 @@ void MUCController::handleDestroyRoomRequest() {
muc_->destroyRoom();
}

void MUCController::handleInvitePersonToThisMUCRequest(const JID& jid, const std::string& reason) {
muc_->invitePerson(jid, reason);
}

}
1 change: 1 addition & 0 deletions Swift/Controllers/Chat/MUCController.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace Swift {
void handleConfigurationFailed(ErrorPayload::ref);
void handleConfigurationFormReceived(Form::ref);
void handleDestroyRoomRequest();
void handleInvitePersonToThisMUCRequest(const JID& jid, const std::string& reason);

private:
MUC::ref muc_;
Expand Down
3 changes: 3 additions & 0 deletions Swift/Controllers/UIInterfaces/ChatWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Swift {
virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) = 0;
virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
virtual void setFileTransferStatus(std::string, const FileTransferState state, const std::string& msg = "") = 0;
virtual void addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password) = 0;

virtual void setContactChatState(ChatState::ChatStateType state) = 0;
virtual void setName(const std::string& name) = 0;
Expand All @@ -74,6 +75,7 @@ namespace Swift {
virtual void setAckState(const std::string& id, AckState state) = 0;
virtual void flash() = 0;
virtual void setSubject(const std::string& subject) = 0;

/**
* Set an alert on the window.
* @param alertText Description of alert (required).
Expand Down Expand Up @@ -103,6 +105,7 @@ namespace Swift {
boost::signal<void (const std::string&)> onChangeSubjectRequest;
boost::signal<void (Form::ref)> onConfigureRequest;
boost::signal<void ()> onDestroyRequest;
boost::signal<void (const JID&, const std::string& /*reason*/)> onInvitePersonToThisMUCRequest;

// File transfer related
boost::signal<void (std::string /* id */)> onFileTransferCancel;
Expand Down
1 change: 1 addition & 0 deletions Swift/Controllers/UnitTest/MockChatWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Swift {
void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {}
void setSubject(const std::string& /*subject*/) {}
virtual void showRoomConfigurationForm(Form::ref) {}
virtual void addMUCInvitation(const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/) {};

boost::signal<void ()> onClosed;
boost::signal<void ()> onAllMessagesRead;
Expand Down
34 changes: 34 additions & 0 deletions Swift/QtUI/QtChatWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include "SwifTools/TabComplete.h"
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIEvents/SendFileUIEvent.h>
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
#include "QtFileTransferJSBridge.h"

#include <boost/cstdint.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>

#include <QLabel>
#include <QMessageBox>
#include <QInputDialog>
#include <QApplication>
#include <QBoxLayout>
Expand Down Expand Up @@ -702,6 +704,7 @@ void QtChatWindow::handleActionButtonClicked() {
QAction* changeSubject = contextMenu.addAction(tr("Change subject"));
QAction* configure = contextMenu.addAction(tr("Configure room"));
QAction* destroy = contextMenu.addAction(tr("Destroy room"));
QAction* invite = contextMenu.addAction(tr("Invite person to this room"));
QAction* result = contextMenu.exec(QCursor::pos());
if (result == changeSubject) {
bool ok;
Expand All @@ -716,6 +719,13 @@ void QtChatWindow::handleActionButtonClicked() {
else if (result == destroy) {
onDestroyRequest();
}
else if (result == invite) {
bool ok;
QString jid = QInputDialog::getText(this, tr("Enter person's address"), tr("Address:"), QLineEdit::Normal, "", &ok);
if (ok) {
onInvitePersonToThisMUCRequest(JID(Q2PSTRING(jid)), "");
}
}
}

void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
Expand All @@ -726,4 +736,28 @@ void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
mucConfigurationWindow->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1));
}

void QtChatWindow::addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password) {
bool accepted = false;
QMessageBox msgBox;
msgBox.setText(QString("You have been invited to the room %1 by %2.").arg(P2QSTRING(jid.toString())).arg(contact_));
QString reasonString;
if (!reason.empty()) {
reasonString = QString("\"%1\"").arg(P2QSTRING(reason));
}
msgBox.setInformativeText(QString("Accept invitation from %1 to enter %2?\n%3").arg(contact_).arg(P2QSTRING(jid.toString())).arg(reasonString));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
accepted = true;
break;
default:
break;
}
if (accepted) {
eventStream_->send(boost::make_shared<JoinMUCUIEvent>(jid));
}
}

}
1 change: 1 addition & 0 deletions Swift/QtUI/QtChatWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace Swift {
virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions);
void setSubject(const std::string& subject);
void showRoomConfigurationForm(Form::ref);
void addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password);

public slots:
void handleChangeSplitterState(QByteArray state);
Expand Down
68 changes: 68 additions & 0 deletions Swiften/Elements/MUCInvitationPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/

#pragma once

#include <string>

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

namespace Swift {
class MUCInvitationPayload : public Payload {
public:
typedef boost::shared_ptr<MUCInvitationPayload> ref;
MUCInvitationPayload() : continuation_(false) {
}

void setIsContinuation(bool b) {
continuation_ = b;
}

bool getIsContinuation() const {
return continuation_;
}

void setJID(const JID& jid) {
jid_ = jid;
}

const JID& getJID() const {
return jid_;
}

void setPassword(const std::string& password) {
password_ = password;
}

const std::string& getPassword() const {
return password_;
}

void setReason(const std::string& text) {
reason_ = text;
}

const std::string& getReason() const {
return reason_;
}

void setThread(const std::string& thread) {
thread_ = thread;
}

const std::string& getThread() const {
return thread_;
}

private:
bool continuation_;
JID jid_;
std::string password_;
std::string reason_;
std::string thread_;
};
}
12 changes: 12 additions & 0 deletions Swiften/MUC/MUC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Swiften/Elements/MUCAdminPayload.h>
#include <Swiften/Elements/MUCPayload.h>
#include <Swiften/Elements/MUCDestroyPayload.h>
#include <Swiften/Elements/MUCInvitationPayload.h>
#include <Swiften/MUC/MUCRegistry.h>
#include <Swiften/Queries/GenericRequest.h>

Expand Down Expand Up @@ -286,6 +287,17 @@ void MUC::destroyRoom() {
request->send();
}

void MUC::invitePerson(const JID& person, const std::string& reason) {
Message::ref message = boost::make_shared<Message>();
message->setTo(person);
message->setType(Message::Normal);
MUCInvitationPayload::ref invite = boost::make_shared<MUCInvitationPayload>();
invite->setReason(reason);
invite->setJID(ownMUCJID.toBare());
message->addPayload(invite);
stanzaChannel->sendMessage(message);
}

//TODO: Invites(direct/mediated)

//TODO: requesting membership
Expand Down
2 changes: 2 additions & 0 deletions Swiften/MUC/MUC.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace Swift {
void requestConfigurationForm();
void configureRoom(Form::ref);
void destroyRoom();
/** Send an invite for the person to join the MUC */
void invitePerson(const JID& person, const std::string& reason = "");
public:
boost::signal<void (const std::string& /*nick*/)> onJoinComplete;
boost::signal<void (ErrorPayload::ref)> onJoinFailed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h>
#include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/NicknameParser.h>
#include <Swiften/Parser/PayloadParsers/ReplaceParser.h>
Expand Down Expand Up @@ -105,6 +106,10 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<ChatStateParserFactory>());
factories_.push_back(boost::make_shared<MUCUserPayloadParserFactory>(this));
factories_.push_back(boost::make_shared<MUCOwnerPayloadParserFactory>(this));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCAdminPayloadParser>("query", "http://jabber.org/protocol/muc#admin")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCInvitationPayloadParser>("x", "jabber:x:conference")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCDestroyPayloadParser>("destroy", "http://jabber.org/protocol/muc#user")));
factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCDestroyPayloadParser>("destroy", "http://jabber.org/protocol/muc#owner")));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner"));
Expand Down
Loading

0 comments on commit 4ea336d

Please sign in to comment.