suggest sync on login + hard code api server

This commit is contained in:
Daniel Gultsch 2018-11-06 09:13:43 +01:00
parent d8fc03b2f7
commit fe90c6f846
2 changed files with 12 additions and 14 deletions

View File

@ -292,6 +292,7 @@ public class XmppConnectionService extends Service {
} }
account.getRoster().clearPresences(); account.getRoster().clearPresences();
mJingleConnectionManager.cancelInTransmission(); mJingleConnectionManager.cancelInTransmission();
mQuickConversationsService.considerSync();
fetchRosterFromServer(account); fetchRosterFromServer(account);
if (!account.getXmppConnection().getFeatures().bookmarksConversion()) { if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
fetchBookmarks(account); fetchBookmarks(account);

View File

@ -57,7 +57,9 @@ public class QuickConversationsService extends AbstractQuickConversationsService
public static final int API_ERROR_SSL_HANDSHAKE = -4; public static final int API_ERROR_SSL_HANDSHAKE = -4;
public static final int API_ERROR_AIRPLANE_MODE = -5; public static final int API_ERROR_AIRPLANE_MODE = -5;
private static final String BASE_URL = "https://api.quicksy.im"; private static final String API_DOMAIN = "api."+Config.QUICKSY_DOMAIN;
private static final String BASE_URL = "https://"+API_DOMAIN;
private static final String INSTALLATION_ID = "eu.siacs.conversations.installation-id"; private static final String INSTALLATION_ID = "eu.siacs.conversations.installation-id";
@ -68,7 +70,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private final AtomicBoolean mVerificationRequestInProgress = new AtomicBoolean(false); private final AtomicBoolean mVerificationRequestInProgress = new AtomicBoolean(false);
private CountDownLatch awaitingAccountStateChange; private CountDownLatch awaitingAccountStateChange;
private Attempt mLastSyncAttempt = new Attempt(0, 0); private Attempt mLastSyncAttempt = Attempt.NULL;
QuickConversationsService(XmppConnectionService xmppConnectionService) { QuickConversationsService(XmppConnectionService xmppConnectionService) {
super(xmppConnectionService); super(xmppConnectionService);
@ -111,9 +113,6 @@ public class QuickConversationsService extends AbstractQuickConversationsService
if (mVerificationRequestInProgress.compareAndSet(false, true)) { if (mVerificationRequestInProgress.compareAndSet(false, true)) {
new Thread(() -> { new Thread(() -> {
try { try {
Thread.sleep(5000);
final URL url = new URL(BASE_URL + "/authentication/" + e164); final URL url = new URL(BASE_URL + "/authentication/" + e164);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
@ -183,9 +182,6 @@ public class QuickConversationsService extends AbstractQuickConversationsService
if (mVerificationInProgress.compareAndSet(false, true)) { if (mVerificationInProgress.compareAndSet(false, true)) {
new Thread(() -> { new Thread(() -> {
try { try {
Thread.sleep(5000);
final URL url = new URL(BASE_URL + "/password"); final URL url = new URL(BASE_URL + "/password");
final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
@ -324,12 +320,7 @@ public class QuickConversationsService extends AbstractQuickConversationsService
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not attempt sync"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not attempt sync");
return false; return false;
} }
XmppConnection xmppConnection = account.getXmppConnection(); final Jid syncServer = Jid.of(API_DOMAIN);
Jid syncServer = xmppConnection == null ? null : xmppConnection.findDiscoItemByFeature(Namespace.SYNCHRONIZATION);
if (syncServer == null) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": skipping sync. no sync server found");
return false;
}
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending phone list to " + syncServer); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending phone list to " + syncServer);
List<Element> entries = new ArrayList<>(); List<Element> entries = new ArrayList<>();
for (PhoneNumberContact c : contacts.values()) { for (PhoneNumberContact c : contacts.values()) {
@ -370,6 +361,10 @@ public class QuickConversationsService extends AbstractQuickConversationsService
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": phone number contact list remains unchanged"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": phone number contact list remains unchanged");
} }
} else if (response.getType() == IqPacket.TYPE.TIMEOUT) {
mLastSyncAttempt = Attempt.NULL;
} else {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": failed to sync contact list with api server");
} }
service.syncRoster(account); service.syncRoster(account);
service.updateRosterUi(); service.updateRosterUi();
@ -398,6 +393,8 @@ public class QuickConversationsService extends AbstractQuickConversationsService
private final long timestamp; private final long timestamp;
private int hash; private int hash;
private static final Attempt NULL = new Attempt(0,0);
private Attempt(long timestamp, int hash) { private Attempt(long timestamp, int hash) {
this.timestamp = timestamp; this.timestamp = timestamp;
this.hash = hash; this.hash = hash;