mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Allow Roster for anonymous connections
Fixes SMACK-628.
This commit is contained in:
parent
6c637d5784
commit
dddba8f08c
1 changed files with 2 additions and 24 deletions
|
@ -101,13 +101,13 @@ public final class Roster extends Manager {
|
||||||
* Returns the roster for the user.
|
* Returns the roster for the user.
|
||||||
* <p>
|
* <p>
|
||||||
* This method will never return <code>null</code>, instead if the user has not yet logged into
|
* This method will never return <code>null</code>, instead if the user has not yet logged into
|
||||||
* the server or is logged in anonymously all modifying methods of the returned roster object
|
* the server all modifying methods of the returned roster object
|
||||||
* like {@link Roster#createEntry(Jid, String, String[])},
|
* like {@link Roster#createEntry(Jid, String, String[])},
|
||||||
* {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing
|
* {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing
|
||||||
* {@link RosterListener}s will throw an IllegalStateException.
|
* {@link RosterListener}s will throw an IllegalStateException.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return the user's roster.
|
* @return the user's roster.
|
||||||
* @throws IllegalStateException if the connection is anonymous
|
|
||||||
*/
|
*/
|
||||||
public static synchronized Roster getInstanceFor(XMPPConnection connection) {
|
public static synchronized Roster getInstanceFor(XMPPConnection connection) {
|
||||||
Roster roster = INSTANCES.get(connection);
|
Roster roster = INSTANCES.get(connection);
|
||||||
|
@ -213,11 +213,6 @@ public final class Roster extends Manager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||||
// Anonymous users can't have a roster, but it is possible that a Roster instance is
|
|
||||||
// retrieved if getRoster() is called *before* connect(). So we have to check here
|
|
||||||
// again if it's an anonymous connection.
|
|
||||||
if (connection.isAnonymous())
|
|
||||||
return;
|
|
||||||
if (!isRosterLoadedAtLogin())
|
if (!isRosterLoadedAtLogin())
|
||||||
return;
|
return;
|
||||||
// We are done here if the connection was resumed
|
// We are done here if the connection was resumed
|
||||||
|
@ -296,9 +291,6 @@ public final class Roster extends Manager {
|
||||||
if (!connection.isAuthenticated()) {
|
if (!connection.isAuthenticated()) {
|
||||||
throw new NotLoggedInException();
|
throw new NotLoggedInException();
|
||||||
}
|
}
|
||||||
if (connection.isAnonymous()) {
|
|
||||||
throw new IllegalStateException("Anonymous users can't have a roster.");
|
|
||||||
}
|
|
||||||
|
|
||||||
RosterPacket packet = new RosterPacket();
|
RosterPacket packet = new RosterPacket();
|
||||||
if (rosterStore != null && isRosterVersioningSupported()) {
|
if (rosterStore != null && isRosterVersioningSupported()) {
|
||||||
|
@ -438,13 +430,9 @@ public final class Roster extends Manager {
|
||||||
*
|
*
|
||||||
* @param name the name of the group.
|
* @param name the name of the group.
|
||||||
* @return a new group, or null if the group already exists
|
* @return a new group, or null if the group already exists
|
||||||
* @throws IllegalStateException if logged in anonymously
|
|
||||||
*/
|
*/
|
||||||
public RosterGroup createGroup(String name) {
|
public RosterGroup createGroup(String name) {
|
||||||
final XMPPConnection connection = connection();
|
final XMPPConnection connection = connection();
|
||||||
if (connection.isAnonymous()) {
|
|
||||||
throw new IllegalStateException("Anonymous users can't have a roster.");
|
|
||||||
}
|
|
||||||
if (groups.containsKey(name)) {
|
if (groups.containsKey(name)) {
|
||||||
return groups.get(name);
|
return groups.get(name);
|
||||||
}
|
}
|
||||||
|
@ -473,9 +461,6 @@ public final class Roster extends Manager {
|
||||||
if (!connection.isAuthenticated()) {
|
if (!connection.isAuthenticated()) {
|
||||||
throw new NotLoggedInException();
|
throw new NotLoggedInException();
|
||||||
}
|
}
|
||||||
if (connection.isAnonymous()) {
|
|
||||||
throw new IllegalStateException("Anonymous users can't have a roster.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and send roster entry creation packet.
|
// Create and send roster entry creation packet.
|
||||||
RosterPacket rosterPacket = new RosterPacket();
|
RosterPacket rosterPacket = new RosterPacket();
|
||||||
|
@ -551,9 +536,6 @@ public final class Roster extends Manager {
|
||||||
if (!connection.isAuthenticated()) {
|
if (!connection.isAuthenticated()) {
|
||||||
throw new NotLoggedInException();
|
throw new NotLoggedInException();
|
||||||
}
|
}
|
||||||
if (connection.isAnonymous()) {
|
|
||||||
throw new IllegalStateException("Anonymous users can't have a roster.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection.hasFeature(SubscriptionPreApproval.ELEMENT, SubscriptionPreApproval.NAMESPACE);
|
return connection.hasFeature(SubscriptionPreApproval.ELEMENT, SubscriptionPreApproval.NAMESPACE);
|
||||||
}
|
}
|
||||||
|
@ -570,16 +552,12 @@ public final class Roster extends Manager {
|
||||||
* @throws NoResponseException SmackException if there was no response from the server.
|
* @throws NoResponseException SmackException if there was no response from the server.
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* @throws IllegalStateException if connection is not logged in or logged in anonymously
|
|
||||||
*/
|
*/
|
||||||
public void removeEntry(RosterEntry entry) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void removeEntry(RosterEntry entry) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
final XMPPConnection connection = connection();
|
final XMPPConnection connection = connection();
|
||||||
if (!connection.isAuthenticated()) {
|
if (!connection.isAuthenticated()) {
|
||||||
throw new NotLoggedInException();
|
throw new NotLoggedInException();
|
||||||
}
|
}
|
||||||
if (connection.isAnonymous()) {
|
|
||||||
throw new IllegalStateException("Anonymous users can't have a roster.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only remove the entry if it's in the entry list.
|
// Only remove the entry if it's in the entry list.
|
||||||
// The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
|
// The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
|
||||||
|
|
Loading…
Reference in a new issue