Support for server federation.

This commit is contained in:
Moxie Marlinspike
2013-10-18 22:45:27 -07:00
parent 25a2ad7289
commit fa5ccc3f8a
15 changed files with 372 additions and 116 deletions

View File

@@ -10,6 +10,7 @@ import android.util.Log;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.push.ContactTokenDetails;
import org.whispersystems.textsecure.push.PushServiceSocket;
import java.util.List;
@@ -61,11 +62,14 @@ public class DirectoryRefreshService extends Service {
String password = TextSecurePreferences.getPushServerPassword(context);
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(localNumber);
List<String> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(localNumber);
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
if (activeTokens != null) {
eligibleContactTokens.removeAll(activeTokens);
for (ContactTokenDetails activeToken : activeTokens) {
eligibleContactTokens.remove(activeToken.getToken());
}
directory.setTokens(activeTokens, eligibleContactTokens);
}

View File

@@ -20,6 +20,7 @@ import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.PreKeyUtil;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.push.ContactTokenDetails;
import org.whispersystems.textsecure.push.PushServiceSocket;
import org.whispersystems.textsecure.storage.PreKeyRecord;
import org.whispersystems.textsecure.util.Util;
@@ -282,11 +283,13 @@ public class RegistrationService extends Service {
String gcmRegistrationId = waitForGcmRegistrationId();
socket.registerGcmId(gcmRegistrationId);
Set<String> contactTokens = Directory.getInstance(this).getPushEligibleContactTokens(number);
List<String> activeTokens = socket.retrieveDirectory(contactTokens);
Set<String> contactTokens = Directory.getInstance(this).getPushEligibleContactTokens(number);
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(contactTokens);
if (activeTokens != null) {
contactTokens.removeAll(activeTokens);
for (ContactTokenDetails activeToken : activeTokens) {
contactTokens.remove(activeToken.getToken());
}
Directory.getInstance(this).setTokens(activeTokens, contactTokens);
}