From bb8e878514f1194ff53145c294a161c64cbd06e9 Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Fri, 19 Sep 2014 23:16:27 +0200 Subject: [PATCH] Tweaking presence communication. --- .../impl/protocol/irc/IrcStack.java | 6 ++- ...OperationSetPersistentPresenceIrcImpl.java | 25 +++++------ .../impl/protocol/irc/PresenceManager.java | 43 +++++++++++++++---- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index 602272b76..b819131c3 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -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, true for away, false 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); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetPersistentPresenceIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetPersistentPresenceIrcImpl.java index 3e2baddb9..4d5b087f3 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/OperationSetPersistentPresenceIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/OperationSetPersistentPresenceIrcImpl.java @@ -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 { diff --git a/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java b/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java index 7e29e7867..027ed3b97 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/PresenceManager.java @@ -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 * null message. * - * @param awayMessage away message to set. If away message is null - * or empty away status will be cancelled. + * @param isAway true to enable away mode + message, or + * false to disable + * @param awayMessage away message, the message is only available when the + * local user is set to away. If null 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; } /**