Class ContactExchangeManager
- java.lang.Object
-
- rocks.xmpp.core.stanza.AbstractIQHandler
-
- rocks.xmpp.extensions.rosterx.ContactExchangeManager
-
- All Implemented Interfaces:
ExtensionProtocol
,InboundMessageHandler
,IQHandler
,DiscoverableInfo
public final class ContactExchangeManager extends AbstractIQHandler implements InboundMessageHandler, ExtensionProtocol, DiscoverableInfo
Manages contact exchange between entities.Usage
Listen for inbound contact suggestions and eventually approve a roster item.
If you add a trusted entity, it will be auto-approved without notifying listeners.
In order to suggest contacts to another entity use
suggestContactAddition(Jid, Contact...)
.- See Also:
- XEP-0144: Roster Item Exchange
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContactExchangeListener(Consumer<ContactExchangeEvent> contactExchangeListener)
Adds a contact exchange listener.boolean
addTrustedEntity(Jid jid)
Adds a trusted entity for which roster item exchange suggestions are approved automatically (no listeners will be called).ContactExchange.Item.Action
approve(ContactExchange.Item item)
Approves a roster exchange item by modifying the roster accordingly.Set<String>
getFeatures()
Gets the features.String
getNamespace()
The protocol's main namespace.Collection<Jid>
getTrustedEntities()
Gets a unmodifiable collection of trusted entities for which roster item exchange suggestions are approved automatically (no listeners will be called).void
handleInboundMessage(MessageEvent e)
Handles an inbound message.boolean
isEnabled()
Indicates whether this protocol is enabled.void
removeContactExchangeListener(Consumer<ContactExchangeEvent> contactExchangeListener)
Removes a previously added contact exchange listener.boolean
removeTrustedEntity(Jid jid)
Removes a trusted entity for which roster item exchange suggestions are approved automatically.AsyncResult<Void>
suggestContactAddition(Jid jid, Contact... contacts)
Suggests the addition of one or more contacts to another user.-
Methods inherited from class rocks.xmpp.core.stanza.AbstractIQHandler
getPayloadClass, handleRequest
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rocks.xmpp.extensions.disco.model.info.DiscoverableInfo
getExtensions, getIdentities
-
-
-
-
Method Detail
-
getTrustedEntities
public final Collection<Jid> getTrustedEntities()
Gets a unmodifiable collection of trusted entities for which roster item exchange suggestions are approved automatically (no listeners will be called).- Returns:
- The trusted entities.
- See Also:
- 8.1 Trusted Entities,
addTrustedEntity(Jid)
-
addTrustedEntity
public final boolean addTrustedEntity(Jid jid)
Adds a trusted entity for which roster item exchange suggestions are approved automatically (no listeners will be called).- Parameters:
jid
- The bare JID.- Returns:
- True, if the entity was added.
- See Also:
- 8.1 Trusted Entities,
removeTrustedEntity(Jid)
-
removeTrustedEntity
public final boolean removeTrustedEntity(Jid jid)
Removes a trusted entity for which roster item exchange suggestions are approved automatically.- Parameters:
jid
- The bare JID.- Returns:
- True, if the entity was removed.
- See Also:
addTrustedEntity(Jid)
-
suggestContactAddition
public AsyncResult<Void> suggestContactAddition(Jid jid, Contact... contacts)
Suggests the addition of one or more contacts to another user.- Parameters:
jid
- The recipient.contacts
- The contacts.- Returns:
- The async result.
-
approve
public ContactExchange.Item.Action approve(ContactExchange.Item item)
Approves a roster exchange item by modifying the roster accordingly.If the item is to be added and does not yet exist, it will be added to your roster and you are subscribed to its presence. If it already exists in your roster but in a different group than suggested, it will additionally be added to the suggested group.
If the item is to be deleted, it will be deleted from your roster, if the suggested group(s) matches the same group(s) in your roster. Otherwise it will be edited, so that it no longer belongs to the suggested groups.
If the item is to be modified, it will be modified accordingly, if it exists.
- Parameters:
item
- The roster exchange item.- Returns:
- The action, which was actually performed. This may vary from the specified action, e.g. if you add a contact that already exists, only its groups are updated. If no action was performed, e.g. if you want to delete a contact, that does not exist, null is returned.
-
addContactExchangeListener
public void addContactExchangeListener(Consumer<ContactExchangeEvent> contactExchangeListener)
Adds a contact exchange listener.- Parameters:
contactExchangeListener
- The listener.- See Also:
removeContactExchangeListener(Consumer)
-
removeContactExchangeListener
public void removeContactExchangeListener(Consumer<ContactExchangeEvent> contactExchangeListener)
Removes a previously added contact exchange listener.- Parameters:
contactExchangeListener
- The listener.- See Also:
addContactExchangeListener(Consumer)
-
handleInboundMessage
public final void handleInboundMessage(MessageEvent e)
Description copied from interface:InboundMessageHandler
Handles an inbound message.- Specified by:
handleInboundMessage
in interfaceInboundMessageHandler
- Parameters:
e
- The message event.
-
getNamespace
public final String getNamespace()
Description copied from interface:ExtensionProtocol
The protocol's main namespace. This is used to uniquely identify the extension protocol.- Specified by:
getNamespace
in interfaceExtensionProtocol
- Returns:
- The main namespace.
-
isEnabled
public final boolean isEnabled()
Description copied from interface:ExtensionProtocol
Indicates whether this protocol is enabled.- Specified by:
isEnabled
in interfaceExtensionProtocol
- Returns:
- true, if enabled; false if disabled.
-
getFeatures
public final Set<String> getFeatures()
Description copied from interface:DiscoverableInfo
Gets the features.- Specified by:
getFeatures
in interfaceDiscoverableInfo
- Returns:
- The features.
-
-