From 526e82a9e382fd496d5aed78dc108487d46721e6 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Sun, 16 Feb 2020 09:30:05 +1100 Subject: [PATCH] Clean up naming & indentation --- .../conversation/ConversationActivity.java | 5 --- .../securesms/jobs/PushDecryptJob.java | 31 +++++++++---------- .../securesms/jobs/PushMediaSendJob.java | 10 +++--- .../securesms/jobs/PushTextSendJob.java | 12 +++---- .../securesms/sms/MessageSender.java | 14 ++++----- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index df801ae584..04a96108a5 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2413,13 +2413,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity sendTextMessage(forceSms, expiresIn, subscriptionId, initiating); } } catch (RecipientFormattingException ex) { - Toast.makeText(ConversationActivity.this, - R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation, - Toast.LENGTH_LONG).show(); Log.w(TAG, ex); } catch (InvalidMessageException ex) { - // Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_message_is_empty_exclamation, - // Toast.LENGTH_SHORT).show(); Log.w(TAG, ex); } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index afb86f70b6..49163e4f2f 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -283,7 +283,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType { return; } - if (shouldIgnore(content)) { Log.i(TAG, "Ignoring message."); return; @@ -869,7 +868,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // Ignore messages from ourselves if (sender.serialize().equalsIgnoreCase(TextSecurePreferences.getLocalNumber(context))) { return; } - IncomingMediaMessage mediaMessage = new IncomingMediaMessage(sender, message.getTimestamp(), -1, + IncomingMediaMessage mediaMessage = new IncomingMediaMessage(sender, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000L, false, content.isNeedsReceipt(), message.getBody(), message.getGroupInfo(), message.getAttachments(), quote, sharedContacts, linkPreviews, sticker); @@ -913,12 +912,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); } - // Loki - Run db updates in the background, we should look into fixing this in the future + // Loki - Run database updates in the background, we should look into fixing this in the future AsyncTask.execute(() -> { // Loki - Store message server ID updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); - // Loki - Update mapping of message to original thread id + // Loki - Update mapping of message to original thread ID if (insertResult.isPresent()) { ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context); LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context); @@ -1036,10 +1035,10 @@ public class PushDecryptJob extends BaseJob implements InjectableType { @NonNull Optional messageServerIDOrNull) throws StorageFailedException { - SmsDatabase database = DatabaseFactory.getSmsDatabase(context); - String body = message.getBody().isPresent() ? message.getBody().get() : ""; + SmsDatabase database = DatabaseFactory.getSmsDatabase(context); + String body = message.getBody().isPresent() ? message.getBody().get() : ""; Recipient originalRecipient = getRecipientForMessage(content, message); - Recipient masterRecipient = getMasterRecipientForMessage(content, message); + Recipient masterRecipient = getMasterRecipientForMessage(content, message); if (message.getExpiresInSeconds() != originalRecipient.getExpireMessages()) { handleExpirationUpdate(content, message, Optional.absent()); @@ -1062,14 +1061,14 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // Ignore messages from ourselves if (sender.serialize().equalsIgnoreCase(TextSecurePreferences.getLocalNumber(context))) { return; } - IncomingTextMessage _textMessage = new IncomingTextMessage(sender, - content.getSenderDevice(), - message.getTimestamp(), body, - message.getGroupInfo(), - message.getExpiresInSeconds() * 1000L, - content.isNeedsReceipt()); + IncomingTextMessage tm = new IncomingTextMessage(sender, + content.getSenderDevice(), + message.getTimestamp(), body, + message.getGroupInfo(), + message.getExpiresInSeconds() * 1000L, + content.isNeedsReceipt()); - IncomingEncryptedMessage textMessage = new IncomingEncryptedMessage(_textMessage, body); + IncomingEncryptedMessage textMessage = new IncomingEncryptedMessage(tm, body); // Ignore the message if the body is empty if (textMessage.getMessageBody().length() == 0) { return; } @@ -1087,7 +1086,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MessageNotifier.updateNotification(context, threadId); } - // Loki - Run db updates in background, we should look into fixing this in the future + // Loki - Run database updates in background, we should look into fixing this in the future AsyncTask.execute(() -> { if (insertResult.isPresent()) { InsertResult result = insertResult.get(); @@ -1098,7 +1097,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // Loki - Store message server ID updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); - // Loki - Update mapping of message to original thread id + // Loki - Update mapping of message to original thread ID if (result.getMessageId() > -1) { ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context); LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context); diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 322642bc7b..09bab54caa 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -289,11 +289,11 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { } else { LokiSyncMessage syncMessage = null; if (shouldSendSyncMessage) { - // Set the sync message destination the primary device, this way it will show that we sent a message to the primary device and not a secondary device - String primaryDevice = PromiseUtil.get(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(address.getNumber()), null); - SignalServiceAddress primaryAddress = primaryDevice == null ? address : new SignalServiceAddress(primaryDevice); - // We also need to use the original message id and not -1 - syncMessage = new LokiSyncMessage(primaryAddress, templateMessageId); + // Set the sync message destination to the master device, this way it will show that we sent a message to the master device and not the slave device + String masterDevice = PromiseUtil.get(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(address.getNumber()), null); + SignalServiceAddress masterAddress = masterDevice == null ? address : new SignalServiceAddress(masterDevice); + // We also need to use the original message ID and not -1 + syncMessage = new LokiSyncMessage(masterAddress, templateMessageId); } return messageSender.sendMessage(messageId, address, UnidentifiedAccessUtil.getAccessFor(context, recipient), mediaMessage, Optional.fromNullable(syncMessage)).getSuccess().isUnidentified(); } diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index 95d6cc8908..7c0f04834a 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -200,7 +200,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { { try { // rotateSenderCertificateIfNecessary(); - Recipient recipient = Recipient.from(context, destination, false); + Recipient recipient = Recipient.from(context, destination, false); SignalServiceAddress address = getPushAddress(recipient.getAddress()); Optional profileKey = getProfileKey(recipient); Optional unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient); @@ -235,11 +235,11 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { } else { LokiSyncMessage syncMessage = null; if (shouldSendSyncMessage) { - // Set the sync message destination to the primary device, this way it will show that we sent a message to the primary device and not a secondary device - String primaryDevice = PromiseUtil.get(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(address.getNumber()), null); - SignalServiceAddress primaryAddress = primaryDevice == null ? address : new SignalServiceAddress(primaryDevice); - // We also need to use the original message id and not -1 - syncMessage = new LokiSyncMessage(primaryAddress, templateMessageId); + // Set the sync message destination to the master device, this way it will show that we sent a message to the master device and not the slave device + String masterDevice = PromiseUtil.get(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(address.getNumber()), null); + SignalServiceAddress masterAddress = masterDevice == null ? address : new SignalServiceAddress(masterDevice); + // We also need to use the original message ID and not -1 + syncMessage = new LokiSyncMessage(masterAddress, templateMessageId); } return messageSender.sendMessage(messageId, address, unidentifiedAccess, textSecureMessage, Optional.fromNullable(syncMessage)).getSuccess().isUnidentified(); } diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index d8c8e20fc5..16e7a06842 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -306,8 +306,8 @@ public class MessageSender { JobManager jobManager = ApplicationContext.getInstance(context).getJobManager(); // Just send the message normally if it's a group message or we're sending to one of our devices - String recipientPublicKey = recipient.getAddress().serialize(); - if (GeneralUtilitiesKt.isPublicChat(context, recipientPublicKey) || PromiseUtil.get(MultiDeviceUtilities.isOneOfOurDevices(context, recipient.getAddress()), false)) { + String recipientHexEncodedPublicKey = recipient.getAddress().serialize(); + if (GeneralUtilitiesKt.isPublicChat(context, recipientHexEncodedPublicKey) || PromiseUtil.get(MultiDeviceUtilities.isOneOfOurDevices(context, recipient.getAddress()), false)) { if (type == MessageType.MEDIA) { PushMediaSendJob.enqueue(context, jobManager, messageId, recipient.getAddress(), false); } else { @@ -318,16 +318,16 @@ public class MessageSender { // If we get here then we are sending a message to a device that is not ours boolean[] hasSentSyncMessage = { false }; - MultiDeviceUtilities.getAllDevicePublicKeysWithFriendStatus(context, recipientPublicKey).success(devices -> { + MultiDeviceUtilities.getAllDevicePublicKeysWithFriendStatus(context, recipientHexEncodedPublicKey).success(devices -> { int friendCount = MultiDeviceUtilities.getFriendCount(context, devices.keySet()); Util.runOnMain(() -> { ArrayList jobs = new ArrayList<>(); for (Map.Entry entry : devices.entrySet()) { - String devicePublicKey = entry.getKey(); + String deviceHexEncodedPublicKey = entry.getKey(); boolean isFriend = entry.getValue(); - Address address = Address.fromSerialized(devicePublicKey); - long messageIDToUse = recipientPublicKey.equals(devicePublicKey) ? messageId : -1L; + Address address = Address.fromSerialized(deviceHexEncodedPublicKey); + long messageIDToUse = recipientHexEncodedPublicKey.equals(deviceHexEncodedPublicKey) ? messageId : -1L; if (isFriend) { // Send a normal message if the user is friends with the recipient @@ -340,7 +340,7 @@ public class MessageSender { } if (shouldSendSyncMessage) { hasSentSyncMessage[0] = true; } } else { - // Send friend requests to non friends. If the user is friends with any + // Send friend requests to non-friends. If the user is friends with any // of the devices then send out a default friend request message. boolean isFriendsWithAny = (friendCount > 0); String defaultFriendRequestMessage = isFriendsWithAny ? "Please accept to enable messages to be synced across devices" : null;