Skip to content

Commit

Permalink
[xmpp] add group nickname to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
akallabeth committed Dec 20, 2024
1 parent 0a41a0e commit 8f38009
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class XMPPClient implements IncomingChatMessageListener, ConnectionListen
private @Nullable HttpFileUploadManager httpFileUploadManager;
private Set<XMPPClientMessageSubscriber> subscribers = new HashSet<>();
private final XMPPClientEventlistener eventListener;
private String username = "";
private String nickname = "";

public XMPPClient(XMPPClientEventlistener eventListener) {
this.eventListener = eventListener;
Expand All @@ -78,15 +78,20 @@ public void unsubscribe(XMPPClientMessageSubscriber channel) {
subscribers.remove(channel);
}

public void connect(String host, Integer port, String login, String domain, String password,
public void connect(String host, Integer port, String login, String nick, String domain, String password,
SecurityMode securityMode) throws XMPPClientConfigException, XMPPClientException {
disconnect();
String serverHost = domain;
if (!host.isBlank()) {
serverHost = host;
}

username = login;
if (!nick.isEmpty()) {
nickname = nick;
} else {
nickname = login;
}

XMPPTCPConnectionConfiguration config;
try {
config = XMPPTCPConnectionConfiguration.builder() //
Expand Down Expand Up @@ -171,7 +176,7 @@ public void sendGroupMessage(String to, String message) {
MultiUserChat chat = multiUserChatManager.getMultiUserChat(jid);

if (!chat.isJoined()) {
chat.join(Resourcepart.from(username));
chat.join(Resourcepart.from(nickname));
}

chat.sendMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class XMPPClientConfiguration {
public @Nullable String host;
public Integer port = 5222;
public String username = "";
public String nickname = "";
public String password = "";
public String domain = "";
public String securityMode = SecurityMode.required.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private void doConnect() {
}

try {
xmppClient.connect(Objects.requireNonNullElse(config.host, ""), config.port, config.username, config.domain,
config.password, SecurityMode.valueOf(config.securityMode));
xmppClient.connect(Objects.requireNonNullElse(config.host, ""), config.port, config.username,
config.nickname, config.domain, config.password, SecurityMode.valueOf(config.securityMode));
updateStatus(ThingStatus.ONLINE);
} catch (XMPPClientConfigException e) {
logger.debug("XMPP connection error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<label>Username</label>
<description>The XMPP Username (the left side of JID, e.g. user for JID [email protected])</description>
</parameter>
<parameter name="nickname" type="text" required="false">
<label>Nickname</label>
<description>The XMPP Nickname to use in multi user chats. (Defaults to Username)</description>
<advanced>true</advanced>
</parameter>
<parameter name="domain" type="text" required="true">
<label>Domain</label>
<description>The XMPP Domain (the right side of JID, e.g. example.com for JID [email protected])</description>
Expand Down

0 comments on commit 8f38009

Please sign in to comment.