Tweaking presence communication.

cefexperiments
Danny van Heumen 11 years ago
parent 9c9b7bf0be
commit bb8e878514

@ -1049,15 +1049,17 @@ public boolean isAway()
* Set or unset away message. In case the awayMessage is null the away
* message will be disabled and as a consequence the away-status is removed.
*
* @param away away status, <tt>true</tt> for away, <tt>false</tt> for
* available
* @param awayMessage the away message to set, or null to remove away-status
*/
public void away(final String awayMessage)
public void away(final boolean away, final String awayMessage)
{
if (!isConnected())
{
throw new IllegalStateException("Not connected to an IRC server.");
}
this.presence.setAway(awayMessage);
this.presence.away(away, awayMessage);
}
/**

@ -331,31 +331,26 @@ public PresenceStatus getPresenceStatus()
*/
@Override
public void publishPresenceStatus(final PresenceStatus status,
final String statusMessage)
String statusMessage)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
if (statusMessage != null && statusMessage.isEmpty())
{
// if we provide a message, make sure it isn't empty
statusMessage =
IrcActivator.getResources().getI18NString(
"service.gui.AWAY_STATUS");
}
final IrcStack provider = this.parentProvider.getIrcStack();
if (status.getStatus() >= IrcStatusEnum.AVAILABLE_THRESHOLD)
{
provider.away(null);
provider.away(false, statusMessage);
}
else if (status.getStatus() >= IrcStatusEnum.AWAY_THRESHOLD)
{
final String awayMessage;
if (statusMessage == null || statusMessage.isEmpty())
{
// FIXME replace with entry for default away message?
awayMessage =
IrcActivator.getResources().getI18NString(
"service.gui.AWAY_STATUS");
}
else
{
awayMessage = statusMessage;
}
provider.away(awayMessage);
provider.away(true, statusMessage);
}
else
{

@ -16,6 +16,8 @@
/**
* Manager for presence status of IRC connection.
*
* TODO Check length of away message against server allowed size.
*
* TODO Support for 'a' (Away) user mode. (Check this again, since I also see
* 'a' used for other purposes. This may be one of those ambiguous letters that
* every server interprets differently.)
@ -63,7 +65,7 @@ public class PresenceManager
/**
* Proposed away message.
*/
private String submittedMessage = "";
private String submittedMessage = "Away";
/**
* Constructor.
@ -119,20 +121,45 @@ public String getMessage()
* Set away status and message. Disable away status by providing
* <tt>null</tt> message.
*
* @param awayMessage away message to set. If away message is <tt>null</tt>
* or empty away status will be cancelled.
* @param isAway <tt>true</tt> to enable away mode + message, or
* <tt>false</tt> to disable
* @param awayMessage away message, the message is only available when the
* local user is set to away. If <tt>null</tt> is provided, don't
* set a new away message.
*/
public void setAway(final String awayMessage)
public void away(final boolean isAway, final String awayMessage)
{
if (awayMessage == null || awayMessage.isEmpty())
if (awayMessage != null)
{
this.submittedMessage = verifyMessage(awayMessage);
}
if (isAway && (!this.away || awayMessage != null))
{
// In case we aren't AWAY yet, or in case the message has changed.
this.irc.rawMessage("AWAY :" + this.submittedMessage);
}
else if (isAway != this.away)
{
this.irc.rawMessage("AWAY");
}
else
}
/**
* Set new prepared away message for later moment when IRC connection is set
* to away.
*
* @param message the away message to prepare
* @return returns message after verification
*/
private String verifyMessage(final String message)
{
if (message == null || message.isEmpty())
{
this.submittedMessage = awayMessage;
this.irc.rawMessage("AWAY :" + awayMessage);
throw new IllegalArgumentException(
"away message must be non-null and non-empty");
}
return message;
}
/**

Loading…
Cancel
Save