mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-08 14:11:07 +01:00
Add support for XEP-0333: Chat Markers
Fixes SMACK-736
This commit is contained in:
parent
5372c1bcf4
commit
6d74d0383c
15 changed files with 795 additions and 0 deletions
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
|
||||
/**
|
||||
* Chat Markers Manager class (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public final class ChatMarkersManager extends Manager {
|
||||
|
||||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
@Override
|
||||
public void connectionCreated(XMPPConnection connection) {
|
||||
getInstanceFor(connection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final Map<XMPPConnection, ChatMarkersManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
/**
|
||||
* Get the singleton instance of ChatMarkersManager.
|
||||
*
|
||||
* @param connection
|
||||
* @return the instance of ChatMarkersManager
|
||||
*/
|
||||
public static synchronized ChatMarkersManager getInstanceFor(XMPPConnection connection) {
|
||||
ChatMarkersManager chatMarkersManager = INSTANCES.get(connection);
|
||||
|
||||
if (chatMarkersManager == null) {
|
||||
chatMarkersManager = new ChatMarkersManager(connection);
|
||||
INSTANCES.put(connection, chatMarkersManager);
|
||||
}
|
||||
|
||||
return chatMarkersManager;
|
||||
}
|
||||
|
||||
private ChatMarkersManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Chat Markers is supported by the server.
|
||||
*
|
||||
* @return true if Chat Markers is supported by the server.
|
||||
* @throws NotConnectedException
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public boolean isSupportedByServer()
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection())
|
||||
.serverSupportsFeature(ChatMarkersElements.NAMESPACE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,234 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
* Chat Markers elements (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public class ChatMarkersElements {
|
||||
|
||||
public static final String NAMESPACE = "urn:xmpp:chat-markers:0";
|
||||
|
||||
/**
|
||||
* Markable extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class MarkableExtension implements ExtensionElement {
|
||||
|
||||
/**
|
||||
* markable element.
|
||||
*/
|
||||
public static final String ELEMENT = "markable";
|
||||
|
||||
public MarkableExtension() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static MarkableExtension from(Message message) {
|
||||
return (MarkableExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Received extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class ReceivedExtension implements ExtensionElement {
|
||||
|
||||
/**
|
||||
* received element.
|
||||
*/
|
||||
public static final String ELEMENT = "received";
|
||||
|
||||
private final String id;
|
||||
|
||||
public ReceivedExtension(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static ReceivedExtension from(Message message) {
|
||||
return (ReceivedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displayed extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class DisplayedExtension implements ExtensionElement {
|
||||
|
||||
/**
|
||||
* displayed element.
|
||||
*/
|
||||
public static final String ELEMENT = "displayed";
|
||||
|
||||
private final String id;
|
||||
|
||||
public DisplayedExtension(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static DisplayedExtension from(Message message) {
|
||||
return (DisplayedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acknowledged extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class AcknowledgedExtension implements ExtensionElement {
|
||||
|
||||
/**
|
||||
* acknowledged element.
|
||||
*/
|
||||
public static final String ELEMENT = "acknowledged";
|
||||
|
||||
private final String id;
|
||||
|
||||
public AcknowledgedExtension(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static AcknowledgedExtension from(Message message) {
|
||||
return (AcknowledgedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Chat Markers elements (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
*
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.element;
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* XEP-0333: Chat Markers.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
*
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.provider;
|
||||
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.AcknowledgedExtension;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Acknowledged extension provider class (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public class AcknowledgedProvider extends ExtensionElementProvider<AcknowledgedExtension> {
|
||||
|
||||
@Override
|
||||
public AcknowledgedExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
String id = parser.getAttributeValue("", "id");
|
||||
return new AcknowledgedExtension(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.provider;
|
||||
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Displayed extension provider class (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public class DisplayedProvider extends ExtensionElementProvider<DisplayedExtension> {
|
||||
|
||||
@Override
|
||||
public DisplayedExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
String id = parser.getAttributeValue("", "id");
|
||||
return new DisplayedExtension(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.provider;
|
||||
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.MarkableExtension;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Markable extension provider class (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public class MarkableProvider extends ExtensionElementProvider<MarkableExtension> {
|
||||
|
||||
@Override
|
||||
public MarkableExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
return new MarkableExtension();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.provider;
|
||||
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Received extension provider class (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public class ReceivedProvider extends ExtensionElementProvider<ReceivedExtension> {
|
||||
|
||||
@Override
|
||||
public ReceivedExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
String id = parser.getAttributeValue("", "id");
|
||||
return new ReceivedExtension(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Chat Markers providers (XEP-0333).
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
*
|
||||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.provider;
|
||||
|
|
@ -211,4 +211,26 @@
|
|||
<className>org.jivesoftware.smackx.push_notifications.provider.RemoteDisablingProvider</className>
|
||||
</extensionProvider>
|
||||
|
||||
<!-- XEP-0333: Chat Markers -->
|
||||
<extensionProvider>
|
||||
<elementName>markable</elementName>
|
||||
<namespace>urn:xmpp:chat-markers:0</namespace>
|
||||
<className>org.jivesoftware.smackx.chat_markers.provider.MarkableProvider</className>
|
||||
</extensionProvider>
|
||||
<extensionProvider>
|
||||
<elementName>received</elementName>
|
||||
<namespace>urn:xmpp:chat-markers:0</namespace>
|
||||
<className>org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider</className>
|
||||
</extensionProvider>
|
||||
<extensionProvider>
|
||||
<elementName>displayed</elementName>
|
||||
<namespace>urn:xmpp:chat-markers:0</namespace>
|
||||
<className>org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider</className>
|
||||
</extensionProvider>
|
||||
<extensionProvider>
|
||||
<elementName>acknowledged</elementName>
|
||||
<namespace>urn:xmpp:chat-markers:0</namespace>
|
||||
<className>org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider</className>
|
||||
</extensionProvider>
|
||||
|
||||
</smackProviders>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue