Issue #2700 added contact request dialog

user is now prompted to accept contact request
added support for managing contacts that haven't accepted contact requests
contacts list shows new icon for contacts that haven't accepted contact requests


Former-commit-id: bd19366ada [formerly 8ad4c1674d2719a7781eb137669eb15212a1488c]
Former-commit-id: 6b1843f19a
This commit is contained in:
Brian Clements 2014-01-27 17:21:17 -06:00
parent 766af8b281
commit b4d930bcb9
17 changed files with 751 additions and 98 deletions

View file

@ -24,6 +24,7 @@ import java.util.Map;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder; import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
/** /**
* Chat server account management interface * Chat server account management interface
@ -45,6 +46,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionRespo
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Mar 16, 2012 jkorman Initial creation * Mar 16, 2012 jkorman Initial creation
* Jan 27, 2014 2700 bclement reworked responder methods
* added method to send presence without updating status
* *
* </pre> * </pre>
* *
@ -54,24 +57,25 @@ import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionRespo
public interface IAccountManager { public interface IAccountManager {
/**
* Disable automatically accepting subscribe requests
*/
public void disableAutoSubscribe();
/** /**
* @return true if automatically accepts subscribe requests * @return true if there is a request responder set to handle subscription
* requests and events. If there is not a responder set, the default
* action is to accept all requests.
*/ */
public boolean autoSubscribeEnabled(); public boolean isSubscriptionRequestResponderSet();
/** /**
* Set a responder to handle subscription requests and events (ie prompt
* user for authorization)
* *
* @param responder * @param responder
*/ */
public void setSubscriptionRequestResponder(ISubscriptionResponder responder); public void setSubscriptionRequestResponder(ISubscriptionResponder responder);
/** /**
* Removes the current subscription request responder. * Removes the current subscription request responder. The default action
* without a responder is to accept all requests.
*/ */
public void removeSubscriptionRequestResponder(); public void removeSubscriptionRequestResponder();
@ -121,4 +125,15 @@ public interface IAccountManager {
* @throws CollaborationException * @throws CollaborationException
*/ */
public void sendPresence(Presence presence) throws CollaborationException; public void sendPresence(Presence presence) throws CollaborationException;
/**
* Send presence packet directly to user. This does not affect the account's
* current presence.
*
* @param toId
* @param userPresence
* @throws CollaborationException
*/
public void sendPresence(UserId toId, Presence userPresence)
throws CollaborationException;
} }

View file

@ -19,9 +19,7 @@
**/ **/
package com.raytheon.uf.viz.collaboration.comm.identity.roster; package com.raytheon.uf.viz.collaboration.comm.identity.roster;
import org.jivesoftware.smack.packet.Presence; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
/** /**
* Interface for handling subscription invitation events from other users * Interface for handling subscription invitation events from other users
@ -33,6 +31,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Mar 16, 2012 jkorman Initial creation * Mar 16, 2012 jkorman Initial creation
* Jan 27, 2014 2700 bclement handle subscribe request returns a boolean
* all methods take user id instead of qualified id
* *
* </pre> * </pre>
* *
@ -43,22 +43,25 @@ import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
public interface ISubscriptionResponder { public interface ISubscriptionResponder {
/** /**
* Triggered when a contact requests a presence subscription
* *
* @param fromID * @param fromID
* @return The response that should be returned to the subscriber. * @return true if the subscribe request is accepted.
*/ */
public Presence.Type handleSubscribeRequest(IQualifiedID fromID); public boolean handleSubscribeRequest(UserId fromID);
/** /**
* Triggered when a contact subscribes to user
* *
* @param fromID * @param fromID
*/ */
public void handleSubscribed(IQualifiedID fromID); public void handleSubscribed(UserId fromID);
/** /**
* Triggered when a contact unsubscribes to user
* *
* @param fromID * @param fromID
*/ */
public void handleUnsubscribed(IQualifiedID fromID); public void handleUnsubscribed(UserId fromID);
} }

View file

@ -23,6 +23,7 @@ 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.RosterEntry;
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;
@ -35,8 +36,12 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager; import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession; import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IRosterChangeEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.event.RosterChangeType;
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder; import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent; import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter; import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
@ -58,6 +63,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Mar 16, 2012 jkorman Initial creation * Mar 16, 2012 jkorman Initial creation
* 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
* *
* </pre> * </pre>
* *
@ -69,7 +75,12 @@ public class AccountManager implements IAccountManager {
private final IUFStatusHandler log = UFStatus.getHandler(this.getClass()); private final IUFStatusHandler log = UFStatus.getHandler(this.getClass());
private PacketListener autoResponder = new PacketListener() { /**
* Listens for subscription events including subscription requests. If the
* subscription responder is null, the default action is to accept
* subscription requests.
*/
private PacketListener subscriptionEventListener = new PacketListener() {
@Override @Override
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
@ -82,17 +93,23 @@ public class AccountManager implements IAccountManager {
UserId fromId = IDConverter.convertFrom(pres.getFrom()); UserId fromId = IDConverter.convertFrom(pres.getFrom());
switch (type) { switch (type) {
case subscribe: case subscribe:
handleSubRequest(fromId); boolean accept = true;
if (responder != null) {
accept = responder.handleSubscribeRequest(fromId);
}
handleSubRequest(fromId, accept);
break; break;
case subscribed: case subscribed:
if (responder != null) { if (responder != null) {
responder.handleSubscribed(fromId); responder.handleSubscribed(fromId);
} }
handleSubscribed(fromId);
break; break;
case unsubscribed: case unsubscribed:
if (responder != null) { if (responder != null) {
responder.handleUnsubscribed(fromId); responder.handleUnsubscribed(fromId);
} }
handleUnsubscribed(fromId);
break; break;
default: default:
// do nothing // do nothing
@ -101,16 +118,58 @@ public class AccountManager implements IAccountManager {
} }
} }
private void handleSubRequest(UserId fromId) { /**
* notify UI that someone subscribed to user
*
* @param fromID
*/
private void handleSubscribed(UserId fromID) {
ContactsManager cm = sessionManager.getContactsManager();
RosterEntry entry = cm.getRosterEntry((UserId) fromID);
IRosterChangeEvent event = new RosterChangeEvent(
RosterChangeType.ADD, entry);
sessionManager.postEvent(event);
}
/**
* notify UI that someone unsubscribed to user
*
* @param fromID
*/
private void handleUnsubscribed(UserId fromID) {
ContactsManager cm = sessionManager.getContactsManager();
RosterEntry entry = cm.getRosterEntry((UserId) fromID);
if (entry == null) {
return;
}
IRosterChangeEvent event = new RosterChangeEvent(
RosterChangeType.DELETE, entry);
sessionManager.postEvent(event);
}
/**
* process subscription request
*
* @param fromId
*/
private void handleSubRequest(UserId fromId, boolean accept) {
Presence.Type subscribedType; Presence.Type subscribedType;
if (responder != null) {
subscribedType = responder.handleSubscribeRequest(fromId); if (accept) {
ContactsManager cm = sessionManager.getContactsManager();
RosterEntry entry = cm.getRosterEntry(fromId);
if (entry == null || ContactsManager.isBlocked(entry)) {
// we aren't subscribed to them, subscribe back
subscribedType = Presence.Type.subscribe;
} else {
// we are already subscribed, let them know
subscribedType = Presence.Type.subscribed;
}
} else { } else {
subscribedType = Presence.Type.subscribed; subscribedType = Presence.Type.unsubscribed;
} }
Presence presence = new Presence(subscribedType, null, 0, Presence presence = new Presence(subscribedType);
Presence.Mode.available);
try { try {
sendPresence(fromId, presence); sendPresence(fromId, presence);
} catch (CollaborationException e) { } catch (CollaborationException e) {
@ -135,20 +194,10 @@ public class AccountManager implements IAccountManager {
sessionManager = manager; sessionManager = manager;
smackManager = new org.jivesoftware.smack.AccountManager( smackManager = new org.jivesoftware.smack.AccountManager(
manager.getXmppConnection()); manager.getXmppConnection());
sessionManager.getXmppConnection().addPacketListener(autoResponder, sessionManager.getXmppConnection().addPacketListener(subscriptionEventListener,
new PacketTypeFilter(Presence.class)); new PacketTypeFilter(Presence.class));
} }
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager#
* disableAutoSubscribe()
*/
public void disableAutoSubscribe() {
responder = null;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -156,7 +205,7 @@ public class AccountManager implements IAccountManager {
* autoSubscribeEnabled() * autoSubscribeEnabled()
*/ */
@Override @Override
public boolean autoSubscribeEnabled() { public boolean isSubscriptionRequestResponderSet() {
return responder != null; return responder != null;
} }
@ -274,7 +323,6 @@ public class AccountManager implements IAccountManager {
throws CollaborationException { throws CollaborationException {
userPresence.setFrom(sessionManager.getUser().getFQName()); userPresence.setFrom(sessionManager.getUser().getFQName());
userPresence.setTo(toId.getNormalizedId()); userPresence.setTo(toId.getNormalizedId());
sessionManager.setPresence(userPresence);
sessionManager.getXmppConnection().sendPacket(userPresence); sessionManager.getXmppConnection().sendPacket(userPresence);
} }

View file

@ -34,6 +34,8 @@ 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.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.SharedGroupManager; import org.jivesoftware.smackx.SharedGroupManager;
@ -64,6 +66,8 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn
* Jan 24, 2014 2701 bclement removed roster manager * Jan 24, 2014 2701 bclement removed roster manager
* switched local groups to roster groups * switched local groups to roster groups
* added shared groups * added shared groups
* Jan 27, 2014 2700 bclement fixed ungrouped entries being out of date
* added utility methods for subscription status
* *
* </pre> * </pre>
* *
@ -567,7 +571,62 @@ public class ContactsManager {
* @return * @return
*/ */
public Collection<RosterEntry> getNonGroupedContacts() { public Collection<RosterEntry> getNonGroupedContacts() {
return getRoster().getUnfiledEntries(); Collection<RosterEntry> unfiled = getRoster().getUnfiledEntries();
List<RosterEntry> rval = new ArrayList<RosterEntry>(unfiled.size());
for (RosterEntry entry : unfiled) {
if (isBlocked(entry)) {
// check to see if we are really blocked
entry = update(entry);
}
if (hasInteraction(entry)) {
rval.add(entry);
}
}
return rval;
}
/**
* Get updated entry from roster. This is a work around for a smack
* limitation where unfiled entry objects are not updated when the roster
* entry objects are.
*
* @param entry
* @return
*/
public RosterEntry update(RosterEntry entry) {
RosterEntry rval = searchRoster(entry.getUser());
return rval != null ? rval : entry;
}
/**
* @param entry
* @return true if we are blocked from seeing updates from user in entry
*/
public static boolean isBlocked(RosterEntry entry) {
ItemType type = entry.getType();
return type != null
&& (type.equals(ItemType.none) || type.equals(ItemType.from));
}
/**
* Test for interaction between this user and entry. Returns true if either
* has a subscription to the other or there is a pending subscription
* request.
*
* @param entry
* @return
*/
public static boolean hasInteraction(RosterEntry entry) {
ItemType type = entry.getType();
boolean rval = true;
if (type != null) {
if (type.equals(ItemType.none)) {
ItemStatus status = entry.getStatus();
rval = status != null
&& status.equals(ItemStatus.SUBSCRIPTION_PENDING);
}
}
return rval;
} }
/** /**

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

View file

@ -26,12 +26,17 @@ import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode; import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type; import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation; import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
/** /**
@ -44,6 +49,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jul 24, 2012 bsteffen Initial creation * Jul 24, 2012 bsteffen Initial creation
* Jan 27, 2014 2700 bclement added roster entry support
* *
* </pre> * </pre>
* *
@ -57,10 +63,14 @@ public abstract class AbstractUserLabelProvider extends ColumnLabelProvider {
@Override @Override
public String getText(Object element) { public String getText(Object element) {
if (!(element instanceof UserId)) { UserId user;
if (element instanceof UserId) {
user = (UserId) element;
} else if ( element instanceof RosterEntry){
user = IDConverter.convertFrom((RosterEntry) element);
} else {
return null; return null;
} }
UserId user = (UserId) element;
StringBuilder name = new StringBuilder(); StringBuilder name = new StringBuilder();
name.append(getDisplayName(user)); name.append(getDisplayName(user));
Presence presence = getPresence(user); Presence presence = getPresence(user);
@ -83,10 +93,14 @@ public abstract class AbstractUserLabelProvider extends ColumnLabelProvider {
@Override @Override
public Image getImage(Object element) { public Image getImage(Object element) {
if (!(element instanceof UserId)) { UserId user;
if (element instanceof UserId) {
user = (UserId) element;
} else if (element instanceof RosterEntry) {
user = IDConverter.convertFrom((RosterEntry) element);
} else {
return null; return null;
} }
UserId user = (UserId) element;
Presence presence = getPresence(user); Presence presence = getPresence(user);
String key = ""; String key = "";
if (presence != null && presence.getType() == Type.available) { if (presence != null && presence.getType() == Type.available) {
@ -98,6 +112,11 @@ public abstract class AbstractUserLabelProvider extends ColumnLabelProvider {
} else { } else {
key = "contact_disabled"; key = "contact_disabled";
} }
if (element instanceof RosterEntry) {
if (ContactsManager.isBlocked((RosterEntry) element)) {
key = "blocked";
}
}
if (imageMap.get(key) == null && !key.equals("")) { if (imageMap.get(key) == null && !key.equals("")) {
imageMap.put(key, CollaborationUtils.getNodeImage(key)); imageMap.put(key, CollaborationUtils.getNodeImage(key));
} }
@ -106,16 +125,20 @@ public abstract class AbstractUserLabelProvider extends ColumnLabelProvider {
@Override @Override
public String getToolTipText(Object element) { public String getToolTipText(Object element) {
if (!(element instanceof UserId)) { UserId user;
if (element instanceof UserId) {
user = (UserId) element;
} else if (element instanceof RosterEntry) {
user = IDConverter.convertFrom((RosterEntry) element);
} else {
return null; return null;
} }
UserId user = (UserId) element;
Presence presence = getPresence(user); Presence presence = getPresence(user);
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
text.append("Name: ").append(getDisplayName(user)).append("\n"); text.append("Name: ").append(getDisplayName(user)).append("\n");
text.append("Status: "); text.append("Status: ");
if (presence == null || presence.getType() != Type.available) { if (presence == null || presence.getType() != Type.available) {
text.append("Offline\n"); text.append("Offline \n");
} else { } else {
text.append(CollaborationUtils.formatMode(presence.getMode())) text.append(CollaborationUtils.formatMode(presence.getMode()))
.append("\n"); .append("\n");
@ -130,6 +153,17 @@ public abstract class AbstractUserLabelProvider extends ColumnLabelProvider {
} }
} }
} }
if (element instanceof RosterEntry) {
RosterEntry entry = (RosterEntry) element;
ItemType type = entry.getType();
if (type != null) {
text.append("Subscription: ").append(type).append("\n");
}
ItemStatus status = entry.getStatus();
if (status != null) {
text.append(status).append(" pending\n");
}
}
// delete trailing newline // delete trailing newline
text.deleteCharAt(text.length() - 1); text.deleteCharAt(text.length() - 1);
return text.toString(); return text.toString();

View file

@ -111,6 +111,7 @@ import com.raytheon.uf.viz.collaboration.ui.actions.LogoutAction;
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction; import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
import com.raytheon.uf.viz.collaboration.ui.actions.RemoveFromGroupAction; import com.raytheon.uf.viz.collaboration.ui.actions.RemoveFromGroupAction;
import com.raytheon.uf.viz.collaboration.ui.actions.RemoveFromRosterAction; import com.raytheon.uf.viz.collaboration.ui.actions.RemoveFromRosterAction;
import com.raytheon.uf.viz.collaboration.ui.actions.SendSubReqAction;
import com.raytheon.uf.viz.collaboration.ui.actions.ShowVenueAction; import com.raytheon.uf.viz.collaboration.ui.actions.ShowVenueAction;
import com.raytheon.uf.viz.collaboration.ui.actions.UserSearchAction; import com.raytheon.uf.viz.collaboration.ui.actions.UserSearchAction;
import com.raytheon.uf.viz.collaboration.ui.data.AlertWordWrapper; import com.raytheon.uf.viz.collaboration.ui.data.AlertWordWrapper;
@ -138,6 +139,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
* Dec 20, 2013 2563 bclement fixed support for ungrouped roster items * Dec 20, 2013 2563 bclement fixed support for ungrouped roster items
* Jan 24, 2014 2701 bclement removed local groups, added shared groups * Jan 24, 2014 2701 bclement removed local groups, added shared groups
* removed option to create empty group * removed option to create empty group
* Jan 27, 2014 2700 bclement fixed context menu for roster entries
* *
* </pre> * </pre>
* *
@ -391,18 +393,33 @@ public class CollaborationGroupView extends CaveFloatingView implements
manager.add(new ArchiveViewerAction((IVenueSession) o)); manager.add(new ArchiveViewerAction((IVenueSession) o));
return; return;
} else if (o instanceof RosterEntry) { } else if (o instanceof RosterEntry) {
// roster entries that are not in a group
RosterEntry entry = (RosterEntry) o; RosterEntry entry = (RosterEntry) o;
UserId user = IDConverter.convertFrom(entry); UserId user = IDConverter.convertFrom(entry);
addOnlineMenuOptions(manager, selection, user); addOnlineMenuOptions(manager, selection, user);
addAliasAction(manager, selection, user); addAliasAction(manager, selection, user);
manager.add(new ArchiveViewerAction(user)); manager.add(new ArchiveViewerAction(user));
manager.add(new AddToGroupAction(entry)); manager.add(new AddToGroupAction(getSelectedUsers()));
manager.add(new RemoveFromRosterAction(entry)); String groupName = null;
Object group = selection.getPaths()[0].getFirstSegment();
if (group instanceof RosterGroup) {
groupName = ((RosterGroup) group).getName();
manager.add(new RemoveFromGroupAction(groupName,
getSelectedUsers()));
} else if (!(group instanceof SharedGroup)) {
manager.add(new RemoveFromRosterAction(entry));
}
if (ContactsManager.isBlocked(entry)) {
manager.add(new SendSubReqAction(entry));
}
} else if (o instanceof UserId) { } else if (o instanceof UserId) {
// the user, both the logged in user as well as entries in groups // the user
UserId user = (UserId) o; UserId user = (UserId) o;
fillContextMenu(manager, selection, user); CollaborationConnection connection = CollaborationConnection
.getConnection();
UserId me = connection.getUser();
if (me.isSameUser(user)) {
createMenu(manager);
}
} else if (o instanceof RosterGroup || o instanceof SharedGroup) { } else if (o instanceof RosterGroup || o instanceof SharedGroup) {
manager.add(createSessionAction); manager.add(createSessionAction);
if (o instanceof RosterGroup) { if (o instanceof RosterGroup) {
@ -415,36 +432,6 @@ public class CollaborationGroupView extends CaveFloatingView implements
} }
} }
/**
* Populate menu for roster entries. Checks for current user to create
* appropriate menu.
*
* @param manager
* @param selection
* @param user
*/
private void fillContextMenu(IMenuManager manager, TreeSelection selection,
UserId user) {
CollaborationConnection connection = CollaborationConnection
.getConnection();
UserId me = connection.getUser();
if (me.isSameUser(user)) {
createMenu(manager);
return;
}
addOnlineMenuOptions(manager, selection, user);
addAliasAction(manager, selection, user);
manager.add(new ArchiveViewerAction(user));
manager.add(new AddToGroupAction(getSelectedUsers()));
String groupName = null;
Object group = selection.getPaths()[0].getFirstSegment();
if (group instanceof RosterGroup) {
groupName = ((RosterGroup) group).getName();
manager.add(new RemoveFromGroupAction(groupName, getSelectedUsers()));
}
}
/** /**
* Add interaction menu options for contact if they are online * Add interaction menu options for contact if they are online
* *
@ -905,6 +892,7 @@ public class CollaborationGroupView extends CaveFloatingView implements
@Override @Override
public void groupDeleted(RosterGroup group) { public void groupDeleted(RosterGroup group) {
refreshUsersTreeViewerAsync(group);
refreshUsersTreeViewerAsync(usersTreeViewer.getInput()); refreshUsersTreeViewerAsync(usersTreeViewer.getInput());
} }

View file

@ -50,6 +50,7 @@ import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr; import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction; import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut; import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut;
import com.raytheon.uf.viz.collaboration.ui.prefs.AutoSubscribePropertyListener;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants; import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView; import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
@ -69,7 +70,8 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 8, 2012 njensen Initial creation * Jun 8, 2012 njensen Initial creation
* Dec 18, 2013 2562 bclement fixed venue invite * Dec 18, 2013 2562 bclement fixed venue invite
* Jan 14, 2014 2630 bclement added away timeout * Jan 14, 2014 2630 bclement added away timeout
* Jan 27, 2014 2700 bclement added auto subscribe property listener
* *
* </pre> * </pre>
* *
@ -89,7 +91,11 @@ public class ConnectionSubscriber {
private final AwayTimeOut awayTimeOut = new AwayTimeOut(); private final AwayTimeOut awayTimeOut = new AwayTimeOut();
private ConnectionSubscriber() { private ConnectionSubscriber() {
Activator
.getDefault()
.getPreferenceStore()
.addPropertyChangeListener(
AutoSubscribePropertyListener.getInstance());
} }
/** /**
@ -121,6 +127,9 @@ public class ConnectionSubscriber {
private void setup(final CollaborationConnection connection) { private void setup(final CollaborationConnection connection) {
if (connection != null) { if (connection != null) {
AutoSubscribePropertyListener autoSub = AutoSubscribePropertyListener
.getInstance();
autoSub.initialize(connection);
// Register handlers and events for the new sessionManager. // Register handlers and events for the new sessionManager.
connection.registerEventHandler(this); connection.registerEventHandler(this);
try { try {
@ -164,6 +173,9 @@ public class ConnectionSubscriber {
"Error unregistering peer to peer handler", e); "Error unregistering peer to peer handler", e);
} }
connection.unregisterEventHandler(this); connection.unregisterEventHandler(this);
AutoSubscribePropertyListener autoSub = AutoSubscribePropertyListener
.getInstance();
autoSub.close();
} }
PlatformUI.getWorkbench().removeWorkbenchListener(wbListener); PlatformUI.getWorkbench().removeWorkbenchListener(wbListener);
} }

View file

@ -64,6 +64,7 @@ import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
* Jun 12, 2012 mnash Initial creation * Jun 12, 2012 mnash Initial creation
* Jan 08, 2014 2563 bclement duplicate code elimination * Jan 08, 2014 2563 bclement duplicate code elimination
* added methods to partially modify user config * added methods to partially modify user config
* Jan 27, 2014 2700 bclement fixed null list from jaxb object
* *
* </pre> * </pre>
* *
@ -470,10 +471,12 @@ public class SiteConfigurationManager {
*/ */
public static List<String> getSubscribeList(String site) { public static List<String> getSubscribeList(String site) {
List<String> subscribed = new ArrayList<String>(); List<String> subscribed = new ArrayList<String>();
for (SiteConfig config : instance.getConfig()) { if (instance.getConfig() != null) {
if (config.getSite().equals(site)) { for (SiteConfig config : instance.getConfig()) {
subscribed = Arrays.asList(config.getSubscribedSites()); if (config.getSite().equals(site)) {
break; subscribed = Arrays.asList(config.getSubscribedSites());
break;
}
} }
} }
return subscribed; return subscribed;
@ -491,7 +494,7 @@ public class SiteConfigurationManager {
if (userInstance == null) { if (userInstance == null) {
readUserSiteConfigInformation(); readUserSiteConfigInformation();
} }
if (userInstance != null) { if (userInstance != null && userInstance.getConfig() != null) {
for (SiteConfig config : userInstance.getConfig()) { for (SiteConfig config : userInstance.getConfig()) {
if (config.getSubscribedSites() != null) { if (config.getSubscribedSites() != null) {
subscribed = new ArrayList<String>(); subscribed = new ArrayList<String>();

View file

@ -0,0 +1,183 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.jivesoftware.smack.RosterGroup;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
/**
* Dialog to respond to a chat subscription request
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 27, 2014 2700 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class SubRequestDialog extends Dialog {
private final String title;
private final String message;
private final UserId userid;
private Combo groupCombo;
/**
* @param parentShell
*/
public SubRequestDialog(Shell parentShell, String title, String message,
UserId userid) {
super(parentShell);
this.title = title;
this.message = message;
this.userid = userid;
}
/**
* @param parentShell
*/
public SubRequestDialog(IShellProvider parentShell, String title,
String message, UserId userid) {
super(parentShell);
this.title = title;
this.message = message;
this.userid = userid;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
*/
@Override
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
int count = groupCombo.getItemCount();
int index = groupCombo.getSelectionIndex();
String group = null;
if ( index == count - 1){
// new group
CreateGroupDialog dialog = new CreateGroupDialog(Display
.getCurrent().getActiveShell());
dialog.open();
group = dialog.getNewGroup();
} else if ( index >= 0){
group = groupCombo.getItem(index);
}
CollaborationConnection connection = CollaborationConnection.getConnection();
if ( group != null && connection != null){
ContactsManager cm = connection.getContactsManager();
cm.addToGroup(group, userid);
}
}
super.buttonPressed(buttonId);
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
new Label(container, SWT.NONE).setText(message);
Composite groupComposite = new Composite(container, SWT.NONE);
groupComposite.setLayout(new GridLayout(2, false));
groupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.DEFAULT,
true, false));
new Label(groupComposite, SWT.NONE).setText("Group: ");
groupCombo = new Combo(groupComposite, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN);
groupCombo.setItems(getGroupNames());
return container;
}
/**
* @return list of existing group names
*/
private String[] getGroupNames() {
CollaborationConnection connection = CollaborationConnection
.getConnection();
if (connection == null) {
return new String[0];
}
Collection<RosterGroup> groups = connection.getContactsManager()
.getGroups();
String[] rval = new String[groups.size() + 1];
Iterator<RosterGroup> iter = groups.iterator();
int i = 0;
for (; iter.hasNext(); ++i) {
rval[i] = iter.next().getName();
}
rval[i] = "New Group...";
return rval;
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(title);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
* .swt.widgets.Composite)
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Allow", true);
createButton(parent, IDialogConstants.CANCEL_ID, "Deny", false);
}
}

View file

@ -32,7 +32,7 @@ import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup; import org.jivesoftware.smack.RosterGroup;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter; import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.SharedGroup; import com.raytheon.uf.viz.collaboration.comm.provider.user.SharedGroup;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.ui.data.CollaborationGroupContainer; import com.raytheon.uf.viz.collaboration.ui.data.CollaborationGroupContainer;
@ -50,6 +50,7 @@ import com.raytheon.uf.viz.collaboration.ui.data.SessionGroupContainer;
* Mar 1, 2012 rferrel Initial creation * Mar 1, 2012 rferrel Initial creation
* Dec 6, 2013 2561 bclement removed ECF * Dec 6, 2013 2561 bclement removed ECF
* Jan 24, 2014 2701 bclement removed local groups, added shared groups * Jan 24, 2014 2701 bclement removed local groups, added shared groups
* Jan 27, 2014 2700 bclement added support roster entries
* *
* </pre> * </pre>
* *
@ -135,12 +136,14 @@ public class UsersTreeContentProvider implements ITreeContentProvider {
* @return * @return
*/ */
private Object[] getRosterChildren(Collection<RosterEntry> entries) { private Object[] getRosterChildren(Collection<RosterEntry> entries) {
List<UserId> result = new ArrayList<UserId>(); List<RosterEntry> result = new ArrayList<RosterEntry>();
UserId localUser = CollaborationConnection.getConnection().getUser(); CollaborationConnection connection = CollaborationConnection.getConnection();
UserId localUser = connection.getUser();
for (RosterEntry entry : entries) { for (RosterEntry entry : entries) {
String user = entry.getUser(); String user = entry.getUser();
if (!localUser.isSameUser(user)) { if (!localUser.isSameUser(user)
result.add(IDConverter.convertFrom(entry)); && ContactsManager.hasInteraction(entry)) {
result.add(entry);
} }
} }
return result.toArray(); return result.toArray();

View file

@ -42,7 +42,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo; import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.SharedGroup; import com.raytheon.uf.viz.collaboration.comm.provider.user.SharedGroup;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.ui.data.SessionGroupContainer; import com.raytheon.uf.viz.collaboration.ui.data.SessionGroupContainer;
@ -60,6 +59,7 @@ import com.raytheon.uf.viz.collaboration.ui.data.SessionGroupContainer;
* Dec 6, 2013 2561 bclement removed ECF * Dec 6, 2013 2561 bclement removed ECF
* Dec 20, 2013 2563 bclement fixed support for ungrouped roster items * Dec 20, 2013 2563 bclement fixed support for ungrouped roster items
* Jan 24, 2014 2701 bclement removed local groups, added shared groups * Jan 24, 2014 2701 bclement removed local groups, added shared groups
* Jan 27, 2014 2700 bclement pass roster entries directly to userLabelProvider
* *
* </pre> * </pre>
* *
@ -103,8 +103,7 @@ public class UsersTreeLabelProvider extends ColumnLabelProvider {
if (element instanceof UserId) { if (element instanceof UserId) {
return userLabelProvider.getImage(element); return userLabelProvider.getImage(element);
} else if (element instanceof RosterEntry) { } else if (element instanceof RosterEntry) {
return userLabelProvider.getImage(IDConverter return userLabelProvider.getImage((RosterEntry) element);
.convertFrom((RosterEntry) element));
} else if (element instanceof RosterGroup) { } else if (element instanceof RosterGroup) {
key = "roster_group"; key = "roster_group";
} else if (element instanceof SharedGroup) { } else if (element instanceof SharedGroup) {
@ -128,8 +127,7 @@ public class UsersTreeLabelProvider extends ColumnLabelProvider {
} else if (element instanceof SharedGroup) { } else if (element instanceof SharedGroup) {
return ((SharedGroup) element).getName(); return ((SharedGroup) element).getName();
} else if (element instanceof RosterEntry) { } else if (element instanceof RosterEntry) {
return userLabelProvider.getText(IDConverter return userLabelProvider.getText((RosterEntry) element);
.convertFrom((RosterEntry) element));
} else if (element instanceof SessionGroupContainer) { } else if (element instanceof SessionGroupContainer) {
return "Active Sessions"; return "Active Sessions";
} else if (element instanceof UserId) { } else if (element instanceof UserId) {
@ -185,8 +183,7 @@ public class UsersTreeLabelProvider extends ColumnLabelProvider {
if (element instanceof UserId) { if (element instanceof UserId) {
return userLabelProvider.getToolTipText(element); return userLabelProvider.getToolTipText(element);
} else if (element instanceof RosterEntry) { } else if (element instanceof RosterEntry) {
return userLabelProvider.getToolTipText(IDConverter return userLabelProvider.getToolTipText((RosterEntry) element);
.convertFrom((RosterEntry) element));
} }
// builds the tooltip text for the session group // builds the tooltip text for the session group
// portion of the view // portion of the view

View file

@ -0,0 +1,81 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.actions;
import org.eclipse.jface.action.Action;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.ui.Activator;
/**
* Action to send a subscription request to a user
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 24, 2014 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class SendSubReqAction extends Action {
private final RosterEntry entry;
/**
* @param entry
* roster entry to request a subscription to
*/
public SendSubReqAction(RosterEntry entry) {
super("Send Contact Request");
this.entry = entry;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
CollaborationConnection connection = CollaborationConnection.getConnection();
IAccountManager manager = connection.getAccountManager();
try {
manager.sendPresence(IDConverter.convertFrom(entry), new Presence(
Type.subscribe));
} catch (CollaborationException e) {
Activator.statusHandler.error(
"Unable to send subscription request", e);
}
}
}

View file

@ -0,0 +1,215 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.prefs;
import java.util.List;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jivesoftware.smack.XMPPException;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserSearch;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.SubRequestDialog;
import com.raytheon.uf.viz.core.VizApp;
/**
* Listens to collaboration preferences and alters the subscription request
* handler as appropriate.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 24, 2014 2700 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class AutoSubscribePropertyListener implements IPropertyChangeListener {
private static final IUFStatusHandler log = UFStatus
.getHandler(AutoSubscribePropertyListener.class);
private static AutoSubscribePropertyListener instance;
private static final Object INSTANCE_MUTEX = new Object();
public static AutoSubscribePropertyListener getInstance() {
synchronized (INSTANCE_MUTEX) {
if (instance == null) {
instance = new AutoSubscribePropertyListener();
}
}
return instance;
}
private CollaborationConnection connection;
private IAccountManager accountManager;
private AutoSubscribePropertyListener() {
}
/**
* Initialize auto subscribe state after login
*
* @param connection
*/
public synchronized void initialize(CollaborationConnection connection) {
this.connection = connection;
this.accountManager = connection.getAccountManager();
updateManager(isAutoInPrefs());
}
/**
* Clean up auto subscribe state after logout
*/
public synchronized void close() {
this.accountManager = null;
this.connection = null;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
* .jface.util.PropertyChangeEvent)
*/
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(
CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE)
&& accountManager != null) {
updateManager((Boolean) event.getNewValue());
}
}
/**
* @return true if preferences have auto accept enabled
*/
private boolean isAutoInPrefs() {
IPersistentPreferenceStore prefs = Activator.getDefault()
.getPreferenceStore();
return prefs.getBoolean(CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE);
}
/**
* Update auto subscribe state in account manager
*
* @param auto
*/
private void updateManager(boolean auto) {
// manager auto accepts by default if responder is not set
boolean accountManagerAutoAccepts = !accountManager
.isSubscriptionRequestResponderSet();
// update if the settings don't match
if (auto != accountManagerAutoAccepts) {
if (auto) {
accountManager.removeSubscriptionRequestResponder();
} else {
accountManager.setSubscriptionRequestResponder(newResponder());
}
}
}
/**
* Create responder to handle subscription requests
*
* @return
*/
private ISubscriptionResponder newResponder() {
return new ISubscriptionResponder() {
private final UserSearch search = connection.createSearch();
@Override
public void handleUnsubscribed(UserId fromID) {
}
@Override
public void handleSubscribed(UserId fromID) {
}
@Override
public boolean handleSubscribeRequest(final UserId fromID) {
String displayName = getDisplayName(fromID);
StringBuilder builder = new StringBuilder();
builder.append(fromID.getFQName());
if ( displayName != null){
builder.append(" (").append(displayName).append(")");
}
builder.append(" wants to add you to his or her contacts list.");
final String msg = builder.toString();
final boolean[] rval = new boolean[1];
VizApp.runSync(new Runnable() {
@Override
public void run() {
Shell shell = new Shell(Display.getCurrent());
SubRequestDialog dlg = new SubRequestDialog(shell,
"Authorize Collaboration Contact", msg, fromID);
int index = dlg.open();
rval[0] = index == Window.OK;
}
});
return rval[0];
}
/**
* Get display name for user from server
*
* @param fromID
* @return null if none found
*/
private String getDisplayName(UserId fromID) {
String rval = null;
try {
List<UserId> users = search.byUsername(fromID.getName());
if ( users != null && !users.isEmpty()){
UserId user = users.get(0);
return user.getAlias();
}
} catch (XMPPException e) {
log.error("Unable to get display name for user: " + fromID,
e);
}
return rval;
}
};
}
}

View file

@ -30,6 +30,7 @@ package com.raytheon.uf.viz.collaboration.ui.prefs;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 24, 2012 njensen Initial creation * Apr 24, 2012 njensen Initial creation
* Jan 14, 2014 2630 bclement added away on idle constants * Jan 14, 2014 2630 bclement added away on idle constants
* Jan 27, 2014 2700 bclement added auto accept subscribe
* *
* </pre> * </pre>
* *
@ -52,6 +53,8 @@ public class CollabPrefConstants {
public static final String AWAY_TIMEOUT = "awayTimeOut"; public static final String AWAY_TIMEOUT = "awayTimeOut";
public static final String AUTO_ACCEPT_SUBSCRIBE = "autoAcceptSubscribe";
public static final int AWAY_TIMEOUT_DEFAULT = 10; // ten minutes public static final int AWAY_TIMEOUT_DEFAULT = 10; // ten minutes
public class HttpCollaborationConfiguration { public class HttpCollaborationConfiguration {

View file

@ -36,6 +36,7 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 24, 2012 njensen Initial creation * Apr 24, 2012 njensen Initial creation
* Jan 14, 2014 2630 bclement added away on idle defaults * Jan 14, 2014 2630 bclement added away on idle defaults
* Jan 27, 2014 2700 bclement added auto accept subscribe
* *
* </pre> * </pre>
* *
@ -67,6 +68,7 @@ public class CollabPrefInitializer extends AbstractPreferenceInitializer {
store.setDefault(CollabPrefConstants.AWAY_ON_IDLE, true); store.setDefault(CollabPrefConstants.AWAY_ON_IDLE, true);
store.setDefault(CollabPrefConstants.AWAY_TIMEOUT, store.setDefault(CollabPrefConstants.AWAY_TIMEOUT,
CollabPrefConstants.AWAY_TIMEOUT_DEFAULT); CollabPrefConstants.AWAY_TIMEOUT_DEFAULT);
store.setDefault(CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE, false);
} }
} }

View file

@ -40,6 +40,7 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 27, 2012 mnash Initial creation * Apr 27, 2012 mnash Initial creation
* Jan 14, 2014 2630 bclement added away on idle * Jan 14, 2014 2630 bclement added away on idle
* Jan 27, 2014 2700 bclement added auto accept subscribe
* *
* </pre> * </pre>
* *
@ -90,6 +91,12 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage
CollabPrefConstants.AWAY_TIMEOUT, CollabPrefConstants.AWAY_TIMEOUT,
"Minutes Before Becoming Idle:", getFieldEditorParent()); "Minutes Before Becoming Idle:", getFieldEditorParent());
this.addField(awayTimeOut); this.addField(awayTimeOut);
FieldEditor autoSubscribe = new BooleanFieldEditor(
CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE,
"Automatically Accept Contact Requests",
getFieldEditorParent());
this.addField(autoSubscribe);
} }
/* /*