Include own profile key in normal contact sync

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-09-12 22:49:30 -07:00
parent 2e5b0bcee2
commit 93395c3ff4
2 changed files with 13 additions and 0 deletions

View File

@ -12,6 +12,10 @@ import java.io.IOException;
public class ProfileKeyUtil { public class ProfileKeyUtil {
public static synchronized boolean hasProfileKey(@NonNull Context context) {
return TextSecurePreferences.getProfileKey(context) != null;
}
public static synchronized @NonNull byte[] getProfileKey(@NonNull Context context) { public static synchronized @NonNull byte[] getProfileKey(@NonNull Context context) {
try { try {
String encodedProfileKey = TextSecurePreferences.getProfileKey(context); String encodedProfileKey = TextSecurePreferences.getProfileKey(context);

View File

@ -13,6 +13,7 @@ import android.util.Log;
import org.thoughtcrime.securesms.contacts.ContactAccessor; import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData; import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.IdentityDatabase; import org.thoughtcrime.securesms.database.IdentityDatabase;
@ -20,6 +21,7 @@ import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule.SignalMessageSenderFactory; import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule.SignalMessageSenderFactory;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement; import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.jobqueue.requirements.NetworkRequirement;
@ -137,6 +139,13 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
out.write(new DeviceContact(address.toPhoneString(), name, getAvatar(contactUri), color, verified, profileKey)); out.write(new DeviceContact(address.toPhoneString(), name, getAvatar(contactUri), color, verified, profileKey));
} }
if (ProfileKeyUtil.hasProfileKey(context)) {
out.write(new DeviceContact(TextSecurePreferences.getLocalNumber(context),
Optional.absent(), Optional.absent(),
Optional.absent(), Optional.absent(),
Optional.of(ProfileKeyUtil.getProfileKey(context))));
}
out.close(); out.close();
sendUpdate(messageSender, contactDataFile, true); sendUpdate(messageSender, contactDataFile, true);
} catch(InvalidNumberException e) { } catch(InvalidNumberException e) {