mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add (partial) support for IoT XEPs
That is XEP-0323, -0324, -0325, and -0347. SMACK-727.
This commit is contained in:
parent
d1fe5c2933
commit
b91978dcc4
110 changed files with 5395 additions and 40 deletions
|
@ -1074,13 +1074,7 @@ public final class Roster extends Manager {
|
|||
if (entry == null) {
|
||||
return false;
|
||||
}
|
||||
switch (entry.getType()) {
|
||||
case from:
|
||||
case both:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return entry.canSeeMyPresence();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -176,6 +176,39 @@ public final class RosterEntry extends Manager {
|
|||
return item.isSubscriptionPending();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the contact is subscribed to "my" presence. This allows the contact to see the presence information.
|
||||
*
|
||||
* @return true if the contact has a presence subscription.
|
||||
* @since 4.2
|
||||
*/
|
||||
public boolean canSeeMyPresence() {
|
||||
switch (getType()) {
|
||||
case from:
|
||||
case both:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are subscribed to the contact's presence. If <code>true</code> then the contact has allowed us to
|
||||
* receive presence information.
|
||||
*
|
||||
* @return true if we are subscribed to the contact's presence.
|
||||
* @since 4.2
|
||||
*/
|
||||
public boolean canSeeHisPresence() {
|
||||
switch (getType()) {
|
||||
case to:
|
||||
case both:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (getName() != null) {
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Florian Schmaus
|
||||
*
|
||||
* 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.smack.roster;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public class RosterUtil {
|
||||
|
||||
public static void waitUntilOtherEntityIsSubscribed(Roster roster, BareJid otherEntity, long timeoutMillis)
|
||||
throws InterruptedException, TimeoutException {
|
||||
Date deadline = new Date(System.currentTimeMillis() + timeoutMillis);
|
||||
waitUntilOtherEntityIsSubscribed(roster, otherEntity, deadline);
|
||||
}
|
||||
|
||||
public static void waitUntilOtherEntityIsSubscribed(Roster roster, final BareJid otherEntity, Date deadline)
|
||||
throws InterruptedException, TimeoutException {
|
||||
final Lock lock = new ReentrantLock();
|
||||
final Condition maybeSubscribed = lock.newCondition();
|
||||
RosterListener rosterListener = new AbstractRosterListener() {
|
||||
private void signal() {
|
||||
lock.lock();
|
||||
try {
|
||||
// No need to use signalAll() here.
|
||||
maybeSubscribed.signal();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entriesAdded(Collection<Jid> addresses) {
|
||||
signal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entriesUpdated(Collection<Jid> addresses) {
|
||||
signal();
|
||||
}
|
||||
};
|
||||
|
||||
roster.addRosterListener(rosterListener);
|
||||
|
||||
boolean stillWaiting = true;
|
||||
// Using the example code pattern from Condition.awaitUntil(Date) javadoc.
|
||||
lock.lock();
|
||||
try {
|
||||
while (!roster.isSubscribedToMyPresence(otherEntity)) {
|
||||
if (!stillWaiting) {
|
||||
throw new TimeoutException();
|
||||
}
|
||||
stillWaiting = maybeSubscribed.awaitUntil(deadline);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
// Make sure the listener is removed, so we don't leak it.
|
||||
roster.removeRosterListener(rosterListener);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue