Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 committed Jul 12, 2024
2 parents 7f590fa + 30b41f7 commit 3a1e347
Show file tree
Hide file tree
Showing 245 changed files with 21,030 additions and 3,669 deletions.
8 changes: 4 additions & 4 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ repositories {
}
}

def verName = "10.13.1"
def verCode = 1181
def verName = "10.14.3"
def verCode = 1185


def officialVer = "10.13.1"
def officialCode = 4845
def officialVer = "10.14.3"
def officialCode = 4927

def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

Expand Down
8 changes: 5 additions & 3 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,11 @@ class Delegate : public ConnectiosManagerDelegate {
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onPremiumFloodWait, instanceNum, requestToken, isUpload);
}

void onIntegrityCheckClassic(int32_t instanceNum, int32_t requestToken, std::string nonce) {
void onIntegrityCheckClassic(int32_t instanceNum, int32_t requestToken, std::string project, std::string nonce) {
jstring projectStr = jniEnv[instanceNum]->NewStringUTF(project.c_str());
jstring nonceStr = jniEnv[instanceNum]->NewStringUTF(nonce.c_str());
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onIntegrityCheckClassic, instanceNum, requestToken, nonceStr);
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onIntegrityCheckClassic, instanceNum, requestToken, projectStr, nonceStr);
jniEnv[instanceNum]->DeleteLocalRef(projectStr);
jniEnv[instanceNum]->DeleteLocalRef(nonceStr);
}

Expand Down Expand Up @@ -719,7 +721,7 @@ extern "C" int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env) {
if (jclass_ConnectionsManager_onPremiumFloodWait == 0) {
return JNI_FALSE;
}
jclass_ConnectionsManager_onIntegrityCheckClassic = env->GetStaticMethodID(jclass_ConnectionsManager, "onIntegrityCheckClassic", "(IILjava/lang/String;)V");
jclass_ConnectionsManager_onIntegrityCheckClassic = env->GetStaticMethodID(jclass_ConnectionsManager, "onIntegrityCheckClassic", "(IILjava/lang/String;Ljava/lang/String;)V");
if (jclass_ConnectionsManager_onIntegrityCheckClassic == 0) {
return JNI_FALSE;
}
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/gifvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ enum PARAM_NUM {
PARAM_NUM_COUNT = 11,
};

extern "C" JNIEXPORT void JNICALL Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoInfo(JNIEnv *env, jclass clazz,jint sdkVersion, jstring src, jintArray data) {
extern "C" JNIEXPORT void JNICALL Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoInfo(JNIEnv *env, jclass clazz, jint sdkVersion, jstring src, jintArray data) {
VideoInfo *info = new VideoInfo();

char const *srcString = env->GetStringUTFChars(src, 0);
Expand Down
7 changes: 5 additions & 2 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,15 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
}
} else if (error->error_code == 403 && error->error_message.find(integrityCheckClassic) != std::string::npos) {
discardResponse = true;
std::string nonce = error->error_message.substr(integrityCheckClassic.size(), error->error_message.size() - integrityCheckClassic.size());
std::string err = error->error_message;
int index = err.find('_', integrityCheckClassic.size());
std::string project = err.substr(integrityCheckClassic.size(), index - integrityCheckClassic.size());
std::string nonce = err.substr(integrityCheckClassic.size() + project.size() + 1, err.size() - (integrityCheckClassic.size() + project.size() + 1));
request->awaitingIntegrityCheck = true;
request->startTime = 0;
request->startTimeMillis = 0;
if (delegate != nullptr) {
delegate->onIntegrityCheckClassic(instanceNum, request->requestToken, nonce);
delegate->onIntegrityCheckClassic(instanceNum, request->requestToken, project, nonce);
}
} else {
bool failServerErrors = (request->requestFlags & RequestFlagFailOnServerErrors) == 0 || processEvenFailed;
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/tgnet/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ typedef struct ConnectiosManagerDelegate {
virtual void getHostByName(std::string domain, int32_t instanceNum, ConnectionSocket *socket) = 0;
virtual int32_t getInitFlags(int32_t instanceNum) = 0;
virtual void onPremiumFloodWait(int32_t instanceNum, int32_t requestToken, bool isUpload) = 0;
virtual void onIntegrityCheckClassic(int32_t instanceNum, int32_t requestToken, std::string nonce) = 0;
virtual void onIntegrityCheckClassic(int32_t instanceNum, int32_t requestToken, std::string project, std::string nonce) = 0;
} ConnectiosManagerDelegate;

typedef struct HandshakeDelegate {
Expand Down
13 changes: 13 additions & 0 deletions TMessagesProj/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="ton"/>
</intent>

<package android:name="com.android.chrome" />
<package android:name="org.mozilla.firefox" />
<package android:name="com.microsoft.emmx" />
<package android:name="com.opera.browser" />
<package android:name="com.opera.mini.native" />
<package android:name="com.brave.browser" />
<package android:name="com.duckduckgo.mobile.android" />
<package android:name="com.sec.android.app.sbrowser" />
<package android:name="com.vivaldi.browser" />
<package android:name="com.kiwibrowser.browser" />
<package android:name="com.UCMobile.intl" />
<package android:name="org.torproject.torbrowser" />
</queries>

<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.ui.Cells.DialogCell;

import java.util.ArrayList;
import java.util.List;

import tw.nekomimi.nekogram.NekoConfig;
import xyz.nextalone.nagram.NaConfig;

/**
* This is a utility class to add swipe to dismiss and drag & drop support to RecyclerView.
Expand Down Expand Up @@ -1257,6 +1259,11 @@ public boolean isIdle() {
}

public int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
if (viewHolder != null && viewHolder.itemView instanceof DialogCell) {
if (((DialogCell) viewHolder.itemView).getCurrentDialogFolderId() == 0 && NaConfig.INSTANCE.getDoNotUnarchiveBySwipe().Bool()) {
return 0;
}
}
if ((flags & (LEFT | RIGHT)) != 0) {
final int dirFlag = mDx > 0 ? RIGHT : LEFT;
if (mVelocityTracker != null && mActivePointerId > -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.fonts.Font;
import android.graphics.fonts.FontFamily;
import android.graphics.fonts.FontStyle;
import android.graphics.fonts.SystemFonts;
import android.net.Uri;
import android.os.Build;
Expand Down Expand Up @@ -100,7 +101,9 @@
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
Expand Down Expand Up @@ -323,15 +326,25 @@ public static Typeface bold() {
public static Pattern LONG_BAD_CHARS_PATTERN = null;
public static Pattern BAD_CHARS_MESSAGE_PATTERN = null;
public static Pattern BAD_CHARS_MESSAGE_LONG_PATTERN = null;
public static Pattern REMOVE_MULTIPLE_DIACRITICS = null;
private static Pattern singleTagPatter = null;

public static String removeDiacritics(String str) {
if (str == null) return null;
if (REMOVE_MULTIPLE_DIACRITICS == null) return str;
Matcher matcher = REMOVE_MULTIPLE_DIACRITICS.matcher(str);
if (matcher == null) return str;
return matcher.replaceAll("$1");
}

static {
try {
final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
BAD_CHARS_PATTERN = Pattern.compile("[\u2500-\u25ff]");
LONG_BAD_CHARS_PATTERN = Pattern.compile("[\u4e00-\u9fff]");
BAD_CHARS_MESSAGE_LONG_PATTERN = Pattern.compile("[\u0300-\u036f\u2066-\u2067]+");
BAD_CHARS_MESSAGE_LONG_PATTERN = Pattern.compile("[\u0300-\u036f\u2066-\u2067]");
BAD_CHARS_MESSAGE_PATTERN = Pattern.compile("[\u2066-\u2067]+");
REMOVE_MULTIPLE_DIACRITICS = Pattern.compile("([\\u0300-\\u036f]{1,2})[\\u0300-\\u036f]+");
final Pattern IP_ADDRESS = Pattern.compile(
"((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(25[0-5]|2[0-4]"
+ "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]"
Expand Down Expand Up @@ -583,6 +596,34 @@ public void updateDrawState(TextPaint textPaint) {
return spannableStringBuilder;
}


public static SpannableStringBuilder replaceMultipleTags(String str, Runnable ...runnables) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(str);
for (int i = 0; i < runnables.length; ++i) {
Runnable runnable = runnables[i];

int start = charSequenceIndexOf(spannableStringBuilder, "**");
int end = charSequenceIndexOf(spannableStringBuilder, "**", start + 2);
if (start < 0 || end < 0) break;

spannableStringBuilder.delete(start, start + 2);
end = end - 2;
spannableStringBuilder.delete(end, end + 2);
spannableStringBuilder.setSpan(new ClickableSpan() {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
@Override
public void onClick(@NonNull View widget) {
if (runnable != null) runnable.run();
}
}, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannableStringBuilder;
}

public static SpannableStringBuilder replaceSingleLink(String str, int color) {
return replaceSingleLink(str, color, null);
}
Expand Down Expand Up @@ -1851,7 +1892,7 @@ public String getValue(boolean format) {
calendar.set(Calendar.YEAR, Utilities.parseInt(date[0]));
calendar.set(Calendar.MONTH, Utilities.parseInt(date[1]) - 1);
calendar.set(Calendar.DAY_OF_MONTH, Utilities.parseInt(date[2]));
return LocaleController.getInstance().formatterYearMax.format(calendar.getTime());
return LocaleController.getInstance().getFormatterYearMax().format(calendar.getTime());
}
}
}
Expand Down Expand Up @@ -1889,13 +1930,17 @@ public String getRawType(boolean first) {
}

public String getType() {
if (type == 5) {
return LocaleController.getString("ContactBirthday", R.string.ContactBirthday);
if (type == 4) {
return LocaleController.getString(R.string.ContactNote);
} else if (type == 3) {
return LocaleController.getString(R.string.ContactUrl);
} else if (type == 5) {
return LocaleController.getString(R.string.ContactBirthday);
} else if (type == 6) {
if ("ORG".equalsIgnoreCase(getRawType(true))) {
return LocaleController.getString("ContactJob", R.string.ContactJob);
return LocaleController.getString(R.string.ContactJob);
} else {
return LocaleController.getString("ContactJobTitle", R.string.ContactJobTitle);
return LocaleController.getString(R.string.ContactJobTitle);
}
}
int idx = fullData.indexOf(':');
Expand Down Expand Up @@ -5263,6 +5308,15 @@ public static void lerp(Rect a, Rect b, float f, Rect to) {
}
}

public static void lerpCentered(RectF a, RectF b, float f, RectF to) {
if (to == null) return;
final float cx = lerp(a.centerX(), b.centerX(), f);
final float cy = lerp(a.centerY(), b.centerY(), f);
final float hw = lerp(a.width(), b.width(), Math.min(1, f)) / 2f;
final float hh = lerp(a.height(), b.height(), Math.min(1, f)) / 2f;
to.set(cx - hw, cy - hh, cx + hw, cy + hh);
}

public static void lerp(int[] a, int[] b, float f, int[] to) {
if (to == null) return;
for (int i = 0; i < to.length; ++i) {
Expand Down Expand Up @@ -6434,4 +6488,95 @@ public static void vibrate(View view) {
} catch (Exception ignore) {}
}

public static void applySpring(Animator anim, float stiffness, float damping) {
applySpring(anim, stiffness, damping, 1);
}

public static void applySpring(Animator anim, float stiffness, float damping, float mass) {
final double delta = damping / (2.0 * Math.sqrt(stiffness * mass));
final double undampedFrequency = Math.sqrt(stiffness / mass);
final double omega_0 = Math.sqrt(stiffness / mass);
final double zeta = damping / (2 * Math.sqrt(stiffness * mass));
final double threshold = 0.0025;
final double duration = Math.log(threshold) / (-zeta * omega_0);
anim.setDuration((long) (duration * 1000L));
anim.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float t) {
if (delta < 1) {
final double dampedFrequency = undampedFrequency * Math.sqrt(1 - delta * delta);
return (float) (1 - Math.exp(-delta * undampedFrequency * t) *
(Math.cos(dampedFrequency * t) + (delta * undampedFrequency / dampedFrequency) * Math.sin(dampedFrequency * t)));
} else {
final double a = -delta * undampedFrequency * t;
return (float) (1 - (1 + a) * Math.exp(a));
}
}
});
}

public static boolean isWebAppLink(String url) {
if (url == null) return false;
try {
Uri uri = Uri.parse(url);
final String scheme = uri.getScheme();
if (scheme == null) return false;
final String path = uri.getPath();
if (path == null) return false;
switch (scheme) {
case "http":
case "https": {
if (path.isEmpty()) return false;
String host = uri.getHost().toLowerCase();
Matcher prefixMatcher = LaunchActivity.PREFIX_T_ME_PATTERN.matcher(host);
boolean isPrefix = prefixMatcher.find();
if (host.equals("telegram.me") || host.equals("t.me") || host.equals("telegram.dog") || isPrefix) {
ArrayList<String> segments = new ArrayList<>(uri.getPathSegments());
if (segments.size() > 0 && segments.get(0).equals("s")) {
segments.remove(0);
}
if (segments.size() > 0) {
if (segments.size() >= 3 && "s".equals(segments.get(1))) {
return false;
} else if (segments.size() > 1) {
final String segment = segments.get(1);
if (TextUtils.isEmpty(segment)) return false;
switch (segment) {
case "joinchat":
case "login":
case "addstickers":
case "addemoji":
case "msg":
case "share":
case "confirmphone":
case "setlanguage":
case "addtheme":
case "boost":
case "c":
case "contact":
case "folder":
case "addlist":
return false;
}
return true;
} else if (segments.size() == 1) {
return !TextUtils.isEmpty(uri.getQueryParameter("startapp"));
}
}
}
break;
}
case "tg": {
if (url.startsWith("tg:resolve") || url.startsWith("tg://resolve")) {
return !TextUtils.isEmpty(uri.getQueryParameter("appname"));
}
break;
}
}
} catch (Exception e) {
FileLog.e(e);
}
return false;
}

}
Loading

0 comments on commit 3a1e347

Please sign in to comment.