diff options
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
| -rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 78 | 
1 files changed, 52 insertions, 26 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 50eee68..c41c078 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2013 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -24,6 +24,7 @@  #include <Swift/Controllers/UIEvents/UIEventStream.h>  #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>  #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> +#include <Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h>  #include <Swift/Controllers/Roster/GroupRosterItem.h>  #include <Swift/Controllers/Roster/ContactRosterItem.h>  #include <Swiften/Avatars/AvatarManager.h> @@ -35,6 +36,8 @@  #include <Swift/Controllers/Roster/SetPresence.h>  #include <Swiften/Disco/EntityCapsProvider.h>  #include <Swiften/Roster/XMPPRoster.h> +#include <Swift/Controllers/Highlighter.h> +#include <Swift/Controllers/Chat/ChatMessageParser.h>  #define MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS 60000 @@ -61,8 +64,10 @@ MUCController::MUCController (  		EntityCapsProvider* entityCapsProvider,  		XMPPRoster* roster,  		HistoryController* historyController, -		MUCRegistry* mucRegistry) : -			ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc->getJID(), presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry), muc_(muc), nick_(nick), desiredNick_(nick), password_(password) { +		MUCRegistry* mucRegistry, +		HighlightManager* highlightManager, +		ChatMessageParser* chatMessageParser) : +			ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc->getJID(), presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser), muc_(muc), nick_(nick), desiredNick_(nick), password_(password), renameCounter_(0) {  	parting_ = true;  	joined_ = false;  	lastWasPresence_ = false; @@ -98,6 +103,8 @@ MUCController::MUCController (  	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)); +	highlighter_->setMode(Highlighter::MUCMode); +	highlighter_->setNick(nick_);  	if (timerFactory) {  		loginCheckTimer_ = boost::shared_ptr<Timer>(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS));  		loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this)); @@ -146,6 +153,7 @@ void MUCController::handleWindowOccupantSelectionChanged(ContactRosterItem* item  		if (muc_->getOccupant(item->getJID().getResource()).getRealJID()) {  			actions.push_back(ChatWindow::AddContact);  		} +		actions.push_back(ChatWindow::ShowProfile);  	}  	chatWindow_->setAvailableOccupantActions(actions);  } @@ -164,6 +172,7 @@ void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction a  		case ChatWindow::MakeParticipant: muc_->changeOccupantRole(mucJID, MUCOccupant::Participant);break;  		case ChatWindow::MakeVisitor: muc_->changeOccupantRole(mucJID, MUCOccupant::Visitor);break;  		case ChatWindow::AddContact: if (occupant.getRealJID()) events_->send(boost::make_shared<RequestAddUserDialogUIEvent>(realJID, occupant.getNick()));break; +		case ChatWindow::ShowProfile: events_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(mucJID));break;  	}  } @@ -219,7 +228,7 @@ const std::string& MUCController::getNick() {  void MUCController::handleJoinTimeoutTick() {  	receivedActivity(); -	chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "Room %1% is not responding. This operation may never complete.")) % toJID_.toString())); +	chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Room %1% is not responding. This operation may never complete.")) % toJID_.toString())), ChatWindow::DefaultDirection);  }  void MUCController::receivedActivity() { @@ -228,6 +237,9 @@ void MUCController::receivedActivity() {  	}  } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch-enum" +  void MUCController::handleJoinFailed(boost::shared_ptr<ErrorPayload> error) {  	receivedActivity();  	std::string errorMessage = QT_TRANSLATE_NOOP("", "Unable to enter this room"); @@ -267,20 +279,24 @@ void MUCController::handleJoinFailed(boost::shared_ptr<ErrorPayload> error) {  		}  	}  	errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't join room: %1%.")) % errorMessage); -	chatWindow_->addErrorMessage(errorMessage); +	chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));  	parting_ = true; -	if (!rejoinNick.empty()) { -		nick_ = rejoinNick; +	if (!rejoinNick.empty() && renameCounter_ < 10) { +		renameCounter_++; +		setNick(rejoinNick);  		rejoin();  	}  } +#pragma clang diagnostic pop +  void MUCController::handleJoinComplete(const std::string& nick) {  	receivedActivity(); +	renameCounter_ = 0;  	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); +	setNick(nick); +	chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(joinMessage), ChatWindow::DefaultDirection);  #ifdef SWIFT_EXPERIMENTAL_HISTORY  	addRecentLogs(); @@ -298,8 +314,7 @@ 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)); +	roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid), JID::WithResource));  }  void MUCController::handleWindowClosed() { @@ -323,7 +338,7 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {  	NickJoinPart event(occupant.getNick(), Join);  	appendToJoinParts(joinParts_, event);  	std::string groupName(roleToGroupName(occupant.getRole())); -	roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid).string()); +	roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid));  	roster_->getGroup(groupName)->setManualSort(roleToSortName(occupant.getRole()));  	if (joined_) {  		std::string joinString; @@ -338,7 +353,6 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {  			updateJoinParts();  		} else {  			addPresenceMessage(joinString); -  		}  	}  	if (avatarManager_ != NULL) { @@ -348,7 +362,7 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {  void MUCController::addPresenceMessage(const std::string& message) {  	lastWasPresence_ = true; -	chatWindow_->addPresenceMessage(message); +	chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(message), ChatWindow::DefaultDirection);  } @@ -386,6 +400,7 @@ std::string MUCController::roleToFriendlyName(MUCOccupant::Role role) {  	case MUCOccupant::Visitor: return QT_TRANSLATE_NOOP("", "visitor");  	case MUCOccupant::NoRole: return "";  	} +	assert(false);  	return "";  } @@ -396,6 +411,7 @@ std::string MUCController::roleToSortName(MUCOccupant::Role role) {  	case MUCOccupant::Visitor: return "3";  	case MUCOccupant::NoRole: return "4";  	} +	assert(false);  	return "5";  } @@ -433,7 +449,7 @@ void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> mes  	joined_ = true;  	if (message->hasSubject() && message->getBody().empty()) { -		chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "The room subject is now: %1%")) % message->getSubject()));; +		chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The room subject is now: %1%")) % message->getSubject())), ChatWindow::DefaultDirection);;  		chatWindow_->setSubject(message->getSubject());  		doneGettingHistory_ = true;  	} @@ -448,10 +464,13 @@ void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> mes  	}  } -void MUCController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) { +void MUCController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent, const HighlightAction& highlight) {  	boost::shared_ptr<Message> message = messageEvent->getStanza();  	if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && messageTargetsMe(message) && !message->getPayload<Delay>()) {  		eventController_->handleIncomingEvent(messageEvent); +		if (!messageEvent->getConcluded()) { +			highlighter_->handleHighlightAction(highlight); +		}  	}  } @@ -465,9 +484,9 @@ void MUCController::handleOccupantRoleChanged(const std::string& nick, const MUC  		realJID = occupant.getRealJID().get();  	}  	std::string group(roleToGroupName(occupant.getRole())); -	roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid).string()); +	roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid));  	roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole())); -	chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole()))); +	chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole()))), ChatWindow::DefaultDirection);  	if (nick == nick_) {  		setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());  	} @@ -487,7 +506,6 @@ std::string MUCController::roleToGroupName(MUCOccupant::Role role) {  	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; -	default: assert(false);  	}  	return result;  } @@ -500,11 +518,12 @@ void MUCController::setOnline(bool online) {  		processUserPart();  	} else {  		if (shouldJoinOnReconnect_) { -			chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "Trying to enter room %1%")) % toJID_.toString())); +			renameCounter_ = 0; +			chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Trying to enter room %1%")) % toJID_.toString())), ChatWindow::DefaultDirection);  			if (loginCheckTimer_) {  				loginCheckTimer_->start();  			} -			nick_ = desiredNick_; +			setNick(desiredNick_);  			rejoin();  		}  	} @@ -598,7 +617,7 @@ boost::optional<boost::posix_time::ptime> MUCController::getMessageTimestamp(boo  }  void MUCController::updateJoinParts() { -	chatWindow_->replaceLastMessage(generateJoinPartString(joinParts_)); +	chatWindow_->replaceLastMessage(chatMessageParser_->parseMessageBody(generateJoinPartString(joinParts_)));  }  void MUCController::appendToJoinParts(std::vector<NickJoinPart>& joinParts, const NickJoinPart& newEvent) { @@ -611,7 +630,8 @@ void MUCController::appendToJoinParts(std::vector<NickJoinPart>& joinParts, cons  			switch (newEvent.type) {  				case Join: type = (type == Part) ? PartThenJoin : Join; break;  				case Part: type = (type == Join) ? JoinThenPart : Part; break; -				default: /*Nothing to see here */;break; +				case PartThenJoin: break; +				case JoinThenPart: break;  			}  			(*it).type = type;  			break; @@ -717,13 +737,13 @@ void MUCController::handleConfigureRequest(Form::ref form) {  void MUCController::handleConfigurationFailed(ErrorPayload::ref error) {  	std::string errorMessage = getErrorMessage(error);  	errorMessage = str(format(QT_TRANSLATE_NOOP("", "Room configuration failed: %1%.")) % errorMessage); -	chatWindow_->addErrorMessage(errorMessage); +	chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));  }  void MUCController::handleOccupantRoleChangeFailed(ErrorPayload::ref error, const JID&, MUCOccupant::Role) {  	std::string errorMessage = getErrorMessage(error);  	errorMessage = str(format(QT_TRANSLATE_NOOP("", "Occupant role change failed: %1%.")) % errorMessage); -	chatWindow_->addErrorMessage(errorMessage); +	chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));  }  void MUCController::handleConfigurationFormReceived(Form::ref form) { @@ -811,7 +831,7 @@ void MUCController::addRecentLogs() {  		bool senderIsSelf = nick_ == message.getFromJID().getResource();  		// the chatWindow uses utc timestamps -		addMessage(message.getMessage(), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), std::string(avatarManager_->getAvatarPath(message.getFromJID()).string()), message.getTime() - boost::posix_time::hours(message.getOffset())); +		addMessage(message.getMessage(), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), avatarManager_->getAvatarPath(message.getFromJID()), message.getTime() - boost::posix_time::hours(message.getOffset()), HighlightAction());  	}  } @@ -840,4 +860,10 @@ void MUCController::checkDuplicates(boost::shared_ptr<Message> newMessage) {  	}  } +void MUCController::setNick(const std::string& nick) +{ +	nick_ = nick; +	highlighter_->setNick(nick_); +} +  }  | 
 Swift