SPARK-2119: check if pre-approve is supported

This commit is contained in:
Sergey Ponomarev
2026-07-14 19:50:14 +03:00
parent 990b1f1ae2
commit 417496c2ea

View File

@ -519,7 +519,7 @@ public class RosterDialog implements ActionListener {
boolean isNewContact = userEntry == null || userEntry.getGroups().isEmpty();
if (isNewContact) {
try {
roster.preApproveAndCreateEntry(jid, nickname, new String[]{group});
addContactToRoster(jid, nickname, new String[]{group}, roster);
return true;
}
catch (XMPPException | SmackException | InterruptedException e) {
@ -540,6 +540,17 @@ public class RosterDialog implements ActionListener {
}
}
private void addContactToRoster(BareJid contactJid, String displayName, String[] parentNames, Roster roster) throws SmackException, XMPPException.XMPPErrorException, InterruptedException {
if (roster.isSubscriptionPreApprovalSupported()) {
try {
roster.preApproveAndCreateEntry(contactJid, displayName, parentNames);
} catch (SmackException.FeatureNotSupportedException ignored) {
}
} else {
roster.createItemAndRequestSubscription(contactJid, displayName, parentNames);
}
}
public List<AccountItem> getAccounts() {
List<AccountItem> list = new ArrayList<>();
for (Transport transport : TransportUtils.getTransports()) {