From af3f57cf7e66948a60a51c73dede20d6ef0a80a8 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 12 Oct 2024 15:43:52 +0800 Subject: [PATCH] feat: Send Without Pangu --- .../messenger/SendMessagesHelper.java | 8 +-- .../ui/Components/ChatActivityEnterView.java | 65 +++++++++++++++---- .../top/qwq2333/nullgram/utils/StringUtils.kt | 7 ++ .../src/main/res/values/strings_na.xml | 2 + 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java index bb83d5da9..5c436e1c0 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java @@ -3598,7 +3598,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe long stars = sendMessageParams.stars; boolean canSendGames = sendMessageParams.canSendGames; - boolean canUsePangu = sendMessageParams.canUsePangu; + boolean canUsePangu = sendMessageParams.canUsePangu == null ? NaConfig.INSTANCE.getEnablePanguOnSending().Bool() : sendMessageParams.canUsePangu; if (user != null && user.phone == null) { return; } @@ -3782,7 +3782,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe newMsg = new TLRPC.TL_message(); } - if (poll.poll != null && canUsePangu && NaConfig.INSTANCE.getEnablePanguOnSending().Bool()) { + if (poll.poll != null && canUsePangu) { poll.poll.question = StringUtils.spacingText(poll.poll.question); for (int i = 0; i < poll.poll.answers.size(); i++) { poll.poll.answers.get(i).text = StringUtils.spacingText(poll.poll.answers.get(i).text); @@ -4256,7 +4256,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe isFinalGroupMedia = params.get("final") != null; } - if (!((params != null && params.containsKey("fwd_id")) || MessageObject.isForwardedMessage(newMsg)) && canUsePangu && NaConfig.INSTANCE.getEnablePanguOnSending().Bool()) { + if (!((params != null && params.containsKey("fwd_id")) || MessageObject.isForwardedMessage(newMsg)) && canUsePangu) { Pair> pair; if (caption != null) { pair = StringUtils.spacingText(caption, entities); @@ -9677,7 +9677,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe public long stars; public boolean canSendGames = true; - public boolean canUsePangu = true; + public Boolean canUsePangu = null; public static SendMessageParams of(String string, long dialogId) { return of(string, null, null, null, null, null, null, null, null, null, dialogId, null, null, null, null, true, null, null, null, null, false, 0, 0, null, null, false); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 8bf17cf69..1bf7cda42 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -217,6 +217,7 @@ import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import kotlin.Unit; import kotlin.text.StringsKt; +import top.qwq2333.nullgram.utils.StringUtils; import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.cc.CCConverter; import tw.nekomimi.nekogram.cc.CCTarget; @@ -4985,10 +4986,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific if (containsMarkdown(messageEditText.getText())) { boolean withoutMarkdown = NaConfig.INSTANCE.getDisableMarkdown().Bool(); int markdownButtonDrawable = withoutMarkdown ? R.drawable.round_code_white : R.drawable.round_code_off_white; - String markdownButtonStr = withoutMarkdown ? getString("SendWithMarkdown", R.string.SendWithMarkdown) : getString("SendWithoutMarkdown", R.string.SendWithoutMarkdown); + String markdownButtonStr = withoutMarkdown ? getString(R.string.SendWithMarkdown) : getString(R.string.SendWithoutMarkdown); options.add(markdownButtonDrawable, markdownButtonStr, () -> { sentFromPreview = System.currentTimeMillis(); - sendMessageInternal(true, 0, true, withoutMarkdown, true); + sendMessageInternal(true, 0, true, SendMessageInternalParams.markdown(withoutMarkdown)); if (!containsSendMessage && messageSendPreview != null) { messageSendPreview.dismiss(true); messageSendPreview = null; @@ -4998,9 +4999,24 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific } }); } else if (canSendAsDice(messageEditText.getText().toString(), parentFragment, dialog_id)) { - options.add(R.drawable.casino_icon, getString("SendAsEmoji", R.string.SendAsEmoji), () -> { + options.add(R.drawable.casino_icon, getString(R.string.SendAsEmoji), () -> { sentFromPreview = System.currentTimeMillis(); - sendMessageInternal(true, 0, true, null, false); + sendMessageInternal(true, 0, true, SendMessageInternalParams.game(false)); + if (!containsSendMessage && messageSendPreview != null) { + messageSendPreview.dismiss(true); + messageSendPreview = null; + } else { + AndroidUtilities.cancelRunOnUIThread(dismissSendPreview); + AndroidUtilities.runOnUIThread(dismissSendPreview, 500); + } + }); + } else if (StringUtils.canUsePangu(messageEditText.getText().toString())) { + boolean shouldUsePangu = !NaConfig.INSTANCE.getEnablePanguOnSending().Bool(); + int markdownButtonDrawable = shouldUsePangu ? R.drawable.round_code_white : R.drawable.round_code_off_white; + String markdownButtonStr = shouldUsePangu ? getString(R.string.SendWithPangu) : getString(R.string.SendWithoutPangu); + options.add(markdownButtonDrawable, markdownButtonStr, () -> { + sentFromPreview = System.currentTimeMillis(); + sendMessageInternal(true, 0, true, SendMessageInternalParams.pangu(shouldUsePangu)); if (!containsSendMessage && messageSendPreview != null) { messageSendPreview.dismiss(true); messageSendPreview = null; @@ -7351,14 +7367,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific private boolean premiumEmojiBulletin = true; private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm) { - sendMessageInternal(notify, scheduleDate, allowConfirm, null, true); + sendMessageInternal(notify, scheduleDate, allowConfirm, new SendMessageInternalParams()); } - private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm, Boolean withMarkdown, boolean withGame) { - boolean disableMarkdown = NaConfig.INSTANCE.getDisableMarkdown().Bool(); - if (withMarkdown == null) { - withMarkdown = !disableMarkdown; - } + private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm, SendMessageInternalParams internalParams) { if (slowModeTimer == Integer.MAX_VALUE && !isInScheduleMode()) { if (delegate != null) { delegate.scrollToSendingMessage(); @@ -7453,7 +7465,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific if (delegate != null) { delegate.beforeMessageSend(message, notify, scheduleDate); } - if (processSendingText(message, notify, scheduleDate, withMarkdown, withGame)) { + if (processSendingText(message, notify, scheduleDate, internalParams)) { if (delegate.hasForwardingMessages() || (scheduleDate != 0 && !isInScheduleMode()) || isInScheduleMode()) { if (messageEditText != null) { messageEditText.setText(""); @@ -7484,6 +7496,30 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific } } + public static class SendMessageInternalParams { + public Boolean withMarkdown = null; + public boolean withGame = true; + public Boolean canUsePangu = null; + + public static SendMessageInternalParams markdown(Boolean withMarkdown) { + SendMessageInternalParams params = new SendMessageInternalParams(); + params.withMarkdown = withMarkdown; + return params; + } + + public static SendMessageInternalParams game(boolean withGame) { + SendMessageInternalParams params = new SendMessageInternalParams(); + params.withGame = withGame; + return params; + } + + public static SendMessageInternalParams pangu(Boolean canUsePangu) { + SendMessageInternalParams params = new SendMessageInternalParams(); + params.canUsePangu = canUsePangu; + return params; + } + } + protected boolean showConfirmAlert(Runnable onConfirmed) { return false; } @@ -7756,7 +7792,11 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific setEditingMessageObject(null, null, false); } - public boolean processSendingText(CharSequence text, boolean notify, int scheduleDate, boolean withMarkdown, boolean withGame) { + public boolean processSendingText(CharSequence text, boolean notify, int scheduleDate, SendMessageInternalParams internalParams) { + boolean withMarkdown = internalParams.withMarkdown == null ? !NaConfig.INSTANCE.getDisableMarkdown().Bool() : internalParams.withMarkdown; + boolean withGame = internalParams.withGame; + Boolean canUsePangu = internalParams.canUsePangu; + if (replyingQuote != null && parentFragment != null && replyingQuote.outdated) { parentFragment.showQuoteMessageUpdate(); return false; @@ -7849,6 +7889,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific } SendMessagesHelper.SendMessageParams params = SendMessagesHelper.SendMessageParams.of(message[0].toString(), dialog_id, replyingMessageObject, replyToTopMsg, messageWebPage, messageWebPageSearch, entities, null, null, notify, scheduleDate, sendAnimationData, updateStickersOrder); params.canSendGames = withGame; + params.canUsePangu = canUsePangu; params.quick_reply_shortcut = parentFragment != null ? parentFragment.quickReplyShortcut : null; params.quick_reply_shortcut_id = parentFragment != null ? parentFragment.getQuickReplyId() : 0; params.effect_id = effectId; diff --git a/TMessagesProj/src/main/java/top/qwq2333/nullgram/utils/StringUtils.kt b/TMessagesProj/src/main/java/top/qwq2333/nullgram/utils/StringUtils.kt index c8386be92..16ca1a2e6 100644 --- a/TMessagesProj/src/main/java/top/qwq2333/nullgram/utils/StringUtils.kt +++ b/TMessagesProj/src/main/java/top/qwq2333/nullgram/utils/StringUtils.kt @@ -115,6 +115,13 @@ object StringUtils { } } + @JvmStatic + fun canUsePangu(text: String): Boolean { + if (text.startsWith("/")) return false + val panguText = pangu.spacingText(text) + return panguText.length != text.length + } + @JvmStatic fun spacingText(text: String, entities: ArrayList?): Pair?> { if (text.startsWith("/")) return Pair(text, entities) // command diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index cd4270cbb..f0e9d853e 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -164,4 +164,6 @@ Enable Pangu on receiving Enable Pangu on sending Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean), half-width English, digit and symbol characters. + Send with Pangu + Send without Pangu