diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 0ab5c36206..f6ba00526d 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -510,7 +510,6 @@ public class ConversationFragment extends Fragment builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount)); builder.setCancelable(true); - // Loki - The delete option is only visible to the user in a public chat LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId); builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { @@ -522,42 +521,52 @@ public class ConversationFragment extends Fragment { @Override protected Void doInBackground(MessageRecord... messageRecords) { - ArrayList serverIDs = new ArrayList<>(); - ArrayList ignoredMessages = new ArrayList<>(); - ArrayList failedMessages = new ArrayList<>(); - boolean isSentByUser = true; - LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(getContext()).getLokiPublicChatAPI(); - for (MessageRecord messageRecord : messageRecords) { - isSentByUser = isSentByUser && messageRecord.isOutgoing(); - Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id); - if (serverID != null) { - serverIDs.add(serverID); - } else { - ignoredMessages.add(messageRecord.getId()); - } - } - if (publicChat != null && publicChatAPI != null) { - publicChatAPI - .deleteMessages(serverIDs, publicChat.getChannel(), publicChat.getServer(), isSentByUser) - .success(l -> { - for (MessageRecord messageRecord : messageRecords) { - Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id); - if (l.contains(serverID)) { - if (messageRecord.isMms()) { - DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId()); - } else { - DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId()); - } - } else if (!ignoredMessages.contains(serverID)) { - failedMessages.add(messageRecord.getId()); - Log.d("Loki", "Failed to delete message: " + messageRecord.getId() + "."); - } + if (publicChat != null) { + ArrayList serverIDs = new ArrayList<>(); + ArrayList ignoredMessages = new ArrayList<>(); + ArrayList failedMessages = new ArrayList<>(); + boolean isSentByUser = true; + LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(getContext()).getLokiPublicChatAPI(); + for (MessageRecord messageRecord : messageRecords) { + isSentByUser = isSentByUser && messageRecord.isOutgoing(); + Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id); + if (serverID != null) { + serverIDs.add(serverID); + } else { + ignoredMessages.add(messageRecord.getId()); } - return null; - }). fail(e -> { - Log.d("Loki", "Couldn't delete message due to error: " + e.toString() + "."); - return null; - }); + } + if (publicChat != null && publicChatAPI != null) { + publicChatAPI + .deleteMessages(serverIDs, publicChat.getChannel(), publicChat.getServer(), isSentByUser) + .success(l -> { + for (MessageRecord messageRecord : messageRecords) { + Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id); + if (l.contains(serverID)) { + if (messageRecord.isMms()) { + DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId()); + } else { + DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId()); + } + } else if (!ignoredMessages.contains(serverID)) { + failedMessages.add(messageRecord.getId()); + Log.d("Loki", "Failed to delete message: " + messageRecord.getId() + "."); + } + } + return null; + }). fail(e -> { + Log.d("Loki", "Couldn't delete message due to error: " + e.toString() + "."); + return null; + }); + } + } else { + for (MessageRecord messageRecord : messageRecords) { + if (messageRecord.isMms()) { + DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId()); + } else { + DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId()); + } + } } return null; } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt index 1ff3367301..5eb2a16be7 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt @@ -40,11 +40,12 @@ class DisplayNameActivity : BaseActionBarActivity() { TextSecurePreferences.setProfileName(this, displayName) TextSecurePreferences.setHasSeenWelcomeScreen(this, true) TextSecurePreferences.setPromptedPushRegistration(this, true) + val application = ApplicationContext.getInstance(this) + application.setUpStorageAPIIfNeeded() + application.setUpP2PAPI() val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI if (publicChatAPI != null) { // TODO: This won't be necessary anymore when we don't auto-join the Loki Public Chat anymore - val application = ApplicationContext.getInstance(this) - application.setUpStorageAPIIfNeeded() application.createDefaultPublicChatsIfNeeded() val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers() servers.forEach { publicChatAPI.setDisplayName(displayName, it) } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt index d2693add68..c57d1b6d25 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/JoinPublicChatActivity.kt @@ -80,7 +80,7 @@ class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCode finish() }.failUi { hideLoader() - Toast.makeText(this, "Couldn't Join Channel", Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Couldn't join channel", Toast.LENGTH_SHORT).show() } } // endregion