mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-10 14:16:00 +01:00
Initial commit
This commit is contained in:
parent
9d626bf787
commit
1fe2aa2dca
4 changed files with 281 additions and 0 deletions
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Paul Schaub.
|
||||
*
|
||||
* 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.inbox;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
public final class InboxManager extends Manager {
|
||||
|
||||
public static final String NAMESPACE_1 = "urn:xmpp:inbox:1";
|
||||
private static final Map<XMPPConnection, InboxManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private InboxManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
public static InboxManager getInstanceFor(XMPPConnection connection) {
|
||||
InboxManager inboxManager = INSTANCES.get(connection);
|
||||
if (inboxManager == null) {
|
||||
inboxManager = new InboxManager(connection);
|
||||
INSTANCES.put(connection, inboxManager);
|
||||
}
|
||||
return inboxManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Paul Schaub.
|
||||
*
|
||||
* 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.inbox.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.inbox.InboxManager;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
|
||||
public class EntryElement implements ExtensionElement {
|
||||
|
||||
public static final String ELEMENT = "entry";
|
||||
public static final String ATTR_UNREAD = "unread";
|
||||
public static final String ATTR_JID = "jid";
|
||||
public static final String ATTR_ID = "id";
|
||||
|
||||
private final int unreadCount;
|
||||
private final EntityBareJid jid;
|
||||
private final String id; // TODO: Legacy Stanza ID, Origin ID, Stanza ID or MAM ID?
|
||||
|
||||
public EntryElement(int unreadCount, EntityBareJid jid, String id) {
|
||||
this.unreadCount = unreadCount;
|
||||
this.jid = jid;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
return unreadCount;
|
||||
}
|
||||
|
||||
public EntityBareJid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return InboxManager.NAMESPACE_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
return new XmlStringBuilder(this)
|
||||
.attribute(ATTR_UNREAD, getUnreadCount())
|
||||
.attribute(ATTR_JID, getJid())
|
||||
.attribute(ATTR_ID, getId())
|
||||
.closeEmptyElement();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Paul Schaub.
|
||||
*
|
||||
* 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.inbox.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.inbox.InboxManager;
|
||||
import org.jivesoftware.smackx.rsm.packet.RSMSet;
|
||||
|
||||
public class FinElement implements ExtensionElement {
|
||||
|
||||
public static final String ELEMENT = "fin";
|
||||
public static final String ATTR_TOTAL = "total";
|
||||
public static final String ATTR_UNREAD = "unread";
|
||||
public static final String ATTR_ALL_UNREAD = "all-unread";
|
||||
|
||||
private final int total;
|
||||
private final int unread;
|
||||
private final int allUnread;
|
||||
|
||||
private RSMSet rsmData; // TODO: What is RSM data? RSM set?
|
||||
|
||||
public FinElement(RSMSet rsmData, int total, int unread, int allUnread) {
|
||||
this.rsmData = rsmData;
|
||||
this.total = total;
|
||||
this.unread = unread;
|
||||
this.allUnread = allUnread;
|
||||
}
|
||||
|
||||
public RSMSet getRsmData() {
|
||||
return rsmData;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getUnread() {
|
||||
return unread;
|
||||
}
|
||||
|
||||
public int getAllUnread() {
|
||||
return allUnread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return InboxManager.NAMESPACE_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
return new XmlStringBuilder(this)
|
||||
.attribute(ATTR_TOTAL, getTotal())
|
||||
.attribute(ATTR_UNREAD, getUnread())
|
||||
.attribute(ATTR_ALL_UNREAD, getAllUnread())
|
||||
.rightAngleBracket()
|
||||
.optAppend(getRsmData())
|
||||
.closeElement(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Paul Schaub.
|
||||
*
|
||||
* 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.inbox.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.inbox.InboxManager;
|
||||
import org.jivesoftware.smackx.rsm.packet.RSMSet;
|
||||
|
||||
public class InboxElement implements ExtensionElement {
|
||||
|
||||
public static final String ELEMENT = "inbox";
|
||||
public static final String ATTR_UNREAD_ONLY = "unread-only";
|
||||
public static final String ATTR_MESSAGES = "messages";
|
||||
|
||||
private final RSMSet filter;
|
||||
private final boolean unreadOnly;
|
||||
private final boolean includeMessages;
|
||||
|
||||
public InboxElement() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public InboxElement(RSMSet filter) {
|
||||
this(filter, false, true);
|
||||
}
|
||||
|
||||
public InboxElement(RSMSet filter, boolean unreadOnly, boolean includeMessages) {
|
||||
this.filter = filter;
|
||||
this.unreadOnly = unreadOnly;
|
||||
this.includeMessages = includeMessages;
|
||||
}
|
||||
|
||||
public RSMSet getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public boolean isUnreadOnly() {
|
||||
return unreadOnly;
|
||||
}
|
||||
|
||||
public boolean isIncludeMessages() {
|
||||
return includeMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return InboxManager.NAMESPACE_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this)
|
||||
.optBooleanAttribute(ATTR_UNREAD_ONLY, isUnreadOnly())
|
||||
.optBooleanAttributeDefaultTrue(ATTR_MESSAGES, isIncludeMessages());
|
||||
|
||||
if (getFilter() == null) {
|
||||
return xml.closeEmptyElement();
|
||||
} else {
|
||||
return xml.rightAngleBracket()
|
||||
.append(getFilter())
|
||||
.closeElement(this);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue