Skip to content

Commit

Permalink
[FIXED JENKINS-11903] Use nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed Nov 25, 2012
1 parent efd755e commit 7ea7d16
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>instant-messaging-parent</artifactId>
<version>1.20</version>
<version>1.22-SNAPSHOT</version>
<relativePath>../instant-messaging-parent-plugin/pom.xml</relativePath>
</parent>

Expand Down
Expand Up @@ -11,7 +11,6 @@
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;
Expand Down
Expand Up @@ -57,6 +57,7 @@
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.packet.Nick;
import org.jivesoftware.smackx.packet.VCard;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -137,7 +138,7 @@ class JabberIMConnection extends AbstractIMConnection {
this.authentication = authentication;
this.hostnameOverride = desc.getHostname();
this.port = desc.getPort();
this.nick = JabberUtil.getUserPart(desc.getJabberId());
this.nick = desc.getNickname();
this.resource = JabberUtil.getResourcePart(desc.getJabberId());
this.passwd = desc.getPassword();
this.enableSASL = desc.isEnableSASL();
Expand All @@ -146,8 +147,7 @@ class JabberIMConnection extends AbstractIMConnection {
this.proxyport = desc.getProxyPort();
this.proxyuser = desc.getProxyUser();
this.proxypass = desc.getProxyPass();
this.groupChatNick = desc.getGroupChatNickname() != null ?
desc.getGroupChatNickname() : this.nick;
this.groupChatNick = desc.getNickname();
this.botCommandPrefix = desc.getCommandPrefix();
this.groupChats = desc.getDefaultTargets();
this.impresence = desc.isExposePresence() ? IMPresence.AVAILABLE : IMPresence.UNAVAILABLE;
Expand Down Expand Up @@ -587,6 +587,8 @@ private void sendPresence() {
throw new IllegalStateException("Don't know how to handle "
+ impresence);
}

presence.addExtension(new Nick(this.nick));
this.connection.sendPacket(presence);
} finally {
unlock();
Expand Down
Expand Up @@ -62,7 +62,7 @@ public class JabberPublisherDescriptor extends BuildStepDescriptor<Publisher> im
public static final String PARAMETERNAME_PRESENCE = PREFIX + "exposePresence";
public static final String PARAMETERNAME_PASSWORD = PREFIX + "password";
public static final String PARAMETERNAME_JABBERID = PREFIX + "jabberId";
public static final String PARAMETERNAME_GROUP_NICKNAME = PREFIX + "groupNick";
public static final String PARAMETERNAME_NICKNAME = PREFIX + "nickname";
public static final String PARAMETERNAME_TARGETS = PREFIX + "targets";
public static final String PARAMETERNAME_INITIAL_GROUPCHATS = PREFIX + "initialGroupChats";
public static final String PARAMETERNAME_COMMAND_PREFIX = PREFIX + "commandPrefix";
Expand Down Expand Up @@ -106,6 +106,11 @@ public class JabberPublisherDescriptor extends BuildStepDescriptor<Publisher> im
// the following 2 are actually the Jabber nick and password. For backward compatibility I cannot rename them
private String hudsonNickname;
private String hudsonPassword;
/**
* Nickname to be used in private chats and chat rooms.
* <p>
* For historical reason still called 'groupChatNickname'.
*/
private String groupChatNickname;
private boolean exposePresence = true;
private boolean enableSASL = true;
Expand Down Expand Up @@ -226,7 +231,7 @@ private void applyPassword(final HttpServletRequest req, boolean check) throws F

private void applyGroupChatNickname(final HttpServletRequest req) throws FormException
{
this.groupChatNickname = req.getParameter(PARAMETERNAME_GROUP_NICKNAME);
this.groupChatNickname = req.getParameter(PARAMETERNAME_NICKNAME);
if (this.groupChatNickname != null && this.groupChatNickname.trim().length() == 0)
{
this.groupChatNickname = null;
Expand Down Expand Up @@ -425,11 +430,14 @@ public String getPassword() {
return Scrambler.descramble(this.hudsonPassword);
}

public String getGroupChatNickname()
{
return this.groupChatNickname;
public String getNickname() {
if (Util.fixEmptyAndTrim(this.groupChatNickname) != null) {
return this.groupChatNickname;
} else {
return JabberUtil.getUserPart(getJabberId());
}
}

@Override
public int getPort()
{
Expand Down
Expand Up @@ -68,9 +68,9 @@
<f:textbox name="${descriptor.PARAMETERNAME_COMMAND_PREFIX}"
value="${descriptor.commandPrefix}" />
</f:entry>
<f:entry title="Group chat nickname" help="${base}/help-group-nick.html">
<f:textbox name="${descriptor.PARAMETERNAME_GROUP_NICKNAME}"
value="${descriptor.groupChatNickname}" />
<f:entry title="Nickname" help="${base}/help-nick.html">
<f:textbox name="${descriptor.PARAMETERNAME_NICKNAME}"
value="${descriptor.nickname}" />
</f:entry>

<super:global-jenkinsLogin />
Expand Down
3 changes: 0 additions & 3 deletions src/main/webapp/help-group-nick.html

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/webapp/help-nick.html
@@ -0,0 +1,3 @@
<div>
Alternate nickname to use in chats. Leave blank to use Jabber ID from above.
</div>

0 comments on commit 7ea7d16

Please sign in to comment.