diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-03-18 10:36:41 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2015-03-19 18:28:55 (GMT) |
commit | d62c9ba2dad0d9833c76452b5aa780a215548a5e (patch) | |
tree | ff0ad21e1394dc2202c1d1e14d169c577a313b96 /src/com/isode/stroke/chat | |
parent | 07117577091cee230bb0da8245856e19a9c7da8c (diff) | |
download | stroke-d62c9ba2dad0d9833c76452b5aa780a215548a5e.zip stroke-d62c9ba2dad0d9833c76452b5aa780a215548a5e.tar.bz2 |
Add functionality for ChatState.
Adds the Element, Parser, Serializer, ChatStateTracker and ChatStateSerializerTest.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Ported serializer test from Swiften, which passes.
Change-Id: I314eda2db0f2be0499f8aa74d043319fb5cf57a8
Diffstat (limited to 'src/com/isode/stroke/chat')
-rw-r--r-- | src/com/isode/stroke/chat/ChatStateTracker.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/com/isode/stroke/chat/ChatStateTracker.java b/src/com/isode/stroke/chat/ChatStateTracker.java new file mode 100644 index 0000000..c63d967 --- /dev/null +++ b/src/com/isode/stroke/chat/ChatStateTracker.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.chat; + +import com.isode.stroke.elements.Message; +import com.isode.stroke.elements.Presence; +import com.isode.stroke.elements.ChatState; +import com.isode.stroke.signals.Signal1; +import com.isode.stroke.base.NotNull; + +public class ChatStateTracker { + + private ChatState.ChatStateType currentState_; + public final Signal1<ChatState.ChatStateType> onChatStateChange = new Signal1<ChatState.ChatStateType>(); + + /** + * ChatStateTracker(); + */ + public ChatStateTracker() { + currentState_ = ChatState.ChatStateType.Gone; + } + + /** + * @param message, notnull + */ + public void handleMessageReceived(Message message) { + NotNull.exceptIfNull(message, "message"); + if (message.getType() == Message.Type.Error) { + return; + } + ChatState statePayload = message.getPayload(new ChatState()); + if (statePayload != null) { + changeState(statePayload.getChatState()); + } + } + + /** + * @param newPresence, notnull + */ + public void handlePresenceChange(Presence newPresence) { + NotNull.exceptIfNull(newPresence, "newPresence"); + if (newPresence.getType() == Presence.Type.Unavailable) { + onChatStateChange.emit(ChatState.ChatStateType.Gone); + } + } + + private void changeState(ChatState.ChatStateType state) { + if (state != currentState_) { + currentState_ = state; + onChatStateChange.emit(state); + } + } +} |