diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java index 7ae1a13782..75d79edbd3 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java @@ -46,7 +46,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -183,8 +185,8 @@ public class MultiDeviceContactUpdateJob extends BaseJob implements InjectableTy File contactDataFile = createTempFile("multidevice-contact-update"); try { - DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile)); - Collection contacts = ContactAccessor.getInstance().getContactsWithPush(context); + DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile)); + List contacts = getAllContacts(); for (ContactData contactData : contacts) { Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactData.id)); @@ -192,7 +194,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob implements InjectableTy Recipient recipient = Recipient.from(context, address, false); Optional identity = DatabaseFactory.getIdentityDatabase(context).getIdentity(address); Optional verified = getVerifiedMessage(recipient, identity); - Optional name = Optional.fromNullable(DatabaseFactory.getLokiUserDatabase(context).getDisplayName(address.serialize())); + Optional name = Optional.fromNullable(contactData.name); Optional color = Optional.of(recipient.getColor().serialize()); Optional profileKey = Optional.fromNullable(recipient.getProfileKey()); boolean blocked = recipient.isBlocked(); @@ -222,6 +224,20 @@ public class MultiDeviceContactUpdateJob extends BaseJob implements InjectableTy } } + private List getAllContacts() { + List
contactAddresses = DatabaseFactory.getRecipientDatabase(context).getRegistered(); + List contacts = new ArrayList<>(contactAddresses.size()); + for (Address address : contactAddresses) { + if (!address.isPhone()) { continue; } + long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, address, false)); + String name = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(address.serialize()); + ContactData contactData = new ContactData(threadId, name); + contactData.numbers.add(new ContactAccessor.NumberData("TextSecure", address.serialize())); + contacts.add(contactData); + } + return contacts; + } + private LokiThreadFriendRequestStatus getFriendRequestStatus(Recipient recipient) { long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient); return DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId); @@ -259,6 +275,9 @@ public class MultiDeviceContactUpdateJob extends BaseJob implements InjectableTy } private Optional getAvatar(@Nullable Uri uri) throws IOException { + return Optional.absent(); + + /* Loki - Disabled until we support custom avatars. This will need to be reworked if (uri == null) { return Optional.absent(); } @@ -312,6 +331,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob implements InjectableTy cursor.close(); } } + */ } private Optional getVerifiedMessage(Recipient recipient, Optional identity) throws InvalidNumberException { diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index d556f69499..df0d474136 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -667,7 +667,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MessageSender.sendBackgroundFriendRequest(context, deviceContact.getNumber(), "This is an automated friend request. Still under testing!"); } else if (status == LokiThreadFriendRequestStatus.REQUEST_RECEIVED) { // Accept the incoming friend request - becomeFriendsWithContact(deviceContact.getNumber()); + becomeFriendsWithContact(deviceContact.getNumber(), false); } // TODO: Handle blocked - If user is not blocked then we should do the friend request logic otherwise add them to our block list @@ -1131,10 +1131,10 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) { // If we get anything other than a friend request, we can assume that we have a session with the other user if (envelope.isFriendRequest() || isGroupChatMessage(content)) { return; } - becomeFriendsWithContact(content.getSender()); + becomeFriendsWithContact(content.getSender(), true); } - private void becomeFriendsWithContact(String pubKey) { + private void becomeFriendsWithContact(String pubKey, boolean syncContact) { LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context); Recipient contactID = Recipient.from(context, Address.fromSerialized(pubKey), false); long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(contactID); @@ -1144,7 +1144,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // it must be a friend request accepted message. Declining a friend request doesn't send a message. lokiThreadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); // Send out a contact sync message - MessageSender.syncContact(context, contactID.getAddress()); + if (syncContact) { + MessageSender.syncContact(context, contactID.getAddress()); + } // Update the last message if needed LokiStorageAPI.shared.getPrimaryDevicePublicKey(pubKey).success(primaryDevice -> { Util.runOnMain(() -> { @@ -1161,7 +1163,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { boolean shouldBecomeFriends = PromiseUtil.get(MultiDeviceUtilities.shouldAutomaticallyBecomeFriendsWithDevice(content.getSender(), context), false); if (shouldBecomeFriends) { // Become friends AND update the message they sent - becomeFriendsWithContact(content.getSender()); + becomeFriendsWithContact(content.getSender(), true); // Send them an accept message back MessageSender.sendBackgroundMessage(context, content.getSender()); } else {