aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java68
1 files changed, 14 insertions, 54 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 1d1f0108..a7bd8006 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -161,7 +161,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
};
private MessageGenerator mMessageGenerator = new MessageGenerator();
- private PresenceGenerator mPresenceGenerator = new PresenceGenerator();
private List<Account> accounts;
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager();
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@@ -1258,9 +1257,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
conversation.endOtrIfNeeded();
if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
Log.d(Config.LOGTAG, "Canceling presence request from " + conversation.getJid().toString());
- sendPresencePacket(
+ XmppSendUtil.sendPresencePacket(
conversation.getAccount(),
- mPresenceGenerator.stopPresenceUpdatesTo(conversation.getContact())
+ PresenceGenerator.stopPresenceUpdatesTo(conversation.getContact())
);
}
}
@@ -1662,26 +1661,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final MucOptions mucOptions = conversation.getMucOptions();
final Jid joinJid = mucOptions.getSelf().getFullJid();
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
- PresencePacket packet = new PresencePacket();
- packet.setFrom(conversation.getAccount().getJid());
- packet.setTo(joinJid);
- Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
- if (conversation.getMucOptions().getPassword() != null) {
- x.addChild("password").setContent(conversation.getMucOptions().getPassword());
- }
-
- if (mucOptions.mamSupport()) {
- // Use MAM instead of the limited muc history to get history
- x.addChild("history").setAttribute("maxchars", "0");
- } else {
- // Fallback to muc history
- x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted()));
- }
- String sig = account.getPgpSignature();
- if (sig != null) {
- packet.addChild("x", "jabber:x:signed").setContent(sig);
- }
- sendPresencePacket(account, packet);
+ long lastMessageTransmitted = conversation.getLastMessageTransmitted();
+ PresencePacket packet = PresenceGenerator.generateMucJoin(account, joinJid, mucOptions, lastMessageTransmitted);
+ XmppSendUtil.sendPresencePacket(account, packet);
if (onConferenceJoined != null) {
onConferenceJoined.onConferenceJoined(conversation);
}
@@ -1787,16 +1769,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
});
- PresencePacket packet = new PresencePacket();
- packet.setTo(joinJid);
- packet.setFrom(conversation.getAccount().getJid());
-
- String sig = account.getPgpSignature();
- if (sig != null) {
- packet.addChild("status").setContent("online");
- packet.addChild("x", "jabber:x:signed").setContent(sig);
- }
- sendPresencePacket(account, packet);
+ PresencePacket packet = PresenceGenerator.generateMucRename(account, joinJid);
+ XmppSendUtil.sendPresencePacket(account, packet);
} else {
conversation.setContactJid(joinJid);
databaseBackend.updateConversation(conversation);
@@ -1820,14 +1794,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) {
- PresencePacket packet = new PresencePacket();
- packet.setTo(conversation.getMucOptions().getSelf().getFullJid());
- packet.setFrom(conversation.getAccount().getJid());
- packet.setAttribute("type", "unavailable");
- sendPresencePacket(conversation.getAccount(), packet);
+ PresencePacket packet = PresenceGenerator.generateOfflinePresencePacketTo(account, conversation.getMucOptions().getSelf().getFullJid());
+ XmppSendUtil.sendPresencePacket(account, packet);
conversation.getMucOptions().setOffline();
conversation.deregisterWithBookmark();
- Logging.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid()
+ Logging.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": leaving muc " + conversation.getJid());
} else {
account.pendingConferenceLeaves.add(conversation);
@@ -2169,12 +2140,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
iq.query(Xmlns.ROSTER).addChild(contact.asElement());
account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
if (sendUpdates) {
- sendPresencePacket(account,
- mPresenceGenerator.sendPresenceUpdatesTo(contact));
+ XmppSendUtil.sendPresencePacket(account, PresenceGenerator.sendPresenceUpdatesTo(contact));
}
if (ask) {
- sendPresencePacket(account,
- mPresenceGenerator.requestPresenceUpdatesFrom(contact));
+ XmppSendUtil.sendPresencePacket(account, PresenceGenerator.requestPresenceUpdatesFrom(contact));
}
}
}
@@ -2450,11 +2419,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
XmppSendUtil.sendMessagePacket(account, packet);
}
- @Deprecated
- public void sendPresencePacket(Account account, PresencePacket packet) {
- XmppSendUtil.sendPresencePacket(account, packet);
- }
-
public void sendCreateAccountWithCaptchaPacket(Account account, String id, Data data) {
XmppConnection connection = account.getXmppConnection();
if (connection != null) {
@@ -2468,7 +2432,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void sendPresence(final Account account) {
- XmppSendUtil.sendPresencePacket(account, mPresenceGenerator.selfPresence(account, getTargetPresence()));
+ XmppSendUtil.sendPresencePacket(account, PresenceGenerator.selfPresence(account, getTargetPresence()));
}
public void refreshAllPresences() {
@@ -2488,17 +2452,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void sendOfflinePresence(final Account account) {
- XmppSendUtil.sendPresencePacket(account, mPresenceGenerator.sendOfflinePresence(account));
+ XmppSendUtil.sendPresencePacket(account, PresenceGenerator.generateOfflinePresencePacket(account));
}
public MessageGenerator getMessageGenerator() {
return this.mMessageGenerator;
}
- public PresenceGenerator getPresenceGenerator() {
- return this.mPresenceGenerator;
- }
-
public IqGenerator getIqGenerator() {
return this.mIqGenerator;
}