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

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;
@ -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) {
case REQUEST_START_DOWNLOAD:
if (this.mPendingDownloadableMessage != null) { if (this.mPendingDownloadableMessage != null) {
startDownloadable(this.mPendingDownloadableMessage); startDownloadable(this.mPendingDownloadableMessage);
} }
} else if (requestCode == REQUEST_ADD_EDITOR_CONTENT) { break;
case REQUEST_ADD_EDITOR_CONTENT:
if (this.mPendingEditorContent != null) { if (this.mPendingEditorContent != null) {
attachEditorContentToConversation(this.mPendingEditorContent); attachEditorContentToConversation(this.mPendingEditorContent);
} }
} else { break;
case REQUEST_COMMIT_ATTACHMENTS:
commitAttachments();
break;
default:
attachFile(requestCode); 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();
@ -2554,7 +2566,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
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)) {