From fd9f1b712fcc99833c16a5efb921bc39e26c2985 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 18 Oct 2019 12:40:41 +1100 Subject: [PATCH] Get attachment logic to work. --- res/layout/attachment_type_selector.xml | 166 ++++++++++-------- res/menu/conversation.xml | 4 +- .../conversation/ConversationActivity.java | 4 +- .../conversation/ConversationItem.java | 2 +- .../securesms/database/MmsSmsDatabase.java | 2 +- .../securesms/jobs/PushDecryptJob.java | 5 + .../securesms/jobs/RetrieveProfileJob.java | 3 + .../securesms/sms/MessageSender.java | 37 ++-- 8 files changed, 114 insertions(+), 109 deletions(-) diff --git a/res/layout/attachment_type_selector.xml b/res/layout/attachment_type_selector.xml index 7f96eaae2c..31bdb96240 100644 --- a/res/layout/attachment_type_selector.xml +++ b/res/layout/attachment_type_selector.xml @@ -27,7 +27,7 @@ android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:layout_marginTop="16dp" - android:weightSum="4"> + android:weightSum="2"> + android:layout_height="wrap_content" + android:layout_weight="1" + android:gravity="center" + android:orientation="vertical"> + android:id="@+id/camera_button" + android:layout_width="53dp" + android:layout_height="53dp" + android:src="@drawable/ic_camera_white_24dp" + android:scaleType="center" + android:contentDescription="@string/attachment_type_selector__camera_description" + app:circleColor="@color/green_400"/> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + style="@style/AttachmentTypeLabel" + android:text="@string/attachment_type_selector__camera"/> - + + android:id="@+id/audio_button" + android:layout_width="53dp" + android:layout_height="53dp" + android:contentDescription="@string/attachment_type_selector__audio_description" + android:scaleType="center" + android:src="@drawable/ic_headset_white_24dp" + app:circleColor="@color/orange_400" /> - + + + + + + + + + @@ -102,7 +132,8 @@ android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" - android:layout_weight="1"> + android:layout_weight="1" + android:visibility="gone"> + android:weightSum="2"> - + + android:id="@+id/location_button" + android:layout_width="53dp" + android:layout_height="53dp" + android:contentDescription="@string/attachment_type_selector__location_description" + android:scaleType="center" + android:src="@drawable/ic_location_on_white_24dp" + app:circleColor="@color/blue_grey_400" /> - - - - - - - - - + @@ -223,7 +233,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/AttachmentTypeLabel" - android:text=" "/> + android:text=""/> diff --git a/res/menu/conversation.xml b/res/menu/conversation.xml index 7213e498c3..cd33628267 100644 --- a/res/menu/conversation.xml +++ b/res/menu/conversation.xml @@ -2,10 +2,10 @@ - diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 39412b48ee..d5903cce96 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -792,7 +792,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity switch (item.getItemId()) { case R.id.menu_call_secure: handleDial(getRecipient(), true); return true; case R.id.menu_call_insecure: handleDial(getRecipient(), false); return true; - // case R.id.menu_view_media: handleViewMedia(); return true; + case R.id.menu_view_media: handleViewMedia(); return true; case R.id.menu_add_shortcut: handleAddShortcut(); return true; case R.id.menu_search: handleSearch(); return true; case R.id.menu_add_to_contacts: handleAddToContacts(); return true; @@ -2408,7 +2408,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } if (composeText.getText().length() == 0 && !attachmentManager.isAttachmentPresent()) { - buttonToggle.display(sendButton); + buttonToggle.display(attachButton); quickAttachmentToggle.show(); inlineAttachmentToggle.hide(); } else { diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index 57fbe13391..7e66fbbcd3 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -473,7 +473,7 @@ public class ConversationItem extends LinearLayout if (isCaptionlessMms(messageRecord)) { bodyText.setVisibility(View.GONE); - } else { ; + } else { Spannable text = MentionUtilities.highlightMentions(linkifyMessageBody(messageRecord.getDisplayBody(context), batchSelected.isEmpty()), messageRecord.isOutgoing(), messageRecord.getThreadId(), context); text = SearchUtil.getHighlightedSpan(locale, () -> new BackgroundColorSpan(Color.YELLOW), text, searchQuery); text = SearchUtil.getHighlightedSpan(locale, () -> new ForegroundColorSpan(Color.BLACK), text, searchQuery); diff --git a/src/org/thoughtcrime/securesms/database/MmsSmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsSmsDatabase.java index a2c4da21ff..bfe549eb29 100644 --- a/src/org/thoughtcrime/securesms/database/MmsSmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsSmsDatabase.java @@ -98,7 +98,7 @@ public class MmsSmsDatabase extends Database { public Cursor getConversation(long threadId, long offset, long limit) { String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC"; - String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND LENGTH(" + MmsSmsColumns.BODY + ") > 0"; + String selection = MmsSmsColumns.THREAD_ID + " = " + threadId; String limitStr = limit > 0 || offset > 0 ? offset + ", " + limit : null; Cursor cursor = queryTables(PROJECTION, selection, order, limitStr); diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 0007d8c87c..3abcbcdaea 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -795,6 +795,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MmsDatabase database = DatabaseFactory.getMmsDatabase(context); database.beginTransaction(); + // Ignore message if it has no body and no attachments or anything + if (mediaMessage.getBody().isEmpty() && mediaMessage.getAttachments().isEmpty() && mediaMessage.getSharedContacts().isEmpty() && mediaMessage.getLinkPreviews().isEmpty()) { + return; + } + Optional insertResult; try { diff --git a/src/org/thoughtcrime/securesms/jobs/RetrieveProfileJob.java b/src/org/thoughtcrime/securesms/jobs/RetrieveProfileJob.java index e7effa2eb5..43d3fdde7d 100644 --- a/src/org/thoughtcrime/securesms/jobs/RetrieveProfileJob.java +++ b/src/org/thoughtcrime/securesms/jobs/RetrieveProfileJob.java @@ -77,12 +77,15 @@ public class RetrieveProfileJob extends BaseJob implements InjectableType { @Override public void onRun() throws IOException, InvalidKeyException { + // Loki - Disable retrieve profile + /* try { if (recipient.isGroupRecipient()) handleGroupRecipient(recipient); else handleIndividualRecipient(recipient); } catch (InvalidNumberException e) { Log.w(TAG, e); } + */ } @Override diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index d6cb29279d..195db0e6d9 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -58,6 +58,7 @@ import org.whispersystems.signalservice.loki.api.LokiStorageAPI; import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import java.io.IOException; +import java.util.function.Function; import kotlin.Unit; @@ -117,32 +118,18 @@ public class MessageSender { // 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); - // Loki - Set the message's friend request status as soon as it has hit the database - if (message.isFriendRequest) { - DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_SENDING); - } - sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn()); - } catch (Exception e) { - Log.w(TAG, e); - // TODO: Handle - } - } else { - try { - long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); - // Loki - Set the message's friend request status as soon as it has hit the database - if (message.isFriendRequest) { - DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_SENDING); - } - sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn()); - } catch (MmsException e) { - Log.w(TAG, e); - // TODO: Handle + Attachment attachment = attachmentOrNull.orNull(); + try { + if (attachment != null) { message.getAttachments().add(attachment); } + long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); + // Loki - Set the message's friend request status as soon as it has hit the database + if (message.isFriendRequest) { + DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_SENDING); } + sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn()); + } catch (Exception e) { + Log.w(TAG, e); + // TODO: Handle } })); } else {