ask for permission when committing attachments. fixes #3248

This commit is contained in:
Daniel Gultsch 2018-10-24 20:00:06 +02:00
parent 185d36d270
commit bb6ddae76b
1 changed files with 26 additions and 14 deletions

View File

@ -129,6 +129,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public static final int REQUEST_TRUST_KEYS_ATTACHMENTS = 0x0209; public static final int REQUEST_TRUST_KEYS_ATTACHMENTS = 0x0209;
public static final int REQUEST_START_DOWNLOAD = 0x0210; public static final int REQUEST_START_DOWNLOAD = 0x0210;
public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211; public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211;
public static final int REQUEST_COMMIT_ATTACHMENTS = 0x0212;
public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
@ -723,7 +724,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return; return;
} }
final Editable text = this.binding.textinput.getText(); final Editable text = this.binding.textinput.getText();
final String body = text == null ? "" : text.toString(); final String body = text == null ? "" : text.toString();
final Conversation conversation = this.conversation; final Conversation conversation = this.conversation;
if (body.length() == 0 || conversation == null) { if (body.length() == 0 || conversation == null) {
return; return;
@ -861,6 +862,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
private void commitAttachments() { private void commitAttachments() {
if (!hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
return;
}
if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) { if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) {
return; return;
} }
@ -1402,16 +1406,23 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if (grantResults.length > 0) { if (grantResults.length > 0) {
if (allGranted(grantResults)) { if (allGranted(grantResults)) {
if (requestCode == REQUEST_START_DOWNLOAD) { switch (requestCode) {
if (this.mPendingDownloadableMessage != null) { case REQUEST_START_DOWNLOAD:
startDownloadable(this.mPendingDownloadableMessage); if (this.mPendingDownloadableMessage != null) {
} startDownloadable(this.mPendingDownloadableMessage);
} else if (requestCode == REQUEST_ADD_EDITOR_CONTENT) { }
if (this.mPendingEditorContent != null) { break;
attachEditorContentToConversation(this.mPendingEditorContent); case REQUEST_ADD_EDITOR_CONTENT:
} if (this.mPendingEditorContent != null) {
} else { attachEditorContentToConversation(this.mPendingEditorContent);
attachFile(requestCode); }
break;
case REQUEST_COMMIT_ATTACHMENTS:
commitAttachments();
break;
default:
attachFile(requestCode);
break;
} }
} else { } else {
@StringRes int res; @StringRes int res;
@ -1430,6 +1441,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (activity != null && activity.xmppConnectionService != null) { if (activity != null && activity.xmppConnectionService != null) {
activity.xmppConnectionService.restartFileObserver(); activity.xmppConnectionService.restartFileObserver();
} }
refresh();
} }
} }
@ -2047,7 +2059,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private List<Uri> cleanUris(List<Uri> uris) { private List<Uri> cleanUris(List<Uri> uris) {
Iterator<Uri> iterator = uris.iterator(); Iterator<Uri> iterator = uris.iterator();
while(iterator.hasNext()) { while (iterator.hasNext()) {
final Uri uri = iterator.next(); final Uri uri = iterator.next();
if (FileBackend.weOwnFile(getActivity(), uri)) { if (FileBackend.weOwnFile(getActivity(), uri)) {
iterator.remove(); iterator.remove();
@ -2552,9 +2564,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return; return;
} }
final Editable editable = this.binding.textinput.getText(); final Editable editable = this.binding.textinput.getText();
String previous = editable == null ? "" : editable.toString(); String previous = editable == null ? "" : editable.toString();
if (doNotAppend && !TextUtils.isEmpty(previous)) { if (doNotAppend && !TextUtils.isEmpty(previous)) {
Toast.makeText(getActivity(),R.string.already_drafting_message, Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), R.string.already_drafting_message, Toast.LENGTH_LONG).show();
return; return;
} }
if (UIHelper.isLastLineQuote(previous)) { if (UIHelper.isLastLineQuote(previous)) {