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 Oct 19, 2024
2 parents 913217a + 5d8d2e1 commit 3bfce86
Show file tree
Hide file tree
Showing 213 changed files with 14,482 additions and 4,989 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
}

def verName = APP_VERSION_NAME
def verCode = 1194
def verCode = 1196


def officialVer = APP_VERSION_NAME
Expand Down
6 changes: 3 additions & 3 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jint getTimeDifference(JNIEnv *env, jclass c, jint instanceNum) {
void sendRequest(JNIEnv *env, jclass c, jint instanceNum, jlong object, jint flags, jint datacenterId, jint connectionType, jboolean immediate, jint token) {
TL_api_request *request = new TL_api_request();
request->request = (NativeByteBuffer *) (intptr_t) object;
ConnectionsManager::getInstance(instanceNum).sendRequest(request, ([instanceNum, token](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
ConnectionsManager::getInstance(instanceNum).sendRequest(request, ([instanceNum, token](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
TL_api_response *resp = (TL_api_response *) response;
jlong ptr = 0;
jint errorCode = 0;
Expand All @@ -118,7 +118,7 @@ void sendRequest(JNIEnv *env, jclass c, jint instanceNum, jlong object, jint fla
errorText = jniEnv[instanceNum]->NewStringUTF("UTF-8 ERROR");
}
}
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onRequestComplete, instanceNum, token, ptr, errorCode, errorText, networkType, responseTime, msgId);
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onRequestComplete, instanceNum, token, ptr, errorCode, errorText, networkType, responseTime, msgId, dcId);
if (errorText != nullptr) {
jniEnv[instanceNum]->DeleteLocalRef(errorText);
}
Expand Down Expand Up @@ -640,7 +640,7 @@ extern "C" int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env) {
if (jclass_ConnectionsManager_onRequestClear == 0) {
return JNI_FALSE;
}
jclass_ConnectionsManager_onRequestComplete = env->GetStaticMethodID(jclass_ConnectionsManager, "onRequestComplete", "(IIJILjava/lang/String;IJJ)V");
jclass_ConnectionsManager_onRequestComplete = env->GetStaticMethodID(jclass_ConnectionsManager, "onRequestComplete", "(IIJILjava/lang/String;IJJI)V");
if (jclass_ConnectionsManager_onRequestComplete == 0) {
return JNI_FALSE;
}
Expand Down
30 changes: 18 additions & 12 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ void ConnectionsManager::cleanUp(bool resetKeys, int32_t datacenterId) {
auto error = new TL_error();
error->code = -1000;
error->text = "";
request->onComplete(nullptr, error, 0, 0, request->messageId);
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
request->onComplete(nullptr, error, 0, 0, request->messageId, dcId);
delete error;
}
iter = requestsQueue.erase(iter);
Expand All @@ -644,7 +645,8 @@ void ConnectionsManager::cleanUp(bool resetKeys, int32_t datacenterId) {
auto error = new TL_error();
error->code = -1000;
error->text = "";
request->onComplete(nullptr, error, 0, 0, request->messageId);
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
request->onComplete(nullptr, error, 0, 0, request->messageId, dcId);
delete error;
}
DEBUG_D("1) erase request %d 0x%" PRIx64, request->requestToken, request->messageId);
Expand Down Expand Up @@ -1203,7 +1205,8 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
for (auto iter = runningRequests.begin(); iter != runningRequests.end(); iter++) {
Request *request = iter->get();
if (request->respondsToMessageId(requestMid)) {
request->onComplete(response, nullptr, connection->currentNetworkType, timeMessage, requestMid);
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
request->onComplete(response, nullptr, connection->currentNetworkType, timeMessage, requestMid, dcId);
request->completed = true;
DEBUG_D("4) erase request %d 0x%" PRIx64, request->requestToken, request->messageId);
runningRequests.erase(iter);
Expand Down Expand Up @@ -1448,12 +1451,13 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
}

if (!discardResponse) {
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
if (implicitError != nullptr || error2 != nullptr) {
isError = true;
request->onComplete(nullptr, implicitError != nullptr ? implicitError : error2, connection->currentNetworkType, timeMessage, request->messageId);
request->onComplete(nullptr, implicitError != nullptr ? implicitError : error2, connection->currentNetworkType, timeMessage, request->messageId, dcId);
delete error2;
} else {
request->onComplete(response->result.get(), nullptr, connection->currentNetworkType, timeMessage, request->messageId);
request->onComplete(response->result.get(), nullptr, connection->currentNetworkType, timeMessage, request->messageId, dcId);
}
}

Expand Down Expand Up @@ -2102,7 +2106,7 @@ bool ConnectionsManager::cancelRequestInternal(int32_t token, int64_t messageId,
auto dropAnswer = new TL_rpc_drop_answer();
dropAnswer->req_msg_id = request->messageId;
if (onCancelled != nullptr) {
sendRequest(dropAnswer, ([onCancelled](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) -> void {
sendRequest(dropAnswer, ([onCancelled](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) -> void {
if (onCancelled != nullptr) {
onCancelled();
}
Expand Down Expand Up @@ -2159,7 +2163,8 @@ void ConnectionsManager::failNotRunningRequest(int32_t token) {
auto error = new TL_error();
error->code = -2000;
error->text = "CANCELLED_REQUEST";
request->onComplete(nullptr, error, 0, 0, request->messageId);
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
request->onComplete(nullptr, error, 0, 0, request->messageId, dcId);

request->cancelled = true;
if (LOGS_ENABLED) DEBUG_D("cancelled queued rpc request %p - %s", request->rawRequest, typeid(*request->rawRequest).name());
Expand Down Expand Up @@ -2302,7 +2307,7 @@ void ConnectionsManager::requestSaltsForDatacenter(Datacenter *datacenter, bool
requestingSaltsForDc.push_back(id);
auto request = new TL_get_future_salts();
request->num = 32;
sendRequest(request, [&, datacenter, id, media](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
sendRequest(request, [&, datacenter, id, media](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
auto iter = std::find(requestingSaltsForDc.begin(), requestingSaltsForDc.end(), id);
if (iter != requestingSaltsForDc.end()) {
requestingSaltsForDc.erase(iter);
Expand Down Expand Up @@ -2337,7 +2342,7 @@ void ConnectionsManager::registerForInternalPushUpdates() {
request->token_type = 7;
request->token = to_string_uint64((uint64_t) pushSessionId);

sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if (error == nullptr) {
registeredForInternalPush = true;
if (LOGS_ENABLED) DEBUG_D("registered for internal push");
Expand Down Expand Up @@ -2560,7 +2565,8 @@ void ConnectionsManager::processRequestQueue(uint32_t connectionTypes, uint32_t
auto error = new TL_error();
error->code = -123;
error->text = "RETRY_LIMIT";
request->onComplete(nullptr, error, connection->currentNetworkType, 0, request->messageId);
int32_t dcId = request->datacenterId != DEFAULT_DATACENTER_ID ? request->datacenterId : currentDatacenterId;
request->onComplete(nullptr, error, connection->currentNetworkType, 0, request->messageId, dcId);
delete error;
DEBUG_D("12) erase request %d 0x%" PRIx64, request->requestToken, request->messageId);
iter = runningRequests.erase(iter);
Expand Down Expand Up @@ -3271,7 +3277,7 @@ void ConnectionsManager::updateDcSettings(uint32_t dcNum, bool workaround, bool
}

auto request = new TL_help_getConfig();
sendRequest(request, [&, workaround](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
sendRequest(request, [&, workaround](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if ((!workaround && !updatingDcSettings) || (workaround && !updatingDcSettingsWorkaround)) {
return;
}
Expand Down Expand Up @@ -3420,7 +3426,7 @@ void ConnectionsManager::authorizeOnMovingDatacenter() {
auto request = new TL_auth_importAuthorization();
request->id = currentUserId;
request->bytes = std::move(movingAuthorization);
sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if (error == nullptr) {
authorizedOnMovingDatacenter();
} else {
Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/jni/tgnet/Datacenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,14 +1447,14 @@ void Datacenter::exportAuthorization() {
auto request = new TL_auth_exportAuthorization();
request->dc_id = datacenterId;
if (LOGS_ENABLED) DEBUG_D("dc%u begin export authorization", datacenterId);
ConnectionsManager::getInstance(instanceNum).sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
ConnectionsManager::getInstance(instanceNum).sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if (error == nullptr) {
auto res = (TL_auth_exportedAuthorization *) response;
auto request2 = new TL_auth_importAuthorization();
request2->bytes = std::move(res->bytes);
request2->id = res->id;
if (LOGS_ENABLED) DEBUG_D("dc%u begin import authorization", datacenterId);
ConnectionsManager::getInstance(instanceNum).sendRequest(request2, [&](TLObject *response2, TL_error *error2, int32_t networkType, int64_t responseTime, int64_t msgId) {
ConnectionsManager::getInstance(instanceNum).sendRequest(request2, [&](TLObject *response2, TL_error *error2, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if (error2 == nullptr) {
authorized = true;
ConnectionsManager::getInstance(instanceNum).onDatacenterExportAuthorizationComplete(this);
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 @@ -47,7 +47,7 @@ class NativeByteBuffer;
class Handshake;
class ConnectionSocket;

typedef std::function<void(TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId)> onCompleteFunc;
typedef std::function<void(TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId)> onCompleteFunc;
typedef std::function<void()> onQuickAckFunc;
typedef std::function<void()> onWriteToSocketFunc;
typedef std::function<void()> onRequestClearFunc;
Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/jni/tgnet/Handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void Handshake::processHandshakeResponse_serverDHParamsAnswer(TLObject *message,
request->encrypted_message = currentDatacenter->createRequestsData(array, nullptr, connection, true);
};

authKeyPendingRequestId = ConnectionsManager::getInstance(currentDatacenter->instanceNum).sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
authKeyPendingRequestId = ConnectionsManager::getInstance(currentDatacenter->instanceNum).sendRequest(request, [&](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
authKeyPendingMessageId = 0;
authKeyPendingRequestId = 0;
if (response != nullptr && typeid(*response) == typeid(TL_boolTrue)) {
Expand Down Expand Up @@ -992,7 +992,7 @@ void Handshake::loadCdnConfig(Datacenter *datacenter) {
loadingCdnKeys = true;
auto request = new TL_help_getCdnConfig();

ConnectionsManager::getInstance(datacenter->instanceNum).sendRequest(request, [&, datacenter](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId) {
ConnectionsManager::getInstance(datacenter->instanceNum).sendRequest(request, [&, datacenter](TLObject *response, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msgId, int32_t dcId) {
if (response != nullptr) {
auto config = (TL_cdnConfig *) response;
size_t count = config->public_keys.size();
Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/jni/tgnet/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ void Request::clear(bool time) {
}
}

void Request::onComplete(TLObject *result, TL_error *error, int32_t networkType, int64_t responseTime, int64_t requestMsgId) {
void Request::onComplete(TLObject *result, TL_error *error, int32_t networkType, int64_t responseTime, int64_t requestMsgId, int32_t dcId) {
if (onCompleteRequestCallback != nullptr && (result != nullptr || error != nullptr)) {
completedSent = true;
onCompleteRequestCallback(result, error, networkType, responseTime, requestMsgId);
onCompleteRequestCallback(result, error, networkType, responseTime, requestMsgId, dcId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/tgnet/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Request {
void addRespondMessageId(int64_t id);
bool respondsToMessageId(int64_t id);
void clear(bool time);
void onComplete(TLObject *result, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msg_id);
void onComplete(TLObject *result, TL_error *error, int32_t networkType, int64_t responseTime, int64_t msg_id, int32_t dcId);
void onQuickAck();
void onWriteToSocket();
bool isMediaRequest();
Expand Down
8 changes: 8 additions & 0 deletions TMessagesProj/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@
</intent-filter>
</receiver>

<receiver
android:name=".CopyCodeReceiver"
android:exported="false">
<intent-filter>
<action android:name="org.telegram.messenger.ACTION_COPY_CODE"/>
</intent-filter>
</receiver>

<receiver
android:name=".NotificationsDisabledReceiver"
android:exported="false">
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/assets/darkblue.attheme
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,4 @@ iv_backgroundGray=-14737633
iv_navigationBackground=-16777216
table_background=177390847
table_border=436207615
dialogCardShadow=1073741824
1 change: 1 addition & 0 deletions TMessagesProj/src/main/assets/night.attheme
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,4 @@ iv_backgroundGray=-14737633
iv_navigationBackground=-16777216
table_background=177390847
table_border=436207615
dialogCardShadow=1073741824
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package androidx.recyclerview.widget;

import android.text.TextUtils;
import android.util.Log;

import androidx.core.util.Pools;

import org.telegram.messenger.BuildVars;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
Expand Down Expand Up @@ -68,6 +72,29 @@ class AdapterHelper implements OpReorderer.Callback {

private int mExistingUpdateTypes = 0;

private final ArrayList<String> lastNotifies = BuildVars.DEBUG_VERSION ? new ArrayList<String>() : null;
private void logNotify(String name) {
if (lastNotifies == null) return;
while (lastNotifies.size() > 5) lastNotifies.remove(0);
final StringBuilder sb = new StringBuilder();
sb.append(new Date().toString()).append(" ").append(name).append("\n");
final StackTraceElement[] trace = new Exception().getStackTrace();
for (int i = 0, j = 0; i < trace.length && j < 5; ++i) {
final String traceElement = trace[i].toString();
if (traceElement.startsWith("androidx.recyclerview.widget.") && j == 0) {
continue;
}
sb.append("\n").append(traceElement).append("\n");
j++;
}
lastNotifies.add(sb.toString());
}

public String getLastNotifies() {
if (lastNotifies == null) return null;
return TextUtils.join("\n\n", lastNotifies);
}

AdapterHelper(Callback callback) {
this(callback, false);
}
Expand Down Expand Up @@ -504,6 +531,9 @@ boolean onItemRangeChanged(int positionStart, int itemCount, Object payload) {
if (itemCount < 1) {
return false;
}
if (BuildVars.DEBUG_VERSION) {
logNotify("onItemRangeChanged(" + positionStart + ", " + itemCount + ", " + payload + ")");
}
mPendingUpdates.add(obtainUpdateOp(UpdateOp.UPDATE, positionStart, itemCount, payload));
mExistingUpdateTypes |= UpdateOp.UPDATE;
return mPendingUpdates.size() == 1;
Expand All @@ -516,6 +546,9 @@ boolean onItemRangeInserted(int positionStart, int itemCount) {
if (itemCount < 1) {
return false;
}
if (BuildVars.DEBUG_VERSION) {
logNotify("onItemRangeInserted(" + positionStart + ", " + itemCount + ")");
}
mPendingUpdates.add(obtainUpdateOp(UpdateOp.ADD, positionStart, itemCount, null));
mExistingUpdateTypes |= UpdateOp.ADD;
return mPendingUpdates.size() == 1;
Expand All @@ -528,6 +561,9 @@ boolean onItemRangeRemoved(int positionStart, int itemCount) {
if (itemCount < 1) {
return false;
}
if (BuildVars.DEBUG_VERSION) {
logNotify("onItemRangeRemoved(" + positionStart + ", " + itemCount + ")");
}
mPendingUpdates.add(obtainUpdateOp(UpdateOp.REMOVE, positionStart, itemCount, null));
mExistingUpdateTypes |= UpdateOp.REMOVE;
return mPendingUpdates.size() == 1;
Expand All @@ -543,6 +579,9 @@ boolean onItemRangeMoved(int from, int to, int itemCount) {
if (itemCount != 1) {
throw new IllegalArgumentException("Moving more than 1 item is not supported yet");
}
if (BuildVars.DEBUG_VERSION) {
logNotify("onItemRangeMoved(" + from + ", " + to + ", " + itemCount + ")");
}
mPendingUpdates.add(obtainUpdateOp(UpdateOp.MOVE, from, to, null));
mExistingUpdateTypes |= UpdateOp.MOVE;
return mPendingUpdates.size() == 1;
Expand Down
Loading

0 comments on commit 3bfce86

Please sign in to comment.