Issue #2700 fixed subscribe back after contact request accept

we were sending the wrong presence type when accepting request
pidgin handled it, but it wasn't to the spec
fixed by adding contact to roster if not already a friend
request authorization dialog doesn't prompt for group if they are already in one


Former-commit-id: dc59e8fa2d [formerly 7176bf59b8] [formerly b88eaeb73e] [formerly dc59e8fa2d [formerly 7176bf59b8] [formerly b88eaeb73e] [formerly b0402be1d3 [formerly b88eaeb73e [formerly 4d860337ea821975b6ddb4846f102199347a4dcc]]]]
Former-commit-id: b0402be1d3
Former-commit-id: 7678703ae0 [formerly 9210aae10a] [formerly 49b91dbbac727f3af22f35a351ce544d8ce31b75 [formerly b651ada4b3]]
Former-commit-id: e467e72241d8923b566978180702bf8b00148966 [formerly 7e1425c419]
Former-commit-id: f2a97eb00e
This commit is contained in:
Brian Clements 2014-01-31 13:07:47 -06:00
parent b9a7590177
commit fb03f7b570
3 changed files with 65 additions and 14 deletions

View file

@ -23,7 +23,9 @@ import java.util.Arrays;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster.SubscriptionMode;
import org.jivesoftware.smack.RosterEntry; import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
@ -64,6 +66,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Dec 6, 2013 2561 bclement removed ECF * Dec 6, 2013 2561 bclement removed ECF
* Jan 07, 2013 2563 bclement fixed id parsing in auto responder * Jan 07, 2013 2563 bclement fixed id parsing in auto responder
* Jan 27, 2014 2700 bclement changes to subscription request responders * Jan 27, 2014 2700 bclement changes to subscription request responders
* Jan 31, 2014 2700 bclement fixed subscribe back after accepting subscription
* *
* </pre> * </pre>
* *
@ -154,16 +157,13 @@ public class AccountManager implements IAccountManager {
*/ */
private void handleSubRequest(UserId fromId, boolean accept) { private void handleSubRequest(UserId fromId, boolean accept) {
Presence.Type subscribedType; Presence.Type subscribedType;
if (accept) {
ContactsManager cm = sessionManager.getContactsManager(); ContactsManager cm = sessionManager.getContactsManager();
RosterEntry entry = cm.getRosterEntry(fromId); boolean addToRoster = false;
if (entry == null || ContactsManager.isBlocked(entry)) { if (accept) {
// we aren't subscribed to them, subscribe back
subscribedType = Presence.Type.subscribe;
} else {
// we are already subscribed, let them know
subscribedType = Presence.Type.subscribed; subscribedType = Presence.Type.subscribed;
RosterEntry entry = cm.getRosterEntry(fromId);
if (entry == null) {
addToRoster = true;
} }
} else { } else {
subscribedType = Presence.Type.unsubscribed; subscribedType = Presence.Type.unsubscribed;
@ -172,6 +172,9 @@ public class AccountManager implements IAccountManager {
Presence presence = new Presence(subscribedType); Presence presence = new Presence(subscribedType);
try { try {
sendPresence(fromId, presence); sendPresence(fromId, presence);
if (addToRoster) {
cm.addToRoster(fromId);
}
} catch (CollaborationException e) { } catch (CollaborationException e) {
AccountManager.this.log.error("Unable to send presence", e); AccountManager.this.log.error("Unable to send presence", e);
} }
@ -192,8 +195,10 @@ public class AccountManager implements IAccountManager {
AccountManager( AccountManager(
CollaborationConnection manager) { CollaborationConnection manager) {
sessionManager = manager; sessionManager = manager;
XMPPConnection xmppConnection = manager.getXmppConnection();
smackManager = new org.jivesoftware.smack.AccountManager( smackManager = new org.jivesoftware.smack.AccountManager(
manager.getXmppConnection()); xmppConnection);
xmppConnection.getRoster().setSubscriptionMode(SubscriptionMode.manual);
sessionManager.getXmppConnection().addPacketListener(subscriptionEventListener, sessionManager.getXmppConnection().addPacketListener(subscriptionEventListener,
new PacketTypeFilter(Presence.class)); new PacketTypeFilter(Presence.class));
} }

View file

@ -34,6 +34,7 @@ import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.RosterPacket.ItemStatus; import org.jivesoftware.smack.packet.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType; import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
@ -68,6 +69,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn
* Jan 27, 2014 2700 bclement fixed ungrouped entries being out of date * Jan 27, 2014 2700 bclement fixed ungrouped entries being out of date
* added utility methods for subscription status * added utility methods for subscription status
* Jan 30, 2014 2698 bclement removed unneeded nickname changed event * Jan 30, 2014 2698 bclement removed unneeded nickname changed event
* Jan 31, 2014 2700 bclement added addToRoster, fixed add to group when in roster, but blocked
* *
* </pre> * </pre>
* *
@ -182,9 +184,20 @@ public class ContactsManager {
String id = user.getNormalizedId(); String id = user.getNormalizedId();
RosterEntry entry = group.getEntry(id); RosterEntry entry = group.getEntry(id);
if (entry != null) { if (entry != null) {
if (isBlocked(entry)) {
// entry is in roster, but we aren't subscribed. Request a
// subscription.
try {
connection.getAccountManager().sendPresence(user,
new Presence(Type.subscribe));
} catch (CollaborationException e) {
statusHandler.error("Problem subscribing to user", e);
}
} else {
statusHandler statusHandler
.debug("Attempted to add user to group it was already in: " .debug("Attempted to add user to group it was already in: "
+ id + " in " + groupName); + id + " in " + groupName);
}
return; return;
} }
try { try {
@ -225,6 +238,31 @@ public class ContactsManager {
} }
} }
/**
* Ensure that user is in roster.
*
* @param user
* @throws CollaborationException
*/
public void addToRoster(UserId user) throws CollaborationException {
RosterEntry entry = getRosterEntry(user);
if (entry == null) {
// we dont have user as a contact at all
// ensure that the user object is up-to-date
user = findUser(user.getName());
String alias = user.getAlias();
if (StringUtils.isBlank(alias)) {
alias = user.getName();
}
try {
getRoster().createEntry(user.getFQName(), alias, new String[0]);
} catch (XMPPException e) {
throw new CollaborationException(
"Unable to add user to roster: " + user, e);
}
}
}
/** /**
* Remove user from group. * Remove user from group.
* *
@ -380,7 +418,7 @@ public class ContactsManager {
public Collection<RosterGroup> getGroups(UserId user) { public Collection<RosterGroup> getGroups(UserId user) {
RosterEntry entry = getRoster().getEntry(user.getNormalizedId()); RosterEntry entry = getRoster().getEntry(user.getNormalizedId());
if (entry == null) { if (entry == null) {
statusHandler.error("Requested groups for user not in roster: " statusHandler.debug("Requested groups for user not in roster: "
+ user); + user);
return Collections.emptyList(); return Collections.emptyList();
} }

View file

@ -50,6 +50,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jan 27, 2014 2700 bclement Initial creation * Jan 27, 2014 2700 bclement Initial creation
* Jan 31, 2014 2700 bclement don't prompt for group if user is already in one
* *
* </pre> * </pre>
* *
@ -129,10 +130,17 @@ public class SubRequestDialog extends Dialog {
groupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.DEFAULT, groupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.DEFAULT,
true, false)); true, false));
new Label(groupComposite, SWT.NONE).setText("Group: "); new Label(groupComposite, SWT.NONE).setText("Group: ");
groupCombo = new Combo(groupComposite, SWT.BORDER | SWT.READ_ONLY groupCombo = new Combo(groupComposite, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN); | SWT.DROP_DOWN);
groupCombo.setItems(getGroupNames()); groupCombo.setItems(getGroupNames());
CollaborationConnection conn = CollaborationConnection.getConnection();
Collection<RosterGroup> groups = conn.getContactsManager().getGroups(
userid);
if (!groups.isEmpty()) {
// we already have this user in a group in our roster, no need to
// prompt
groupComposite.setVisible(false);
}
return container; return container;
} }