aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java112
1 files changed, 98 insertions, 14 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 5f7a9a9e..72a5f8dd 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -430,6 +430,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
this.wakeLock.acquire();
+ boolean pingNow = false;
+ HashSet<Account> pingCandidates = new HashSet<>();
+
for (Account account : accounts) {
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
if (!hasInternetConnection()) {
@@ -458,13 +461,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
int secs = (int) (pingTimeoutIn / 1000);
this.scheduleWakeUpCall(secs, account.getUuid().hashCode());
}
- } else if (msToNextPing <= 0) {
- account.getXmppConnection().sendPing();
- Logging.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping");
- this.scheduleWakeUpCall(Config.PING_TIMEOUT, account.getUuid().hashCode());
+ } else {
+ pingCandidates.add(account);
+ if (msToNextPing <= 0) {
+ pingNow = true;
} else {
this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode());
}
+ }
} else if (account.getStatus() == Account.State.OFFLINE) {
reconnectAccount(account, true, interactive);
} else if (account.getStatus() == Account.State.CONNECTING) {
@@ -474,6 +478,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
long timeout = Config.CONNECT_TIMEOUT - secondsSinceLastConnect;
if (timeout < 0) {
Logging.d(Config.LOGTAG, account.getJid() + ": time out during connect reconnecting");
+ account.getXmppConnection().resetAttemptCount();
reconnectAccount(account, true, interactive);
} else if (discoTimeout < 0) {
account.getXmppConnection().sendDiscoTimeout();
@@ -493,6 +498,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
}
+ if (pingNow) {
+ for (Account account : pingCandidates) {
+ account.getXmppConnection().sendPing();
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + " send ping");
+ this.scheduleWakeUpCall(Config.PING_TIMEOUT, account.getUuid().hashCode());
+ }
+ }
if (wakeLock.isHeld()) {
try {
wakeLock.release();
@@ -1388,6 +1400,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
account.setPassword(newPassword);
+ account.setOption(Account.OPTION_MAGIC_CREATE, false);
databaseBackend.updateAccount(account);
callback.onPasswordChangeSucceeded();
} else {
@@ -1769,7 +1782,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
for(Element child : query.getChildren()) {
if ("item".equals(child.getName())) {
- conversation.getMucOptions().putMember(child.getAttributeAsJid("jid"));
+ MucOptions.User user = AbstractParser.parseItem(conversation,child);
+ if (!user.realJidMatchesAccount()) {
+ conversation.getMucOptions().addUser(user);
+ getAvatarService().clear(conversation);
+ updateMucRosterUi();
+ updateConversationUi();
+ }
}
}
} else {
@@ -2039,13 +2058,15 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
- public void changeAffiliationInConference(final Conversation conference, Jid user, MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
+ public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
final Jid jid = user.toBareJid();
IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
+ conference.getMucOptions().changeAffiliation(jid, affiliation);
+ getAvatarService().clear(conference);
callback.onAffiliationChangedSuccessful(jid);
} else {
callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);
@@ -2057,8 +2078,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
List<Jid> jids = new ArrayList<>();
for (MucOptions.User user : conference.getMucOptions().getUsers()) {
- if (user.getAffiliation() == before && user.getJid() != null) {
- jids.add(user.getJid());
+ if (user.getAffiliation() == before && user.getRealJid() != null) {
+ jids.add(user.getRealJid());
}
}
IqPacket request = this.mIqGenerator.changeAffiliation(conference, jids, after.toString());
@@ -2240,6 +2261,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (connection == null) {
connection = createConnection(account);
account.setXmppConnection(connection);
+ } else {
+ connection.interrupt();
}
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
if (!force) {
@@ -2343,17 +2366,15 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public boolean displayCaptchaRequest(Account account, String id, Data data, Bitmap captcha) {
- boolean rc = false;
if (mOnCaptchaRequested != null) {
DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
Bitmap scaled = Bitmap.createScaledBitmap(captcha, (int) (captcha.getWidth() * metrics.scaledDensity),
(int) (captcha.getHeight() * metrics.scaledDensity), false);
mOnCaptchaRequested.onCaptchaRequested(account, id, data, scaled);
- rc = true;
+ return true;
}
-
- return rc;
+ return false;
}
public void updateBlocklistUi(final OnUpdateBlocklist.Status status) {
@@ -2496,6 +2517,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
}
+ if(Config.DOMAIN_LOCK != null && !hosts.contains(Config.DOMAIN_LOCK)) {
+ hosts.add(Config.DOMAIN_LOCK);
+ }
+ if(Config.MAGIC_CREATE_DOMAIN != null && !hosts.contains(Config.MAGIC_CREATE_DOMAIN)) {
+ hosts.add(Config.MAGIC_CREATE_DOMAIN);
+ }
return hosts;
}
@@ -2535,7 +2562,17 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void sendPresence(final Account account) {
- XmppSendUtil.sendPresencePacket(account, mPresenceGenerator.selfPresence(account, getTargetPresence()));
+ PresencePacket packet;
+ if (manuallyChangePresence()) {
+ packet = mPresenceGenerator.selfPresence(account, account.getPresenceStatus());
+ String message = account.getPresenceStatusMessage();
+ if (message != null && !message.isEmpty()) {
+ packet.addChild(new Element("status").setContent(message));
+ }
+ } else {
+ packet = mPresenceGenerator.selfPresence(account, getTargetPresence());
+ }
+ XmppSendUtil.sendPresencePacket(account, packet);
}
public void refreshAllPresences() {
@@ -2674,7 +2711,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
- private ServiceDiscoveryResult getCachedServiceDiscoveryResult(Pair<String,String> key) {
+ public ServiceDiscoveryResult getCachedServiceDiscoveryResult(Pair<String, String> key) {
ServiceDiscoveryResult result = discoCache.get(key);
if (result != null) {
return result;
@@ -2748,6 +2785,53 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return mPushManagementService;
}
+ public Account getPendingAccount() {
+ Account pending = null;
+ for(Account account : getAccounts()) {
+ if (account.isOptionSet(Account.OPTION_REGISTER)) {
+ pending = account;
+ } else {
+ return null;
+ }
+ }
+ return pending;
+ }
+
+ public void changeStatus(Account account, Presence.Status status, String statusMessage, boolean send) {
+ if (!statusMessage.isEmpty()) {
+ databaseBackend.insertPresenceTemplate(new PresenceTemplate(status, statusMessage));
+ }
+ changeStatusReal(account, status, statusMessage, send);
+ }
+
+ private void changeStatusReal(Account account, Presence.Status status, String statusMessage, boolean send) {
+ account.setPresenceStatus(status);
+ account.setPresenceStatusMessage(statusMessage);
+ databaseBackend.updateAccount(account);
+ if (!account.isOptionSet(Account.OPTION_DISABLED) && send) {
+ sendPresence(account);
+ }
+ }
+
+ public void changeStatus(Presence.Status status, String statusMessage) {
+ if (!statusMessage.isEmpty()) {
+ databaseBackend.insertPresenceTemplate(new PresenceTemplate(status, statusMessage));
+ }
+ for(Account account : getAccounts()) {
+ changeStatusReal(account, status, statusMessage, true);
+ }
+ }
+
+ public List<PresenceTemplate> getPresenceTemplates(Account account) {
+ List<PresenceTemplate> templates = databaseBackend.getPresenceTemplates();
+ for(PresenceTemplate template : account.getSelfContact().getPresences().asTemplates()) {
+ if (!templates.contains(template)) {
+ templates.add(0, template);
+ }
+ }
+ return templates;
+ }
+
public interface OnMamPreferencesFetched {
void onPreferencesFetched(Element prefs);
void onPreferencesFetchFailed();