Skip to content

Commit

Permalink
Merge remote-tracking branch 'telegram/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Aug 25, 2023
2 parents fffe3e8 + 702839a commit 04016ff
Show file tree
Hide file tree
Showing 67 changed files with 1,884 additions and 733 deletions.
8 changes: 4 additions & 4 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import cn.hutool.core.util.RuntimeUtil
apply plugin: "com.android.application"
apply plugin: "kotlin-android"

def verName = "10.0.1"
def verCode = 1134
def verName = "10.0.3"
def verCode = 1135


def officialVer = "10.0.1"
def officialCode = 3793
def officialVer = "10.0.3"
def officialCode = 3801

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

Expand Down
8 changes: 5 additions & 3 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,11 +1307,11 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
request->startTime = 0;
request->startTimeMillis = 0;
request->minStartTime = (int32_t) (getCurrentTimeMonotonicMillis() / 1000 + 2);
} else if (error->error_code == 420) {
} else if (error->error_code == 420 && (request->requestFlags & RequestFlagIgnoreFloodWait) == 0 && error->error_message.find("STORY_SEND_FLOOD") == std::string::npos) {
int32_t waitTime = 2;
static std::string floodWait = "FLOOD_WAIT_";
static std::string slowmodeWait = "SLOWMODE_WAIT_";
discardResponse = (request->requestFlags & RequestFlagIgnoreFloodWait) == 0;
discardResponse = true;
if (error->error_message.find(floodWait) != std::string::npos) {
std::string num = error->error_message.substr(floodWait.size(), error->error_message.size() - floodWait.size());
waitTime = atoi(num.c_str());
Expand Down Expand Up @@ -3058,7 +3058,9 @@ void ConnectionsManager::updateDcSettings(uint32_t dcNum, bool workaround, bool
if (!workaround && updatingDcSettingsAgain && updatingDcSettingsAgainDcNum == dcNum) {
updatingDcSettingsAgain = false;
for (auto & datacenter : datacenters) {
datacenter.second->resetInitVersion();
if (datacenter.first == dcNum) {
datacenter.second->resetInitVersion();
}
}
updateDcSettings(updatingDcSettingsAgainDcNum, false, false);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ public static void normalizeTimePart(StringBuilder stringBuilder, long time) {
public static void getViewPositionInParent(View view, ViewGroup parent, float[] pointPosition) {
pointPosition[0] = 0;
pointPosition[1] = 0;
if (view == null || parent == null) {
return;
}
View currentView = view;
while (currentView != parent) {
//fix strange offset inside view pager
Expand Down Expand Up @@ -759,6 +762,22 @@ public static void getBitmapFromSurface(SurfaceView surfaceView, Bitmap surfaceB
}
}

@RequiresApi(api = Build.VERSION_CODES.N)
public static void getBitmapFromSurface(Surface surface, Bitmap surfaceBitmap) {
if (surface == null || !surface.isValid()) {
return;
}
CountDownLatch countDownLatch = new CountDownLatch(1);
PixelCopy.request(surface, surfaceBitmap, copyResult -> {
countDownLatch.countDown();
}, Utilities.searchQueue.getHandler());
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

public static float[] getCoordinateInParent(ViewGroup parentView, View view) {
float x = 0, y = 0;
View child = view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,13 @@ public static int migrate(MessagesStorage messagesStorage, int version) throws E
version = 128;
}

if (version == 128) {
database.executeFast("ALTER TABLE story_drafts ADD COLUMN type INTEGER default 0").stepThis().dispose();

database.executeFast("PRAGMA user_version = 129").stepThis().dispose();
version = 129;
}

return version;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static class Preset {
public int maxVideoBitrate;

public Preset(int[] m, long p, long v, long f, boolean pv, boolean pm, boolean e, boolean l, int bitrate, boolean preloadStories) {
System.arraycopy(m, 0, mask, 0, mask.length);
System.arraycopy(m, 0, mask, 0, Math.max(m.length, mask.length));
sizes[PRESET_SIZE_NUM_PHOTO] = p;
sizes[PRESET_SIZE_NUM_VIDEO] = v;
sizes[PRESET_SIZE_NUM_DOCUMENT] = f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@ public int getPositionInQueue() {
public boolean checkPrefixPreloadFinished() {
if (preloadPrefixSize > 0 && downloadedBytes > preloadPrefixSize) {
long minStart = Long.MAX_VALUE;
for (int b = 0; b < notLoadedBytesRanges.size(); b++) {
Range range = notLoadedBytesRanges.get(b);
minStart = Math.min(minStart, range.start);
ArrayList<Range> array = notLoadedBytesRanges;
if (array == null) {
return true;
}
try {
for (int b = 0; b < array.size(); b++) {
Range range = array.get(b);
minStart = Math.min(minStart, range.start);
}
} catch (Throwable e) {
FileLog.e(e);
return true;
}
if (minStart > preloadPrefixSize) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ public boolean isLoadingVideoAny(TLRPC.Document document) {
}

public void cancelFileUpload(final String location, final boolean enc) {
if (location == null) {
return;
}
fileLoaderQueue.postRunnable(() -> {
FileUploadOperation operation;
if (!enc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -226,4 +228,29 @@ public static void setPriorityForDocument(TLRPC.Document document, int priority)
priorityMap.put(document.id, priority);
}
}

@Nullable
public static Uri prepareUri(int currentAccount, TLRPC.Document document, Object parent) {
String attachFileName = FileLoader.getAttachFileName(document);
File file = FileLoader.getInstance(currentAccount).getPathToAttach(document);

if (file != null && file.exists()) {
return Uri.fromFile(file);
}
try {
String params = "?account=" + currentAccount +
"&id=" + document.id +
"&hash=" + document.access_hash +
"&dc=" + document.dc_id +
"&size=" + document.size +
"&mime=" + URLEncoder.encode(document.mime_type, "UTF-8") +
"&rid=" + FileLoader.getInstance(currentAccount).getFileReference(parent) +
"&name=" + URLEncoder.encode(FileLoader.getDocumentFileName(document), "UTF-8") +
"&reference=" + Utilities.bytesToHex(document.file_reference != null ? document.file_reference : new byte[0]);
return Uri.parse("tg://" + attachFileName + params);
} catch (UnsupportedEncodingException e) {
FileLog.e(e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ public boolean hasImageLoaded() {
}

public boolean hasNotThumb() {
return currentImageDrawable != null || currentMediaDrawable != null || staticThumbDrawable instanceof VectorAvatarThumbDrawable;
return currentImageDrawable != null || currentMediaDrawable != null || staticThumbDrawable instanceof VectorAvatarThumbDrawable || (staticThumbDrawable != null && currentImageKey == null && currentMediaKey == null);
}

public boolean hasStaticThumb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class MessagesController extends BaseController implements NotificationCe
public StoriesController storiesController;
private boolean hasArchivedChats;
private boolean hasStories;
public long storiesChangelogUserId;
public long storiesChangelogUserId = 777000;

public static TLRPC.Peer getPeerFromInputPeer(TLRPC.InputPeer peer) {
if (peer.chat_id != 0) {
Expand Down Expand Up @@ -412,10 +412,9 @@ protected void setLocal(int currentAccount, Integer arguments, TLRPC.TL_help_app
try {
SQLiteDatabase database = MessagesStorage.getInstance(currentAccount).getDatabase();
if (database != null) {
if (data == null) {
database.executeFast("DELETE FROM app_config").stepThis().dispose();
} else {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO app_config VALUES(?)");
database.executeFast("DELETE FROM app_config").stepThis().dispose();
if (data != null) {
SQLitePreparedStatement state = database.executeFast("INSERT INTO app_config VALUES(?)");
state.requery();
NativeByteBuffer buffer = new NativeByteBuffer(data.getObjectSize());
data.serializeToStream(buffer);
Expand Down Expand Up @@ -16509,7 +16508,7 @@ public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, ArrayList<TLR
}
}
} else if (baseUpdate instanceof TLRPC.TL_updateSentStoryReaction) {
storiesController.updateStoryReaction(((TLRPC.TL_updateSentStoryReaction) baseUpdate).user_id, ((TLRPC.TL_updateSentStoryReaction) baseUpdate).story_id, ((TLRPC.TL_updateSentStoryReaction) baseUpdate).reaction);
getStoriesController().updateStoryReaction(((TLRPC.TL_updateSentStoryReaction) baseUpdate).user_id, ((TLRPC.TL_updateSentStoryReaction) baseUpdate).story_id, ((TLRPC.TL_updateSentStoryReaction) baseUpdate).reaction);
}
}
if (editor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class MessagesStorage extends BaseController {
private static SparseArray<MessagesStorage> Instance = new SparseArray();
private static final Object lockObject = new Object();

public final static int LAST_DB_VERSION = 128;
public final static int LAST_DB_VERSION = 129;
private boolean databaseMigrationInProgress;
public boolean showClearDatabaseAlert;
private LongSparseIntArray dialogIsForum = new LongSparseIntArray();
Expand Down Expand Up @@ -679,7 +679,7 @@ public static void createTables(SQLiteDatabase database) throws SQLiteException
database.executeFast("CREATE TABLE profile_stories (dialog_id INTEGER, story_id INTEGER, data BLOB, PRIMARY KEY(dialog_id, story_id));").stepThis().dispose();
database.executeFast("CREATE TABLE archived_stories (story_id INTEGER PRIMARY KEY, data BLOB);").stepThis().dispose();

database.executeFast("CREATE TABLE story_drafts (id INTEGER PRIMARY KEY, date INTEGER, data BLOB);").stepThis().dispose();
database.executeFast("CREATE TABLE story_drafts (id INTEGER PRIMARY KEY, date INTEGER, data BLOB, type INTEGER);").stepThis().dispose();

database.executeFast("CREATE TABLE story_pushes (uid INTEGER, sid INTEGER, date INTEGER, localName TEXT, flags INTEGER, expire_date INTEGER, PRIMARY KEY(uid, sid));").stepThis().dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ public static void sendRegistrationToServer(@PushType int pushType, String token
req.events.add(event);

sendStat = false;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error != null) {
SharedConfig.pushStatSent = true;
SharedConfig.saveConfig();
}
}));
SharedConfig.pushStatSent = true;
SharedConfig.saveConfig();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, null);
}
AndroidUtilities.runOnUIThread(() -> MessagesController.getInstance(currentAccount).registerForPush(pushType, token));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4738,11 +4738,15 @@ public void sendMessage(SendMessageParams sendMessageParams) {
reqSend.reply_to = SendMessagesHelper.creteReplyInput(replyToTopMsg.getId());
reqSend.flags |= 512;
}

if (newMsg.from_id != null) {
reqSend.send_as = getMessagesController().getInputPeer(newMsg.from_id);
}
reqSend.hide_via = !params.containsKey("bot");
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
if (replyToStoryItem != null) {
reqSend.reply_to = creteReplyInput(replyToStoryItem);
reqSend.flags |= 1;
} else if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
reqSend.flags |= 1;
reqSend.reply_to = SendMessagesHelper.creteReplyInput(newMsg.reply_to.reply_to_msg_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,22 @@ public static boolean isAppUpdateAvailable() {
}

public static boolean setNewAppVersionAvailable(TLRPC.TL_help_appUpdate update) {
if (update == null) {
String updateVersionString = null;
int versionCode = 0;
try {
PackageInfo packageInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
versionCode = packageInfo.versionCode;
updateVersionString = packageInfo.versionName;
} catch (Exception e) {
FileLog.e(e);
}
if (versionCode == 0) {
versionCode = BuildVars.BUILD_VERSION;
}
if (updateVersionString == null) {
updateVersionString = BuildVars.BUILD_VERSION_STRING;
}
if (update == null || update.version == null || versionBiggerOrEqual(updateVersionString, update.version)) {
pendingAppUpdate = null;
pendingAppUpdateBuildVersion = 0;
saveConfig();
Expand All @@ -1626,6 +1641,22 @@ public static boolean setNewAppVersionAvailable(TLRPC.TL_help_appUpdate update)
return true;
}

// returns a >= b
private static boolean versionBiggerOrEqual(String a, String b) {
String[] partsA = a.split("\\.");
String[] partsB = b.split("\\.");
for (int i = 0; i < Math.min(partsA.length, partsB.length); ++i) {
int numA = Integer.parseInt(partsA[i]);
int numB = Integer.parseInt(partsB[i]);
if (numA < numB) {
return false;
} else if (numA > numB) {
return true;
}
}
return true;
}

public static boolean checkPasscode(String passcode) {
if (passcodeSalt.length == 0) {
boolean result = Utilities.MD5(passcode).equals(passcodeHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private void checkPremiumSelf(TLRPC.User oldUser, TLRPC.User newUser) {

getMediaDataController().loadPremiumPromo(false);
getMediaDataController().loadReactions(false, true);
getMessagesController().getStoriesController().invalidateStoryLimit();
});
}
}
Expand Down
Loading

0 comments on commit 04016ff

Please sign in to comment.