diff options
| author | Kevin Smith <git@kismith.co.uk> | 2010-02-10 15:29:44 (GMT) | 
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2010-02-10 15:29:44 (GMT) | 
| commit | 1d20eabbc32274b491b4c2bedf73d19933d97bfd (patch) | |
| tree | b5a2760b4e72a88f24041f7821e788d34a184522 /Swiften/Chat/ChatStateNotifier.cpp | |
| parent | 4d0c1d3b8a40cb74cfb30ed27a294afaa6ced56f (diff) | |
| download | swift-contrib-1d20eabbc32274b491b4c2bedf73d19933d97bfd.zip swift-contrib-1d20eabbc32274b491b4c2bedf73d19933d97bfd.tar.bz2 | |
ChatStateNotifier and tests, ready for XEP-85 support.
Diffstat (limited to 'Swiften/Chat/ChatStateNotifier.cpp')
| -rw-r--r-- | Swiften/Chat/ChatStateNotifier.cpp | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/Swiften/Chat/ChatStateNotifier.cpp b/Swiften/Chat/ChatStateNotifier.cpp new file mode 100644 index 0000000..432f708 --- /dev/null +++ b/Swiften/Chat/ChatStateNotifier.cpp @@ -0,0 +1,45 @@ +#include "Swiften/Chat/ChatStateNotifier.h" + +namespace Swift { + +ChatStateNotifier::ChatStateNotifier() { +	contactHas85Caps_ = false; +	isInConversation_ = false; +	contactHasSentActive_ = false; +	userIsTyping_ = false; +} + +void ChatStateNotifier::setContactHas85Caps(bool hasCaps) { +	contactHas85Caps_ = hasCaps; +} + +void ChatStateNotifier::setUserIsTyping() { +	if (contactShouldReceiveStates() && !userIsTyping_) { +		userIsTyping_ = true; +		onChatStateChanged(Composing); +	} +} + +void ChatStateNotifier::userSentMessage() { +	userIsTyping_ = false; +} + +void ChatStateNotifier::userCancelledNewMessage() { +	if (userIsTyping_) { +		userIsTyping_ = false; +		onChatStateChanged(Active); +	} +} + +void ChatStateNotifier::receivedMessageFromContact(bool hasActiveElement) { +	isInConversation_ = true; +	contactHasSentActive_ = 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.*/ +	return contactHasSentActive_ || (contactHas85Caps_ && !isInConversation_);; +} + +} | 
 Swift
 Swift