diff options
| author | Remko Tronçon <git@el-tramo.be> | 2010-10-27 21:22:16 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2010-10-29 18:09:04 (GMT) | 
| commit | bbd3bbf5747c28ec5925a89ea43fd4767d135f6e (patch) | |
| tree | 7082ca4c7aa66cf66e3b1ebb24a90a5c1d37a1cd /Swiften/Chat/ChatStateNotifier.cpp | |
| parent | 420654a8e323beb7c8877453393568240a3f2a07 (diff) | |
| download | swift-bbd3bbf5747c28ec5925a89ea43fd4767d135f6e.zip swift-bbd3bbf5747c28ec5925a89ea43fd4767d135f6e.tar.bz2  | |
Make ChatStateNotifier use StanzaChannel directly.
Diffstat (limited to 'Swiften/Chat/ChatStateNotifier.cpp')
| -rw-r--r-- | Swiften/Chat/ChatStateNotifier.cpp | 61 | 
1 files changed, 46 insertions, 15 deletions
diff --git a/Swiften/Chat/ChatStateNotifier.cpp b/Swiften/Chat/ChatStateNotifier.cpp index 1aee9cf..cb7fa9a 100644 --- a/Swiften/Chat/ChatStateNotifier.cpp +++ b/Swiften/Chat/ChatStateNotifier.cpp @@ -6,32 +6,41 @@  #include "Swiften/Chat/ChatStateNotifier.h" -namespace Swift { +#include <boost/bind.hpp> -ChatStateNotifier::ChatStateNotifier() { -	contactJIDHasChanged(); -} +#include "Swiften/Elements/Message.h" +#include "Swiften/Elements/ChatState.h" +#include "Swiften/Client/StanzaChannel.h" +#include "Swiften/Disco/EntityCapsProvider.h" -void ChatStateNotifier::setContactHas85Caps(bool hasCaps) { -	contactHas85Caps_ = hasCaps; +namespace Swift { + +ChatStateNotifier::ChatStateNotifier(StanzaChannel* stanzaChannel, const JID& contact, EntityCapsProvider* entityCapsManager) : stanzaChannel_(stanzaChannel), entityCapsManager_(entityCapsManager), contact_(contact) { +	setContact(contact); +	entityCapsManager_->onCapsChanged.connect(boost::bind(&ChatStateNotifier::handleCapsChanged, this, _1));  } -void ChatStateNotifier::setContactIsOnline(bool online) { -	contactIsOnline_ = online; +ChatStateNotifier::~ChatStateNotifier() { +	entityCapsManager_->onCapsChanged.disconnect(boost::bind(&ChatStateNotifier::handleCapsChanged, this, _1));  } -void ChatStateNotifier::contactJIDHasChanged() { +void ChatStateNotifier::setContact(const JID& contact) {  	contactHasSentActive_ = false; -	contactHas85Caps_ = false;  	userIsTyping_ = false;  	contactIsOnline_ = false; +	contact_ = contact; +	handleCapsChanged(contact_); +} + +void ChatStateNotifier::setContactIsOnline(bool online) { +	contactIsOnline_ = online;  }  void ChatStateNotifier::setUserIsTyping() {  	bool should = contactShouldReceiveStates();  	if (should && !userIsTyping_) {  		userIsTyping_ = true; -		onChatStateChanged(ChatState::Composing); +		changeState(ChatState::Composing);  	}  } @@ -42,7 +51,7 @@ void ChatStateNotifier::userSentMessage() {  void ChatStateNotifier::userCancelledNewMessage() {  	if (userIsTyping_) {  		userIsTyping_ = false; -		onChatStateChanged(ChatState::Active); +		changeState(ChatState::Active);  	}  } @@ -52,10 +61,32 @@ void ChatStateNotifier::receivedMessageFromContact(bool hasActiveElement) {  bool ChatStateNotifier::contactShouldReceiveStates() {  	/* So, yes, the XEP says to look at caps, but it also says that once you've -	   heard from the contact, the active state overrides this. -	   *HOWEVER* it says that the MUST NOT send csn if you haven't received -	   active is OPTIONAL behaviour for if you haven't got caps.*/ +		 heard from the contact, the active state overrides this. +		 *HOWEVER* it says that the MUST NOT send csn if you haven't received +		 active is OPTIONAL behaviour for if you haven't got caps.*/  	return contactIsOnline_ && (contactHasSentActive_ || contactHas85Caps_);  } +void ChatStateNotifier::changeState(ChatState::ChatStateType state) { +	boost::shared_ptr<Message> message(new Message()); +	message->setTo(contact_); +	message->addPayload(boost::shared_ptr<Payload>(new ChatState(state))); +	stanzaChannel_->sendMessage(message); +} + +void ChatStateNotifier::addChatStateRequest(Message::ref message) { +	if (contactShouldReceiveStates()) { +		message->addPayload(boost::shared_ptr<Payload>(new ChatState(ChatState::Active))); +	} +} + + +void ChatStateNotifier::handleCapsChanged(const JID& jid) { +	if (jid == contact_) { +		DiscoInfo::ref caps = entityCapsManager_->getCaps(contact_); +		bool hasCSN = caps && caps->hasFeature(ChatState::getFeatureNamespace()); +		contactHas85Caps_ = hasCSN; +	} +} +  }  | 
 Swift