summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp55
1 files changed, 49 insertions, 6 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index fd37d27..52cd262 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -80,18 +80,19 @@ MUCController::MUCController (
chatWindow_->onInvitePersonToThisMUCRequest.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1, _2));
chatWindow_->onGetAffiliationsRequest.connect(boost::bind(&MUCController::handleGetAffiliationsRequest, this));
chatWindow_->onChangeAffiliationsRequest.connect(boost::bind(&MUCController::handleChangeAffiliationsRequest, this, _1));
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));
muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
muc_->onOccupantRoleChanged.connect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
+ muc_->onOccupantAffiliationChanged.connect(boost::bind(&MUCController::handleOccupantAffiliationChanged, this, _1, _2, _3));
muc_->onConfigurationFailed.connect(boost::bind(&MUCController::handleConfigurationFailed, this, _1));
muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1));
muc_->onRoleChangeFailed.connect(boost::bind(&MUCController::handleOccupantRoleChangeFailed, this, _1, _2, _3));
muc_->onAffiliationListReceived.connect(boost::bind(&MUCController::handleAffiliationListReceived, this, _1, _2));
if (timerFactory) {
loginCheckTimer_ = boost::shared_ptr<Timer>(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS));
loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this));
loginCheckTimer_->start();
}
@@ -109,26 +110,33 @@ MUCController::~MUCController() {
if (loginCheckTimer_) {
loginCheckTimer_->stop();
}
chatWindow_->setTabComplete(NULL);
delete completer_;
}
void MUCController::handleWindowOccupantSelectionChanged(ContactRosterItem* item) {
std::vector<ChatWindow::OccupantAction> actions;
- /* FIXME: all of these should be conditional */
+
if (item) {
- actions.push_back(ChatWindow::Kick);
- actions.push_back(ChatWindow::Ban);
- actions.push_back(ChatWindow::MakeModerator);
- actions.push_back(ChatWindow::MakeParticipant);
- actions.push_back(ChatWindow::MakeVisitor);
+ MUCOccupant::Affiliation affiliation = muc_->getOccupant(getNick()).getAffiliation();
+ MUCOccupant::Role role = muc_->getOccupant(getNick()).getRole();
+ if (role == MUCOccupant::Moderator)
+ {
+ if (affiliation == MUCOccupant::Admin || affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Ban);
+ }
+ actions.push_back(ChatWindow::Kick);
+ actions.push_back(ChatWindow::MakeModerator);
+ actions.push_back(ChatWindow::MakeParticipant);
+ actions.push_back(ChatWindow::MakeVisitor);
+ }
// Add contact is available only if the real JID is also available
if (muc_->getOccupant(item->getJID().getResource()).getRealJID()) {
actions.push_back(ChatWindow::AddContact);
}
}
chatWindow_->setAvailableOccupantActions(actions);
}
void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction action, ContactRosterItem* item) {
@@ -253,18 +261,20 @@ void MUCController::handleJoinFailed(boost::shared_ptr<ErrorPayload> error) {
void MUCController::handleJoinComplete(const std::string& nick) {
receivedActivity();
joined_ = true;
std::string joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have entered room %1% as %2%.")) % toJID_.toString() % nick);
nick_ = nick;
chatWindow_->addSystemMessage(joinMessage);
clearPresenceQueue();
shouldJoinOnReconnect_ = true;
setEnabled(true);
+ MUCOccupant occupant = muc_->getOccupant(nick);
+ setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
onUserJoined();
}
void MUCController::handleAvatarChanged(const JID& jid) {
if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) {
return;
}
std::string path = avatarManager_->getAvatarPath(jid).string();
roster_->applyOnItems(SetAvatar(jid, path, JID::WithResource));
@@ -313,18 +323,41 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {
handleAvatarChanged(jid);
}
}
void MUCController::addPresenceMessage(const std::string& message) {
lastWasPresence_ = true;
chatWindow_->addPresenceMessage(message);
}
+
+void MUCController::setAvailableRoomActions(const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Role& role)
+{
+ std::vector<ChatWindow::RoomAction> actions;
+
+ if (role <= MUCOccupant::Participant) {
+ actions.push_back(ChatWindow::ChangeSubject);
+ }
+ if (affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Configure);
+ }
+ if (affiliation <= MUCOccupant::Admin) {
+ actions.push_back(ChatWindow::Affiliations);
+ }
+ if (affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Destroy);
+ }
+ if (role <= MUCOccupant::Visitor) {
+ actions.push_back(ChatWindow::Invite);
+ }
+ chatWindow_->setAvailableRoomActions(actions);
+}
+
void MUCController::clearPresenceQueue() {
lastWasPresence_ = false;
joinParts_.clear();
}
std::string MUCController::roleToFriendlyName(MUCOccupant::Role role) {
switch (role) {
case MUCOccupant::Moderator: return QT_TRANSLATE_NOOP("", "moderator");
case MUCOccupant::Participant: return QT_TRANSLATE_NOOP("", "participant");
@@ -404,18 +437,28 @@ void MUCController::handleOccupantRoleChanged(const std::string& nick, const MUC
roster_->removeContactFromGroup(jid, roleToGroupName(oldRole));
JID realJID;
if (occupant.getRealJID()) {
realJID = occupant.getRealJID().get();
}
std::string group(roleToGroupName(occupant.getRole()));
roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid).string());
roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole()));
chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole())));
+ if (nick == nick_) {
+ setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
+ }
+}
+
+void MUCController::handleOccupantAffiliationChanged(const std::string& nick, const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Affiliation& oldAffiliation)
+{
+ if (nick == nick_) {
+ setAvailableRoomActions(affiliation, muc_->getOccupant(nick_).getRole());
+ }
}
std::string MUCController::roleToGroupName(MUCOccupant::Role role) {
std::string result;
switch (role) {
case MUCOccupant::Moderator: result = QT_TRANSLATE_NOOP("", "Moderators"); break;
case MUCOccupant::Participant: result = QT_TRANSLATE_NOOP("", "Participants"); break;
case MUCOccupant::Visitor: result = QT_TRANSLATE_NOOP("", "Visitors"); break;
case MUCOccupant::NoRole: result = QT_TRANSLATE_NOOP("", "Occupants"); break;