@@ -17804,7 +17804,7 @@ private int getMessageType(MessageObject messageObject) {
17804
17804
}
17805
17805
}
17806
17806
if (!canSave) {
17807
- if (messageObject.mediaExists) {
17807
+ if (messageObject.mediaExists() ) {
17808
17808
canSave = true;
17809
17809
}
17810
17810
}
@@ -31683,12 +31683,25 @@ private void saveMessageToGallery(MessageObject messageObject) {
31683
31683
}
31684
31684
}
31685
31685
if (TextUtils.isEmpty(path)) {
31686
- path = FileLoader.getInstance(currentAccount).getPathToMessage(messageObject.messageOwner).toString();
31686
+ File f = FileLoader.getInstance(currentAccount).getPathToMessage(messageObject.messageOwner);
31687
+ if (f != null && f.exists()) {
31688
+ path = f.getPath();
31689
+ }
31690
+ }
31691
+ if (TextUtils.isEmpty(path) && messageObject.cachedQuality != null && messageObject.cachedQuality.isCached()) {
31692
+ File f = new File(messageObject.cachedQuality.uri.getPath());
31693
+ if (f != null && f.exists()) {
31694
+ path = f.getPath();
31695
+ }
31687
31696
}
31688
- if (messageObject.qualityToSave != null) {
31697
+ if (TextUtils.isEmpty(path) && messageObject.qualityToSave != null) {
31689
31698
File f = FileLoader.getInstance(currentAccount).getPathToAttach(messageObject.qualityToSave, null, false, true);
31690
- if (f == null) return;
31691
- path = f.getPath();
31699
+ if (f != null && f.exists()) {
31700
+ path = f.getPath();
31701
+ }
31702
+ }
31703
+ if (TextUtils.isEmpty(path)) {
31704
+ return;
31692
31705
}
31693
31706
MediaController.saveFile(path, getParentActivity(), messageObject.isVideo() ? 1 : 0, null, null);
31694
31707
}
@@ -31900,8 +31913,23 @@ private void processSelectedOption(int option) {
31900
31913
path = null;
31901
31914
}
31902
31915
}
31903
- if (path == null || path.length() == 0) {
31904
- path = getFileLoader().getPathToMessage(selectedObject.messageOwner).toString();
31916
+ if (TextUtils.isEmpty(path)) {
31917
+ File f = FileLoader.getInstance(currentAccount).getPathToMessage(selectedObject.messageOwner);
31918
+ if (f != null && f.exists()) {
31919
+ path = f.getPath();
31920
+ }
31921
+ }
31922
+ if (TextUtils.isEmpty(path) && selectedObject.cachedQuality != null && selectedObject.cachedQuality.isCached()) {
31923
+ File f = new File(selectedObject.cachedQuality.uri.getPath());
31924
+ if (f != null && f.exists()) {
31925
+ path = f.getPath();
31926
+ }
31927
+ }
31928
+ if (TextUtils.isEmpty(path) && selectedObject.qualityToSave != null) {
31929
+ File f = FileLoader.getInstance(currentAccount).getPathToAttach(selectedObject.qualityToSave, null, false, true);
31930
+ if (f != null && f.exists()) {
31931
+ path = f.getPath();
31932
+ }
31905
31933
}
31906
31934
if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
31907
31935
getParentActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
@@ -31910,6 +31938,9 @@ private void processSelectedOption(int option) {
31910
31938
selectedObjectToEditCaption = null;
31911
31939
return;
31912
31940
}
31941
+ if (TextUtils.isEmpty(path)) {
31942
+ return;
31943
+ }
31913
31944
MediaController.saveFile(path, getParentActivity(), 0, null, null);
31914
31945
BulletinFactory.createSaveToGalleryBulletin(this, selectedObject.isVideo(), themeDelegate).show();
31915
31946
break;
@@ -31992,8 +32023,23 @@ private void processSelectedOption(int option) {
31992
32023
path = null;
31993
32024
}
31994
32025
}
31995
- if (path == null || path.length() == 0) {
31996
- path = getFileLoader().getPathToMessage(selectedObject.messageOwner).toString();
32026
+ if (TextUtils.isEmpty(path)) {
32027
+ File f = FileLoader.getInstance(currentAccount).getPathToMessage(selectedObject.messageOwner);
32028
+ if (f != null && f.exists()) {
32029
+ path = f.getPath();
32030
+ }
32031
+ }
32032
+ if (TextUtils.isEmpty(path) && selectedObject.cachedQuality != null && selectedObject.cachedQuality.isCached()) {
32033
+ File f = new File(selectedObject.cachedQuality.uri.getPath());
32034
+ if (f != null && f.exists()) {
32035
+ path = f.getPath();
32036
+ }
32037
+ }
32038
+ if (TextUtils.isEmpty(path) && selectedObject.qualityToSave != null) {
32039
+ File f = FileLoader.getInstance(currentAccount).getPathToAttach(selectedObject.qualityToSave, null, false, true);
32040
+ if (f != null && f.exists()) {
32041
+ path = f.getPath();
32042
+ }
31997
32043
}
31998
32044
MediaController.saveFile(path, getParentActivity(), 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : "", uri -> {
31999
32045
if (getParentActivity() == null) {
0 commit comments