Skip to content

Commit 9dd68bc

Browse files
dallo28claude
andcommitted
Respect protected content for photos in rich text messages
Photos inside a rich text message are opened through ChatActivity.openArticlePhoto(), which uses PhotoViewer's page-block mode (originally built for Instant View). That entry point passes no MessageObject and dialogId 0, so the no-forwards check in page-block mode (isPeerNoForwards(currentDialogId)) always passed: "Save to Gallery", "Open in" and "Save GIF" stayed available and FLAG_SECURE was never set, even in chats with protected content or private chats with Disable Sharing on. Resolve protection from the adapter's parent MessageObject (peer no-forwards, per-message noforwards, revealed paid media) and use it to compute allowShare, hide the Save to Gallery button, guard the save action, and apply FLAG_SECURE. Instant View articles, whose parent is the page itself, are unaffected. Also reset the "Stop downloading" item in onPhotoShow() together with the other menu items. It kept its initial VISIBLE state on the first open, so checkHideMenuItem() left the "more" button visible; with "Save to Gallery" hidden this showed an empty popup. checkProgress() still shows the item when the media is actually loading. Fixes https://bugs.telegram.org/c/64694 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f32ffee commit 9dd68bc

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

‎TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4918,6 +4918,9 @@ public void onItemClick(int id) {
49184918
}
49194919
closePhoto(true, false);
49204920
} else if (id == gallery_menu_save) {
4921+
if (pageBlocksAdapter != null && !allowShare) {
4922+
return;
4923+
}
49214924
if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
49224925
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
49234926
return;
@@ -13998,6 +14001,7 @@ private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLoca
1399814001
menuItem.hideSubItem(gallery_menu_edit_avatar);
1399914002
menuItem.hideSubItem(gallery_menu_set_as_main);
1400014003
menuItem.hideSubItem(gallery_menu_delete);
14004+
menuItem.hideSubItem(gallery_menu_cancel_loading);
1400114005
speedItem.setVisibility(View.GONE);
1400214006
speedGap.setVisibility(View.GONE);
1400314007
videoItem.setVisibility(View.GONE);
@@ -15144,7 +15148,7 @@ private void setIsAboutToSwitchToIndex(int index, boolean init, boolean animated
1514415148
}
1514515149
menuItem.hideSubItem(gallery_menu_translate);
1514615150
menuItem.hideSubItem(gallery_menu_hide_translation);
15147-
allowShare = !MessagesController.getInstance(currentAccount).isPeerNoForwards(currentDialogId) && (currentMessageObject == null || !currentMessageObject.hasRevealedExtendedMedia());
15151+
allowShare = !MessagesController.getInstance(currentAccount).isPeerNoForwards(currentDialogId) && (currentMessageObject == null || !currentMessageObject.hasRevealedExtendedMedia()) && !isPageBlocksNoForwards(pageBlocksAdapter);
1514815152
TL_iv.PageBlock pageBlock = pageBlocksAdapter.get(switchingToIndex);
1514915153
caption = pageBlocksAdapter.getCaption(switchingToIndex);
1515015154
isVideo = pageBlocksAdapter.isVideo(switchingToIndex);
@@ -15193,8 +15197,8 @@ private void setIsAboutToSwitchToIndex(int index, boolean init, boolean animated
1519315197
title = getString(R.string.AttachPhoto);
1519415198
}
1519515199
}
15196-
galleryButton.setVisibility(View.VISIBLE);
15197-
galleryGap.setVisibility(View.VISIBLE);
15200+
galleryButton.setVisibility(allowShare ? View.VISIBLE : View.GONE);
15201+
galleryGap.setVisibility(allowShare ? View.VISIBLE : View.GONE);
1519815202
menuItem.hideSubItem(gallery_menu_savegif);
1519915203
menuItem.checkHideMenuItem();
1520015204
}
@@ -17445,7 +17449,8 @@ public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLoca
1744517449
if (chatActivity != null && chatActivity.getCurrentEncryptedChat() != null ||
1744617450
avatarsDialogId != 0 && MessagesController.getInstance(currentAccount).isPeerNoForwards(avatarsDialogId) ||
1744717451
messageObject != null && (MessagesController.getInstance(currentAccount).isPeerNoForwards(messageObject.getDialogId()) ||
17448-
(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) || messageObject != null && messageObject.hasRevealedExtendedMedia()
17452+
(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) || messageObject != null && messageObject.hasRevealedExtendedMedia() ||
17453+
isPageBlocksNoForwards(pageBlocksAdapter)
1744917454
) {
1745017455
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
1745117456
AndroidUtilities.logFlagSecure();
@@ -19442,6 +19447,20 @@ private boolean shouldMessageObjectAutoPlayed(MessageObject messageObject) {
1944219447
return messageObject != null && messageObject.isVideo() && (messageObject.mediaExists || messageObject.attachPathExists || messageObject.hasVideoQualities() || messageObject.canStreamVideo() && SharedConfig.streamMedia) && SharedConfig.isAutoplayVideo();
1944319448
}
1944419449

19450+
private boolean isPageBlocksNoForwards(PageBlocksAdapter adapter) {
19451+
if (adapter == null) {
19452+
return false;
19453+
}
19454+
// rich messages open their media as page blocks without a MessageObject/dialogId,
19455+
// so protected content has to be resolved from the adapter's parent message
19456+
final Object parent = adapter.getParentObject();
19457+
if (parent instanceof MessageObject && ((MessageObject) parent).messageOwner != null) {
19458+
final MessageObject messageObject = (MessageObject) parent;
19459+
return MessagesController.getInstance(currentAccount).isPeerNoForwards(messageObject.getDialogId()) || messageObject.messageOwner.noforwards || messageObject.hasRevealedExtendedMedia();
19460+
}
19461+
return false;
19462+
}
19463+
1944519464
private boolean shouldIndexAutoPlayed(int index) {
1944619465
if (pageBlocksAdapter != null) {
1944719466
if ((pageBlocksAdapter.isVideo(index) || pageBlocksAdapter.isHardwarePlayer(index)) && SharedConfig.isAutoplayVideo()) {

0 commit comments

Comments
 (0)