Skip to content

Commit 50122ce

Browse files
committed
Added webview bots options.
1 parent 2c24de9 commit 50122ce

7 files changed

Lines changed: 119 additions & 13 deletions

File tree

TMessagesProj/src/main/java/org/telegram/ui/ForkSettingsActivity.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public void invalidate() {
163163
private int largePhoto;
164164
private int disableSlideToNextChannel;
165165
private int disableRecentFilesAttachment;
166+
private int botSkipShare;
167+
private int botSkipFullscreen;
166168

167169
private int stickerSizeRow;
168170

@@ -233,6 +235,10 @@ public boolean onFragmentCreate() {
233235
largePhoto = rowCount++;
234236
disableSlideToNextChannel = rowCount++;
235237
disableRecentFilesAttachment = rowCount++;
238+
239+
emptyRows.add(rowCount++);
240+
botSkipShare = rowCount++;
241+
botSkipFullscreen = rowCount++;
236242

237243
emptyRows.add(rowCount++);
238244
sectionRows.add(rowCount++);
@@ -345,6 +351,10 @@ public boolean supportsPredictiveItemAnimations() {
345351
toggleGlobalMainSetting("disableSlideToNextChannel", view, false);
346352
} else if (position == disableRecentFilesAttachment) {
347353
toggleGlobalMainSetting("disableRecentFilesAttachment", view, false);
354+
} else if (position == botSkipShare) {
355+
toggleGlobalMainSetting("botSkipShare", view, false);
356+
} else if (position == botSkipFullscreen) {
357+
toggleGlobalMainSetting("botSkipFullscreen", view, false);
348358
} else if (position == lockPremium) {
349359
toggleGlobalMainSetting("lockPremium", view, false);
350360
} else if (position == replaceForward) {
@@ -491,6 +501,12 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
491501
} else if (position == disableRecentFilesAttachment) {
492502
String t = LocaleController.getString("DisableRecentFilesAttachment", R.string.DisableRecentFilesAttachment);
493503
textCell.setTextAndCheck(t, preferences.getBoolean("disableRecentFilesAttachment", false), false);
504+
} else if (position == botSkipShare) {
505+
String t = LocaleController.getString("BotSkipShare", R.string.BotSkipShare);
506+
textCell.setTextAndCheck(t, preferences.getBoolean("botSkipShare", false), false);
507+
} else if (position == botSkipFullscreen) {
508+
String t = LocaleController.getString("BotSkipFullscreen", R.string.BotSkipFullscreen);
509+
textCell.setTextAndCheck(t, preferences.getBoolean("botSkipFullscreen", false), false);
494510
} else if (position == lockPremium) {
495511
String t = LocaleController.getString("LockPremium", R.string.LockPremium);
496512
String info = LocaleController.getString("SquareAvatarsInfo", R.string.SquareAvatarsInfo);
@@ -560,6 +576,8 @@ public boolean isEnabled(RecyclerView.ViewHolder holder) {
560576
|| position == largePhoto
561577
|| position == disableSlideToNextChannel
562578
|| position == disableRecentFilesAttachment
579+
|| position == botSkipShare
580+
|| position == botSkipFullscreen
563581
|| position == lockPremium
564582
|| position == replaceForward
565583
|| position == mentionByName
@@ -628,6 +646,8 @@ public int getItemViewType(int position) {
628646
|| position == largePhoto
629647
|| position == disableSlideToNextChannel
630648
|| position == disableRecentFilesAttachment
649+
|| position == botSkipShare
650+
|| position == botSkipFullscreen
631651
|| position == lockPremium
632652
|| position == replaceForward
633653
|| position == mentionByName
@@ -690,4 +710,13 @@ public ArrayList<ThemeDescription> getThemeDescriptions() {
690710

691711
return themeDescriptions;
692712
}
713+
714+
public static String GetBotPlatform(int currentAccount, long botId) {
715+
return MessagesController.getMainSettings(currentAccount).getString("bot_platform_" + botId, "android");
716+
}
717+
718+
public static boolean GetBotCopyLink(int currentAccount, long botId) {
719+
return MessagesController.getMainSettings(currentAccount).getBoolean("bot_copy_link_" + botId, false);
720+
}
721+
693722
}

TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewAttachedSheet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ public void onItemClick(int id) {
10951095
TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView();
10961096
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
10971097
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(botId);
1098-
req.platform = "android";
1098+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
10991099
req.compact = props.compact;
11001100
req.fullscreen = props.fullscreen;
11011101

@@ -1124,7 +1124,7 @@ public void onItemClick(int id) {
11241124
TLRPC.TL_messages_requestSimpleWebView req = new TLRPC.TL_messages_requestSimpleWebView();
11251125
req.from_switch_webview = (props.flags & FLAG_FROM_INLINE_SWITCH) != 0;
11261126
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
1127-
req.platform = "android";
1127+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
11281128
req.from_side_menu = (props.flags & FLAG_FROM_SIDE_MENU) != 0;
11291129
req.compact = props.compact;
11301130
req.fullscreen = props.fullscreen;
@@ -1156,7 +1156,7 @@ public void onItemClick(int id) {
11561156
TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView();
11571157
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(peerId);
11581158
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
1159-
req.platform = "android";
1159+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
11601160
req.compact = props.compact;
11611161
req.fullscreen = props.fullscreen;
11621162
if (props.buttonUrl != null) {
@@ -1202,7 +1202,7 @@ public void onItemClick(int id) {
12021202

12031203
req.app = botApp;
12041204
req.write_allowed = props.allowWrite;
1205-
req.platform = "android";
1205+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
12061206
req.peer = fragment instanceof ChatActivity ? ((ChatActivity) fragment).getCurrentUser() != null ? MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentUser()) : MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentChat())
12071207
: MessagesController.getInputPeer(props.botUser);
12081208
req.compact = props.compact;
@@ -1232,7 +1232,7 @@ public void onItemClick(int id) {
12321232
case TYPE_WEB_VIEW_BOT_MAIN: {
12331233
TLRPC.TL_messages_requestMainWebView req = new TLRPC.TL_messages_requestMainWebView();
12341234

1235-
req.platform = "android";
1235+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
12361236
req.bot = MessagesController.getInstance(currentAccount).getInputUser(props.botId);
12371237
req.peer = fragment instanceof ChatActivity ? ((ChatActivity) fragment).getCurrentUser() != null ? MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentUser()) : MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentChat())
12381238
: MessagesController.getInputPeer(props.botUser);

TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewMenuContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ private void loadWebView() {
955955
TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView();
956956
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
957957
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(botId);
958-
req.platform = "android";
958+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
959959

960960
req.url = botUrl;
961961
req.flags |= 2;

TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewSheet.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ public void onItemClick(int id) {
14591459
TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView();
14601460
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
14611461
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(botId);
1462-
req.platform = "android";
1462+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
14631463
req.compact = props.compact;
14641464
req.fullscreen = props.fullscreen;
14651465

@@ -1488,7 +1488,7 @@ public void onItemClick(int id) {
14881488
TLRPC.TL_messages_requestSimpleWebView req = new TLRPC.TL_messages_requestSimpleWebView();
14891489
req.from_switch_webview = (props.flags & FLAG_FROM_INLINE_SWITCH) != 0;
14901490
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
1491-
req.platform = "android";
1491+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
14921492
req.from_side_menu = (props.flags & FLAG_FROM_SIDE_MENU) != 0;
14931493
req.compact = props.compact;
14941494
req.fullscreen = props.fullscreen;
@@ -1520,7 +1520,7 @@ public void onItemClick(int id) {
15201520
TLRPC.TL_messages_requestWebView req = new TLRPC.TL_messages_requestWebView();
15211521
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(peerId);
15221522
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
1523-
req.platform = "android";
1523+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
15241524
req.compact = props.compact;
15251525
req.fullscreen = props.fullscreen;
15261526
if (props.buttonUrl != null) {
@@ -1566,7 +1566,7 @@ public void onItemClick(int id) {
15661566

15671567
req.app = botApp;
15681568
req.write_allowed = props.allowWrite;
1569-
req.platform = "android";
1569+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
15701570
req.peer = fragment instanceof ChatActivity ? ((ChatActivity) fragment).getCurrentUser() != null ? MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentUser()) : MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentChat())
15711571
: MessagesController.getInputPeer(props.botUser);
15721572
req.compact = props.compact;
@@ -1597,7 +1597,7 @@ public void onItemClick(int id) {
15971597
TLRPC.TL_messages_requestMainWebView req = new TLRPC.TL_messages_requestMainWebView();
15981598

15991599
req.bot = MessagesController.getInstance(currentAccount).getInputUser(props.botId);
1600-
req.platform = "android";
1600+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
16011601
req.peer = fragment instanceof ChatActivity ? ((ChatActivity) fragment).getCurrentUser() != null ? MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentUser()) : MessagesController.getInputPeer(((ChatActivity) fragment).getCurrentChat())
16021602
: MessagesController.getInputPeer(props.botUser);
16031603
req.compact = props.compact;
@@ -1693,6 +1693,41 @@ private void openOptions() {
16931693
})
16941694
.addIf(currentBot != null && (currentBot.show_in_side_menu || currentBot.show_in_attach_menu), R.drawable.msg_delete, LocaleController.getString(R.string.BotWebViewDeleteBot), () -> {
16951695
deleteBot(currentAccount, botId, () -> dismiss());
1696+
})
1697+
.addSpaceGap()
1698+
.add(R.drawable.msg_bot, LocaleController.getString(R.string.BotSetPlatform), () -> {
1699+
String[] platforms = { "android", "tdesktop", "ios", "macos" };
1700+
int[] icons = new int[platforms.length];
1701+
String wasPlatform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
1702+
for (int i = 0; i < platforms.length; i++) {
1703+
icons[i] = (wasPlatform.equals(platforms[i])) ? R.drawable.msg_text_check : 0;
1704+
}
1705+
1706+
AlertDialog dialog = new AlertDialog.Builder(getContext())
1707+
.setTitle(LocaleController.getString(R.string.BotSetPlatformTitle))
1708+
.forceVerticalButtons()
1709+
.setMessage(LocaleController.getString(R.string.BotSetPlatformAbout))
1710+
.setNegativeButton(LocaleController.getString(R.string.Cancel), null)
1711+
.setItems(platforms, icons, (d, which) -> {
1712+
android.content.SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
1713+
editor.putString("bot_platform_" + botId, platforms[which]);
1714+
editor.commit();
1715+
})
1716+
.create();
1717+
dialog.show();
1718+
})
1719+
.add(org.telegram.ui.ForkSettingsActivity.GetBotCopyLink(currentAccount, botId)
1720+
? R.drawable.msg_text_check
1721+
: 0,
1722+
LocaleController.getString(R.string.BotCopyUrl),
1723+
() -> {
1724+
android.content.SharedPreferences.Editor editor = MessagesController.getMainSettings(currentAccount).edit();
1725+
editor.putBoolean("bot_copy_link_" + botId, !org.telegram.ui.ForkSettingsActivity.GetBotCopyLink(currentAccount, botId));
1726+
editor.commit();
1727+
android.widget.Toast.makeText(
1728+
getContext(),
1729+
LocaleController.getString(R.string.OK),
1730+
android.widget.Toast.LENGTH_SHORT).show();
16961731
});
16971732

16981733
if (actionBarColor != Theme.getColor(Theme.key_windowBackgroundWhite)) {
@@ -2174,7 +2209,10 @@ private void updateWebViewBackgroundColor() {
21742209

21752210
private boolean resetOffsetY = true;
21762211
private ValueAnimator fullscreenAnimator;
2177-
public void setFullscreen(boolean fullscreen, boolean animated) {
2212+
public void setFullscreen(boolean fullscreenF, boolean animated) {
2213+
final boolean fullscreen = org.telegram.messenger.MessagesController.getGlobalMainSettings().getBoolean("botSkipFullscreen", false)
2214+
? false
2215+
: fullscreenF;
21782216
if (this.fullscreen == fullscreen) return;
21792217
this.fullscreen = fullscreen;
21802218
if (fullscreenAnimator != null) {

TMessagesProj/src/main/java/org/telegram/ui/bots/ChatAttachAlertBotWebViewLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public void requestWebView(int currentAccount, long peerId, long botId, boolean
508508
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(peerId);
509509
req.bot = MessagesController.getInstance(currentAccount).getInputUser(botId);
510510
req.silent = silent;
511-
req.platform = "android";
511+
req.platform = org.telegram.ui.ForkSettingsActivity.GetBotPlatform(currentAccount, botId);
512512

513513
if (peerId < 0) {
514514
TLRPC.ChatFull chatFull = MessagesController.getInstance(currentAccount).getChatFull(-peerId);

TMessagesProj/src/main/java/org/telegram/ui/web/BotWebViewContainer.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,14 @@ public void didReceivedNotification(int id, int account, Object... args) {
16621662
try {
16631663
JSONObject jsonData = new JSONObject(eventData);
16641664
Uri uri = Uri.parse(jsonData.optString("url"));
1665+
if (org.telegram.ui.ForkSettingsActivity.GetBotCopyLink(currentAccount, botUser.id)) {
1666+
AndroidUtilities.addToClipboard(uri.toString());
1667+
android.widget.Toast.makeText(
1668+
getContext(),
1669+
LocaleController.getString(R.string.AffiliateProgramLinkCopiedTitle),
1670+
android.widget.Toast.LENGTH_SHORT).show();
1671+
break;
1672+
}
16651673
String browser = jsonData.optString("try_browser");
16661674
if (MessagesController.getInstance(currentAccount).webAppAllowedProtocols != null &&
16671675
MessagesController.getInstance(currentAccount).webAppAllowedProtocols.contains(uri.getScheme())) {
@@ -1676,6 +1684,14 @@ public void didReceivedNotification(int id, int account, Object... args) {
16761684
try {
16771685
JSONObject jsonData = new JSONObject(eventData);
16781686
String pathFull = jsonData.optString("path_full");
1687+
if (org.telegram.ui.ForkSettingsActivity.GetBotCopyLink(currentAccount, botUser.id)) {
1688+
AndroidUtilities.addToClipboard(pathFull);
1689+
android.widget.Toast.makeText(
1690+
getContext(),
1691+
LocaleController.getString(R.string.AffiliateProgramLinkCopiedTitle),
1692+
android.widget.Toast.LENGTH_SHORT).show();
1693+
break;
1694+
}
16791695
boolean force_request = jsonData.optBoolean("force_request", false);
16801696
if (pathFull.startsWith("/")) {
16811697
pathFull = pathFull.substring(1);
@@ -2573,6 +2589,12 @@ public boolean isLightStatusBar() {
25732589
notifyEvent("prepared_message_failed", obj("error", "MESSAGE_EXPIRED"));
25742590
return;
25752591
}
2592+
if (org.telegram.messenger.MessagesController.getGlobalMainSettings().getBoolean("botSkipShare", false)) {
2593+
AndroidUtilities.runOnUIThread(() -> {
2594+
notifyEvent("prepared_message_sent", null);
2595+
}, 1500);
2596+
break;
2597+
}
25762598

25772599
BotShareSheet.share(getContext(), currentAccount, botUser.id, id, resourcesProvider, () -> {
25782600
if (delegate != null) {
@@ -3800,7 +3822,18 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
38003822
opener.botWebViewContainer.delegate.onCloseToTabs();
38013823
}
38023824
}
3825+
if (botWebViewContainer.botUser != null
3826+
&& org.telegram.ui.ForkSettingsActivity.GetBotCopyLink(
3827+
botWebViewContainer.currentAccount,
3828+
botWebViewContainer.botUser.id)) {
3829+
AndroidUtilities.addToClipboard(uriNew.toString());
3830+
android.widget.Toast.makeText(
3831+
getContext(),
3832+
LocaleController.getString(R.string.AffiliateProgramLinkCopiedTitle),
3833+
android.widget.Toast.LENGTH_SHORT).show();
3834+
} else {
38033835
botWebViewContainer.onOpenUri(uriNew);
3836+
}
38043837
}
38053838
d("shouldOverrideUrlLoading("+url+") = true");
38063839
return true;

TMessagesProj/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9543,4 +9543,10 @@
95439543
<string name="LargePhoto">2560px for sending photos</string>
95449544
<string name="DisableSlideToNextChannel">Disable slide to next channel</string>
95459545
<string name="DisableRecentFilesAttachment">Disable Recent Files</string>
9546+
<string name="BotSkipShare">Skip share boxes from bots</string>
9547+
<string name="BotSkipFullscreen">Disable fullscreen for bots</string>
9548+
<string name="BotSetPlatform">Change platform</string>
9549+
<string name="BotSetPlatformTitle">Change bot platform</string>
9550+
<string name="BotSetPlatformAbout">Please restart after change to apply a new platform for the current bot.</string>
9551+
<string name="BotCopyUrl">Copy every clicked link</string>
95469552
</resources>

0 commit comments

Comments
 (0)