summaryrefslogtreecommitdiffstats
blob: 667c244a5771e6f555cd5b073ffea72ef0b8ce2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include "Swiften/Chat/ChatStateNotifier.h"

namespace Swift {

ChatStateNotifier::ChatStateNotifier() {
	contactJIDHasChanged();
}

void ChatStateNotifier::setContactHas85Caps(bool hasCaps) {
	contactHas85Caps_ = hasCaps;
}

void ChatStateNotifier::contactJIDHasChanged() {
	contactHasSentActive_ = false;
	contactHas85Caps_ = false;
	userIsTyping_ = false;
}

void ChatStateNotifier::setUserIsTyping() {
	bool should = contactShouldReceiveStates();
	if (should && !userIsTyping_) {
		userIsTyping_ = true;
		onChatStateChanged(ChatState::Composing);
	}
}

void ChatStateNotifier::userSentMessage() {
	userIsTyping_ = false;
}

void ChatStateNotifier::userCancelledNewMessage() {
	if (userIsTyping_) {
		userIsTyping_ = false;
		onChatStateChanged(ChatState::Active);
	}
}

void ChatStateNotifier::receivedMessageFromContact(bool hasActiveElement) {
	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.
	   *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_ ;
}

}