|
23 | 23 | import android.content.DialogInterface; |
24 | 24 | import android.content.Intent; |
25 | 25 | import android.content.IntentFilter; |
26 | | -import android.graphics.Bitmap; |
27 | | -import android.graphics.drawable.BitmapDrawable; |
28 | 26 | import android.net.Uri; |
29 | 27 | import android.os.AsyncTask; |
30 | 28 | import android.os.Build; |
|
92 | 90 | import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage; |
93 | 91 | import org.thoughtcrime.securesms.sms.OutgoingTextMessage; |
94 | 92 | import org.thoughtcrime.securesms.util.BitmapDecodingException; |
95 | | -import org.thoughtcrime.securesms.util.BitmapUtil; |
96 | 93 | import org.thoughtcrime.securesms.util.CharacterCalculator; |
97 | 94 | import org.thoughtcrime.securesms.util.Dialogs; |
98 | 95 | import org.thoughtcrime.securesms.util.DirectoryHelper; |
@@ -538,6 +535,7 @@ private void handleDeleteThread() { |
538 | 535 | public void onClick(DialogInterface dialog, int which) { |
539 | 536 | if (threadId > 0) { |
540 | 537 | DatabaseFactory.getThreadDatabase(ConversationActivity.this).deleteConversation(threadId); |
| 538 | + threadId = -1; |
541 | 539 | finish(); |
542 | 540 | } |
543 | 541 | } |
@@ -919,28 +917,34 @@ private Drafts getDraftsForCurrentState() { |
919 | 917 | } |
920 | 918 |
|
921 | 919 | private void saveDraft() { |
922 | | - if (this.threadId <= 0 || this.recipients == null || this.recipients.isEmpty()) |
| 920 | + if (this.recipients == null || this.recipients.isEmpty()) |
923 | 921 | return; |
924 | 922 |
|
925 | | - final Drafts drafts = getDraftsForCurrentState(); |
926 | | - final long thisThreadId = this.threadId; |
927 | | - final MasterSecret thisMasterSecret = this.masterSecret.parcelClone(); |
| 923 | + final Drafts drafts = getDraftsForCurrentState(); |
| 924 | + final long thisThreadId = this.threadId; |
| 925 | + final MasterSecret thisMasterSecret = this.masterSecret.parcelClone(); |
| 926 | + final int thisDistributionType = this.distributionType; |
928 | 927 |
|
929 | | - new AsyncTask<Void, Void, Void>() { |
| 928 | + new AsyncTask<Long, Void, Void>() { |
930 | 929 | @Override |
931 | | - protected Void doInBackground(Void... params) { |
932 | | - MasterCipher masterCipher = new MasterCipher(thisMasterSecret); |
933 | | - DatabaseFactory.getDraftDatabase(ConversationActivity.this).insertDrafts(masterCipher, thisThreadId, drafts); |
| 930 | + protected Void doInBackground(Long... params) { |
934 | 931 | ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this); |
| 932 | + DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this); |
| 933 | + long threadId = params[0]; |
| 934 | + |
935 | 935 | if (drafts.size() > 0) { |
936 | | - threadDatabase.updateSnippet(thisThreadId, drafts.getSnippet(ConversationActivity.this), Types.BASE_DRAFT_TYPE); |
937 | | - } else { |
938 | | - threadDatabase.update(thisThreadId); |
| 936 | + if (threadId == -1) threadId = threadDatabase.getThreadIdFor(getRecipients(), thisDistributionType); |
| 937 | + |
| 938 | + draftDatabase.insertDrafts(new MasterCipher(thisMasterSecret), threadId, drafts); |
| 939 | + threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), Types.BASE_DRAFT_TYPE); |
| 940 | + } else if (threadId > 0) { |
| 941 | + threadDatabase.update(threadId); |
939 | 942 | } |
| 943 | + |
940 | 944 | MemoryCleaner.clean(thisMasterSecret); |
941 | 945 | return null; |
942 | 946 | } |
943 | | - }.execute(); |
| 947 | + }.execute(thisThreadId); |
944 | 948 | } |
945 | 949 |
|
946 | 950 | private void calculateCharactersRemaining() { |
|
0 commit comments