diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java index e45e6b5de..d0c58448b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java @@ -20,12 +20,10 @@ import android.text.TextUtils; import android.text.style.URLSpan; import android.text.util.Linkify; -import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLObject; import org.telegram.tgnet.TLRPC; import org.telegram.ui.ActionBar.Theme; import org.telegram.ui.Components.TypefaceSpan; -import org.telegram.ui.Components.URLSpanBotCommand; import org.telegram.ui.Components.URLSpanNoUnderline; import org.telegram.ui.Components.URLSpanNoUnderlineBold; import org.telegram.ui.Components.URLSpanReplacement; @@ -755,12 +753,12 @@ public class MessageObject { } catch (Exception e) { FileLog.e("tmessages", e); } - addUsernamesAndHashtags(caption, true); + addUsernamesAndHashtags(caption); } } } - private static void addUsernamesAndHashtags(CharSequence charSequence, boolean botCommands) { + private static void addUsernamesAndHashtags(CharSequence charSequence) { try { if (urlPattern == null) { urlPattern = Pattern.compile("(^|\\s)/[a-zA-Z@\\d_]{1,255}|(^|\\s)@[a-zA-Z\\d_]{1,32}|(^|\\s)#[\\w\\.]+"); @@ -774,9 +772,7 @@ public class MessageObject { } URLSpanNoUnderline url = null; if (charSequence.charAt(start) == '/') { - if (botCommands) { - url = new URLSpanBotCommand(charSequence.subSequence(start, end).toString()); - } + ; } else { url = new URLSpanNoUnderline(charSequence.subSequence(start, end).toString()); } @@ -789,12 +785,7 @@ public class MessageObject { } } - public static void addLinks(CharSequence messageText) { - addLinks(messageText, true); - } - - public static void addLinks(CharSequence messageText, boolean botCommands) { if (messageText instanceof Spannable && containsUrls(messageText)) { if (messageText.length() < 200) { try { @@ -809,7 +800,7 @@ public class MessageObject { FileLog.e("tmessages", e); } } - addUsernamesAndHashtags(messageText, botCommands); + addUsernamesAndHashtags(messageText); } } @@ -893,9 +884,7 @@ public class MessageObject { spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (!useManualParse) { String url = messageOwner.message.substring(entity.offset, entity.offset + entity.length); - if (entity instanceof TLRPC.TL_messageEntityBotCommand) { - spannable.setSpan(new URLSpanBotCommand(url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - } else if (entity instanceof TLRPC.TL_messageEntityHashtag || entity instanceof TLRPC.TL_messageEntityMention) { + if (entity instanceof TLRPC.TL_messageEntityHashtag || entity instanceof TLRPC.TL_messageEntityMention) { spannable.setSpan(new URLSpanNoUnderline(url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (entity instanceof TLRPC.TL_messageEntityEmail) { spannable.setSpan(new URLSpanReplacement("mailto:" + url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java index 36d397cd6..d756a78dc 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java @@ -16,7 +16,7 @@ public class NotificationCenter { private static int totalEvents = 1; - public static final int didReceivedNewMessages = totalEvents++; // I'm not sure if Telegram uses the resulting codes here and there, so better leave the values alone + public static final int didReceivedNewMessages = totalEvents++; public static final int updateInterfaces = totalEvents++; public static final int dialogsNeedReload = totalEvents++; public static final int closeChats = totalEvents++; @@ -50,19 +50,15 @@ public class NotificationCenter { public static final int recentImagesDidLoaded = totalEvents++; public static final int replaceMessagesObjects = totalEvents++; public static final int didSetPasscode = totalEvents++; - public static final int didSetTwoStepPassword = totalEvents++; public static final int screenStateChanged = totalEvents++; public static final int didLoadedReplyMessages = totalEvents++; public static final int didLoadedPinnedMessage = totalEvents++; - public static final int newSessionReceived = totalEvents++; public static final int didReceivedWebpages = totalEvents++; public static final int didReceivedWebpagesInUpdates = totalEvents++; public static final int stickersDidLoaded = totalEvents++; public static final int didReplacedPhotoInMemCache = totalEvents++; public static final int messagesReadContent = totalEvents++; - public static final int botInfoDidLoaded = totalEvents++; public static final int userInfoDidLoaded = totalEvents++; - public static final int botKeyboardDidLoaded = totalEvents++; public static final int chatSearchResultsAvailable = totalEvents++; public static final int musicDidLoaded = totalEvents++; public static final int needShowAlert = totalEvents++; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java index 937a3b20a..2c7970470 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java @@ -19,21 +19,13 @@ import org.telegram.ui.LaunchActivity; public class Browser { public static void openUrl(Context context, String url) { - openUrl(context, Uri.parse(url), true); - } - - public static void openUrl(Context context, Uri uri) { - openUrl(context, uri, true); - } - - public static void openUrl(Context context, String url, boolean allowCustom) { if (context == null || url == null) { return; } - openUrl(context, Uri.parse(url), allowCustom); + openUrl(context, Uri.parse(url)); } - public static void openUrl(Context context, Uri uri, boolean allowCustom) { + public static void openUrl(Context context, Uri uri) { if (context == null || uri == null) { return; } diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index ab9f61fed..05b85edc8 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -214,13 +214,6 @@ public class TLRPC { public byte[] iv; } - public static class BotInfo extends TLObject { - public int user_id; - public String description; - public ArrayList commands = new ArrayList<>(); - public int version; - } - public static class ChatFull extends TLObject { public int flags; public boolean can_view_participants; @@ -229,7 +222,6 @@ public class TLRPC { public int participants_count; public int admins_count; public int kicked_count; - public ArrayList bot_info = new ArrayList<>(); public int migrated_from_chat_id; public int migrated_from_max_id; public int pinned_msg_id; @@ -585,9 +577,6 @@ public class TLRPC { public static class TL_messageEntityTextUrl extends MessageEntity { } - public static class TL_messageEntityBotCommand extends MessageEntity { - } - public static class TL_messageEntityEmail extends MessageEntity { } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MentionsAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MentionsAdapter.java index 4063b6fd6..6c208ef36 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MentionsAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MentionsAdapter.java @@ -24,7 +24,6 @@ import org.telegram.messenger.support.widget.RecyclerView; import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLRPC; import org.telegram.ui.ActionBar.BaseFragment; -import org.telegram.ui.Cells.BotSwitchCell; import org.telegram.ui.Cells.ContextLinkCell; import org.telegram.ui.Cells.MentionCell; @@ -59,7 +58,7 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { //private TLRPC.TL_inlineBotSwitchPM searchResultBotContextSwitch; //private HashMap searchResultBotContextById; private MentionsAdapterDelegate delegate; - private HashMap botInfo; + //private HashMap botInfo; private int resultStartPosition; private boolean allowNewMentions = true; private int resultLength; @@ -159,16 +158,6 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { needBotContext = value; } - public void setBotInfo(HashMap info) { - botInfo = info; - } - - /* - public void setBotsCount(int count) { - botsCount = count; - } - */ - @Override public void clearRecentHashtags() { super.clearRecentHashtags(); @@ -557,12 +546,12 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { resultLength = result.length() + 1; result.insert(0, ch); break; - } else if (a == 0 && botInfo != null && ch == '/') { + } /*else if (a == 0 && botInfo != null && ch == '/') { foundType = 2; resultStartPosition = a; resultLength = result.length() + 1; break; - } + }*/ } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { hasIllegalUsernameCharacters = true; @@ -678,7 +667,7 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { ArrayList newResultHelp = new ArrayList<>(); ArrayList newResultUsers = new ArrayList<>(); String command = result.toString().toLowerCase(); - for (HashMap.Entry entry : botInfo.entrySet()) { + /*for (HashMap.Entry entry : botInfo.entrySet()) { TLRPC.BotInfo botInfo = entry.getValue(); for (int a = 0; a < botInfo.commands.size(); a++) { TLRPC.TL_botCommand botCommand = botInfo.commands.get(a); @@ -688,7 +677,7 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { newResultUsers.add(MessagesController.getInstance().getUser(botInfo.user_id)); } } - } + }*/ searchResultHashtags = null; searchResultUsernames = null; searchResultCommands = newResult; @@ -799,8 +788,8 @@ public class MentionsAdapter extends BaseSearchAdapterRecycler { delegate.onContextClick(cell.getResult()); } }); - } else if (viewType == 2) { - view = new BotSwitchCell(mContext); + //} else if (viewType == 2) { + // view = new BotSwitchCell(mContext); } else { view = new MentionCell(mContext); ((MentionCell) view).setIsDarkTheme(isDarkTheme); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java index f4aa9af9b..8c22372c4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/AboutLinkCell.java @@ -95,7 +95,7 @@ public class AboutLinkCell extends FrameLayout { } oldText = text; stringBuilder = new SpannableStringBuilder(oldText); - MessageObject.addLinks(stringBuilder, false); + MessageObject.addLinks(stringBuilder); Emoji.replaceEmoji(stringBuilder, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false); requestLayout(); if (resId == 0) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotHelpCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotHelpCell.java deleted file mode 100644 index e2f0292fc..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotHelpCell.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 3.x.x. - * It is licensed under GNU GPL v. 2 or later. - * You should have received a copy of the license in this archive (see LICENSE). - * - * Copyright Nikolai Kudashov, 2013-2016. - */ - -package org.telegram.ui.Cells; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.text.Layout; -import android.text.Spannable; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.StaticLayout; -import android.text.TextPaint; -import android.text.style.ClickableSpan; -import android.text.style.URLSpan; -import android.view.MotionEvent; -import android.view.View; - -import org.telegram.messenger.AndroidUtilities; -import org.telegram.messenger.Emoji; -import org.telegram.messenger.LocaleController; -import org.telegram.messenger.MessageObject; -import org.telegram.messenger.FileLog; -import org.telegram.messenger.R; -import org.telegram.messenger.browser.Browser; -import org.telegram.ui.Components.LinkPath; -import org.telegram.ui.ActionBar.Theme; -import org.telegram.ui.Components.TypefaceSpan; -import org.telegram.ui.Components.URLSpanNoUnderline; - -public class BotHelpCell extends View { - - private StaticLayout textLayout; - private TextPaint textPaint; - private Paint urlPaint; - private String oldText; - - private int width; - private int height; - private int textX; - private int textY; - - private ClickableSpan pressedLink; - private LinkPath urlPath = new LinkPath(); - - private BotHelpCellDelegate delegate; - - public interface BotHelpCellDelegate { - void didPressUrl(String url); - } - - public BotHelpCell(Context context) { - super(context); - - textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); - textPaint.setTextSize(AndroidUtilities.dp(16)); - textPaint.setColor(0xff000000); - textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR; - - urlPaint = new Paint(); - urlPaint.setColor(Theme.MSG_LINK_SELECT_BACKGROUND_COLOR); - } - - public void setDelegate(BotHelpCellDelegate botHelpCellDelegate) { - delegate = botHelpCellDelegate; - } - - private void resetPressedLink() { - if (pressedLink != null) { - pressedLink = null; - } - invalidate(); - } - - public void setText(String text) { - if (text == null || text.length() == 0) { - setVisibility(GONE); - return; - } - if (text != null && oldText != null && text.equals(oldText)) { - return; - } - oldText = text; - setVisibility(VISIBLE); - if (AndroidUtilities.isTablet()) { - width = (int) (AndroidUtilities.getMinTabletSide() * 0.7f); - } else { - width = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f); - } - SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); - String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle); - stringBuilder.append(help); - stringBuilder.append("\n\n"); - stringBuilder.append(text); - MessageObject.addLinks(stringBuilder); - stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, help.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - Emoji.replaceEmoji(stringBuilder, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false); - try { - textLayout = new StaticLayout(stringBuilder, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); - width = 0; - height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18); - int count = textLayout.getLineCount(); - for (int a = 0; a < count; a++) { - width = (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) + textLayout.getLineLeft(a))); - } - } catch (Exception e) { - FileLog.e("tmessage", e); - } - width += AndroidUtilities.dp(4 + 18); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - float x = event.getX(); - float y = event.getY(); - - boolean result = false; - if (textLayout != null) { - if (event.getAction() == MotionEvent.ACTION_DOWN || pressedLink != null && event.getAction() == MotionEvent.ACTION_UP) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - resetPressedLink(); - try { - int x2 = (int) (x - textX); - int y2 = (int) (y - textY); - final int line = textLayout.getLineForVertical(y2); - final int off = textLayout.getOffsetForHorizontal(line, x2); - - final float left = textLayout.getLineLeft(line); - if (left <= x2 && left + textLayout.getLineWidth(line) >= x2) { - Spannable buffer = (Spannable) textLayout.getText(); - ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); - if (link.length != 0) { - resetPressedLink(); - pressedLink = link[0]; - result = true; - try { - int start = buffer.getSpanStart(pressedLink); - urlPath.setCurrentLayout(textLayout, start, 0); - textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else { - resetPressedLink(); - } - } else { - resetPressedLink(); - } - } catch (Exception e) { - resetPressedLink(); - FileLog.e("tmessages", e); - } - } else if (pressedLink != null) { - try { - if (pressedLink instanceof URLSpanNoUnderline) { - String url = ((URLSpanNoUnderline) pressedLink).getURL(); - if (url.startsWith("@") || url.startsWith("#") || url.startsWith("/")) { - if (delegate != null) { - delegate.didPressUrl(url); - } - } - } else { - if (pressedLink instanceof URLSpan) { - Browser.openUrl(getContext(), ((URLSpan) pressedLink).getURL()); - } else { - pressedLink.onClick(this); - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - resetPressedLink(); - result = true; - } - } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - resetPressedLink(); - } - } - return result || super.onTouchEvent(event); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), height + AndroidUtilities.dp(8)); - } - - @Override - protected void onDraw(Canvas canvas) { - int x = (canvas.getWidth() - width) / 2; - int y = AndroidUtilities.dp(4); - Theme.backgroundMediaDrawableIn.setBounds(x, y, width + x, height + y); - Theme.backgroundMediaDrawableIn.draw(canvas); - canvas.save(); - canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y); - if (pressedLink != null) { - canvas.drawPath(urlPath, urlPaint); - } - if (textLayout != null) { - textLayout.draw(canvas); - } - canvas.restore(); - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotSwitchCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotSwitchCell.java deleted file mode 100644 index dbe52d888..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/BotSwitchCell.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 3.x.x. - * It is licensed under GNU GPL v. 2 or later. - * You should have received a copy of the license in this archive (see LICENSE). - * - * Copyright Nikolai Kudashov, 2013-2016. - */ - -package org.telegram.ui.Cells; - -import android.content.Context; -import android.os.Build; -import android.text.TextUtils; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.MotionEvent; -import android.widget.FrameLayout; -import android.widget.TextView; - -import org.telegram.messenger.AndroidUtilities; -import org.telegram.messenger.LocaleController; -import org.telegram.messenger.R; -import org.telegram.ui.Components.LayoutHelper; - -public class BotSwitchCell extends FrameLayout { - - private TextView textView; - - public BotSwitchCell(Context context) { - super(context); - setBackgroundResource(R.drawable.list_selector); - - textView = new TextView(context); - textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); - textView.setTextColor(0xff4391cc); - textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); - textView.setSingleLine(true); - textView.setEllipsize(TextUtils.TruncateAt.END); - textView.setMaxLines(1); - textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); - addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 14, 0, 14, 0)); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) { - if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { - getBackground().setHotspot(event.getX(), event.getY()); - } - } - return super.onTouchEvent(event); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY)); - } - - public void setText(String text) { - textView.setText(text); - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index 3ebf043a5..c69da42b2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -56,7 +56,6 @@ import org.telegram.ui.Components.SeekBarWaveform; import org.telegram.ui.Components.StaticLayoutEx; import org.telegram.ui.ActionBar.Theme; import org.telegram.ui.Components.TypefaceSpan; -import org.telegram.ui.Components.URLSpanBotCommand; import org.telegram.ui.Components.URLSpanNoUnderline; import org.telegram.ui.PhotoViewer; @@ -465,7 +464,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate Spannable buffer = (Spannable) currentMessageObject.messageText; ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); boolean ignore = false; - if (link.length == 0 || link.length != 0 && link[0] instanceof URLSpanBotCommand && !URLSpanBotCommand.enabled) { + if ( link.length == 0 ) { ignore = true; } if (!ignore) { @@ -558,7 +557,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate Spannable buffer = (Spannable) currentMessageObject.caption; ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); boolean ignore = false; - if (link.length == 0 || link.length != 0 && link[0] instanceof URLSpanBotCommand && !URLSpanBotCommand.enabled) { + if (link.length == 0 ) { ignore = true; } if (!ignore) { @@ -626,7 +625,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate Spannable buffer = (Spannable) currentMessageObject.linkDescription; ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); boolean ignore = false; - if (link.length == 0 || link.length != 0 && link[0] instanceof URLSpanBotCommand && !URLSpanBotCommand.enabled) { + if (link.length == 0 ) { ignore = true; } if (!ignore) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 3ae213b28..4d7714de2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -101,7 +101,6 @@ import org.telegram.ui.Cells.ChatMessageCell; import org.telegram.ui.Cells.ChatUnreadCell; import org.telegram.ui.Components.BackupImageView; import org.telegram.ui.ActionBar.BaseFragment; -import org.telegram.ui.Cells.BotHelpCell; import org.telegram.ui.Components.ChatActivityEnterView; import org.telegram.messenger.ImageReceiver; import org.telegram.ui.Components.ChatAttachAlert; @@ -115,7 +114,6 @@ import org.telegram.ui.Components.Size; import org.telegram.ui.Components.SizeNotifierFrameLayout; import org.telegram.ui.Components.StickersAlert; import org.telegram.ui.ActionBar.Theme; -import org.telegram.ui.Components.URLSpanBotCommand; import org.telegram.ui.Components.URLSpanNoUnderline; import org.telegram.ui.Components.URLSpanReplacement; import org.telegram.ui.Components.URLSpanUserMention; @@ -134,7 +132,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not protected TLRPC.Chat currentChat; protected TLRPC.User currentUser; // originally currentChat<->currentUser was used to differ between normal or group chats - private TLRPC.EncryptedChat currentEncryptedChat; // always NULL, not needed + private final TLRPC.EncryptedChat currentEncryptedChat = null; private boolean userBlocked = false; @@ -291,15 +289,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not protected TLRPC.ChatFull info = null; - private HashMap botInfo = new HashMap<>(); - private String botUser; - private long inlineReturn; + //private HashMap botInfo = new HashMap<>(); + //private String botUser; + //private long inlineReturn; //private MessageObject botButtons; //private MessageObject botReplyButtons; //private int botsCount; //private boolean hasBotsCommands; - private long chatEnterTime = 0; - private long chatLeaveTime = 0; + //private long chatEnterTime = 0; + //private long chatLeaveTime = 0; private String startVideoEdit = null; @@ -377,7 +375,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not currentChat.id = (int)dialog_id; // /EDIT BY MR - inlineReturn = arguments.getLong("inline_return", 0); + //inlineReturn = arguments.getLong("inline_return", 0); startLoadFromMessageId = arguments.getInt("message_id", 0); scrollToTopOnResume = arguments.getBoolean("scrollToTopOnResume", false); @@ -477,8 +475,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedWebpages); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedWebpagesInUpdates); NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesReadContent); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.botInfoDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.botKeyboardDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatSearchResultsAvailable); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedMessagesViews); NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoCantLoad); @@ -600,8 +596,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedWebpages); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedWebpagesInUpdates); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesReadContent); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botInfoDidLoaded); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botKeyboardDidLoaded); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatSearchResultsAvailable); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedMessagesViews); @@ -1933,9 +1927,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } })); - if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup) { + /*if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup) { mentionsAdapter.setBotInfo(botInfo); - } + }*/ mentionsAdapter.setParentFragment(this); mentionsAdapter.setChatInfo(info); mentionsAdapter.setNeedUsernames(currentChat != null); @@ -2431,24 +2425,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } - private void checkBotCommands() { - URLSpanBotCommand.enabled = false; - /*if (currentUser != null && currentUser.bot) { - URLSpanBotCommand.enabled = true; - } else */if (info instanceof TLRPC.TL_chatFull) { - for (int a = 0; a < info.participants.participants.size(); a++) { - TLRPC.ChatParticipant participant = info.participants.participants.get(a); - TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id); - if (user != null && user.bot) { - URLSpanBotCommand.enabled = true; - break; - } - } - } else if (info instanceof TLRPC.TL_channelFull) { - URLSpanBotCommand.enabled = !info.bot_info.isEmpty(); - } - } - /* public void processInlineBotContextPM(TLRPC.TL_inlineBotSwitchPM object) { if (object == null) { @@ -4274,7 +4250,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not // define the animations that we want to receive during the opening animation -- EDIT BY MR if (!openAnimationEnded) { NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.chatInfoDidLoaded, NotificationCenter.dialogsNeedReload, - NotificationCenter.closeChats, NotificationCenter.botKeyboardDidLoaded/*, NotificationCenter.botInfoDidLoaded*/}); + NotificationCenter.closeChats}); } /* EDIT BY MR -- not sure what this is for @@ -4663,11 +4639,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } - + /* if (messages.isEmpty() && currentEncryptedChat == null && currentUser != null && currentUser.bot && botUser == null) { botUser = ""; updateBottomOverlay(); } + */ if (newRowsCount == 0 && currentEncryptedChat != null && !endReached[0]) { first = true; @@ -4772,7 +4749,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } */ //} - if (currentChat != null || inlineReturn != 0) { + if (currentChat != null /*|| inlineReturn != 0*/ ) { for (int a = 0; a < arr.size(); a++) { MessageObject messageObject = arr.get(a); if (currentChat != null) { @@ -4793,8 +4770,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not // messageObject.generatePinMessageText(null, null); //} } - } else if (inlineReturn != 0) { - /*if (messageObject.messageOwner.reply_markup != null) { + } /*else if (inlineReturn != 0) { + if (messageObject.messageOwner.reply_markup != null) { for (int b = 0; b < messageObject.messageOwner.reply_markup.rows.size(); b++) { TLRPC.TL_keyboardButtonRow row = messageObject.messageOwner.reply_markup.rows.get(b); for (int c = 0; c < row.buttons.size(); c++) { @@ -4805,8 +4782,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } } - }*/ - } + } + }*/ } } @@ -5135,12 +5112,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not waitingForLoad.add(lastLoadIndex); MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReached[0], minDate[0], classGuid, 0, 0, ChatObject.isChannel(currentChat), lastLoadIndex++); loading = true; - } else { + } /*else { if ( currentUser != null && currentUser.bot && botUser == null) { botUser = ""; updateBottomOverlay(); } - } + }*/ } if (updated && chatAdapter != null) { removeUnreadPlane(); @@ -5250,8 +5227,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not avatarContainer.updateSubtitle(); } if (info instanceof TLRPC.TL_chatFull) { - botInfo.clear(); - URLSpanBotCommand.enabled = false; for (int a = 0; a < info.participants.participants.size(); a++) { TLRPC.ChatParticipant participant = info.participants.participants.get(a); TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id); @@ -5260,14 +5235,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not chatListView.invalidateViews(); } } else if (info instanceof TLRPC.TL_channelFull) { - botInfo.clear(); - URLSpanBotCommand.enabled = !info.bot_info.isEmpty(); + //botInfo.clear(); + //URLSpanBotCommand.enabled = !info.bot_info.isEmpty(); if (chatListView != null) { chatListView.invalidateViews(); } - if (mentionsAdapter != null && (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup)) { - mentionsAdapter.setBotInfo(botInfo); - } + //if (mentionsAdapter != null && (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup)) { + // mentionsAdapter.setBotInfo(botInfo); + //} } } } else if (id == NotificationCenter.chatInfoCantLoad) { @@ -5361,10 +5336,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not actionBar.hideActionMode(); updatePinnedMessageView(true); - if ( currentUser != null && currentUser.bot && botUser == null) { + /*if ( currentUser != null && currentUser.bot && botUser == null) { botUser = ""; updateBottomOverlay(); - } + }*/ + if ((Boolean) args[1]) { if (chatAdapter != null) { progressView.setVisibility(chatAdapter.botInfoRow == -1 ? View.VISIBLE : View.INVISIBLE); @@ -5620,7 +5596,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void onTransitionAnimationStart(boolean isOpen, boolean backward) { NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.chatInfoDidLoaded, NotificationCenter.dialogsNeedReload, - NotificationCenter.closeChats, NotificationCenter.messagesDidLoaded, NotificationCenter.botKeyboardDidLoaded/*, NotificationCenter.botInfoDidLoaded*/}); + NotificationCenter.closeChats, NotificationCenter.messagesDidLoaded}); NotificationCenter.getInstance().setAnimationInProgress(true); if (isOpen) { openAnimationEnded = false; @@ -5668,13 +5644,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else { bottomOverlayChatText.setText(LocaleController.getString("Unblock", R.string.Unblock)); } - } else if (botUser != null && currentUser.bot) { + } + /*else if (botUser != null && currentUser.bot) { bottomOverlayChatText.setText(LocaleController.getString("BotStart", R.string.BotStart)); chatActivityEnterView.hidePopup(false); if (getParentActivity() != null) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } - } else { + } */ + else { bottomOverlayChatText.setText(LocaleController.getString("DeleteThisChat", R.string.DeleteThisChat)); } } @@ -6050,7 +6028,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not chatListView.setOnItemClickListener(onItemClickListener); chatListView.setLongClickable(true); } - checkBotCommands(); } @Override @@ -6903,7 +6880,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not public void showOpenUrlAlert(final String url) { if (Browser.isInternalUrl(url)) { - Browser.openUrl(getParentActivity(), url, inlineReturn == 0); + Browser.openUrl(getParentActivity(), url); } else { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("OpenUrlAlert", R.string.OpenUrlAlert, url)); @@ -6911,7 +6888,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - Browser.openUrl(getParentActivity(), url, inlineReturn == 0); + Browser.openUrl(getParentActivity(), url); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); @@ -6933,9 +6910,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not public class ChatActivityAdapter extends RecyclerView.Adapter { private Context mContext; - private boolean isBot; + private final boolean isBot = false; private int rowCount; - private int botInfoRow = -1; + private final int botInfoRow = -1; private int loadingUpRow; private int loadingDownRow; private int messagesStartRow; @@ -6943,16 +6920,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not public ChatActivityAdapter(Context context) { mContext = context; - isBot = currentUser != null && currentUser.bot; } public void updateRows() { rowCount = 0; - if (currentUser != null && currentUser.bot) { - botInfoRow = rowCount++; - } else { - botInfoRow = -1; - } if (!messages.isEmpty()) { if (!endReached[0] || mergeDialogId != 0 && !endReached[1]) { loadingUpRow = rowCount++; @@ -7114,7 +7085,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void onClick(DialogInterface dialog, final int which) { if (which == 0) { - Browser.openUrl(getParentActivity(), urlFinal, inlineReturn == 0); + Browser.openUrl(getParentActivity(), urlFinal); } else if (which == 1) { AndroidUtilities.addToClipboard(urlFinal); } @@ -7125,7 +7096,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (url instanceof URLSpanReplacement) { showOpenUrlAlert(((URLSpanReplacement) url).getURL()); } else if (url instanceof URLSpan) { - Browser.openUrl(getParentActivity(), urlFinal, inlineReturn == 0); + Browser.openUrl(getParentActivity(), urlFinal); } else { url.onClick(fragmentView); } @@ -7213,7 +7184,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } }); - if (currentEncryptedChat == null) { + /*if (currentEncryptedChat == null)*/ { chatMessageCell.setAllowAssistant(true); } } else if (viewType == 1) { @@ -7245,9 +7216,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else if (uid != UserConfig.getClientUserId()) { Bundle args = new Bundle(); args.putInt("user_id", uid); - if (currentEncryptedChat != null && uid == currentUser.id) { + /*if (currentEncryptedChat != null && uid == currentUser.id) { args.putLong("dialog_id", dialog_id); - } + }*/ ProfileActivity fragment = new ProfileActivity(args); fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == uid); presentFragment(fragment); @@ -7268,8 +7239,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (position == botInfoRow) { - BotHelpCell helpView = (BotHelpCell) holder.itemView; - helpView.setText(!botInfo.isEmpty() ? botInfo.get(currentUser.id).description : null); + //BotHelpCell helpView = (BotHelpCell) holder.itemView; + //helpView.setText(!botInfo.isEmpty() ? botInfo.get(currentUser.id).description : null); } else if (position == loadingDownRow || position == loadingUpRow) { ChatLoadingCell loadingCell = (ChatLoadingCell) holder.itemView; loadingCell.setProgressVisible(loadsCount > 1); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/URLSpanBotCommand.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/URLSpanBotCommand.java deleted file mode 100644 index adb870543..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/URLSpanBotCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 3.x.x. - * It is licensed under GNU GPL v. 2 or later. - * You should have received a copy of the license in this archive (see LICENSE). - * - * Copyright Nikolai Kudashov, 2013-2016. - */ - -package org.telegram.ui.Components; - -import android.text.TextPaint; - -import org.telegram.ui.ActionBar.Theme; - -public class URLSpanBotCommand extends URLSpanNoUnderline { - - public static boolean enabled = true; - - public URLSpanBotCommand(String url) { - super(url); - } - - @Override - public void updateDrawState(TextPaint ds) { - super.updateDrawState(ds); - ds.setColor(enabled ? Theme.MSG_LINK_TEXT_COLOR : Theme.MSG_TEXT_COLOR); - ds.setUnderlineText(false); - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index bd95676f4..e815b0b5d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -128,7 +128,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. private TLRPC.EncryptedChat currentEncryptedChat; private TLRPC.Chat currentChat; - private TLRPC.BotInfo botInfo; private int totalMediaCount = -1; private int totalMediaCountMerge = -1; @@ -228,7 +227,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatCreated); NotificationCenter.getInstance().addObserver(this, NotificationCenter.encryptedChatUpdated); NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.botInfoDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.userInfoDidLoaded); if (currentEncryptedChat != null) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedNewMessages); @@ -324,7 +322,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatCreated); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatUpdated); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botInfoDidLoaded); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.userInfoDidLoaded); //MessagesController.getInstance().cancelLoadFullUser(user_id); if (currentEncryptedChat != null) { @@ -485,10 +482,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); - String about = MessagesController.getInstance().getUserAbout(botInfo.user_id); + /*String about = MessagesController.getInstance().getUserAbout(botInfo.user_id); if (botInfo != null && about != null) { intent.putExtra(Intent.EXTRA_TEXT, String.format("%s https://telegram.me/%s", about, user.username)); - } else { + } else*/ { intent.putExtra(Intent.EXTRA_TEXT, String.format("https://telegram.me/%s", user.username)); } startActivityForResult(Intent.createChooser(intent, LocaleController.getString("BotShare", R.string.BotShare)), 500); @@ -1022,12 +1019,12 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. @Override public void onClick(DialogInterface dialogInterface, int i) { try { - String about; + String about = null; if (position == channelInfoRow) { about = info.about; - } else { + } /*else { about = MessagesController.getInstance().getUserAbout(botInfo.user_id); - } + }*/ if (about == null) { return; } @@ -1465,15 +1462,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } } else if (id == NotificationCenter.closeChats) { removeSelfFromStack(); - } else if (id == NotificationCenter.botInfoDidLoaded) { - TLRPC.BotInfo info = (TLRPC.BotInfo) args[0]; - if (info.user_id == user_id) { - botInfo = info; - updateRowsIds(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - } } else if (id == NotificationCenter.userInfoDidLoaded) { int uid = (Integer) args[0]; if (uid == user_id) {