Skip to content

Commit 3c9a4c1

Browse files
committed
update to 9.6.2
1 parent c1e3121 commit 3c9a4c1

File tree

96 files changed

+475
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+475
-383
lines changed

‎TMessagesProj/src/main/java/org/telegram/messenger/AnimatedFileDrawableStream.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class AnimatedFileDrawableStream implements FileLoadOperationStream {
88

9-
private final FileLoadOperation loadOperation;
9+
private FileLoadOperation loadOperation;
1010
private CountDownLatch countDownLatch;
1111
private TLRPC.Document document;
1212
private ImageLocation location;
@@ -76,22 +76,30 @@ public int read(int offset, int readLength) {
7676
return 0;
7777
}
7878
}
79+
countDownLatch = new CountDownLatch(1);
7980
if (loadOperation.isPaused() || lastOffset != offset || preview) {
80-
FileLoader.getInstance(currentAccount).loadStreamFile(this, document, location, parentObject, offset, preview, loadingPriority);
81+
FileLoadOperation loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, location, parentObject, offset, preview, loadingPriority);
82+
if (this.loadOperation != loadOperation) {
83+
this.loadOperation.removeStreamListener(this);
84+
this.loadOperation = loadOperation;
85+
}
86+
lastOffset = offset + availableLength;
8187
}
8288
synchronized (sync) {
8389
if (canceled) {
90+
countDownLatch = null;
8491
cancelLoadingInternal();
8592
return 0;
8693
}
87-
countDownLatch = new CountDownLatch(1);
8894
}
8995
if (!preview) {
9096
FileLoader.getInstance(currentAccount).setLoadingVideo(document, false, true);
9197
}
92-
waitingForLoad = true;
93-
countDownLatch.await();
94-
waitingForLoad = false;
98+
if (countDownLatch != null) {
99+
waitingForLoad = true;
100+
countDownLatch.await();
101+
waitingForLoad = false;
102+
}
95103
}
96104
}
97105
lastOffset = offset + availableLength;
@@ -113,10 +121,17 @@ public void cancel(boolean removeLoading) {
113121
synchronized (sync) {
114122
if (countDownLatch != null) {
115123
countDownLatch.countDown();
124+
countDownLatch = null;
116125
if (removeLoading && !canceled && !preview) {
117126
FileLoader.getInstance(currentAccount).removeLoadingVideo(document, false, true);
118127
}
119128
}
129+
if (parentObject instanceof MessageObject) {
130+
MessageObject messageObject = (MessageObject) parentObject;
131+
if (DownloadController.getInstance(messageObject.currentAccount).isDownloading(messageObject.getId())) {
132+
removeLoading = false;
133+
}
134+
}
120135
if (removeLoading) {
121136
cancelLoadingInternal();
122137
}
@@ -165,6 +180,7 @@ public boolean isWaitingForLoad() {
165180
public void newDataAvailable() {
166181
if (countDownLatch != null) {
167182
countDownLatch.countDown();
183+
countDownLatch = null;
168184
}
169185
}
170186

‎TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class BuildVars {
2424
public static boolean USE_CLOUD_STRINGS = true;
2525
public static boolean CHECK_UPDATES = true;
2626
public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29;
27-
public static int BUILD_VERSION = 3333;
28-
public static String BUILD_VERSION_STRING = "9.6.1";
27+
public static int BUILD_VERSION = 3341;
28+
public static String BUILD_VERSION_STRING = "9.6.2";
2929
public static int APP_ID = 4;
3030
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";
3131

‎TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java

+8
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,14 @@ protected File getCurrentFile() {
619619
return result[0];
620620
}
621621

622+
protected File getCurrentFileFast() {
623+
if (state == stateFinished) {
624+
return cacheFileFinal;
625+
} else {
626+
return cacheFileTemp;
627+
}
628+
}
629+
622630
private long getDownloadedLengthFromOffsetInternal(ArrayList<Range> ranges, final long offset, final long length) {
623631
if (ranges == null || state == stateFinished || ranges.isEmpty()) {
624632
if (state == stateFinished) {

‎TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ public FileLoader(int instance) {
203203
super(instance);
204204
filePathDatabase = new FilePathDatabase(instance);
205205
for (int i = 0; i < smallFilesQueue.length; i++) {
206-
smallFilesQueue[i] = new FileLoaderPriorityQueue("smallFilesQueue dc" + (i + 1), 5);
207-
largeFilesQueue[i] = new FileLoaderPriorityQueue("largeFilesQueue dc" + (i + 1), 2);
206+
smallFilesQueue[i] = new FileLoaderPriorityQueue(instance, "smallFilesQueue dc" + (i + 1), FileLoaderPriorityQueue.TYPE_SMALL);
207+
largeFilesQueue[i] = new FileLoaderPriorityQueue(instance, "largeFilesQueue dc" + (i + 1), FileLoaderPriorityQueue.TYPE_LARGE);
208208
}
209209
dumpFilesQueue();
210210
}

‎TMessagesProj/src/main/java/org/telegram/messenger/FileLoaderPriorityQueue.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44

55
public class FileLoaderPriorityQueue {
66

7-
private final int maxActiveOperationsCount;
7+
public static final int TYPE_SMALL = 0;
8+
public static final int TYPE_LARGE = 1;
89
String name;
10+
int type;
11+
int currentAccount;
912

1013
private ArrayList<FileLoadOperation> allOperations = new ArrayList<>();
1114

1215
private int PRIORITY_VALUE_MAX = (1 << 20);
1316
private int PRIORITY_VALUE_NORMAL = (1 << 16);
1417
private int PRIORITY_VALUE_LOW = 0;
1518

16-
FileLoaderPriorityQueue(String name, int maxActiveOperationsCount) {
19+
FileLoaderPriorityQueue(int currentAccount, String name, int type) {
20+
this.currentAccount = currentAccount;
1721
this.name = name;
18-
this.maxActiveOperationsCount = maxActiveOperationsCount;
22+
this.type = type;
1923
}
2024

2125
public void add(FileLoadOperation operation) {
@@ -55,7 +59,7 @@ public void checkLoadingOperations() {
5559
int activeCount = 0;
5660
int lastPriority = 0;
5761
boolean pauseAllNextOperations = false;
58-
int max = maxActiveOperationsCount;
62+
int max = type == TYPE_LARGE ? MessagesController.getInstance(currentAccount).largeQueueMaxActiveOperations : MessagesController.getInstance(currentAccount).smallQueueMaxActiveOperations;
5963
for (int i = 0; i < allOperations.size(); i++) {
6064
FileLoadOperation operation = allOperations.get(i);
6165
if (i > 0 && !pauseAllNextOperations) {

‎TMessagesProj/src/main/java/org/telegram/messenger/FileStreamLoadOperation.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.telegram.tgnet.TLRPC;
2121

2222
import java.io.EOFException;
23+
import java.io.File;
2324
import java.io.IOException;
2425
import java.io.RandomAccessFile;
2526
import java.util.concurrent.CountDownLatch;
@@ -37,6 +38,7 @@ public class FileStreamLoadOperation extends BaseDataSource implements FileLoadO
3738
private TLRPC.Document document;
3839
private Object parentObject;
3940
private int currentAccount;
41+
File currentFile;
4042

4143
public FileStreamLoadOperation() {
4244
super(/* isNetwork= */ false);
@@ -78,7 +80,7 @@ public long open(DataSpec dataSpec) throws IOException {
7880
opened = true;
7981
transferStarted(dataSpec);
8082
if (loadOperation != null) {
81-
file = new RandomAccessFile(loadOperation.getCurrentFile(), "r");
83+
file = new RandomAccessFile(currentFile = loadOperation.getCurrentFile(), "r");
8284
file.seek(currentOffset);
8385
}
8486
return bytesRemaining;
@@ -99,13 +101,16 @@ public int read(byte[] buffer, int offset, int readLength) throws IOException {
99101
while (availableLength == 0 && opened) {
100102
availableLength = (int) loadOperation.getDownloadedLengthFromOffset(currentOffset, readLength)[0];
101103
if (availableLength == 0) {
104+
countDownLatch = new CountDownLatch(1);
102105
FileLoadOperation loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, null, parentObject, currentOffset, false, FileLoader.PRIORITY_HIGH);
103106
if (this.loadOperation != loadOperation) {
104107
this.loadOperation.removeStreamListener(this);
105108
this.loadOperation = loadOperation;
106109
}
107-
countDownLatch = new CountDownLatch(1);
108-
countDownLatch.await();
110+
if (countDownLatch != null) {
111+
countDownLatch.await();
112+
countDownLatch = null;
113+
}
109114
}
110115
}
111116
if (!opened) {
@@ -146,14 +151,18 @@ public void close() {
146151
transferEnded();
147152
}
148153
if (countDownLatch != null) {
154+
// FileLog.d("FileStreamLoadOperation count down");
149155
countDownLatch.countDown();
156+
countDownLatch = null;
150157
}
151158
}
152159

153160
@Override
154161
public void newDataAvailable() {
155162
if (countDownLatch != null) {
163+
// FileLog.d("FileStreamLoadOperation count down");
156164
countDownLatch.countDown();
165+
countDownLatch = null;
157166
}
158167
}
159168
}

‎TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ public void startRaiseToEarSensors(ChatActivity chatActivity) {
18021802
if (chatActivity == null || accelerometerSensor == null && (gravitySensor == null || linearAcceleration == null) || proximitySensor == null) {
18031803
return;
18041804
}
1805-
if (!SharedConfig.enabledRaiseTo(true) && (playingMessageObject == null || !playingMessageObject.isVoice() && !playingMessageObject.isRoundVideo())) {
1805+
if (!SharedConfig.enabledRaiseTo(false) && (playingMessageObject == null || !playingMessageObject.isVoice() && !playingMessageObject.isRoundVideo())) {
18061806
return;
18071807
}
18081808
raiseChat = chatActivity;

‎TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,32 @@ public MessageObject(int accountNum, TLRPC.TL_channelAdminLogEvent event, ArrayL
24502450
checkMediaExistance();
24512451
}
24522452

2453+
private boolean spoiledLoginCode = false;
2454+
private static Pattern loginCodePattern;
2455+
public void spoilLoginCode() { // spoil login code from +42777
2456+
if (!spoiledLoginCode && messageText != null && messageOwner != null && messageOwner.entities != null && messageOwner.from_id instanceof TLRPC.TL_peerUser && messageOwner.from_id.user_id == 777000) {
2457+
if (loginCodePattern == null) {
2458+
loginCodePattern = Pattern.compile("[\\d\\-]{5,7}");
2459+
}
2460+
try {
2461+
Matcher matcher = loginCodePattern.matcher(messageText);
2462+
if (matcher.find()) {
2463+
TLRPC.TL_messageEntitySpoiler spoiler = new TLRPC.TL_messageEntitySpoiler();
2464+
spoiler.offset = matcher.start();
2465+
spoiler.length = matcher.end() - spoiler.offset;
2466+
messageOwner.entities.add(spoiler);
2467+
}
2468+
} catch (Exception e) {
2469+
FileLog.e(e, false);
2470+
}
2471+
spoiledLoginCode = true;
2472+
}
2473+
}
2474+
2475+
public boolean didSpoilLoginCode() {
2476+
return spoiledLoginCode;
2477+
}
2478+
24532479
private CharSequence getStringFrom(TLRPC.ChatReactions reactions) {
24542480
if (reactions instanceof TLRPC.TL_chatReactionsAll) {
24552481
return LocaleController.getString("AllReactions", R.string.AllReactions);
@@ -4764,6 +4790,9 @@ public static void addUrlsByPattern(boolean isOut, CharSequence charSequence, bo
47644790
}
47654791
matcher = urlPattern.matcher(charSequence);
47664792
}
4793+
if (!(charSequence instanceof Spannable)) {
4794+
return;
4795+
}
47674796
Spannable spannable = (Spannable) charSequence;
47684797
while (matcher.find()) {
47694798
int start = matcher.start();
@@ -5389,6 +5418,7 @@ public void generateLayout(TLRPC.User fromUser) {
53895418
textWidth = 0;
53905419

53915420
ArrayList<TLRPC.MessageEntity> entities = translated && messageOwner.translatedText != null ? messageOwner.translatedText.entities : messageOwner.entities;
5421+
spoilLoginCode();
53925422

53935423
boolean hasEntities;
53945424
if (messageOwner.send_state != MESSAGE_SEND_STATE_SENT) {
@@ -5670,7 +5700,7 @@ public void generateLayout(TLRPC.User fromUser) {
56705700
linesOffset += currentBlockLinesCount;
56715701

56725702
block.spoilers.clear();
5673-
if (!isSpoilersRevealed) {
5703+
if (!isSpoilersRevealed && !spoiledLoginCode) {
56745704
SpoilerEffect.addSpoilers(null, block.textLayout, -1, linesMaxWidthWithLeft, null, block.spoilers);
56755705
}
56765706
}
@@ -7578,6 +7608,9 @@ public boolean hasHighlightedWords() {
75787608
}
75797609

75807610
public boolean equals(MessageObject obj) {
7611+
if (obj == null) {
7612+
return false;
7613+
}
75817614
return getId() == obj.getId() && getDialogId() == obj.getDialogId();
75827615
}
75837616

‎TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java

+22-13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.telephony.TelephonyManager;
2828
import android.text.TextUtils;
2929
import android.util.Base64;
30+
import android.util.Log;
3031
import android.util.Pair;
3132
import android.util.SparseArray;
3233
import android.util.SparseBooleanArray;
@@ -133,6 +134,8 @@ public class MessagesController extends BaseController implements NotificationCe
133134
private LongSparseIntArray pendingUnreadCounter = new LongSparseIntArray();
134135
private int lastPrintingStringCount;
135136
private SparseArray<ChatlistUpdatesStat> chatlistFoldersUpdates = new SparseArray<>();
137+
public int largeQueueMaxActiveOperations = 2;
138+
public int smallQueueMaxActiveOperations = 5;
136139

137140
class ChatlistUpdatesStat {
138141
public ChatlistUpdatesStat() {
@@ -1321,6 +1324,8 @@ public MessagesController(int num) {
13211324
giftAttachMenuIcon = mainPreferences.getBoolean("giftAttachMenuIcon", false);
13221325
giftTextFieldIcon = mainPreferences.getBoolean("giftTextFieldIcon", false);
13231326
checkResetLangpack = mainPreferences.getInt("checkResetLangpack", 0);
1327+
smallQueueMaxActiveOperations = mainPreferences.getInt("smallQueueMaxActiveOperations", 5);
1328+
largeQueueMaxActiveOperations = mainPreferences.getInt("largeQueueMaxActiveOperations", 2);
13241329
boolean isTest = ConnectionsManager.native_isTestBackend(currentAccount) != 0;
13251330
chatlistInvitesLimitDefault = mainPreferences.getInt("chatlistInvitesLimitDefault", 3);
13261331
chatlistInvitesLimitPremium = mainPreferences.getInt("chatlistInvitesLimitPremium", isTest ? 5 : 20);
@@ -2096,6 +2101,20 @@ private void applyAppConfig(TLRPC.TL_jsonObject object) {
20962101
for (int a = 0, N = object.value.size(); a < N; a++) {
20972102
TLRPC.TL_jsonObjectValue value = object.value.get(a);
20982103
switch (value.key) {
2104+
case "large_queue_max_active_operations_count": {
2105+
if (value.value instanceof TLRPC.TL_jsonNumber) {
2106+
largeQueueMaxActiveOperations = (int) ((TLRPC.TL_jsonNumber) value.value).value;
2107+
editor.putInt("largeQueueMaxActiveOperations", largeQueueMaxActiveOperations);
2108+
}
2109+
break;
2110+
}
2111+
case "small_queue_max_active_operations_count": {
2112+
if (value.value instanceof TLRPC.TL_jsonNumber) {
2113+
smallQueueMaxActiveOperations = (int) ((TLRPC.TL_jsonNumber) value.value).value;
2114+
editor.putInt("smallQueueMaxActiveOperations", smallQueueMaxActiveOperations);
2115+
}
2116+
break;
2117+
}
20992118
case "premium_gift_text_field_icon": {
21002119
if (value.value instanceof TLRPC.TL_jsonBool) {
21012120
if (giftTextFieldIcon != ((TLRPC.TL_jsonBool) value.value).value) {
@@ -2356,17 +2375,6 @@ private void applyAppConfig(TLRPC.TL_jsonObject object) {
23562375
}
23572376
break;
23582377
}
2359-
case "autologin_token": {
2360-
if (value.value instanceof TLRPC.TL_jsonString) {
2361-
TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) value.value;
2362-
if (!string.value.equals(autologinToken)) {
2363-
autologinToken = string.value;
2364-
editor.putString("autologinToken", autologinToken);
2365-
changed = true;
2366-
}
2367-
}
2368-
break;
2369-
}
23702378
case "emojies_send_dice": {
23712379
HashSet<String> newEmojies = new HashSet<>();
23722380
if (value.value instanceof TLRPC.TL_jsonArray) {
@@ -3364,6 +3372,7 @@ public void updateConfig(final TLRPC.TL_config config) {
33643372
editor.putInt("webFileDatacenterId", webFileDatacenterId);
33653373
editor.putString("suggestedLangCode", suggestedLangCode);
33663374
editor.putBoolean("forceTryIpV6", forceTryIpV6);
3375+
editor.putString("autologinToken", autologinToken = config.autologin_token);
33673376
editor.commit();
33683377

33693378
getConnectionsManager().setForceTryIpV6(forceTryIpV6);
@@ -11199,9 +11208,9 @@ public void addUsersToChat(TLRPC.Chat currentChat, BaseFragment baseFragment, Ar
1119911208
final ArrayList<TLRPC.User> userRestrictedPrivacy = new ArrayList<>();
1120011209
processed[0] = 0;
1120111210
final Runnable showUserRestrictedPrivacyAlert = () -> {
11202-
AndroidUtilities.runOnUIThread(() ->{
11211+
AndroidUtilities.runOnUIThread(() -> {
1120311212
BaseFragment lastFragment = LaunchActivity.getLastFragment();
11204-
if (lastFragment != null && lastFragment.getParentActivity() != null) {
11213+
if (lastFragment != null && lastFragment.getParentActivity() != null && !lastFragment.getParentActivity().isFinishing()) {
1120511214
// if (ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_INVITE)) {
1120611215
LimitReachedBottomSheet restricterdUsersBottomSheet = new LimitReachedBottomSheet(lastFragment, lastFragment.getParentActivity(), LimitReachedBottomSheet.TYPE_ADD_MEMBERS_RESTRICTED, currentAccount);
1120711216
restricterdUsersBottomSheet.setRestrictedUsers(currentChat, userRestrictedPrivacy);

‎TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13871,7 +13871,7 @@ public static void addUsersAndChatsFromMessage(TLRPC.Message message, ArrayList<
1387113871
}
1387213872
if (message.media instanceof TLRPC.TL_messageMediaPoll) {
1387313873
TLRPC.TL_messageMediaPoll messageMediaPoll = (TLRPC.TL_messageMediaPoll) message.media;
13874-
if (!messageMediaPoll.results.recent_voters.isEmpty()) {
13874+
if (messageMediaPoll.results != null && messageMediaPoll.results.recent_voters != null && !messageMediaPoll.results.recent_voters.isEmpty()) {
1387513875
usersToLoad.addAll(messageMediaPoll.results.recent_voters);
1387613876
}
1387713877
}

0 commit comments

Comments
 (0)