Merge "Omaha #3281 peer2peer chat view improvements" into omaha_14.4.1

Former-commit-id: 61640d5c22 [formerly 61640d5c22 [formerly 449a40d7981b0814f9cc7feb62f52b2259e83e5f]]
Former-commit-id: 172f18a5b1
Former-commit-id: 48995ed5ca
This commit is contained in:
Nate Jensen 2014-06-23 12:12:03 -05:00 committed by Gerrit Code Review
commit 217a0999d0
9 changed files with 190 additions and 42 deletions

View file

@ -31,6 +31,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 27, 2012 jkorman Initial creation
* Jun 20, 2014 3281 bclement added hasError() getError()
*
* </pre>
*
@ -40,9 +41,18 @@ import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
public interface ITextMessageEvent {
/**
* @return the message
*/
public TextMessage getMessage();
/**
* @return true if error is set
*/
public boolean hasError();
/**
* @return error message
*/
public String getError();
}

View file

@ -30,6 +30,7 @@ package com.raytheon.uf.viz.collaboration.comm.identity.user;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 13, 2014 2751 bclement Initial creation
* Jun 20, 2014 3281 bclement added getClientIndependentId()
*
* </pre>
*
@ -45,4 +46,12 @@ public interface IUser extends IQualifiedID {
*/
public boolean isSameUser(IUser other);
/**
* Get the user's id without any information specific to which client the
* user is using (resource)
*
* @return
*/
public String getClientIndependentId();
}

View file

@ -25,6 +25,7 @@ import java.net.URL;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -35,7 +36,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IHttpXmppMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IHttpdCollaborationConfigurationEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.packet.SessionPayload;
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
@ -66,6 +66,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Apr 14, 2014 2903 bclement moved from session subpackage to connection
* Jun 17, 2014 3078 bclement routing for private chat messages
* Jun 17, 2014 3078 bclement only accept config from server, don't route data without sessionId
* Jun 20, 2014 3281 bclement refactored processPacket(), added chat error handling
*
* </pre>
*
@ -131,39 +132,82 @@ public class PeerToPeerCommHelper implements PacketListener {
return;
}
}
XMPPError error = msg.getError();
SessionPayload payload = (SessionPayload) msg
.getExtension(PacketConstants.COLLAB_XMLNS);
String body = msg.getBody();
if (body != null) {
Activator.getDefault().getNetworkStats()
.log(Activator.PEER_TO_PEER, 0, body.length());
if (body.startsWith(Tools.CONFIG_PREAMBLE)) {
// TODO Legacy config support
body = body.substring(Tools.CONFIG_PREAMBLE.length(),
body.length() - Tools.DIRECTIVE_SUFFIX.length());
this.handleConfiguration(fromStr, body);
} else {
// anything else pass to the normal text
routeMessage(msg);
}
} else {
SessionPayload payload = (SessionPayload) msg
.getExtension(PacketConstants.COLLAB_XMLNS);
if (payload != null) {
switch (payload.getPayloadType()) {
case Command:
routeData(payload, msg);
break;
case Config:
handleConfiguration(fromStr, payload.getData()
.toString());
break;
default:
// do nothing
}
}
if (error != null) {
processError(fromStr, msg, error);
} else if (payload != null) {
processPayload(fromStr, msg, payload);
} else if (body != null) {
processBody(fromStr, msg, body);
}
}
}
/**
* Process chat message error
*
* @param fromStr
* @param msg
* @param error
*/
private void processError(String fromStr, Message msg, XMPPError error) {
ChatMessageEvent event = createMessageEvent(msg);
/*
* errors in text messages happen when the message is bounced back from
* the server, inform chat view that the message can't be delivered
*/
String errorText = "Unable to deliver message to " + fromStr;
event.setError(errorText);
routeMessage(msg, event);
}
/**
* Process collaboration payload packet from server
*
* @param fromStr
* @param msg
* @param payload
*/
private void processPayload(String fromStr, Message msg,
SessionPayload payload) {
if (payload != null) {
switch (payload.getPayloadType()) {
case Command:
routeData(payload, msg);
break;
case Config:
handleConfiguration(fromStr, payload.getData().toString());
break;
default:
// do nothing
}
}
}
/**
* Process text message from XMPP server
*
* @param fromStr
* @param msg
* @param body
*/
private void processBody(String fromStr, Message msg, String body) {
Activator.getDefault().getNetworkStats()
.log(Activator.PEER_TO_PEER, 0, body.length());
if (body.startsWith(Tools.CONFIG_PREAMBLE)) {
// TODO Legacy config support
body = body.substring(Tools.CONFIG_PREAMBLE.length(), body.length()
- Tools.DIRECTIVE_SUFFIX.length());
this.handleConfiguration(fromStr, body);
} else {
// anything else pass to the normal text
routeMessage(msg, createMessageEvent(msg));
}
}
/**
* Post data as event to associated session
*
@ -202,11 +246,12 @@ public class PeerToPeerCommHelper implements PacketListener {
}
/**
* Post text message to chat
* Construct TextMessage and ChatMessageEvent from XMPP message
*
* @param message
* @return
*/
private void routeMessage(Message message) {
private ChatMessageEvent createMessageEvent(Message message) {
String fromStr = message.getFrom();
IUser fromId;
if (IDConverter.isFromRoom(fromStr)) {
@ -224,8 +269,15 @@ public class PeerToPeerCommHelper implements PacketListener {
textMsg.setProperty(key, (String) v);
}
}
ITextMessageEvent chatEvent = new ChatMessageEvent(textMsg);
return new ChatMessageEvent(textMsg);
}
/**
* Post text message event to chat
*
* @param message
*/
private void routeMessage(Message message, ChatMessageEvent chatEvent) {
String sessionId = (String) message.getProperty(
Tools.PROP_SESSION_ID);
// Now find out who gets the message. If the message doesn't contain

View file

@ -23,7 +23,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
/**
* TODO Add Description
* Event fired when a text message is received. Carries TextMessage with
* optional error
*
* <pre>
*
@ -32,23 +33,33 @@ import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 27, 2012 jkorman Initial creation
* Jun 20, 2014 3281 bclement added error field
*
* </pre>
*
* @author jkorman
* @version 1.0
*/
public class ChatMessageEvent implements ITextMessageEvent {
private final TextMessage message;
private String error;
/**
*
* @param msg
*/
public ChatMessageEvent(TextMessage msg) {
this(msg, null);
}
/**
* @param msg
* @param error
*/
public ChatMessageEvent(TextMessage msg, String error) {
message = msg;
this.error = error;
}
/**
@ -59,4 +70,37 @@ public class ChatMessageEvent implements ITextMessageEvent {
public TextMessage getMessage() {
return message;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent
* #hasError()
*/
@Override
public boolean hasError() {
return error != null;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent
* #getError()
*/
@Override
public String getError() {
return error;
}
/**
* @param error
* the error to set
*/
public void setError(String error) {
this.error = error;
}
}

View file

@ -42,6 +42,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
* Jan 30, 2014 2698 bclement removed unneeded isSameUser(string, string)
* improved other isSameUser so it won't blow up on nulls
* Feb 13, 2014 2751 bclement changed to implement IUser
* Jun 20, 2014 3281 bclement added getClientIndependentId()
*
* </pre>
*
@ -269,4 +270,15 @@ public class UserId implements IUser {
return builder.isEquals();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IUser#
* getClientIndependentId()
*/
@Override
public String getClientIndependentId() {
return getNormalizedId();
}
}

View file

@ -40,6 +40,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
* Jan 29, 2014 bclement Initial creation
* Feb 13, 2014 2751 bclement no longer is a subclass of UserId
* Apr 22, 2014 3056 bclement made equals case insensitive
* Jun 20, 2014 3281 bclement added getClientIndependentId()
*
* </pre>
*
@ -300,4 +301,16 @@ public class VenueParticipant implements IUser {
return getRoomId() + "/" + handle;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.comm.identity.user.IUser#
* getClientIndependentId()
*/
@Override
public String getClientIndependentId() {
/* room participant id's don't contain client info */
return getFQName();
}
}

View file

@ -74,7 +74,8 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* Apr 08, 2014 2785 mpduff removed preference listener
* Apr 11, 2014 2903 bclement added disconnect handler
* Apr 24, 2014 2955 bclement ignore duplicate session invites
* Jun 17, 2014 3078 bclement reworked peerToPeerMessage() to use IUser
* Jun 17, 2014 3078 bclement reworked peer2PeerMessage() to use IUser
* Jun 20, 2014 3281 bclement added error message display to peer2PeerMessage()
*
* </pre>
*
@ -256,7 +257,7 @@ public class ConnectionSubscriber {
* @param messageEvent
*/
@Subscribe
public void peer2peerMessage(ITextMessageEvent messageEvent) {
public void peer2peerMessage(final ITextMessageEvent messageEvent) {
final TextMessage message = messageEvent.getMessage();
VizApp.runAsync(new Runnable() {
@ -266,8 +267,13 @@ public class ConnectionSubscriber {
PeerToPeerView view = new PeerToPeerChatAction(peer)
.createP2PChat(IWorkbenchPage.VIEW_CREATE);
if (view != null) {
message.setFrom(view.getPeer());
view.appendMessage(message);
if (messageEvent.hasError()) {
view.sendErrorMessage(new StringBuilder(messageEvent
.getError()));
} else {
message.setFrom(view.getPeer());
view.appendMessage(message);
}
}
}
});

View file

@ -51,6 +51,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* ------------ ---------- ----------- --------------------------
* Jul 3, 2012 bsteffen Initial creation
* Jun 17, 2014 3078 bclement changed user type to IUser, added isAvailable()
* Jun 20, 2014 3281 bclement fixed secondary id bug by using user.getClientIndependentId()
*
* </pre>
*
@ -133,7 +134,7 @@ public class PeerToPeerChatAction extends Action {
*/
public PeerToPeerView createP2PChat(Integer viewMode) {
try {
String id = user.getFQName();
String id = user.getClientIndependentId();
PeerToPeerView p2pView = (PeerToPeerView) CaveWorkbenchPageManager
.getActiveInstance().showView(PeerToPeerView.ID, id,
viewMode);

View file

@ -91,6 +91,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
* Mar 06, 2014 #2865 lvenable Fixed font memory leaks added SWT dispose checks when
* running in an asynchronous thread.
* Mar 11, 2014 #2865 lvenable Added null checks for msgArchive.
* Jun 20, 2014 3281 bclement made sendErrorMessage() public
* </pre>
*
* @author rferrel
@ -590,7 +591,7 @@ public abstract class AbstractSessionView<T extends IUser> extends
* @param sb
* builder containing message
*/
protected void sendErrorMessage(StringBuilder sb) {
public void sendErrorMessage(StringBuilder sb) {
sendGenericMessage(sb, SWT.COLOR_RED);
}