summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Chat')
-rw-r--r--Swiften/Chat/ChatStateNotifier.cpp21
-rw-r--r--Swiften/Chat/ChatStateNotifier.h2
-rw-r--r--Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp6
3 files changed, 19 insertions, 10 deletions
diff --git a/Swiften/Chat/ChatStateNotifier.cpp b/Swiften/Chat/ChatStateNotifier.cpp
index 5024958..667c244 100644
--- a/Swiften/Chat/ChatStateNotifier.cpp
+++ b/Swiften/Chat/ChatStateNotifier.cpp
@@ -9,18 +9,22 @@
namespace Swift {
ChatStateNotifier::ChatStateNotifier() {
- contactHas85Caps_ = false;
- isInConversation_ = false;
- contactHasSentActive_ = false;
- userIsTyping_ = false;
+ contactJIDHasChanged();
}
void ChatStateNotifier::setContactHas85Caps(bool hasCaps) {
contactHas85Caps_ = hasCaps;
}
+void ChatStateNotifier::contactJIDHasChanged() {
+ contactHasSentActive_ = false;
+ contactHas85Caps_ = false;
+ userIsTyping_ = false;
+}
+
void ChatStateNotifier::setUserIsTyping() {
- if (contactShouldReceiveStates() && !userIsTyping_) {
+ bool should = contactShouldReceiveStates();
+ if (should && !userIsTyping_) {
userIsTyping_ = true;
onChatStateChanged(ChatState::Composing);
}
@@ -38,14 +42,15 @@ void ChatStateNotifier::userCancelledNewMessage() {
}
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_);;
+ 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 contactHasSentActive_ || contactHas85Caps_ ;
}
}
diff --git a/Swiften/Chat/ChatStateNotifier.h b/Swiften/Chat/ChatStateNotifier.h
index 71febfa..8dcd5cd 100644
--- a/Swiften/Chat/ChatStateNotifier.h
+++ b/Swiften/Chat/ChatStateNotifier.h
@@ -21,11 +21,11 @@ namespace Swift {
void userCancelledNewMessage();
void receivedMessageFromContact(bool hasActiveElement);
bool contactShouldReceiveStates();
+ void contactJIDHasChanged();
boost::signal<void (ChatState::ChatStateType)> onChatStateChanged;
private:
bool contactHas85Caps_;
- bool isInConversation_;
bool contactHasSentActive_;
bool userIsTyping_;
};
diff --git a/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp b/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp
index 712ba10..2fa4c26 100644
--- a/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp
+++ b/Swiften/Chat/UnitTest/ChatStateNotifierTest.cpp
@@ -114,7 +114,11 @@ public:
void testContactShouldReceiveStates_ActiveOverrideOff() {
notifier_->setContactHas85Caps(true);
notifier_->receivedMessageFromContact(false);
- CPPUNIT_ASSERT_EQUAL(false, notifier_->contactShouldReceiveStates());
+ /* I originally read the MUST NOT send after receiving without Active and
+ * thought this should check for false, but I later found it was OPTIONAL
+ * (MAY) behaviour only for if you didn't receive caps.
+ */
+ CPPUNIT_ASSERT_EQUAL(true, notifier_->contactShouldReceiveStates());
}