Skip to content

Commit f108443

Browse files
committed
update to 9.7.2 (3705)
1 parent 65f01a7 commit f108443

File tree

106 files changed

+2381
-869
lines changed

Some content is hidden

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

106 files changed

+2381
-869
lines changed

‎TMessagesProj/src/main/java/org/telegram/DispatchQueuePriority.java

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.telegram;
22

3+
import org.telegram.messenger.FileLog;
4+
35
import java.util.Comparator;
6+
import java.util.concurrent.CountDownLatch;
47
import java.util.concurrent.PriorityBlockingQueue;
58
import java.util.concurrent.ThreadPoolExecutor;
69
import java.util.concurrent.TimeUnit;
@@ -21,8 +24,21 @@ public int compare(Runnable o1, Runnable o2) {
2124
}
2225
return priority2 - priority1;
2326
}
24-
}));
27+
})) {
28+
@Override
29+
protected void beforeExecute(Thread t, Runnable r) {
30+
CountDownLatch latch = pauseLatch;
31+
if (latch != null) {
32+
try {
33+
latch.await();
34+
} catch (InterruptedException e) {
35+
FileLog.e(e);
36+
}
37+
}
38+
}
39+
};
2540

41+
private volatile CountDownLatch pauseLatch;
2642

2743
public DispatchQueuePriority(String threadName) {
2844

@@ -41,23 +57,32 @@ public void postRunnable(Runnable runnable) {
4157
}
4258

4359
public Runnable postRunnable(Runnable runnable, int priority) {
44-
if (priority == 1) {
45-
postRunnable(runnable);
46-
return runnable;
47-
} else {
48-
PriorityRunnable priorityRunnable = new PriorityRunnable(priority, runnable);
49-
50-
threadPoolExecutor.execute(priorityRunnable);
51-
return priorityRunnable;
60+
if (priority != 1) {
61+
runnable = new PriorityRunnable(priority, runnable);
5262
}
63+
postRunnable(runnable);
64+
return runnable;
5365
}
5466

5567
public void cancelRunnable(Runnable runnable) {
5668
if (runnable == null) {
5769
return;
5870
}
5971
threadPoolExecutor.remove(runnable);
72+
}
73+
74+
public void pause() {
75+
if (pauseLatch == null) {
76+
pauseLatch = new CountDownLatch(1);
77+
}
78+
}
6079

80+
public void resume() {
81+
CountDownLatch latch = pauseLatch;
82+
if (latch != null) {
83+
latch.countDown();
84+
pauseLatch = null;
85+
}
6186
}
6287

6388
private static class PriorityRunnable implements Runnable {

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

+42-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
import android.view.inspector.WindowInspector;
100100
import android.webkit.MimeTypeMap;
101101
import android.widget.EdgeEffect;
102-
import android.widget.FrameLayout;
103102
import android.widget.HorizontalScrollView;
104103
import android.widget.ImageView;
105104
import android.widget.LinearLayout;
@@ -123,7 +122,6 @@
123122

124123
import com.android.internal.telephony.ITelephony;
125124
import com.google.android.exoplayer2.util.Consumer;
126-
import com.google.android.exoplayer2.util.Log;
127125
import com.google.android.gms.auth.api.phone.SmsRetriever;
128126
import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
129127
import com.google.android.gms.tasks.Task;
@@ -155,7 +153,6 @@
155153
import org.telegram.ui.Components.PickerBottomLayout;
156154
import org.telegram.ui.Components.RecyclerListView;
157155
import org.telegram.ui.Components.ShareAlert;
158-
import org.telegram.ui.Components.SizeNotifierFrameLayout;
159156
import org.telegram.ui.Components.TypefaceSpan;
160157
import org.telegram.ui.Components.URLSpanReplacement;
161158
import org.telegram.ui.Components.UndoView;
@@ -177,7 +174,6 @@
177174
import java.io.InputStreamReader;
178175
import java.io.OutputStream;
179176
import java.io.RandomAccessFile;
180-
import java.lang.ref.WeakReference;
181177
import java.lang.reflect.Field;
182178
import java.lang.reflect.Method;
183179
import java.net.IDN;
@@ -196,7 +192,6 @@
196192
import java.util.List;
197193
import java.util.Locale;
198194
import java.util.Map;
199-
import java.util.Objects;
200195
import java.util.concurrent.CountDownLatch;
201196
import java.util.concurrent.atomic.AtomicBoolean;
202197
import java.util.concurrent.atomic.AtomicReference;
@@ -590,7 +585,7 @@ public static boolean findClickableView(ViewGroup container, float x, float y) {
590585
}
591586

592587
public static void removeFromParent(View child) {
593-
if (child.getParent() != null) {
588+
if (child != null && child.getParent() != null) {
594589
((ViewGroup) child.getParent()).removeView(child);
595590
}
596591
}
@@ -2750,6 +2745,39 @@ public static SpannableStringBuilder replaceTags(String str, int flag, Object...
27502745
return new SpannableStringBuilder(str);
27512746
}
27522747

2748+
private static Pattern linksPattern;
2749+
public static SpannableStringBuilder replaceLinks(String str, Theme.ResourcesProvider resourcesProvider) {
2750+
if (linksPattern == null) {
2751+
linksPattern = Pattern.compile("\\[(.+?)\\]\\((.+?)\\)");
2752+
}
2753+
SpannableStringBuilder spannable = new SpannableStringBuilder();
2754+
Matcher matcher = linksPattern.matcher(str);
2755+
int lastMatchEnd = 0;
2756+
while (matcher.find()) {
2757+
spannable.append(str, lastMatchEnd, matcher.start());
2758+
String linkText = matcher.group(1);
2759+
String url = matcher.group(2);
2760+
spannable.append(linkText);
2761+
int start = spannable.length() - linkText.length();
2762+
int end = spannable.length();
2763+
spannable.setSpan(new ClickableSpan() {
2764+
@Override
2765+
public void onClick(@NonNull View widget) {
2766+
Browser.openUrl(ApplicationLoader.applicationContext, url);
2767+
}
2768+
@Override
2769+
public void updateDrawState(@NonNull TextPaint ds) {
2770+
ds.setColor(Theme.getColor(Theme.key_chat_messageLinkIn, resourcesProvider));
2771+
ds.setUnderlineText(false);
2772+
}
2773+
}, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
2774+
2775+
lastMatchEnd = matcher.end();
2776+
}
2777+
spannable.append(str, lastMatchEnd, str.length());
2778+
return spannable;
2779+
}
2780+
27532781
public static class LinkMovementMethodMy extends LinkMovementMethod {
27542782
@Override
27552783
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
@@ -5324,4 +5352,12 @@ public static String translitSafe(String str) {
53245352
} catch (Exception ignore) {}
53255353
return "";
53265354
}
5355+
5356+
public static void quietSleep(long millis) {
5357+
try {
5358+
Thread.sleep(millis);
5359+
} catch (InterruptedException ignored) {
5360+
5361+
}
5362+
}
53275363
}

‎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 = 3687;
28-
public static String BUILD_VERSION_STRING = "9.7.0";
27+
public static int BUILD_VERSION = 3705;
28+
public static String BUILD_VERSION_STRING = "9.7.2";
2929
public static int APP_ID = 4;
3030
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";
3131

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

+15
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@
1111
import android.os.Handler;
1212
import android.os.Looper;
1313
import android.os.Message;
14+
import android.os.Process;
1415
import android.os.SystemClock;
1516

1617
import java.util.concurrent.CountDownLatch;
1718

1819
public class DispatchQueue extends Thread {
1920

21+
private static final int THREAD_PRIORITY_DEFAULT = -1000;
22+
2023
private volatile Handler handler = null;
2124
private CountDownLatch syncLatch = new CountDownLatch(1);
2225
private long lastTaskTime;
2326
private static int indexPointer = 0;
2427
public final int index = indexPointer++;
28+
private int priority = THREAD_PRIORITY_DEFAULT;
2529

2630
public DispatchQueue(final String threadName) {
2731
this(threadName, true);
@@ -34,6 +38,14 @@ public DispatchQueue(final String threadName, boolean start) {
3438
}
3539
}
3640

41+
public DispatchQueue(final String threadName, boolean start, int priority) {
42+
this.priority = priority;
43+
setName(threadName);
44+
if (start) {
45+
start();
46+
}
47+
}
48+
3749
public void sendMessage(Message msg, int delay) {
3850
try {
3951
syncLatch.await();
@@ -114,6 +126,9 @@ public void run() {
114126
return true;
115127
});
116128
syncLatch.countDown();
129+
if (priority != THREAD_PRIORITY_DEFAULT) {
130+
Process.setThreadPriority(priority);
131+
}
117132
Looper.loop();
118133
}
119134

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

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import androidx.annotation.UiThread;
77

8+
import org.telegram.ui.Components.Reactions.HwEmojis;
9+
810
import java.util.LinkedList;
911

1012
public class DispatchQueuePool {
@@ -68,6 +70,11 @@ public void execute(Runnable runnable) {
6870
busyQueues.add(queue);
6971
int count = busyQueuesMap.get(queue.index, 0);
7072
busyQueuesMap.put(queue.index, count + 1);
73+
if (HwEmojis.isHwEnabled()) {
74+
queue.setPriority(Thread.MIN_PRIORITY);
75+
} else if (queue.getPriority() != Thread.MAX_PRIORITY) {
76+
queue.setPriority(Thread.MAX_PRIORITY);
77+
}
7178
queue.postRunnable(() -> {
7279
runnable.run();
7380
AndroidUtilities.runOnUIThread(() -> {

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

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import androidx.annotation.UiThread;
77

8+
import org.telegram.ui.Components.Reactions.HwEmojis;
9+
810
import java.util.ArrayList;
911

1012
public class DispatchQueuePoolBackground {
@@ -77,6 +79,11 @@ private void execute(ArrayList<Runnable> runnables) {
7779
busyQueues.add(queue);
7880
int count = busyQueuesMap.get(queue.index, 0);
7981
busyQueuesMap.put(queue.index, count + 1);
82+
if(HwEmojis.isHwEnabled()) {
83+
queue.setPriority(Thread.MIN_PRIORITY);
84+
} else if (queue.getPriority() != Thread.MAX_PRIORITY) {
85+
queue.setPriority(Thread.MAX_PRIORITY);
86+
}
8087
queue.postRunnable(() -> {
8188
runnable.run();
8289
Utilities.globalQueue.postRunnable(() -> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ protected File getCurrentFile() {
638638
final CountDownLatch countDownLatch = new CountDownLatch(1);
639639
final File[] result = new File[1];
640640
Utilities.stageQueue.postRunnable(() -> {
641-
if (state == stateFinished) {
641+
if (state == stateFinished && !preloadFinished) {
642642
result[0] = cacheFileFinal;
643643
} else {
644644
result[0] = cacheFileTemp;
@@ -654,7 +654,7 @@ protected File getCurrentFile() {
654654
}
655655

656656
protected File getCurrentFileFast() {
657-
if (state == stateFinished) {
657+
if (state == stateFinished && !preloadFinished) {
658658
return cacheFileFinal;
659659
} else {
660660
return cacheFileTemp;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ public boolean hasAnotherRefOnFile(String path) {
938938
}
939939

940940
loaderQueue.add(operation);
941-
loaderQueue.checkLoadingOperations();
941+
loaderQueue.checkLoadingOperations(operation.isStory && priority >= PRIORITY_HIGH);
942942

943943
if (BuildVars.LOGS_ENABLED) {
944944
FileLog.d("create load operation fileName=" + finalFileName + " documentName=" + getDocumentFileName(document) + "size=" + AndroidUtilities.formatFileSize(operation.totalBytesCount) + " position in queue " + operation.getPositionInQueue() + " account=" + currentAccount);

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

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public void cancel(FileLoadOperation operation) {
6969
}
7070

7171
public void checkLoadingOperations() {
72+
checkLoadingOperations(false);
73+
}
74+
75+
public void checkLoadingOperations(boolean immediate) {
76+
if (immediate) {
77+
workerQueue.cancelRunnable(checkOperationsRunnable);
78+
checkOperationsRunnable.run();
79+
return;
80+
}
7281
if (checkOperationsScheduled) {
7382
return;
7483
}

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.telegram.messenger.video.MediaCodecVideoConvertor;
2222
import org.telegram.tgnet.TLObject;
2323
import org.telegram.tgnet.TLRPC;
24+
import org.telegram.ui.Components.AnimatedFileDrawable;
2425
import org.telegram.ui.LaunchActivity;
2526

2627
import java.io.File;
@@ -170,7 +171,7 @@ private static void checkGson() {
170171
excludeRequests.add("TL_upload_getFile");
171172
excludeRequests.add("TL_upload_a");
172173

173-
gson = new GsonBuilder().addSerializationExclusionStrategy(new ExclusionStrategy() {
174+
ExclusionStrategy strategy = new ExclusionStrategy() {
174175

175176
@Override
176177
public boolean shouldSkipField(FieldAttributes f) {
@@ -182,12 +183,10 @@ public boolean shouldSkipField(FieldAttributes f) {
182183

183184
@Override
184185
public boolean shouldSkipClass(Class<?> clazz) {
185-
if (clazz.isInstance(ColorStateList.class) || clazz.isInstance(Context.class)) {
186-
return true;
187-
}
188-
return false;
186+
return clazz.isInstance(AnimatedFileDrawable.class) || clazz.isInstance(ColorStateList.class) || clazz.isInstance(Context.class);
189187
}
190-
}).registerTypeAdapterFactory(RuntimeClassNameTypeAdapterFactory.of(TLObject.class, "type_")).create();
188+
};
189+
gson = new GsonBuilder().addSerializationExclusionStrategy(strategy).registerTypeAdapterFactory(RuntimeClassNameTypeAdapterFactory.of(TLObject.class, "type_", strategy)).create();
191190
}
192191
}
193192

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -1059,19 +1059,21 @@ private boolean onRequestComplete(String locationKey, String parentKey, TLObject
10591059
Object arg = requester.args[1];
10601060
if (arg instanceof FileLoadOperation) {
10611061
FileLoadOperation operation = (FileLoadOperation) requester.args[1];
1062-
TLRPC.StoryItem storyItem = (TLRPC.StoryItem) operation.parentObject;
1063-
if (newStoryItem == null) {
1064-
TLRPC.TL_updateStory story = new TLRPC.TL_updateStory();
1065-
story.user_id = storyItem.dialogId;
1066-
story.story = new TLRPC.TL_storyItemDeleted();
1067-
story.story.id = storyItem.id;
1068-
ArrayList<TLRPC.Update> updates = new ArrayList<>();
1069-
updates.add(story);
1070-
getMessagesController().processUpdateArray(updates, null, null, false, 0);
1071-
} else {
1072-
TLRPC.User user = getMessagesController().getUser(storyItem.dialogId);
1073-
if (user != null && user.contact) {
1074-
MessagesController.getInstance(currentAccount).getStoriesController().getStoriesStorage().updateStoryItem(storyItem.dialogId, newStoryItem);
1062+
if (operation.parentObject instanceof TLRPC.StoryItem) {
1063+
TLRPC.StoryItem storyItem = (TLRPC.StoryItem) operation.parentObject;
1064+
if (newStoryItem == null) {
1065+
TLRPC.TL_updateStory story = new TLRPC.TL_updateStory();
1066+
story.user_id = storyItem.dialogId;
1067+
story.story = new TLRPC.TL_storyItemDeleted();
1068+
story.story.id = storyItem.id;
1069+
ArrayList<TLRPC.Update> updates = new ArrayList<>();
1070+
updates.add(story);
1071+
getMessagesController().processUpdateArray(updates, null, null, false, 0);
1072+
} else {
1073+
TLRPC.User user = getMessagesController().getUser(storyItem.dialogId);
1074+
if (user != null && user.contact) {
1075+
MessagesController.getInstance(currentAccount).getStoriesController().getStoriesStorage().updateStoryItem(storyItem.dialogId, newStoryItem);
1076+
}
10751077
}
10761078
}
10771079
}

0 commit comments

Comments
 (0)