diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 480718c3e..357507c26 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -290,7 +290,7 @@ android { } } - defaultConfig.versionCode = 2221 + defaultConfig.versionCode = 2223 applicationVariants.all { variant -> variant.outputs.all { output -> diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index 9409e4c75..a9119e477 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -18,7 +18,7 @@ public class BuildVars { public static boolean LOGS_ENABLED = false; public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; - public static int BUILD_VERSION = 2221; + public static int BUILD_VERSION = 2223; public static String BUILD_VERSION_STRING = "7.4.0"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index e1fb76f95..8a5207588 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -4628,7 +4628,7 @@ public class MessagesStorage extends BaseController { final TLRPC.ChatFull finalInfo = info; AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, finalInfo, 0, false)); - SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?, ?, ?, ?)"); + SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?, ?, ?, ?, ?)"); NativeByteBuffer data = new NativeByteBuffer(info.getObjectSize()); info.serializeToStream(data); state.bindInteger(1, info.id); @@ -4636,6 +4636,7 @@ public class MessagesStorage extends BaseController { state.bindInteger(3, info.pinned_msg_id); state.bindInteger(4, info.online_count); state.bindInteger(5, info.inviterId); + state.bindInteger(6, info.invitesCount); state.step(); state.dispose(); data.reuse(); @@ -5180,7 +5181,7 @@ public class MessagesStorage extends BaseController { final TLRPC.ChatFull finalInfo = info; AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, finalInfo, 0, false)); - SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?, ?, ?, ?)"); + SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?, ?, ?, ?, ?)"); NativeByteBuffer data = new NativeByteBuffer(info.getObjectSize()); info.serializeToStream(data); state.bindInteger(1, chat_id); @@ -5188,6 +5189,7 @@ public class MessagesStorage extends BaseController { state.bindInteger(3, info.pinned_msg_id); state.bindInteger(4, info.online_count); state.bindInteger(5, info.inviterId); + state.bindInteger(6, info.invitesCount); state.step(); state.dispose(); data.reuse(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java index aa6146ae9..a8233220a 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java @@ -5470,6 +5470,9 @@ public class SendMessagesHelper extends BaseController implements NotificationCe } String path = MediaController.copyFileToCache(mediaUri, "txt"); + if (path == null) { + continue; + } final File f = new File(path); long size; if (!f.exists() || (size = f.length()) == 0) { @@ -5483,6 +5486,14 @@ public class SendMessagesHelper extends BaseController implements NotificationCe } importingHistory.totalSize += size; if (a == 0) { + if (size > 32 * 1024 * 1024) { + f.delete(); + AndroidUtilities.runOnUIThread(() -> { + Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("ImportFileTooLarge", R.string.ImportFileTooLarge), Toast.LENGTH_SHORT).show(); + onStartImport.run(0); + }); + return; + } importingHistory.historyPath = path; } else { importingHistory.uploadMedia.add(path); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatUsersActivity.java index fc8664d73..12bb4a6bb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatUsersActivity.java @@ -745,7 +745,9 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente @Override public void invalidate() { super.invalidate(); - fragmentView.invalidate(); + if (fragmentView != null) { + fragmentView.invalidate(); + } } }; listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java index a30160be8..eed0ac20c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/FragmentContextView.java @@ -541,6 +541,10 @@ public class FragmentContextView extends FrameLayout implements NotificationCent } VoIPHelper.startCall(chatActivity.getMessagesController().getChat(call.chatId), false, fragment.getParentActivity()); } else if (currentStyle == 5) { + SendMessagesHelper.ImportingHistory importingHistory = parentFragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) parentFragment).getDialogId()); + if (importingHistory == null) { + return; + } ImportingAlert importingAlert = new ImportingAlert(getContext(), (ChatActivity) fragment); importingAlert.setOnHideListener(dialog -> checkImport(false)); fragment.showDialog(importingAlert); @@ -610,7 +614,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent show = true; } else if (fragment instanceof ChatActivity && fragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) fragment).getDialogId()) != null && !isPlayingVoice()) { show = true; - } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing() && !isPlayingVoice()) { + } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && ((ChatActivity) fragment).getGroupCall().call.participants_count > 0 && !GroupCallPip.isShowing() && !isPlayingVoice()) { show = true; } else { MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); @@ -881,7 +885,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent checkCall(true); } else if (fragment instanceof ChatActivity && fragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) fragment).getDialogId()) != null && !isPlayingVoice()) { checkImport(true); - } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing() && !isPlayingVoice()) { + } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && ((ChatActivity) fragment).getGroupCall().call.participants_count > 0 && !GroupCallPip.isShowing() && !isPlayingVoice()) { checkCall(true); } else { checkPlayer(true); @@ -1220,8 +1224,9 @@ public class FragmentContextView extends FrameLayout implements NotificationCent if (messageObject == null || messageObject.getId() == 0 || messageObject.isVideo()) { lastMessageObject = null; boolean callAvailable = supportsCalls && VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING && !GroupCallPip.isShowing(); - if (!isPlayingVoice() && !callAvailable && fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && !GroupCallPip.isShowing()) { - callAvailable = true; + if (!isPlayingVoice() && !callAvailable && fragment instanceof ChatActivity && !GroupCallPip.isShowing()) { + ChatObject.Call call = ((ChatActivity) fragment).getGroupCall(); + callAvailable = call != null && call.call.participants_count > 0; } if (callAvailable) { checkCall(false); @@ -1600,7 +1605,7 @@ public class FragmentContextView extends FrameLayout implements NotificationCent }); animatorSet.start(); } - } else if (currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1) { + } else if (visible && (currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1)) { visible = false; setVisibility(GONE); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java index 6881a02a8..3e2806efe 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/LinkActionView.java @@ -16,6 +16,7 @@ import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -64,6 +65,8 @@ public class LinkActionView extends LinearLayout { private QRCodeBottomSheet qrCodeBottomSheet; private boolean isPublic; + float[] point = new float[2]; + public LinkActionView(Context context, BaseFragment fragment, BottomSheet bottomSheet, int chatId, boolean permanent) { super(context); this.fragment = fragment; @@ -227,41 +230,29 @@ public class LinkActionView extends LinearLayout { layout.addView(subItem, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); FrameLayout container; - float y = 0; if (bottomSheet == null) { container = fragment.getParentLayout(); } else { container = bottomSheet.getContainer(); } - View v = frameLayout; - while (v != container) { - y += v.getY(); - v = (View) v.getParent(); - if (!(v instanceof ViewGroup)) { - return; - } - } + if (container != null) { - FrameLayout finalContainer = container; + float x = 0; + float y; + getPointOnScreen(frameLayout, container, point); + y = point[1]; + + final FrameLayout finalContainer = container; View dimView = new View(context) { + @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0x33000000); - float x = 0; - float y = 0; - View v = frameLayout; - while (v != finalContainer) { - y += v.getY(); - x += v.getX(); - v = (View) v.getParent(); - if (!(v instanceof ViewGroup)) { - return; - } - } + getPointOnScreen(frameLayout, finalContainer, point); canvas.save(); - canvas.translate(x, y); + canvas.translate(point[0], point[1]); frameLayout.draw(canvas); canvas.restore(); } @@ -302,7 +293,11 @@ public class LinkActionView extends LinearLayout { } }); - actionBarPopupWindow.showAtLocation(container, 0, (int) container.getMeasuredWidth() - layout.getMeasuredWidth() - AndroidUtilities.dp(16), (int) y + frameLayout.getMeasuredHeight()); + if (AndroidUtilities.isTablet()) { + y += container.getPaddingTop(); + x -= container.getPaddingLeft(); + } + actionBarPopupWindow.showAtLocation(container, 0, (int) (container.getMeasuredWidth() - layout.getMeasuredWidth() - AndroidUtilities.dp(16) + container.getX() + x), (int) (y + frameLayout.getMeasuredHeight() + container.getY())); } }); @@ -316,6 +311,27 @@ public class LinkActionView extends LinearLayout { updateColors(); } + private void getPointOnScreen(FrameLayout frameLayout, FrameLayout finalContainer, float[] point) { + float x = 0; + float y = 0; + View v = frameLayout; + while (v != finalContainer) { + y += v.getY(); + x += v.getX(); + if (v instanceof ScrollView) { + y -= v.getScrollY(); + } + v = (View) v.getParent(); + if (!(v instanceof ViewGroup)) { + return; + } + } + x -= finalContainer.getPaddingLeft(); + y -= finalContainer.getPaddingTop(); + point[0] = x; + point[1] = y; + } + private void showQrCode() { qrCodeBottomSheet = new QRCodeBottomSheet(getContext(), link) { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index d5f108455..244085b69 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -2409,10 +2409,11 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa Runnable cancelRunnable = null; String content; + InputStream inputStream = null; try { int linesCount = 0; - InputStream in = getContentResolver().openInputStream(importUri); - BufferedReader r = new BufferedReader(new InputStreamReader(in)); + inputStream = getContentResolver().openInputStream(importUri); + BufferedReader r = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder total = new StringBuilder(); for (String line; (line = r.readLine()) != null && linesCount < 100; ) { total.append(line).append('\n'); @@ -2422,6 +2423,14 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } catch (Exception e) { FileLog.e(e); return; + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (Exception e2) { + FileLog.e(e2); + } } final TLRPC.TL_messages_checkHistoryImport req = new TLRPC.TL_messages_checkHistoryImport(); req.import_head = content; @@ -3388,6 +3397,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa final int account = dialogsFragment != null ? dialogsFragment.getCurrentAccount() : currentAccount; if (exportingChatUri != null) { + Uri uri = exportingChatUri; + ArrayList documentsUris = documentsUrisArray != null ? new ArrayList<>(documentsUrisArray) : null; final AlertDialog progressDialog = new AlertDialog(this, 3); SendMessagesHelper.getInstance(account).prepareImportHistory(dids.get(0), exportingChatUri, documentsUrisArray, (result) -> { if (result != 0) { @@ -3405,7 +3416,12 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa fragment.setOpenImport(); actionBarLayout.presentFragment(fragment, dialogsFragment != null || param, dialogsFragment == null, true, false); } else { - dialogsFragment.finishFragment(); + documentsUrisArray = documentsUris; + if (documentsUrisArray == null) { + documentsUrisArray = new ArrayList<>(); + } + documentsUrisArray.add(0, uri); + openDialogsToSend(true); } try { progressDialog.dismiss(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index b177ca6d5..ddebe802c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -398,7 +398,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. private int transitionIndex; private TLRPC.Document preloadedSticker; - private ArrayList chatParticipants = new ArrayList<>(); + private ArrayList visibleChatParticipants = new ArrayList<>(); + private ArrayList visibleSortedUsers = new ArrayList<>(); private int usersForceShowingIn = 0; private final Property HEADER_SHADOW = new AnimationProperties.FloatProperty("headerShadow") { @@ -1328,7 +1329,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. getNotificationCenter().addObserver(this, NotificationCenter.groupCallUpdated); sortedUsers = new ArrayList<>(); - updateOnlineCount(); + updateOnlineCount(true); if (chatInfo == null) { chatInfo = getMessagesController().getChatFull(chat_id); } @@ -3455,7 +3456,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } } if (changed) { - updateOnlineCount(); + updateOnlineCount(true); updateRowsIds(); listAdapter.notifyDataSetChanged(); } @@ -3819,10 +3820,20 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (chatInfo.participants == null) { chatInfo.participants = new TLRPC.TL_chatParticipants(); } - TLRPC.ChatParticipant participant = new TLRPC.TL_chatParticipant(); - participant.user_id = user.id; - participant.inviter_id = getAccountInstance().getUserConfig().clientUserId; - chatInfo.participants.participants.add(participant); + if (ChatObject.isChannel(currentChat)) { + TLRPC.TL_chatChannelParticipant channelParticipant1 = new TLRPC.TL_chatChannelParticipant(); + channelParticipant1.channelParticipant = new TLRPC.TL_channelParticipant(); + channelParticipant1.channelParticipant.inviter_id = getUserConfig().getClientUserId(); + channelParticipant1.channelParticipant.user_id = user.id; + channelParticipant1.channelParticipant.date = getConnectionsManager().getCurrentTime(); + chatInfo.participants.participants.add(channelParticipant1); + } else { + TLRPC.ChatParticipant participant = new TLRPC.TL_chatParticipant(); + participant.user_id = user.id; + participant.inviter_id = getAccountInstance().getUserConfig().clientUserId; + chatInfo.participants.participants.add(participant); + } + chatInfo.participants_count++; getMessagesController().putUser(user, false); } } @@ -4330,7 +4341,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if ((mask & MessagesController.UPDATE_MASK_CHAT) != 0) { updateListAnimated(true); } else { - updateOnlineCount(); + updateOnlineCount(true); } updateProfileData(); } @@ -4352,7 +4363,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. return; } chatInfo.online_count = (Integer) args[1]; - updateOnlineCount(); + updateOnlineCount(true); updateProfileData(); } else if (id == NotificationCenter.contactsDidLoad) { createActionBarMenu(true); @@ -4855,7 +4866,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. return null; } - private void updateOnlineCount() { + private void updateOnlineCount(boolean notify) { onlineCount = 0; int currentTime = getConnectionsManager().getCurrentTime(); sortedUsers.clear(); @@ -4918,7 +4929,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. FileLog.e(e); } - if (listAdapter != null && membersStartRow > 0) { + if (notify && listAdapter != null && membersStartRow > 0) { listAdapter.notifyItemRangeChanged(membersStartRow, sortedUsers.size()); } if (sharedMediaLayout != null && sharedMediaRow != -1 && (sortedUsers.size() > 5 || usersForceShowingIn == 2) && usersForceShowingIn != 1) { @@ -5052,7 +5063,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. unblockRow = -1; joinRow = -1; lastSectionRow = -1; - chatParticipants.clear(); + visibleChatParticipants.clear(); + visibleSortedUsers.clear(); boolean hasMedia = false; if (sharedMediaPreloader != null) { @@ -5201,7 +5213,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. rowCount += count; membersEndRow = rowCount; membersSectionRow = rowCount++; - chatParticipants.addAll(chatInfo.participants.participants); + visibleChatParticipants.addAll(chatInfo.participants.participants); + if (sortedUsers != null) { + visibleSortedUsers.addAll(sortedUsers); + } usersForceShowingIn = 1; if (sharedMediaLayout != null) { sharedMediaLayout.setChatUsers(null, null); @@ -5237,7 +5252,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. rowCount += chatInfo.participants.participants.size(); membersEndRow = rowCount; membersSectionRow = rowCount++; - chatParticipants.addAll(chatInfo.participants.participants); + visibleChatParticipants.addAll(chatInfo.participants.participants); + if (sortedUsers != null) { + visibleSortedUsers.addAll(sortedUsers); + } if (sharedMediaLayout != null) { sharedMediaLayout.setChatUsers(null, null); } @@ -6686,10 +6704,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. UserCell userCell = (UserCell) holder.itemView; TLRPC.ChatParticipant part; try { - if (!sortedUsers.isEmpty()) { - part = chatInfo.participants.participants.get(sortedUsers.get(position - membersStartRow)); + if (!visibleSortedUsers.isEmpty()) { + part = visibleChatParticipants.get(visibleSortedUsers.get(position - membersStartRow)); } else { - part = chatInfo.participants.participants.get(position - membersStartRow); + part = visibleChatParticipants.get(position - membersStartRow); } } catch (Exception e) { part = null; @@ -7511,7 +7529,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. public void updateListAnimated(boolean updateOnlineCount) { if (listAdapter == null) { if (updateOnlineCount) { - updateOnlineCount(); + updateOnlineCount(false); } updateRowsIds(); return; @@ -7522,14 +7540,12 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. diffCallback.fillPositions(diffCallback.oldPositionToItem); diffCallback.oldChatParticipant.clear(); diffCallback.oldChatParticipantSorted.clear(); - if (sortedUsers != null) { - diffCallback.oldChatParticipantSorted.addAll(sortedUsers); - } - diffCallback.oldChatParticipant.addAll(chatParticipants); + diffCallback.oldChatParticipant.addAll(visibleChatParticipants); + diffCallback.oldChatParticipantSorted.addAll(visibleSortedUsers); diffCallback.oldMembersStartRow = membersStartRow; diffCallback.oldMembersEndRow = membersEndRow; if (updateOnlineCount) { - updateOnlineCount(); + updateOnlineCount(false); } updateRowsIds(); diffCallback.fillPositions(diffCallback.newPositionToItem); @@ -7589,9 +7605,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } if (!sortedUsers.isEmpty()) { - newItem = chatParticipants.get(sortedUsers.get(newItemPosition - membersStartRow)); + newItem = visibleChatParticipants.get(visibleSortedUsers.get(newItemPosition - membersStartRow)); } else { - newItem = chatParticipants.get(newItemPosition - membersStartRow); + newItem = visibleChatParticipants.get(newItemPosition - membersStartRow); } return oldItem.user_id == newItem.user_id; } diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 596da1f48..30e8f7441 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -1123,6 +1123,7 @@ Pinned messages hidden You will see the bar with pinned messages only if a new message is pinned. Imported + Importing file is too large. Audio will play at normal speed. Audio will play two times faster. Message copied to clipboard.