From a78b8a77b64ea279e52d4224480fccf83bfb4136 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 18 Sep 2019 10:00:18 +1000 Subject: [PATCH] Clean --- .../securesms/conversation/ConversationActivity.java | 2 +- .../thoughtcrime/securesms/jobs/PushGroupSendJob.java | 3 ++- .../thoughtcrime/securesms/jobs/PushMediaSendJob.java | 1 + .../thoughtcrime/securesms/loki/LokiMessageDatabase.kt | 2 -- .../thoughtcrime/securesms/loki/LokiUserDatabase.kt | 4 ++-- src/org/thoughtcrime/securesms/loki/RNG.kt | 10 ++++++---- src/org/thoughtcrime/securesms/sms/MessageSender.java | 9 +++++---- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 8da4fd994e..16232c1979 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2186,7 +2186,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity recipient.getAddress().isEmail() || inputPanel.getQuote().isPresent() || linkPreviewViewModel.hasLinkPreview() || - LinkPreviewUtil.isWhitelistedMediaUrl(message) || + LinkPreviewUtil.isWhitelistedMediaUrl(message) || // Loki - Send GIFs as media messages needsSplit; Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection()); diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 4d8b3e5775..c7e6291eff 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -95,6 +95,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { OutgoingMediaMessage message = database.getOutgoingMessage(messageId); List attachments = new LinkedList<>(); + // Loki - For now all attachments are re-fetched by the receiver // attachments.addAll(message.getAttachments()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); @@ -284,7 +285,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { private @NonNull List
getGroupMessageRecipients(String groupId, long messageId) { ArrayList
result = new ArrayList<>(); - result.add(Address.fromSerialized(LokiGroupChatAPI.getPublicChatServer())); + result.add(Address.fromSerialized(LokiGroupChatAPI.getPublicChatServer())); // Loki - All group messages should be directed to the Loki Public Chat for now return result; /* diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index dd39fcb69d..50ec0fa8e1 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -76,6 +76,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { OutgoingMediaMessage message = database.getOutgoingMessage(messageId); List attachments = new LinkedList<>(); + // Loki - For now all attachments are re-fetched by the receiver // attachments.addAll(message.getAttachments()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); diff --git a/src/org/thoughtcrime/securesms/loki/LokiMessageDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiMessageDatabase.kt index b0459cee98..11429c1e84 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiMessageDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiMessageDatabase.kt @@ -18,8 +18,6 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab @JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $serverID INTEGER DEFAULT 0, $friendRequestStatus INTEGER DEFAULT 0);" } - // TODO: Move the server ID stuff to LokiAPIDatabase? - fun getServerID(messageID: Long): Long? { val database = databaseHelper.readableDatabase return database.get(tableName, "${Companion.messageID} = ?", arrayOf( messageID.toString() )) { cursor -> diff --git a/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt index 5b907f8be7..c84279b33e 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt @@ -31,7 +31,7 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database return TextSecurePreferences.getProfileName(context) } else { val database = databaseHelper.readableDatabase - return database.get(displayNameTable, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor -> + return database.get(displayNameTable, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor -> cursor.getString(cursor.getColumnIndexOrThrow(displayName)) } } @@ -48,7 +48,7 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database fun getServerDisplayName(serverID: String, hexEncodedPublicKey: String): String? { val database = databaseHelper.readableDatabase - return database.get(serverDisplayNameTable, "${Companion.hexEncodedPublicKey} = ? AND ${Companion.serverID} = ?", arrayOf(hexEncodedPublicKey, serverID)) { cursor -> + return database.get(serverDisplayNameTable, "${Companion.hexEncodedPublicKey} = ? AND ${Companion.serverID} = ?", arrayOf( hexEncodedPublicKey, serverID )) { cursor -> cursor.getString(cursor.getColumnIndexOrThrow(displayName)) } } diff --git a/src/org/thoughtcrime/securesms/loki/RNG.kt b/src/org/thoughtcrime/securesms/loki/RNG.kt index 208414785a..e445e07a19 100644 --- a/src/org/thoughtcrime/securesms/loki/RNG.kt +++ b/src/org/thoughtcrime/securesms/loki/RNG.kt @@ -4,22 +4,24 @@ class RNG(hash: Long) { private var seed: Long private val initial: Long + private val maxInt32 = Int.MAX_VALUE.toLong() + init { - seed = hash % 2147483647 + seed = hash % maxInt32 if (seed <= 0) { - seed = 2147483646 + seed = maxInt32 - 1 } initial = seed } fun next(): Long { - val newSeed = (seed * 16807) % 2147483647 + val newSeed = (seed * 16807) % maxInt32 seed = newSeed return seed } fun nextFloat(): Float { - return (next() - 1).toFloat() / 2147483646 + return (next() - 1).toFloat() / (maxInt32 - 1) } fun reset() { diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index a33ac1d25e..9f24c9d1ae 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -109,21 +109,22 @@ public class MessageSender { Recipient recipient = message.getRecipient(); + // Loki - Turn into a GIF message if possible if (message.getLinkPreviews().isEmpty() && message.getAttachments().isEmpty() && LinkPreviewUtil.isWhitelistedMediaUrl(message.getBody())) { new LinkPreviewRepository(context).fetchGIF(context, message.getBody(), attachmentOrNull -> Util.runOnMain(() -> { if (attachmentOrNull.isPresent()) { Attachment attachment = attachmentOrNull.get(); try { message.getAttachments().add(attachment); - long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); - sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); + long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); + sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn()); } catch (Exception e) { // TODO: Handle } } else { try { - long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); - sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); + long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); + sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn()); } catch (MmsException e) { // TODO: Handle }