refactor: use messageBuilder.to()

This commit is contained in:
Sergey Ponomarev
2026-07-17 19:11:15 +03:00
parent d9b3067178
commit 79626350fd
10 changed files with 20 additions and 25 deletions

View File

@ -1410,8 +1410,8 @@ public class ContactList extends JPanel implements
BareJid jid = item.getJid();
Presence response = StanzaBuilder.buildPresence()
.ofType(Presence.Type.subscribe)
.to(jid)
.build();
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (SmackException.NotConnectedException | InterruptedException e1) {
@ -1585,8 +1585,8 @@ public class ContactList extends JPanel implements
} catch (XMPPException | SmackException e) {
Presence unsub = StanzaBuilder.buildPresence()
.ofType(Presence.Type.unsubscribed)
.to(presence.getFrom())
.build();
unsub.setTo(presence.getFrom());
try {
SparkManager.getConnection().sendStanza(unsub);
} catch (SmackException.NotConnectedException e1) {

View File

@ -145,9 +145,8 @@ public class SubscriptionDialog {
if (entry != null && entry.getType() == RosterPacket.ItemType.to) {
Presence response = StanzaBuilder.buildPresence()
.ofType(Presence.Type.subscribed)
.to(jid)
.build();
response.setTo(jid);
SparkManager.getConnection().sendStanza(response);
return;
}
@ -175,8 +174,8 @@ public class SubscriptionDialog {
if (!rosterBox.isSelected()) {
Presence response = StanzaBuilder.buildPresence()
.ofType(Presence.Type.subscribed)
.to(jid)
.build();
response.setTo(jid);
try
{
SparkManager.getConnection().sendStanza(response);
@ -193,8 +192,8 @@ public class SubscriptionDialog {
if (addEntry) {
Presence response = StanzaBuilder.buildPresence()
.ofType(Presence.Type.subscribed)
.to(jid)
.build();
response.setTo(jid);
try
{
SparkManager.getConnection().sendStanza(response);
@ -261,8 +260,8 @@ public class SubscriptionDialog {
{
Presence response = StanzaBuilder.buildPresence()
.ofType(Presence.Type.unsubscribe)
.to(jid)
.build();
response.setTo(jid);
try
{
SparkManager.getConnection().sendStanza(response);

View File

@ -82,8 +82,8 @@ public class GatewayButton extends JPanel implements GatewayItem {
.setStatus(oldPresence.getStatus())
.setPriority(oldPresence.getPriority())
.setMode(oldPresence.getMode())
.to(transport.getXMPPServiceDomain())
.build();
presence.setTo(transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(presence);
@ -110,9 +110,8 @@ public class GatewayButton extends JPanel implements GatewayItem {
signOutMenu.addActionListener( actionEvent -> {
final Presence offlinePresence = StanzaBuilder.buildPresence()
.ofType(Presence.Type.unavailable)
.to(transport.getXMPPServiceDomain())
.build();
offlinePresence.setTo(transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(offlinePresence);
@ -128,8 +127,8 @@ public class GatewayButton extends JPanel implements GatewayItem {
signInMenu.addActionListener( actionEvent -> {
final Presence onlinePresence = StanzaBuilder.buildPresence()
.ofType(Presence.Type.available)
.to(transport.getXMPPServiceDomain())
.build();
onlinePresence.setTo(transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(onlinePresence);

View File

@ -294,9 +294,8 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
.setStatus(presence.getStatus())
.setPriority(presence.getPriority())
.setMode(presence.getMode())
.to(transport.getXMPPServiceDomain())
.build();
p.setTo(transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(p);

View File

@ -108,8 +108,8 @@ public class GatewayTabItem extends CollapsiblePane implements GatewayItem {
.setStatus(oldPresence.getStatus())
.setPriority(oldPresence.getPriority())
.setMode(oldPresence.getMode())
.to(transport.getXMPPServiceDomain())
.build();
presence.setTo(transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(presence);
@ -131,8 +131,8 @@ public class GatewayTabItem extends CollapsiblePane implements GatewayItem {
if (signedIn) {
final Presence offlinePresence = StanzaBuilder.buildPresence()
.ofType(Presence.Type.unavailable)
.to(_transport.getXMPPServiceDomain())
.build();
offlinePresence.setTo(_transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(offlinePresence);
@ -146,8 +146,8 @@ public class GatewayTabItem extends CollapsiblePane implements GatewayItem {
} else {
final Presence onlinePresence = StanzaBuilder.buildPresence()
.ofType(Presence.Type.available)
.to(_transport.getXMPPServiceDomain())
.build();
onlinePresence.setTo(_transport.getXMPPServiceDomain());
try
{
SparkManager.getConnection().sendStanza(onlinePresence);

View File

@ -94,8 +94,8 @@ public class VersionViewer {
// Load Version
final Version versionRequest = Version.builder(connection)
.ofType(IQ.Type.get)
.to(jid)
.build();
versionRequest.setTo(jid);
CardLayout cardLayout = (CardLayout) cards.getLayout();
connection.sendIqRequestAsync(versionRequest)
@ -117,8 +117,8 @@ public class VersionViewer {
// Time
final Time time = Time.builder(connection)
.ofType(IQ.Type.get)
.to(jid)
.build();
time.setTo(jid);
connection.sendIqRequestAsync(time)
.onSuccess(iq -> {

View File

@ -33,8 +33,8 @@ public class PrivacyPresenceHandler implements SparkPrivacyItemListener {
{
Presence pack = StanzaBuilder.buildPresence()
.ofType(Presence.Type.unavailable)
.to(jid)
.build();
pack.setTo(jid);
try {
SparkManager.getConnection().sendStanza(pack);
} catch (InterruptedException e) {
@ -56,8 +56,8 @@ public class PrivacyPresenceHandler implements SparkPrivacyItemListener {
.setStatus(presence.getStatus())
.setPriority(1)
.setMode(presence.getMode())
.to(jid)
.build();
pack.setTo(jid);
try {
SparkManager.getConnection().sendStanza(pack);
} catch (InterruptedException e) {

View File

@ -304,9 +304,8 @@ public class FastpathPlugin implements Plugin, ConnectionListener {
.setStatus(actualPresence.getStatus())
.setPriority(actualPresence.getPriority())
.setMode(actualPresence.getMode())
.to(workgroup)
.build();
toWorkgroupPresence.setTo(workgroup);
try {
con.sendStanza(toWorkgroupPresence);
wgroup = new Workgroup(workgroup, con);

View File

@ -388,9 +388,8 @@ public class CoBrowser extends JPanel implements ActionListener, BrowserListener
GroupChatRoom groupChatRoom = (GroupChatRoom)chatRoom;
try {
messageBuilder.ofType(Message.Type.groupchat);
messageBuilder.to(groupChatRoom.getBareJid());
Message message = messageBuilder.build();
message.setTo(groupChatRoom.getBareJid());
MessageEventManager.addNotificationsRequests(message, true, true, true, true);

View File

@ -338,8 +338,8 @@ public class ReversiPanel extends JPanel {
move.setPosition(block.getIndex());
Message message = StanzaBuilder.buildMessage()
.addExtension(move)
.to(opponentJID)
.build();
message.setTo(opponentJID);
try {
connection.sendStanza(message);
} catch (SmackException.NotConnectedException | InterruptedException e1) {