Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6565,15 +6565,45 @@ public boolean isChatNoForwards(TLRPC.Chat chat) {
if (chat == null) {
return false;
}
if (shouldBypassNoForwardsForCurrentUser(chat)) {
return false;
}
if (chat.migrated_to != null) {
TLRPC.Chat migratedTo = getChat(chat.migrated_to.channel_id);
if (migratedTo != null) {
if (shouldBypassNoForwardsForCurrentUser(migratedTo)) {
return false;
}
return migratedTo.noforwards;
}
}
return chat.noforwards;
}

private boolean shouldBypassNoForwardsForCurrentUser(TLRPC.Chat chat) {
if (chat == null || !chat.noforwards) {
return false;
}
if (chat.creator) {
return true;
}
return ChatObject.hasAdminRights(chat) && isNoForwardsAdminsBypassEnabled(chat.id);
}

private String getNoForwardsAdminsBypassKey(long chatId) {
return "noforwards_admins_bypass_" + chatId;
}

public boolean isNoForwardsAdminsBypassEnabled(long chatId) {
return getMainSettings().getBoolean(getNoForwardsAdminsBypassKey(chatId), false);
}

public void setNoForwardsAdminsBypassEnabled(long chatId, boolean enabled) {
SharedPreferences.Editor editor = getMainSettings().edit();
editor.putBoolean(getNoForwardsAdminsBypassKey(chatId), enabled);
editor.apply();
Comment on lines +6601 to +6604

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Persist admin bypass in chat state, not device-local prefs

setNoForwardsAdminsBypassEnabled writes the override flag into mainPreferences, which is local to a single client install, and shouldBypassNoForwardsForCurrentUser relies on that same local key for admin bypass decisions. This means an owner enabling the toggle does not propagate to other admins (or even the owner's other devices), so admins still cannot bypass noforwards despite the owner having enabled the option.

Useful? React with 👍 / 👎.

}

public boolean isChatNoForwards(long chatId) {
return isChatNoForwards(getChat(chatId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class ChatEditTypeActivity extends BaseFragment implements NotificationCe
private LinearLayout saveContainer;
private HeaderCell saveHeaderCell;
private TextCheckCell saveRestrictCell;
private TextCheckCell saveRestrictAdminBypassCell;
private TextInfoPrivacyCell saveRestrictInfoCell;

private JoinToSendSettingsView joinContainer;
Expand All @@ -136,6 +137,7 @@ public class ChatEditTypeActivity extends BaseFragment implements NotificationCe
private long chatId;
private boolean isChannel;
private boolean isSaveRestricted;
private boolean isAdminsSavingRestrictionBypassed;

private boolean canCreatePublic = true;
private boolean loadingAdminedChannels;
Expand Down Expand Up @@ -183,6 +185,7 @@ public boolean onFragmentCreate() {
isPrivate = !isForcePublic && !ChatObject.isPublic(currentChat);
isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup;
isSaveRestricted = currentChat.noforwards;
isAdminsSavingRestrictionBypassed = getMessagesController().isNoForwardsAdminsBypassEnabled(chatId);
if (isForcePublic && !ChatObject.isPublic(currentChat) || isPrivate && currentChat.creator) {
TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername();
req.username = "1";
Expand Down Expand Up @@ -601,8 +604,21 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
saveRestrictCell.setOnClickListener(v -> {
isSaveRestricted = !isSaveRestricted;
((TextCheckCell) v).setChecked(isSaveRestricted);
if (saveRestrictAdminBypassCell != null) {
saveRestrictAdminBypassCell.setVisibility(currentChat.creator && isSaveRestricted ? View.VISIBLE : View.GONE);
}
});
saveContainer.addView(saveRestrictCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

saveRestrictAdminBypassCell = new TextCheckCell(context);
saveRestrictAdminBypassCell.setTextAndCheck(LocaleController.getString(R.string.OverrideRestriction), isAdminsSavingRestrictionBypassed, false);
saveRestrictAdminBypassCell.setOnClickListener(v -> {
isAdminsSavingRestrictionBypassed = !isAdminsSavingRestrictionBypassed;
((TextCheckCell) v).setChecked(isAdminsSavingRestrictionBypassed);
});
saveRestrictAdminBypassCell.setVisibility(currentChat.creator && isSaveRestricted ? View.VISIBLE : View.GONE);
saveContainer.addView(saveRestrictAdminBypassCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

saveRestrictInfoCell = new TextInfoPrivacyCell(context, 12, resourceProvider);
if (isChannel && !ChatObject.isMegagroup(currentChat)) {
saveRestrictInfoCell.setText(LocaleController.getString(R.string.RestrictSavingContentInfoChannel));
Expand Down Expand Up @@ -1124,13 +1140,20 @@ protected void dispatchDraw(Canvas canvas) {
}

private boolean trySetRestrict() {
if (!isSaveRestricted) {
isAdminsSavingRestrictionBypassed = false;
}
if (currentChat.creator) {
getMessagesController().setNoForwardsAdminsBypassEnabled(chatId, isAdminsSavingRestrictionBypassed);
}
if (currentChat.noforwards != isSaveRestricted) {
if (!ChatObject.isChannel(currentChat)) {
updateDoneProgress(true);
getMessagesController().convertToMegaGroup(getParentActivity(), chatId, this, param -> {
if (param != 0) {
chatId = param;
currentChat = getMessagesController().getChat(param);
getMessagesController().setNoForwardsAdminsBypassEnabled(chatId, isAdminsSavingRestrictionBypassed);
getMessagesController().toggleChatNoForwards(chatId, currentChat.noforwards = isSaveRestricted);
processDone();
}
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,4 +1243,5 @@
<string name="RemindTodayAt">\'ذكّرني اليوم عند\' HH:mm</string>
<string name="RemindDayAt">\'ذكّرني بتاريخ\' d MMM \'عند\' HH:mm</string>
<string name="RemindDayYearAt">\'ذكّرني بتاريخ\' d MMM yyyy \'عند\' HH:mm</string>
<string name="OverrideRestriction">تجاوز التقييد</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,4 +1316,5 @@
<string name="RemindDayYearAt">\'Recordar el\' d \'de\' MMM \'de\' yyyy \'a las\' HH:mm</string>
<string name="BotsMenuTitle">Menu</string>
<string name="Understood">👍 Entendido</string>
<string name="OverrideRestriction">Anular restricción</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1249,4 +1249,5 @@
<string name="RemindDayAt">\'Lembrar em\' d \'de\' MMM \'às\' HH:mm</string>
<string name="RemindDayYearAt">\'Lembrar em\' d \'de\' MMM \'de\' yyyy \'às\' HH:mm</string>
<string name="BotsMenuTitle">Menu</string>
<string name="OverrideRestriction">Anular restrição</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,5 @@
<string name="RemindTodayAt">\'Отправить сегодня в\' HH:mm</string>
<string name="RemindDayAt">\'Отправить\' d MMM \'в\' HH:mm</string>
<string name="RemindDayYearAt">\'Напомнить\' d MMM yyyy \'в\' HH:mm</string>
<string name="OverrideRestriction">Отменить ограничение</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10428,4 +10428,5 @@
<string name="TranslateStyleOnMessage">On Message</string>
<string name="TranslateStylePopup">Pop-up Dialogue</string>
<string name="TranslateProviderGoogle">Google Translator</string>
<string name="OverrideRestriction">Override restriction</string>
</resources>