mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +01:00
Code complete chat state manager
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6283 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
dd754e5a7f
commit
5658fb705a
3 changed files with 59 additions and 25 deletions
|
@ -31,11 +31,35 @@
|
||||||
</extensionProvider>
|
</extensionProvider>
|
||||||
|
|
||||||
<!-- Chat State -->
|
<!-- Chat State -->
|
||||||
<!--<extensionProvider>-->
|
<extensionProvider>
|
||||||
<!--<elementName>active</elementName>-->
|
<elementName>active</elementName>
|
||||||
<!--<namespace>http://jabber.org/protocol/chatstates</namespace>-->
|
<namespace>http://jabber.org/protocol/chatstates</namespace>
|
||||||
<!--<className></className>-->
|
<className>org.jivesoftware.smackx.packet.ChatStateExtension.Provider</className>
|
||||||
<!--</extensionProvider>-->
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>composing</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/chatstates</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.packet.ChatStateExtension.Provider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>paused</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/chatstates</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.packet.ChatStateExtension.Provider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>inactive</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/chatstates</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.packet.ChatStateExtension.Provider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>gone</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/chatstates</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.packet.ChatStateExtension.Provider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
<!-- XHTML -->
|
<!-- XHTML -->
|
||||||
<extensionProvider>
|
<extensionProvider>
|
||||||
|
|
|
@ -38,9 +38,9 @@ import java.util.Collection;
|
||||||
* packet extensions and the disco response neccesary for compliance with
|
* packet extensions and the disco response neccesary for compliance with
|
||||||
* <a href="http://www.xmpp.org/extensions/xep-0085.html">XEP-0085</a>.
|
* <a href="http://www.xmpp.org/extensions/xep-0085.html">XEP-0085</a>.
|
||||||
*
|
*
|
||||||
|
* @author Alexander Wenckus
|
||||||
* @see org.jivesoftware.smackx.ChatState
|
* @see org.jivesoftware.smackx.ChatState
|
||||||
* @see org.jivesoftware.smackx.packet.ChatStateExtension
|
* @see org.jivesoftware.smackx.packet.ChatStateExtension
|
||||||
* @author Alexander Wenckus
|
|
||||||
*/
|
*/
|
||||||
public class ChatStateManager {
|
public class ChatStateManager {
|
||||||
|
|
||||||
|
@ -51,10 +51,11 @@ public class ChatStateManager {
|
||||||
* Returns the ChatStateManager related to the XMPPConnection and it will create one if it does
|
* Returns the ChatStateManager related to the XMPPConnection and it will create one if it does
|
||||||
* not yet exist.
|
* not yet exist.
|
||||||
*
|
*
|
||||||
* @param connection the connection to return the ChatStateManager/
|
* @param connection the connection to return the ChatStateManager
|
||||||
* @return the ChatStateManager related the the connection.
|
* @return the ChatStateManager related the the connection.
|
||||||
*/
|
*/
|
||||||
public static ChatStateManager getInstance(XMPPConnection connection) {
|
public static ChatStateManager getInstance(final XMPPConnection connection) {
|
||||||
|
synchronized (connection) {
|
||||||
ChatStateManager manager = managers.get(connection);
|
ChatStateManager manager = managers.get(connection);
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
manager = new ChatStateManager(connection);
|
manager = new ChatStateManager(connection);
|
||||||
|
@ -64,6 +65,7 @@ public class ChatStateManager {
|
||||||
|
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
|
|
||||||
|
@ -89,7 +91,8 @@ public class ChatStateManager {
|
||||||
*
|
*
|
||||||
* @param newState the new state of the chat
|
* @param newState the new state of the chat
|
||||||
* @param chat the chat.
|
* @param chat the chat.
|
||||||
* @throws org.jivesoftware.smack.XMPPException when there is an error sending the message
|
* @throws org.jivesoftware.smack.XMPPException
|
||||||
|
* when there is an error sending the message
|
||||||
* packet.
|
* packet.
|
||||||
*/
|
*/
|
||||||
public void setCurrentState(ChatState newState, Chat chat) throws XMPPException {
|
public void setCurrentState(ChatState newState, Chat chat) throws XMPPException {
|
||||||
|
|
|
@ -29,8 +29,8 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
* Represents a chat state which is an extension to message packets which is used to indicate
|
* Represents a chat state which is an extension to message packets which is used to indicate
|
||||||
* the current status of a chat participant.
|
* the current status of a chat participant.
|
||||||
*
|
*
|
||||||
* @see org.jivesoftware.smackx.ChatState
|
|
||||||
* @author Alexander Wenckus
|
* @author Alexander Wenckus
|
||||||
|
* @see org.jivesoftware.smackx.ChatState
|
||||||
*/
|
*/
|
||||||
public class ChatStateExtension implements PacketExtension {
|
public class ChatStateExtension implements PacketExtension {
|
||||||
|
|
||||||
|
@ -57,10 +57,17 @@ public class ChatStateExtension implements PacketExtension {
|
||||||
return "<" + getElementName() + " xmlns=\"" + getNamespace() + "\" />";
|
return "<" + getElementName() + " xmlns=\"" + getNamespace() + "\" />";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Provider implements PacketExtensionProvider {
|
public static class Provider implements PacketExtensionProvider {
|
||||||
|
|
||||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
||||||
return null;
|
ChatState state;
|
||||||
|
try {
|
||||||
|
state = ChatState.valueOf(parser.getName());
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
state = ChatState.active;
|
||||||
|
}
|
||||||
|
return new ChatStateExtension(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue