diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle
index bc1391f81..f7d331b8b 100644
--- a/TMessagesProj/build.gradle
+++ b/TMessagesProj/build.gradle
@@ -30,16 +30,16 @@ dependencies {
implementation 'com.google.firebase:firebase-config:21.0.1'
implementation 'com.google.firebase:firebase-datatransport:18.1.0'
implementation 'com.google.firebase:firebase-appindexing:20.0.0'
- implementation 'com.google.android.gms:play-services-maps:17.0.1'
- implementation 'com.google.android.gms:play-services-auth:19.2.0'
+ implementation 'com.google.android.gms:play-services-maps:18.1.0'
+ implementation 'com.google.android.gms:play-services-auth:20.4.0'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
- implementation 'com.google.android.gms:play-services-wearable:17.1.0'
- implementation 'com.google.android.gms:play-services-location:18.0.0'
- implementation 'com.google.android.gms:play-services-wallet:18.1.3'
+ implementation 'com.google.android.gms:play-services-wearable:18.0.0'
+ implementation 'com.google.android.gms:play-services-location:21.0.1'
+ implementation 'com.google.android.gms:play-services-wallet:19.1.0'
implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
implementation 'com.stripe:stripe-android:2.0.2'
implementation 'com.google.mlkit:language-id:16.1.1'
- implementation 'com.android.billingclient:billing:5.0.0'
+ implementation 'com.android.billingclient:billing:5.1.0'
implementation 'com.google.code.gson:gson:2.10'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
diff --git a/TMessagesProj/jni/jni.c b/TMessagesProj/jni/jni.c
index 1c34b3e9c..1b0f168bd 100644
--- a/TMessagesProj/jni/jni.c
+++ b/TMessagesProj/jni/jni.c
@@ -219,9 +219,9 @@ int64_t listdir(const char *fileName, int32_t mode, int32_t docType, int64_t tim
value += listdir(buff, mode, docType, time, subdirs);
}
} else {
- stat(buff, &attrib);
+ int rc = stat(buff, &attrib);
if (mode == 0) {
- value += 512 * attrib.st_blocks;
+ value += rc == 0 ? attrib.st_size : 0;
} else if (mode == 1) {
if (attrib.st_atim.tv_sec != 0) {
if (attrib.st_atim.tv_sec < time) {
diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml
index cf4d88066..d350aa887 100644
--- a/TMessagesProj/src/main/AndroidManifest.xml
+++ b/TMessagesProj/src/main/AndroidManifest.xml
@@ -19,6 +19,7 @@
+
@@ -75,6 +76,10 @@
+
+
+
+
0) {
// wanted to achieve an effect of next items covering current
- ((ViewGroup) view.getParent()).bringChildToFront(view);
+ view.bringToFront();
}
animation
.setDuration(getRemoveDuration())
@@ -337,6 +336,14 @@ public class DefaultItemAnimator extends SimpleItemAnimator {
}
+ protected void beforeAnimateMoveImpl(final RecyclerView.ViewHolder holder) {
+
+ }
+
+ protected void afterAnimateMoveImpl(final RecyclerView.ViewHolder holder) {
+
+ }
+
protected void animateMoveImpl(final RecyclerView.ViewHolder holder, MoveInfo moveInfo) {
int fromX = moveInfo.fromX;
int fromY = moveInfo.fromY;
@@ -362,6 +369,7 @@ public class DefaultItemAnimator extends SimpleItemAnimator {
if (translationInterpolator != null) {
animation.setInterpolator(translationInterpolator);
}
+ beforeAnimateMoveImpl(holder);
animation
.setDuration(getMoveDuration())
.setStartDelay(getMoveDelay())
@@ -388,6 +396,8 @@ public class DefaultItemAnimator extends SimpleItemAnimator {
dispatchMoveFinished(holder);
mMoveAnimations.remove(holder);
dispatchFinishedWhenDone();
+
+ afterAnimateMoveImpl(holder);
}
})
.start();
diff --git a/TMessagesProj/src/main/java/androidx/recyclerview/widget/ItemTouchHelper.java b/TMessagesProj/src/main/java/androidx/recyclerview/widget/ItemTouchHelper.java
index 3178efe54..81b297552 100644
--- a/TMessagesProj/src/main/java/androidx/recyclerview/widget/ItemTouchHelper.java
+++ b/TMessagesProj/src/main/java/androidx/recyclerview/widget/ItemTouchHelper.java
@@ -32,8 +32,6 @@ import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.view.animation.Interpolator;
-import org.telegram.messenger.AndroidUtilities;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GestureDetectorCompat;
@@ -41,6 +39,8 @@ import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
+import org.telegram.messenger.AndroidUtilities;
+
import java.util.ArrayList;
import java.util.List;
@@ -506,6 +506,10 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
stopGestureDetection();
}
+ public void clearRecoverAnimations() {
+ mRecoverAnimations.clear();
+ }
+
private void startGestureDetection() {
mItemTouchHelperGestureListener = new ItemTouchHelperGestureListener();
mGestureDetector = new GestureDetectorCompat(mRecyclerView.getContext(),
@@ -561,6 +565,10 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
mRecoverAnimations, mActionState, dx, dy);
}
+ protected boolean shouldSwipeBack() {
+ return false;
+ }
+
/**
* Starts dragging or swiping the given View. Call with null if you want to clear it.
*
@@ -596,28 +604,33 @@ public class ItemTouchHelper extends RecyclerView.ItemDecoration
if (mSelected != null) {
final ViewHolder prevSelected = mSelected;
if (prevSelected.itemView.getParent() != null) {
+ final boolean swipeBack = shouldSwipeBack();
final int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0
: swipeIfNecessary(prevSelected);
releaseVelocityTracker();
// find where we should animate to
final float targetTranslateX, targetTranslateY;
int animationType;
- switch (swipeDir) {
- case LEFT:
- case RIGHT:
- case START:
- case END:
- targetTranslateY = 0;
- targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
- break;
- case UP:
- case DOWN:
- targetTranslateX = 0;
- targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
- break;
- default:
- targetTranslateX = 0;
- targetTranslateY = 0;
+ if (swipeBack) {
+ targetTranslateX = targetTranslateY = 0;
+ } else {
+ switch (swipeDir) {
+ case LEFT:
+ case RIGHT:
+ case START:
+ case END:
+ targetTranslateY = 0;
+ targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
+ break;
+ case UP:
+ case DOWN:
+ targetTranslateX = 0;
+ targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
+ break;
+ default:
+ targetTranslateX = 0;
+ targetTranslateY = 0;
+ }
}
if (prevActionState == ACTION_STATE_DRAG) {
animationType = ANIMATION_TYPE_DRAG;
diff --git a/TMessagesProj/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java b/TMessagesProj/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java
index f6f442d7e..0ac4c5194 100644
--- a/TMessagesProj/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java
+++ b/TMessagesProj/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java
@@ -158,6 +158,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
private int[] mReusableIntPair = new int[2];
private boolean needFixGap = true;
+ private boolean needFixEndGap = true;
/**
* Creates a vertical LinearLayoutManager
@@ -958,7 +959,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
*/
private int fixLayoutEndGap(int endOffset, RecyclerView.Recycler recycler,
RecyclerView.State state, boolean canOffsetChildren) {
- if (!needFixGap) {
+ if (!needFixGap || !needFixEndGap) {
return 0;
}
int gap = mOrientationHelper.getEndAfterPadding() - endOffset;
@@ -981,7 +982,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
return fixOffset;
}
- public int getStarForFixGap() {
+ public int getStartForFixGap() {
return mOrientationHelper.getStartAfterPadding();
}
@@ -993,7 +994,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
if (!needFixGap) {
return 0;
}
- int gap = startOffset - getStarForFixGap();
+ int gap = startOffset - getStartForFixGap();
int fixOffset = 0;
if (gap > 0) {
// check if we should fix this gap.
@@ -2601,4 +2602,8 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager implements
public void setNeedFixGap(boolean needFixGap) {
this.needFixGap = needFixGap;
}
+
+ public void setNeedFixEndGap(boolean needFixEndGap) {
+ this.needFixEndGap = needFixEndGap;
+ }
}
diff --git a/TMessagesProj/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java b/TMessagesProj/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java
index c88b9e5e3..a0e8f37e3 100755
--- a/TMessagesProj/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java
+++ b/TMessagesProj/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java
@@ -32,6 +32,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.encoder.Encoder;
import com.google.zxing.qrcode.encoder.QRCode;
+import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.R;
import org.telegram.messenger.SvgHelper;
import org.telegram.ui.Components.RLottieDrawable;
@@ -51,6 +52,7 @@ public final class QRCodeWriter {
private float[] radii = new float[8];
private int imageBloks;
private int imageBlockX;
+ public boolean includeSideQuads = true;
private int sideQuadSize;
private int imageSize;
@@ -126,57 +128,11 @@ public final class QRCodeWriter {
imageBlockX = (inputWidth - imageBloks) / 2;
imageSize = imageBloks * multiple - 24;
int imageX = (size - imageSize) / 2;
-
- boolean isTransparentBackground = Color.alpha(backgroundColor) == 0;
- Path clipPath = new Path();
- RectF rectF = new RectF();
- for (int a = 0; a < 3; a++) {
- int x, y;
- if (a == 0) {
- x = padding;
- y = padding;
- } else if (a == 1) {
- x = size - sideQuadSize * multiple - padding;
- y = padding;
- } else {
- x = padding;
- y = size - sideQuadSize * multiple - padding;
- }
-
- float r;
- if (isTransparentBackground) {
- rectF.set(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple);
- r = (sideQuadSize * multiple) / 4.0f * radiusFactor;
- clipPath.reset();
- clipPath.addRoundRect(rectF, r, r, Path.Direction.CW);
- clipPath.close();
- canvas.save();
- canvas.clipPath(clipPath, Region.Op.DIFFERENCE);
- }
- r = (sideQuadSize * multiple) / 3.0f * radiusFactor;
- Arrays.fill(radii, r);
- rect.setColor(color);
- rect.setBounds(x, y, x + sideQuadSize * multiple, y + sideQuadSize * multiple);
- rect.draw(canvas);
- canvas.drawRect(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple, blackPaint);
- if (isTransparentBackground) {
- canvas.restore();
- }
-
- if (!isTransparentBackground) {
- r = (sideQuadSize * multiple) / 4.0f * radiusFactor;
- Arrays.fill(radii, r);
- rect.setColor(backgroundColor);
- rect.setBounds(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple);
- rect.draw(canvas);
- }
-
- r = ((sideQuadSize - 2) * multiple) / 4.0f * radiusFactor;
- Arrays.fill(radii, r);
- rect.setColor(color);
- rect.setBounds(x + multiple * 2, y + multiple * 2, x + (sideQuadSize - 2) * multiple, y + (sideQuadSize - 2) * multiple);
- rect.draw(canvas);
+ if (includeSideQuads) {
+ blackPaint.setColor(color);
+ drawSideQuadsGradient(canvas, blackPaint, rect, sideQuadSize, multiple, padding, size, radiusFactor, radii, backgroundColor, color);
}
+ boolean isTransparentBackground = Color.alpha(backgroundColor) == 0;
float r = multiple / 2.0f * radiusFactor;
for (int y = 0, outputY = padding; y < inputHeight; y++, outputY += multiple) {
@@ -241,6 +197,102 @@ public final class QRCodeWriter {
return bitmap;
}
+ public static void drawSideQuadsGradient(Canvas canvas, Paint blackPaint, GradientDrawable rect, float sideQuadSize, float multiple, int padding, float size, float radiusFactor, float[] radii, int backgroundColor, int color) {
+ boolean isTransparentBackground = Color.alpha(backgroundColor) == 0;
+ rect.setShape(GradientDrawable.RECTANGLE);
+ rect.setCornerRadii(radii);
+ Path clipPath = new Path();
+ RectF rectF = new RectF();
+ for (int a = 0; a < 3; a++) {
+ float x, y;
+ if (a == 0) {
+ x = padding;
+ y = padding;
+ } else if (a == 1) {
+ x = size - sideQuadSize * multiple - padding;
+ y = padding;
+ } else {
+ x = padding;
+ y = size - sideQuadSize * multiple - padding;
+ }
+
+ float r;
+ if (isTransparentBackground) {
+ rectF.set(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple);
+ r = (sideQuadSize * multiple) / 4.0f * radiusFactor;
+ clipPath.reset();
+ clipPath.addRoundRect(rectF, r, r, Path.Direction.CW);
+ clipPath.close();
+ canvas.save();
+ canvas.clipPath(clipPath, Region.Op.DIFFERENCE);
+ }
+ r = (sideQuadSize * multiple) / 3.0f * radiusFactor;
+ Arrays.fill(radii, r);
+ rect.setColor(color);
+ rect.setBounds((int) x, (int) y, (int) (x + sideQuadSize * multiple), (int) (y + sideQuadSize * multiple));
+ rect.draw(canvas);
+ canvas.drawRect(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple, blackPaint);
+ if (isTransparentBackground) {
+ canvas.restore();
+ }
+
+ if (!isTransparentBackground) {
+ r = (sideQuadSize * multiple) / 4.0f * radiusFactor;
+ Arrays.fill(radii, r);
+ rect.setColor(backgroundColor);
+ rect.setBounds((int) (x + multiple), (int) (y + multiple), (int) (x + (sideQuadSize - 1) * multiple), (int) (y + (sideQuadSize - 1) * multiple));
+ rect.draw(canvas);
+ }
+
+ r = ((sideQuadSize - 2) * multiple) / 4.0f * radiusFactor;
+ Arrays.fill(radii, r);
+ rect.setColor(color);
+ rect.setBounds((int) (x + multiple * 2), (int) (y + multiple * 2), (int) (x + (sideQuadSize - 2) * multiple), (int) (y + (sideQuadSize - 2) * multiple));
+ rect.draw(canvas);
+ }
+ }
+
+ public static void drawSideQuads(Canvas canvas, float xOffset, float yOffset, Paint blackPaint, float sideQuadSize, float multiple, int padding, float size, float radiusFactor, float[] radii, boolean isTransparentBackground) {
+ Path clipPath = new Path();
+ for (int a = 0; a < 3; a++) {
+ float x, y;
+ if (a == 0) {
+ x = padding;
+ y = padding;
+ } else if (a == 1) {
+ x = size - sideQuadSize * multiple - padding;
+ y = padding;
+ } else {
+ x = padding;
+ y = size - sideQuadSize * multiple - padding;
+ }
+
+ x += xOffset;
+ y += yOffset;
+
+ float r;
+ if (isTransparentBackground) {
+ AndroidUtilities.rectTmp.set(x + multiple, y + multiple, x + (sideQuadSize - 1) * multiple, y + (sideQuadSize - 1) * multiple);
+ r = (sideQuadSize * multiple) / 4.0f * radiusFactor;
+ clipPath.reset();
+ clipPath.addRoundRect(AndroidUtilities.rectTmp, r, r, Path.Direction.CW);
+ clipPath.close();
+ canvas.save();
+ canvas.clipPath(clipPath, Region.Op.DIFFERENCE);
+ }
+ r = (sideQuadSize * multiple) / 3.0f * radiusFactor;
+ AndroidUtilities.rectTmp.set(x, y, x + sideQuadSize * multiple, y + sideQuadSize * multiple);
+ canvas.drawRoundRect(AndroidUtilities.rectTmp, r, r, blackPaint);
+ if (isTransparentBackground) {
+ canvas.restore();
+ }
+
+ r = ((sideQuadSize - 2) * multiple) / 4.0f * radiusFactor;
+ AndroidUtilities.rectTmp.set(x + multiple * 2, y + multiple * 2, x + (sideQuadSize - 2) * multiple, y + (sideQuadSize - 2) * multiple);
+ canvas.drawRoundRect(AndroidUtilities.rectTmp, r, r, blackPaint);
+ }
+ }
+
private boolean has(int x, int y) {
if (x >= imageBlockX && x < imageBlockX + imageBloks && y >= imageBlockX && y < imageBlockX + imageBloks) {
return false;
@@ -257,4 +309,8 @@ public final class QRCodeWriter {
public int getImageSize() {
return imageSize;
}
+
+ public int getSideSize() {
+ return sideQuadSize;
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java
index db1e17980..9eca21043 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java
@@ -475,7 +475,7 @@ public class AndroidUtilities {
return spannableStringBuilder;
}
- public static void recycleBitmaps(ArrayList bitmapToRecycle) {
+ public static void recycleBitmaps(List bitmapToRecycle) {
if (bitmapToRecycle != null && !bitmapToRecycle.isEmpty()) {
AndroidUtilities.runOnUIThread(() -> Utilities.globalQueue.postRunnable(() -> {
for (int i = 0; i < bitmapToRecycle.size(); i++) {
@@ -526,6 +526,10 @@ public class AndroidUtilities {
});
}
+ public static void recycleBitmap(Bitmap image) {
+ recycleBitmaps(Collections.singletonList(image));
+ }
+
private static class LinkSpec {
String url;
int start;
@@ -2636,7 +2640,7 @@ public class AndroidUtilities {
}
public static boolean shouldShowClipboardToast() {
- return Build.VERSION.SDK_INT < Build.VERSION_CODES.S || !OneUIUtilities.hasBuiltInClipboardToasts();
+ return (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || !OneUIUtilities.hasBuiltInClipboardToasts()) && Build.VERSION.SDK_INT < 32 /* TODO: Update to TIRAMISU when compileSdkVersion would be 32 */;
}
public static boolean addToClipboard(CharSequence str) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java
index 6e44ac825..ee09a72d4 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java
@@ -24,8 +24,8 @@ public class BuildVars {
public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = true;
public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29;
- public static int BUILD_VERSION = 2929;
- public static String BUILD_VERSION_STRING = "9.1.6";
+ public static int BUILD_VERSION = 2956;
+ public static String BUILD_VERSION_STRING = "9.2.0";
public static int APP_ID = 4;
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java
index 9993a1999..bd471c81a 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java
@@ -1700,9 +1700,17 @@ public class ChatObject {
}
public static boolean canDeleteTopic(int currentAccount, TLRPC.Chat chat, int topicId) {
+ if (topicId == 1) {
+ // general topic can't be deleted
+ return false;
+ }
return chat != null && canDeleteTopic(currentAccount, chat, MessagesController.getInstance(currentAccount).getTopicsController().findTopic(chat.id, topicId));
}
public static boolean canDeleteTopic(int currentAccount, TLRPC.Chat chat, TLRPC.TL_forumTopic topic) {
+ if (topic != null && topic.id == 1) {
+ // general topic can't be deleted
+ return false;
+ }
return canUserDoAction(chat, ACTION_DELETE_MESSAGES) || isMyTopic(currentAccount, topic) && topic.topMessage != null && topic.topicStartMessage != null && topic.topMessage.id - topic.topicStartMessage.id <= Math.max(1, topic.groupedMessages == null ? 0 : topic.groupedMessages.size()) && MessageObject.peersEqual(topic.from_id, topic.topMessage.from_id);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ChatsWidgetService.java b/TMessagesProj/src/main/java/org/telegram/messenger/ChatsWidgetService.java
index 06b0d3317..21aaa4340 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ChatsWidgetService.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ChatsWidgetService.java
@@ -23,8 +23,6 @@ import android.widget.RemoteViewsService;
import androidx.collection.LongSparseArray;
-import com.google.android.exoplayer2.util.Log;
-
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.AvatarDrawable;
@@ -352,8 +350,6 @@ class ChatsRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.shortcut_widget_item, fillInIntent);
- Log.d("kek", "kek " + name);
-
rv.setViewVisibility(R.id.shortcut_widget_item_divider, position == getCount() ? View.GONE : View.VISIBLE);
return rv;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsWidgetService.java b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsWidgetService.java
index ea0cadb1a..675b4852d 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ContactsWidgetService.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ContactsWidgetService.java
@@ -203,8 +203,6 @@ class ContactsRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactor
}
extras.putInt("currentAccount", accountInstance.getCurrentAccount());
- Log.d("kek", "kek " + name);
-
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(a == 0 ? R.id.contacts_widget_item1 : R.id.contacts_widget_item2, fillInIntent);
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DatabaseMigrationHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/DatabaseMigrationHelper.java
new file mode 100644
index 000000000..a26eaa99a
--- /dev/null
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/DatabaseMigrationHelper.java
@@ -0,0 +1,1217 @@
+package org.telegram.messenger;
+
+import org.telegram.SQLite.SQLiteCursor;
+import org.telegram.SQLite.SQLiteDatabase;
+import org.telegram.SQLite.SQLitePreparedStatement;
+import org.telegram.tgnet.NativeByteBuffer;
+import org.telegram.tgnet.TLRPC;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class DatabaseMigrationHelper {
+ public static int migrate(MessagesStorage messagesStorage, int version) throws Exception {
+ SQLiteDatabase database = messagesStorage.getDatabase();
+ if (version < 4) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_photos(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose();
+
+ database.executeFast("DROP INDEX IF EXISTS read_state_out_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS ttl_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS date_idx_messages;").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages ON messages(mid, out);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages ON messages(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages ON messages(uid, date, mid);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS sent_files_v2(uid TEXT, type INTEGER, data BLOB, PRIMARY KEY (uid, type))").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS download_queue(uid INTEGER, type INTEGER, date INTEGER, data BLOB, PRIMARY KEY (uid, type));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS type_date_idx_download_queue ON download_queue(type, date);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS dialog_settings(did INTEGER PRIMARY KEY, flags INTEGER);").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose();
+
+ database.executeFast("UPDATE messages SET send_state = 2 WHERE mid < 0 AND send_state = 1").stepThis().dispose();
+
+ messagesStorage.fixNotificationSettings();
+ database.executeFast("PRAGMA user_version = 4").stepThis().dispose();
+ version = 4;
+ }
+ if (version == 4) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v2(mid INTEGER PRIMARY KEY, date INTEGER)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v2 ON enc_tasks_v2(date);").stepThis().dispose();
+ database.beginTransaction();
+ SQLiteCursor cursor = database.queryFinalized("SELECT date, data FROM enc_tasks WHERE 1");
+ SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_tasks_v2 VALUES(?, ?)");
+ if (cursor.next()) {
+ int date = cursor.intValue(0);
+ NativeByteBuffer data = cursor.byteBufferValue(1);
+ if (data != null) {
+ int length = data.limit();
+ for (int a = 0; a < length / 4; a++) {
+ state.requery();
+ state.bindInteger(1, data.readInt32(false));
+ state.bindInteger(2, date);
+ state.step();
+ }
+ data.reuse();
+ }
+ }
+ state.dispose();
+ cursor.dispose();
+ database.commitTransaction();
+
+ database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS enc_tasks;").stepThis().dispose();
+
+ database.executeFast("ALTER TABLE messages ADD COLUMN media INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 6").stepThis().dispose();
+ version = 6;
+ }
+ if (version == 6) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS messages_seq(mid INTEGER PRIMARY KEY, seq_in INTEGER, seq_out INTEGER);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS seq_idx_messages_seq ON messages_seq(seq_in, seq_out);").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN layer INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_in INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_out INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 7").stepThis().dispose();
+ version = 7;
+ }
+ if (version == 7 || version == 8 || version == 9) {
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN use_count INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN exchange_id INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN key_date INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN fprint INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN fauthkey BLOB default NULL").stepThis().dispose();
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN khash BLOB default NULL").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 10").stepThis().dispose();
+ version = 10;
+ }
+ if (version == 10) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS web_recent_v3(id TEXT, type INTEGER, image_url TEXT, thumb_url TEXT, local_url TEXT, width INTEGER, height INTEGER, size INTEGER, date INTEGER, PRIMARY KEY (id, type));").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 11").stepThis().dispose();
+ version = 11;
+ }
+ if (version == 11 || version == 12) {
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_idx_media;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS mid_idx_media;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_date_mid_idx_media;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS media;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS media_counts;").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_v2(mid INTEGER PRIMARY KEY, uid INTEGER, date INTEGER, type INTEGER, data BLOB)").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_counts_v2(uid INTEGER, type INTEGER, count INTEGER, PRIMARY KEY(uid, type))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media ON media_v2(uid, mid, type, date);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
+ version = 13;
+ }
+ if (version == 13) {
+ database.executeFast("ALTER TABLE messages ADD COLUMN replydata BLOB default NULL").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 14").stepThis().dispose();
+ version = 14;
+ }
+ if (version == 14) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS hashtag_recent_v2(id TEXT PRIMARY KEY, date INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 15").stepThis().dispose();
+ version = 15;
+ }
+ if (version == 15) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
+ version = 16;
+ }
+ if (version == 16) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN inbox_max INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN outbox_max INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 17").stepThis().dispose();
+ version = 17;
+ }
+ if (version == 17) {
+ database.executeFast("PRAGMA user_version = 18").stepThis().dispose();
+ version = 18;
+ }
+ if (version == 18) {
+ database.executeFast("DROP TABLE IF EXISTS stickers;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS stickers_v2(id INTEGER PRIMARY KEY, data BLOB, date INTEGER, hash INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 19").stepThis().dispose();
+ version = 19;
+ }
+ if (version == 19) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS bot_keyboard(uid INTEGER PRIMARY KEY, mid INTEGER, info BLOB)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS bot_keyboard_idx_mid ON bot_keyboard(mid);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 20").stepThis().dispose();
+ version = 20;
+ }
+ if (version == 20) {
+ database.executeFast("CREATE TABLE search_recent(did INTEGER PRIMARY KEY, date INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 21").stepThis().dispose();
+ version = 21;
+ }
+ if (version == 21) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS chat_settings_v2(uid INTEGER PRIMARY KEY, info BLOB)").stepThis().dispose();
+
+ SQLiteCursor cursor = database.queryFinalized("SELECT uid, participants FROM chat_settings WHERE uid < 0");
+ SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?)");
+ while (cursor.next()) {
+ long chatId = cursor.intValue(0);
+ NativeByteBuffer data = cursor.byteBufferValue(1);
+ if (data != null) {
+ TLRPC.ChatParticipants participants = TLRPC.ChatParticipants.TLdeserialize(data, data.readInt32(false), false);
+ data.reuse();
+ if (participants != null) {
+ TLRPC.TL_chatFull chatFull = new TLRPC.TL_chatFull();
+ chatFull.id = chatId;
+ chatFull.chat_photo = new TLRPC.TL_photoEmpty();
+ chatFull.notify_settings = new TLRPC.TL_peerNotifySettingsEmpty_layer77();
+ chatFull.exported_invite = null;
+ chatFull.participants = participants;
+ NativeByteBuffer data2 = new NativeByteBuffer(chatFull.getObjectSize());
+ chatFull.serializeToStream(data2);
+ state.requery();
+ state.bindLong(1, chatId);
+ state.bindByteBuffer(2, data2);
+ state.step();
+ data2.reuse();
+ }
+ }
+ }
+ state.dispose();
+ cursor.dispose();
+
+ database.executeFast("DROP TABLE IF EXISTS chat_settings;").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN last_mid_i INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN unread_count_i INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN pts INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN date_i INTEGER default 0").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_i_idx_dialogs ON dialogs(last_mid_i);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_i_idx_dialogs ON dialogs(unread_count_i);").stepThis().dispose();
+ database.executeFast("ALTER TABLE messages ADD COLUMN imp INTEGER default 0").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS messages_holes(uid INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, start));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_messages_holes ON messages_holes(uid, end);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 22").stepThis().dispose();
+ version = 22;
+ }
+ if (version == 22) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_holes_v2(uid INTEGER, type INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, type, start));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_media_holes_v2 ON media_holes_v2(uid, type, end);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 23").stepThis().dispose();
+ version = 23;
+ }
+ if (version == 23 || version == 24) {
+ database.executeFast("DELETE FROM media_holes_v2 WHERE uid != 0 AND type >= 0 AND start IN (0, 1)").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 25").stepThis().dispose();
+ version = 25;
+ }
+ if (version == 25 || version == 26) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS channel_users_v2(did INTEGER, uid INTEGER, date INTEGER, data BLOB, PRIMARY KEY(did, uid))").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 27").stepThis().dispose();
+ version = 27;
+ }
+ if (version == 27) {
+ database.executeFast("ALTER TABLE web_recent_v3 ADD COLUMN document BLOB default NULL").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 28").stepThis().dispose();
+ version = 28;
+ }
+ if (version == 28 || version == 29) {
+ database.executeFast("DELETE FROM sent_files_v2 WHERE 1").stepThis().dispose();
+ database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 30").stepThis().dispose();
+ version = 30;
+ }
+ if (version == 30) {
+ database.executeFast("ALTER TABLE chat_settings_v2 ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS chat_settings_pinned_idx ON chat_settings_v2(uid, pinned) WHERE pinned != 0;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS users_data(uid INTEGER PRIMARY KEY, about TEXT)").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 31").stepThis().dispose();
+ version = 31;
+ }
+ if (version == 31) {
+ database.executeFast("DROP TABLE IF EXISTS bot_recent;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS chat_hints(did INTEGER, type INTEGER, rating REAL, date INTEGER, PRIMARY KEY(did, type))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS chat_hints_rating_idx ON chat_hints(rating);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 32").stepThis().dispose();
+ version = 32;
+ }
+ if (version == 32) {
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_idx_imp_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_date_mid_imp_idx_messages;").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 33").stepThis().dispose();
+ version = 33;
+ }
+ if (version == 33) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS pending_tasks(id INTEGER PRIMARY KEY, data BLOB);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 34").stepThis().dispose();
+ version = 34;
+ }
+ if (version == 34) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS stickers_featured(id INTEGER PRIMARY KEY, data BLOB, unread BLOB, date INTEGER, hash INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 35").stepThis().dispose();
+ version = 35;
+ }
+ if (version == 35) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS requested_holes(uid INTEGER, seq_out_start INTEGER, seq_out_end INTEGER, PRIMARY KEY (uid, seq_out_start, seq_out_end));").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 36").stepThis().dispose();
+ version = 36;
+ }
+ if (version == 36) {
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN in_seq_no INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 37").stepThis().dispose();
+ version = 37;
+ }
+ if (version == 37) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS botcache(id TEXT PRIMARY KEY, date INTEGER, data BLOB)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS botcache_date_idx ON botcache(date);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 38").stepThis().dispose();
+ version = 38;
+ }
+ if (version == 38) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 39").stepThis().dispose();
+ version = 39;
+ }
+ if (version == 39) {
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN admin_id INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 40").stepThis().dispose();
+ version = 40;
+ }
+ if (version == 40) {
+ messagesStorage.fixNotificationSettings();
+ database.executeFast("PRAGMA user_version = 41").stepThis().dispose();
+ version = 41;
+ }
+ if (version == 41) {
+ database.executeFast("ALTER TABLE messages ADD COLUMN mention INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE user_contacts_v6 ADD COLUMN imported INTEGER default 0").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages ON messages(uid, mention, read_state);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 42").stepThis().dispose();
+ version = 42;
+ }
+ if (version == 42) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS sharing_locations(uid INTEGER PRIMARY KEY, mid INTEGER, date INTEGER, period INTEGER, message BLOB);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 43").stepThis().dispose();
+ version = 43;
+ }
+ if (version == 43) {
+ database.executeFast("PRAGMA user_version = 44").stepThis().dispose();
+ version = 44;
+ }
+ if (version == 44) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_contacts_v7(key TEXT PRIMARY KEY, uid INTEGER, fname TEXT, sname TEXT, imported INTEGER)").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_phones_v7(key TEXT, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (key, phone))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v7(sphone, deleted);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 45").stepThis().dispose();
+ version = 45;
+ }
+ if (version == 45) {
+ database.executeFast("ALTER TABLE enc_chats ADD COLUMN mtproto_seq INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 46").stepThis().dispose();
+ version = 46;
+ }
+ if (version == 46) {
+ database.executeFast("DELETE FROM botcache WHERE 1").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 47").stepThis().dispose();
+ version = 47;
+ }
+ if (version == 47) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN flags INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 48").stepThis().dispose();
+ version = 48;
+ }
+ if (version == 48) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS unread_push_messages(uid INTEGER, mid INTEGER, random INTEGER, date INTEGER, data BLOB, fm TEXT, name TEXT, uname TEXT, flags INTEGER, PRIMARY KEY(uid, mid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS unread_push_messages_idx_date ON unread_push_messages(date);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS unread_push_messages_idx_random ON unread_push_messages(random);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 49").stepThis().dispose();
+ version = 49;
+ }
+ if (version == 49) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS user_settings(uid INTEGER PRIMARY KEY, info BLOB, pinned INTEGER)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS user_settings_pinned_idx ON user_settings(uid, pinned) WHERE pinned != 0;").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 50").stepThis().dispose();
+ version = 50;
+ }
+ if (version == 50) {
+ database.executeFast("DELETE FROM sent_files_v2 WHERE 1").stepThis().dispose();
+ database.executeFast("ALTER TABLE sent_files_v2 ADD COLUMN parent TEXT").stepThis().dispose();
+ database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
+ database.executeFast("ALTER TABLE download_queue ADD COLUMN parent TEXT").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 51").stepThis().dispose();
+ version = 51;
+ }
+ if (version == 51) {
+ database.executeFast("ALTER TABLE media_counts_v2 ADD COLUMN old INTEGER").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 52").stepThis().dispose();
+ version = 52;
+ }
+ if (version == 52) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS polls_v2(mid INTEGER, uid INTEGER, id INTEGER, PRIMARY KEY (mid, uid));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS polls_id ON polls_v2(id);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 53").stepThis().dispose();
+ version = 53;
+ }
+ if (version == 53) {
+ database.executeFast("ALTER TABLE chat_settings_v2 ADD COLUMN online INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 54").stepThis().dispose();
+ version = 54;
+ }
+ if (version == 54) {
+ database.executeFast("DROP TABLE IF EXISTS wallpapers;").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 55").stepThis().dispose();
+ version = 55;
+ }
+ if (version == 55) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS wallpapers2(uid INTEGER PRIMARY KEY, data BLOB, num INTEGER)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS wallpapers_num ON wallpapers2(num);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 56").stepThis().dispose();
+ version = 56;
+ }
+ if (version == 56 || version == 57) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS emoji_keywords_v2(lang TEXT, keyword TEXT, emoji TEXT, PRIMARY KEY(lang, keyword, emoji));").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS emoji_keywords_info_v2(lang TEXT PRIMARY KEY, alias TEXT, version INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 58").stepThis().dispose();
+ version = 58;
+ }
+ if (version == 58) {
+ database.executeFast("CREATE INDEX IF NOT EXISTS emoji_keywords_v2_keyword ON emoji_keywords_v2(keyword);").stepThis().dispose();
+ database.executeFast("ALTER TABLE emoji_keywords_info_v2 ADD COLUMN date INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 59").stepThis().dispose();
+ version = 59;
+ }
+ if (version == 59) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN folder_id INTEGER default 0").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN data BLOB default NULL").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS folder_id_idx_dialogs ON dialogs(folder_id);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 60").stepThis().dispose();
+ version = 60;
+ }
+ if (version == 60) {
+ database.executeFast("DROP TABLE IF EXISTS channel_admins;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS blocked_users;").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 61").stepThis().dispose();
+ version = 61;
+ }
+ if (version == 61) {
+ database.executeFast("DROP INDEX IF EXISTS send_state_idx_messages;").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages2 ON messages(mid, send_state, date);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 62").stepThis().dispose();
+ version = 62;
+ }
+ if (version == 62) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS scheduled_messages(mid INTEGER PRIMARY KEY, uid INTEGER, send_state INTEGER, date INTEGER, data BLOB, ttl INTEGER, replydata BLOB)").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_scheduled_messages ON scheduled_messages(mid, send_state, date);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_idx_scheduled_messages ON scheduled_messages(uid, date);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 63").stepThis().dispose();
+ version = 63;
+ }
+ if (version == 63) {
+ database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 64").stepThis().dispose();
+ version = 64;
+ }
+ if (version == 64) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS dialog_filter(id INTEGER PRIMARY KEY, ord INTEGER, unread_count INTEGER, flags INTEGER, title TEXT)").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS dialog_filter_ep(id INTEGER, peer INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 65").stepThis().dispose();
+ version = 65;
+ }
+ if (version == 65) {
+ database.executeFast("CREATE INDEX IF NOT EXISTS flags_idx_dialogs ON dialogs(flags);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 66").stepThis().dispose();
+ version = 66;
+ }
+ if (version == 66) {
+ database.executeFast("CREATE TABLE dialog_filter_pin_v2(id INTEGER, peer INTEGER, pin INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 67").stepThis().dispose();
+ version = 67;
+ }
+ if (version == 67) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS stickers_dice(emoji TEXT PRIMARY KEY, data BLOB, date INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 68").stepThis().dispose();
+ version = 68;
+ }
+ if (version == 68) {
+ messagesStorage.executeNoException("ALTER TABLE messages ADD COLUMN forwards INTEGER default 0");
+ database.executeFast("PRAGMA user_version = 69").stepThis().dispose();
+ version = 69;
+ }
+ if (version == 69) {
+ messagesStorage.executeNoException("ALTER TABLE messages ADD COLUMN replies_data BLOB default NULL");
+ messagesStorage.executeNoException("ALTER TABLE messages ADD COLUMN thread_reply_id INTEGER default 0");
+ database.executeFast("PRAGMA user_version = 70").stepThis().dispose();
+ version = 70;
+ }
+ if (version == 70) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS chat_pinned_v2(uid INTEGER, mid INTEGER, data BLOB, PRIMARY KEY (uid, mid));").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 71").stepThis().dispose();
+ version = 71;
+ }
+ if (version == 71) {
+ messagesStorage.executeNoException("ALTER TABLE sharing_locations ADD COLUMN proximity INTEGER default 0");
+ database.executeFast("PRAGMA user_version = 72").stepThis().dispose();
+ version = 72;
+ }
+ if (version == 72) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS chat_pinned_count(uid INTEGER PRIMARY KEY, count INTEGER, end INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 73").stepThis().dispose();
+ version = 73;
+ }
+ if (version == 73) {
+ messagesStorage.executeNoException("ALTER TABLE chat_settings_v2 ADD COLUMN inviter INTEGER default 0");
+ database.executeFast("PRAGMA user_version = 74").stepThis().dispose();
+ version = 74;
+ }
+ if (version == 74) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS shortcut_widget(id INTEGER, did INTEGER, ord INTEGER, PRIMARY KEY (id, did));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS shortcut_widget_did ON shortcut_widget(did);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 75").stepThis().dispose();
+ version = 75;
+ }
+ if (version == 75) {
+ messagesStorage.executeNoException("ALTER TABLE chat_settings_v2 ADD COLUMN links INTEGER default 0");
+ database.executeFast("PRAGMA user_version = 76").stepThis().dispose();
+ version = 76;
+ }
+ if (version == 76) {
+ messagesStorage.executeNoException("ALTER TABLE enc_tasks_v2 ADD COLUMN media INTEGER default -1");
+ database.executeFast("PRAGMA user_version = 77").stepThis().dispose();
+ version = 77;
+ }
+ if (version == 77) {
+ database.executeFast("DROP TABLE IF EXISTS channel_admins_v2;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS channel_admins_v3(did INTEGER, uid INTEGER, data BLOB, PRIMARY KEY(did, uid))").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 78").stepThis().dispose();
+ version = 78;
+ }
+ if (version == 78) {
+ database.executeFast("DROP TABLE IF EXISTS bot_info;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS bot_info_v2(uid INTEGER, dialogId INTEGER, info BLOB, PRIMARY KEY(uid, dialogId))").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 79").stepThis().dispose();
+ version = 79;
+ }
+ if (version == 79) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v3(mid INTEGER, date INTEGER, media INTEGER, PRIMARY KEY(mid, media))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v3 ON enc_tasks_v3(date);").stepThis().dispose();
+
+ database.beginTransaction();
+ SQLiteCursor cursor = database.queryFinalized("SELECT mid, date, media FROM enc_tasks_v2 WHERE 1");
+ SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_tasks_v3 VALUES(?, ?, ?)");
+ if (cursor.next()) {
+ long mid = cursor.longValue(0);
+ int date = cursor.intValue(1);
+ int media = cursor.intValue(2);
+
+ state.requery();
+ state.bindLong(1, mid);
+ state.bindInteger(2, date);
+ state.bindInteger(3, media);
+ state.step();
+ }
+ state.dispose();
+ cursor.dispose();
+ database.commitTransaction();
+
+ database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks_v2;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS enc_tasks_v2;").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 80").stepThis().dispose();
+ version = 80;
+ }
+ if (version == 80) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS scheduled_messages_v2(mid INTEGER, uid INTEGER, send_state INTEGER, date INTEGER, data BLOB, ttl INTEGER, replydata BLOB, PRIMARY KEY(mid, uid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_scheduled_messages_v2 ON scheduled_messages_v2(mid, send_state, date);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_idx_scheduled_messages_v2 ON scheduled_messages_v2(uid, date);").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS bot_keyboard_idx_mid_v2 ON bot_keyboard(mid, uid);").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS bot_keyboard_idx_mid;").stepThis().dispose();
+
+ database.beginTransaction();
+ SQLiteCursor cursor;
+ try {
+ cursor = database.queryFinalized("SELECT mid, uid, send_state, date, data, ttl, replydata FROM scheduled_messages_v2 WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO scheduled_messages_v2 VALUES(?, ?, ?, ?, ?, ?, ?)");
+ while (cursor.next()) {
+ NativeByteBuffer data = cursor.byteBufferValue(4);
+ if (data == null) {
+ continue;
+ }
+ int mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ int sendState = cursor.intValue(2);
+ int date = cursor.intValue(3);
+ int ttl = cursor.intValue(5);
+ NativeByteBuffer replydata = cursor.byteBufferValue(6);
+
+ statement.requery();
+ statement.bindInteger(1, mid);
+ statement.bindLong(2, uid);
+ statement.bindInteger(3, sendState);
+ statement.bindByteBuffer(4, data);
+ statement.bindInteger(5, date);
+ statement.bindInteger(6, ttl);
+ if (replydata != null) {
+ statement.bindByteBuffer(7, replydata);
+ } else {
+ statement.bindNull(7);
+ }
+ statement.step();
+ if (replydata != null) {
+ replydata.reuse();
+ }
+ data.reuse();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ database.executeFast("DROP INDEX IF EXISTS send_state_idx_scheduled_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_date_idx_scheduled_messages;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS scheduled_messages;").stepThis().dispose();
+
+ database.commitTransaction();
+ database.executeFast("PRAGMA user_version = 81").stepThis().dispose();
+ version = 81;
+ }
+ if (version == 81) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_v3(mid INTEGER, uid INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_v3 ON media_v3(uid, mid, type, date);").stepThis().dispose();
+
+ database.beginTransaction();
+ SQLiteCursor cursor;
+ try {
+ cursor = database.queryFinalized("SELECT mid, uid, date, type, data FROM media_v2 WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO media_v3 VALUES(?, ?, ?, ?, ?)");
+ while (cursor.next()) {
+ NativeByteBuffer data = cursor.byteBufferValue(4);
+ if (data == null) {
+ continue;
+ }
+ int mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+ int date = cursor.intValue(2);
+ int type = cursor.intValue(3);
+
+ statement.requery();
+ statement.bindInteger(1, mid);
+ statement.bindLong(2, uid);
+ statement.bindInteger(3, date);
+ statement.bindInteger(4, type);
+ statement.bindByteBuffer(5, data);
+ statement.step();
+ data.reuse();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_type_date_idx_media;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS media_v2;").stepThis().dispose();
+ database.commitTransaction();
+
+ database.executeFast("PRAGMA user_version = 82").stepThis().dispose();
+ version = 82;
+ }
+ if (version == 82) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS randoms_v2(random_id INTEGER, mid INTEGER, uid INTEGER, PRIMARY KEY (random_id, mid, uid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms_v2 ON randoms_v2(mid, uid);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v4(mid INTEGER, uid INTEGER, date INTEGER, media INTEGER, PRIMARY KEY(mid, uid, media))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v4 ON enc_tasks_v4(date);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS polls_v2(mid INTEGER, uid INTEGER, id INTEGER, PRIMARY KEY (mid, uid));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS polls_id_v2 ON polls_v2(id);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending_v2(id INTEGER, mid INTEGER, uid INTEGER, PRIMARY KEY (id, mid, uid));").stepThis().dispose();
+
+ database.beginTransaction();
+
+ SQLiteCursor cursor;
+ try {
+ cursor = database.queryFinalized("SELECT r.random_id, r.mid, m.uid FROM randoms as r INNER JOIN messages as m ON r.mid = m.mid WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO randoms_v2 VALUES(?, ?, ?)");
+ while (cursor.next()) {
+ long randomId = cursor.longValue(0);
+ int mid = cursor.intValue(1);
+ long uid = cursor.longValue(2);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+
+ statement.requery();
+ statement.bindLong(1, randomId);
+ statement.bindInteger(2, mid);
+ statement.bindLong(3, uid);
+ statement.step();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ try {
+ cursor = database.queryFinalized("SELECT p.mid, m.uid, p.id FROM polls as p INNER JOIN messages as m ON p.mid = m.mid WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO polls_v2 VALUES(?, ?, ?)");
+ while (cursor.next()) {
+ int mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ long id = cursor.longValue(2);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+
+ statement.requery();
+ statement.bindInteger(1, mid);
+ statement.bindLong(2, uid);
+ statement.bindLong(3, id);
+ statement.step();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ try {
+ cursor = database.queryFinalized("SELECT wp.id, wp.mid, m.uid FROM webpage_pending as wp INNER JOIN messages as m ON wp.mid = m.mid WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO webpage_pending_v2 VALUES(?, ?, ?)");
+ while (cursor.next()) {
+ long id = cursor.longValue(0);
+ int mid = cursor.intValue(1);
+ long uid = cursor.longValue(2);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+
+ statement.requery();
+ statement.bindLong(1, id);
+ statement.bindInteger(2, mid);
+ statement.bindLong(3, uid);
+ statement.step();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ try {
+ cursor = database.queryFinalized("SELECT et.mid, m.uid, et.date, et.media FROM enc_tasks_v3 as et INNER JOIN messages as m ON et.mid = m.mid WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO enc_tasks_v4 VALUES(?, ?, ?, ?)");
+ while (cursor.next()) {
+ int mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ int date = cursor.intValue(2);
+ int media = cursor.intValue(3);
+
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+
+ statement.requery();
+ statement.bindInteger(1, mid);
+ statement.bindLong(2, uid);
+ statement.bindInteger(3, date);
+ statement.bindInteger(4, media);
+ statement.step();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ database.executeFast("DROP INDEX IF EXISTS mid_idx_randoms;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS randoms;").stepThis().dispose();
+
+ database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks_v3;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS enc_tasks_v3;").stepThis().dispose();
+
+ database.executeFast("DROP INDEX IF EXISTS polls_id;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS polls;").stepThis().dispose();
+
+ database.executeFast("DROP TABLE IF EXISTS webpage_pending;").stepThis().dispose();
+ database.commitTransaction();
+
+ database.executeFast("PRAGMA user_version = 83").stepThis().dispose();
+ version = 83;
+ }
+ if (version == 83) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS messages_v2(mid INTEGER, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER, replydata BLOB, imp INTEGER, mention INTEGER, forwards INTEGER, replies_data BLOB, thread_reply_id INTEGER, is_channel INTEGER, PRIMARY KEY(mid, uid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_v2 ON messages_v2(uid, mid, read_state, out);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages_v2 ON messages_v2(uid, date, mid);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages_v2 ON messages_v2(mid, out);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages_v2 ON messages_v2(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages_v2 ON messages_v2(mid, send_state, date);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_v2 ON messages_v2(uid, mention, read_state);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS is_channel_idx_messages_v2 ON messages_v2(mid, is_channel);").stepThis().dispose();
+
+ database.beginTransaction();
+
+ SQLiteCursor cursor;
+
+ try {
+ cursor = database.queryFinalized("SELECT mid, uid, read_state, send_state, date, data, out, ttl, media, replydata, imp, mention, forwards, replies_data, thread_reply_id FROM messages WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO messages_v2 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ int num = 0;
+ while (cursor.next()) {
+ NativeByteBuffer data = cursor.byteBufferValue(5);
+ if (data == null) {
+ continue;
+ }
+ num++;
+ long mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+ int readState = cursor.intValue(2);
+ int sendState = cursor.intValue(3);
+ int date = cursor.intValue(4);
+ int out = cursor.intValue(6);
+ int ttl = cursor.intValue(7);
+ int media = cursor.intValue(8);
+ NativeByteBuffer replydata = cursor.byteBufferValue(9);
+ int imp = cursor.intValue(10);
+ int mention = cursor.intValue(11);
+ int forwards = cursor.intValue(12);
+ NativeByteBuffer repliesdata = cursor.byteBufferValue(13);
+ int thread_reply_id = cursor.intValue(14);
+ int channelId = (int) (uid >> 32);
+ if (ttl < 0) {
+ TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
+ if (message != null) {
+ message.readAttachPath(data, messagesStorage.getUserConfig().clientUserId);
+ if (message.params == null) {
+ message.params = new HashMap<>();
+ message.params.put("fwd_peer", "" + ttl);
+ }
+ data.reuse();
+ data = new NativeByteBuffer(message.getObjectSize());
+ message.serializeToStream(data);
+ }
+ ttl = 0;
+ }
+
+ statement.requery();
+ statement.bindInteger(1, (int) mid);
+ statement.bindLong(2, uid);
+ statement.bindInteger(3, readState);
+ statement.bindInteger(4, sendState);
+ statement.bindInteger(5, date);
+ statement.bindByteBuffer(6, data);
+ statement.bindInteger(7, out);
+ statement.bindInteger(8, ttl);
+ statement.bindInteger(9, media);
+ if (replydata != null) {
+ statement.bindByteBuffer(10, replydata);
+ } else {
+ statement.bindNull(10);
+ }
+ statement.bindInteger(11, imp);
+ statement.bindInteger(12, mention);
+ statement.bindInteger(13, forwards);
+ if (repliesdata != null) {
+ statement.bindByteBuffer(14, repliesdata);
+ } else {
+ statement.bindNull(14);
+ }
+ statement.bindInteger(15, thread_reply_id);
+ statement.bindInteger(16, channelId > 0 ? 1 : 0);
+ statement.step();
+ if (replydata != null) {
+ replydata.reuse();
+ }
+ if (repliesdata != null) {
+ repliesdata.reuse();
+ }
+ data.reuse();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+
+ ArrayList secretChatsToUpdate = null;
+ ArrayList foldersToUpdate = null;
+ cursor = database.queryFinalized("SELECT did, last_mid, last_mid_i FROM dialogs WHERE 1");
+ SQLitePreparedStatement statement4 = database.executeFast("UPDATE dialogs SET last_mid = ?, last_mid_i = ? WHERE did = ?");
+ while (cursor.next()) {
+ long did = cursor.longValue(0);
+ int lowerId = (int) did;
+ int highId = (int) (did >> 32);
+ if (lowerId == 0) {
+ if (secretChatsToUpdate == null) {
+ secretChatsToUpdate = new ArrayList<>();
+ }
+ secretChatsToUpdate.add(highId);
+ } else if (highId == 2) {
+ if (foldersToUpdate == null) {
+ foldersToUpdate = new ArrayList<>();
+ }
+ foldersToUpdate.add(lowerId);
+ }
+
+ statement4.requery();
+ statement4.bindInteger(1, cursor.intValue(1));
+ statement4.bindInteger(2, cursor.intValue(2));
+ statement4.bindLong(3, did);
+ statement4.step();
+ }
+ statement4.dispose();
+ cursor.dispose();
+
+ cursor = database.queryFinalized("SELECT uid, mid FROM unread_push_messages WHERE 1");
+ statement4 = database.executeFast("UPDATE unread_push_messages SET mid = ? WHERE uid = ? AND mid = ?");
+ while (cursor.next()) {
+ long did = cursor.longValue(0);
+ int mid = cursor.intValue(1);
+ statement4.requery();
+ statement4.bindInteger(1, mid);
+ statement4.bindLong(2, did);
+ statement4.bindInteger(3, mid);
+ statement4.step();
+ }
+ statement4.dispose();
+ cursor.dispose();
+
+ if (secretChatsToUpdate != null) {
+ SQLitePreparedStatement statement = database.executeFast("UPDATE dialogs SET did = ? WHERE did = ?");
+ SQLitePreparedStatement statement2 = database.executeFast("UPDATE dialog_filter_pin_v2 SET peer = ? WHERE peer = ?");
+ SQLitePreparedStatement statement3 = database.executeFast("UPDATE dialog_filter_ep SET peer = ? WHERE peer = ?");
+ for (int a = 0, N = secretChatsToUpdate.size(); a < N; a++) {
+ int sid = secretChatsToUpdate.get(a);
+
+ long newId = DialogObject.makeEncryptedDialogId(sid);
+ long oldId = ((long) sid) << 32;
+ statement.requery();
+ statement.bindLong(1, newId);
+ statement.bindLong(2, oldId);
+ statement.step();
+
+ statement2.requery();
+ statement2.bindLong(1, newId);
+ statement2.bindLong(2, oldId);
+ statement2.step();
+
+ statement3.requery();
+ statement3.bindLong(1, newId);
+ statement3.bindLong(2, oldId);
+ statement3.step();
+ }
+ statement.dispose();
+ statement2.dispose();
+ statement3.dispose();
+ }
+ if (foldersToUpdate != null) {
+ SQLitePreparedStatement statement = database.executeFast("UPDATE dialogs SET did = ? WHERE did = ?");
+ for (int a = 0, N = foldersToUpdate.size(); a < N; a++) {
+ int fid = foldersToUpdate.get(a);
+
+ long newId = DialogObject.makeFolderDialogId(fid);
+ long oldId = (((long) 2) << 32) | fid;
+ statement.requery();
+ statement.bindLong(1, newId);
+ statement.bindLong(2, oldId);
+ statement.step();
+ }
+ statement.dispose();
+ }
+
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_read_out_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_date_mid_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS mid_out_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS task_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS send_state_idx_messages2;").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_mention_idx_messages;").stepThis().dispose();
+ database.executeFast("DROP TABLE IF EXISTS messages;").stepThis().dispose();
+ database.commitTransaction();
+
+ database.executeFast("PRAGMA user_version = 84").stepThis().dispose();
+ version = 84;
+ }
+ if (version == 84) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_v4(mid INTEGER, uid INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid, type))").stepThis().dispose();
+ database.beginTransaction();
+ SQLiteCursor cursor;
+ try {
+ cursor = database.queryFinalized("SELECT mid, uid, date, type, data FROM media_v3 WHERE 1");
+ } catch (Exception e) {
+ cursor = null;
+ FileLog.e(e);
+ }
+ if (cursor != null) {
+ SQLitePreparedStatement statement = database.executeFast("REPLACE INTO media_v4 VALUES(?, ?, ?, ?, ?)");
+ while (cursor.next()) {
+ NativeByteBuffer data = cursor.byteBufferValue(4);
+ if (data == null) {
+ continue;
+ }
+ int mid = cursor.intValue(0);
+ long uid = cursor.longValue(1);
+ int lowerId = (int) uid;
+ if (lowerId == 0) {
+ int highId = (int) (uid >> 32);
+ uid = DialogObject.makeEncryptedDialogId(highId);
+ }
+ int date = cursor.intValue(2);
+ int type = cursor.intValue(3);
+
+ statement.requery();
+ statement.bindInteger(1, mid);
+ statement.bindLong(2, uid);
+ statement.bindInteger(3, date);
+ statement.bindInteger(4, type);
+ statement.bindByteBuffer(5, data);
+ statement.step();
+ data.reuse();
+ }
+ cursor.dispose();
+ statement.dispose();
+ }
+ database.commitTransaction();
+
+ database.executeFast("DROP TABLE IF EXISTS media_v3;").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 85").stepThis().dispose();
+ version = 85;
+ }
+ if (version == 85) {
+ messagesStorage.executeNoException("ALTER TABLE messages_v2 ADD COLUMN reply_to_message_id INTEGER default 0");
+ messagesStorage.executeNoException("ALTER TABLE scheduled_messages_v2 ADD COLUMN reply_to_message_id INTEGER default 0");
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_messages_v2 ON messages_v2(mid, reply_to_message_id);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_scheduled_messages_v2 ON scheduled_messages_v2(mid, reply_to_message_id);").stepThis().dispose();
+
+ messagesStorage.executeNoException("UPDATE messages_v2 SET replydata = NULL");
+ messagesStorage.executeNoException("UPDATE scheduled_messages_v2 SET replydata = NULL");
+ database.executeFast("PRAGMA user_version = 86").stepThis().dispose();
+ version = 86;
+ }
+
+ if (version == 86) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS reactions(data BLOB, hash INTEGER, date INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 87").stepThis().dispose();
+ version = 87;
+ }
+
+ if (version == 87) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN unread_reactions INTEGER default 0").stepThis().dispose();
+ database.executeFast("CREATE TABLE reaction_mentions(message_id INTEGER PRIMARY KEY, state INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 88").stepThis().dispose();
+ version = 88;
+ }
+
+ if (version == 88 || version == 89) {
+ database.executeFast("DROP TABLE IF EXISTS reaction_mentions;").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS reaction_mentions(message_id INTEGER, state INTEGER, dialog_id INTEGER, PRIMARY KEY(dialog_id, message_id));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS reaction_mentions_did ON reaction_mentions(dialog_id);").stepThis().dispose();
+
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_type_date_idx_media_v3").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_v4 ON media_v4(uid, mid, type, date);").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 90").stepThis().dispose();
+
+ version = 90;
+ }
+
+ if (version == 90 || version == 91) {
+ database.executeFast("DROP TABLE IF EXISTS downloading_documents;").stepThis().dispose();
+ database.executeFast("CREATE TABLE downloading_documents(data BLOB, hash INTEGER, id INTEGER, state INTEGER, date INTEGER, PRIMARY KEY(hash, id));").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 92").stepThis().dispose();
+ version = 92;
+ }
+
+ if (version == 92) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS attach_menu_bots(data BLOB, hash INTEGER, date INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 93").stepThis().dispose();
+ version = 95;
+ }
+
+ if (version == 95 || version == 93) {
+ messagesStorage.executeNoException("ALTER TABLE messages_v2 ADD COLUMN custom_params BLOB default NULL");
+ database.executeFast("PRAGMA user_version = 96").stepThis().dispose();
+ version = 96;
+ }
+
+ // skip 94, 95. private beta db rollback
+ if (version == 96) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS premium_promo(data BLOB, date INTEGER);").stepThis().dispose();
+ database.executeFast("UPDATE stickers_v2 SET date = 0");
+ database.executeFast("PRAGMA user_version = 97").stepThis().dispose();
+ version = 97;
+ }
+
+ if (version == 97) {
+ database.executeFast("DROP TABLE IF EXISTS stickers_featured;").stepThis().dispose();
+ database.executeFast("CREATE TABLE stickers_featured(id INTEGER PRIMARY KEY, data BLOB, unread BLOB, date INTEGER, hash INTEGER, premium INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 98").stepThis().dispose();
+ version = 98;
+ }
+
+ if (version == 98) {
+ database.executeFast("CREATE TABLE animated_emoji(document_id INTEGER PRIMARY KEY, data BLOB);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 99").stepThis().dispose();
+ version = 99;
+ }
+
+ if (version == 99) {
+ database.executeFast("ALTER TABLE stickers_featured ADD COLUMN emoji INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 100").stepThis().dispose();
+ version = 100;
+ }
+
+ if (version == 100) {
+ database.executeFast("CREATE TABLE emoji_statuses(data BLOB, type INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 101").stepThis().dispose();
+ version = 101;
+ }
+
+ if (version == 101) {
+ database.executeFast("ALTER TABLE messages_v2 ADD COLUMN group_id INTEGER default NULL").stepThis().dispose();
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN last_mid_group INTEGER default NULL").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_groupid_messages_v2 ON messages_v2(uid, mid, group_id);").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 102").stepThis().dispose();
+ version = 102;
+ }
+
+ if (version == 102) {
+ database.executeFast("CREATE TABLE messages_holes_topics(uid INTEGER, topic_id INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, topic_id, start));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_messages_holes ON messages_holes_topics(uid, topic_id, end);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE messages_topics(mid INTEGER, uid INTEGER, topic_id INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER, replydata BLOB, imp INTEGER, mention INTEGER, forwards INTEGER, replies_data BLOB, thread_reply_id INTEGER, is_channel INTEGER, reply_to_message_id INTEGER, custom_params BLOB, PRIMARY KEY(mid, topic_id, uid))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_topics ON messages_topics(uid, mid, read_state, out);").stepThis().dispose();//move to topic id
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages_topics ON messages_topics(uid, date, mid);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages_topics ON messages_topics(mid, out);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages_topics ON messages_topics(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages_topics ON messages_topics(mid, send_state, date);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_topics ON messages_topics(uid, mention, read_state);").stepThis().dispose();//move to uid, topic_id, mentiin_read_state
+ database.executeFast("CREATE INDEX IF NOT EXISTS is_channel_idx_messages_topics ON messages_topics(mid, is_channel);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_messages_topics ON messages_topics(mid, reply_to_message_id);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_uid_messages_topics ON messages_topics(mid, uid);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS mid_uid_topic_id_messages_topics ON messages_topics(mid, topic_id, uid);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE media_topics(mid INTEGER, uid INTEGER, topic_id INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid, topic_id, type))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_topics ON media_topics(uid, topic_id, mid, type, date);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE media_holes_topics(uid INTEGER, topic_id INTEGER, type INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, topic_id, type, start));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_media_holes_topics ON media_holes_topics(uid, topic_id, type, end);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE topics(did INTEGER, topic_id INTEGER, data BLOB, top_message INTEGER, topic_message BLOB, unread_count INTEGER, max_read_id INTEGER, unread_mentions INTEGER, unread_reactions INTEGER, PRIMARY KEY(did, topic_id));").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS did_top_message_topics ON topics(did, top_message);").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 103").stepThis().dispose();
+ version = 103;
+ }
+
+ if (version == 103) {
+ database.executeFast("CREATE TABLE IF NOT EXISTS media_counts_topics(uid INTEGER, topic_id INTEGER, type INTEGER, count INTEGER, old INTEGER, PRIMARY KEY(uid, topic_id, type))").stepThis().dispose();
+ database.executeFast("CREATE TABLE IF NOT EXISTS reaction_mentions_topics(message_id INTEGER, state INTEGER, dialog_id INTEGER, topic_id INTEGER, PRIMARY KEY(message_id, dialog_id, topic_id))").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS reaction_mentions_topics_did ON reaction_mentions_topics(dialog_id, topic_id);").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 104").stepThis().dispose();
+ version = 104;
+ }
+
+ if (version == 104) {
+ database.executeFast("ALTER TABLE topics ADD COLUMN read_outbox INTEGER default 0").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 105").stepThis().dispose();
+ version = 105;
+ }
+
+ if (version == 105) {
+ database.executeFast("ALTER TABLE topics ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 106").stepThis().dispose();
+ version = 106;
+ }
+
+ if (version == 106) {
+ database.executeFast("DROP INDEX IF EXISTS uid_mid_read_out_idx_messages_topics").stepThis().dispose();
+ database.executeFast("DROP INDEX IF EXISTS uid_mention_idx_messages_topics").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_topics ON messages_topics(uid, topic_id, mid, read_state, out);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_topics ON messages_topics(uid, topic_id, mention, read_state);").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_messages_topics ON messages_topics(uid, topic_id);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_date_mid_messages_topics ON messages_topics(uid, topic_id, date, mid);").stepThis().dispose();
+ database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_mid_messages_topics ON messages_topics(uid, topic_id, mid);").stepThis().dispose();
+
+ database.executeFast("CREATE INDEX IF NOT EXISTS did_topics ON topics(did);").stepThis().dispose();
+
+ database.executeFast("PRAGMA user_version = 107").stepThis().dispose();
+ version = 107;
+ }
+
+ if (version == 107) {
+ database.executeFast("ALTER TABLE topics ADD COLUMN total_messages_count INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 108").stepThis().dispose();
+ version = 108;
+ }
+
+ if (version == 108) {
+ database.executeFast("ALTER TABLE topics ADD COLUMN hidden INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 109").stepThis().dispose();
+ version = 109;
+ }
+
+ if (version == 109) {
+ database.executeFast("ALTER TABLE dialogs ADD COLUMN ttl_period INTEGER default 0").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = 110").stepThis().dispose();
+ version = 110;
+ }
+
+ return version;
+ }
+}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DialogObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/DialogObject.java
index 30b87c88b..1bf846e35 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/DialogObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/DialogObject.java
@@ -8,7 +8,10 @@
package org.telegram.messenger;
+import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
+import org.telegram.ui.Components.AvatarDrawable;
+import org.telegram.ui.Components.BackupImageView;
public class DialogObject {
@@ -98,4 +101,66 @@ public class DialogObject {
public static int getFolderId(long dialogId) {
return (int) dialogId;
}
+
+ public static String getDialogTitle(TLObject dialog) {
+ return setDialogPhotoTitle(null, null, dialog);
+ }
+
+ public static String setDialogPhotoTitle(ImageReceiver imageReceiver, AvatarDrawable avatarDrawable, TLObject dialog) {
+ String title = "";
+ if (dialog instanceof TLRPC.User) {
+ TLRPC.User user = (TLRPC.User) dialog;
+ if (UserObject.isReplyUser(user)) {
+ title = LocaleController.getString("RepliesTitle", R.string.RepliesTitle);
+ if (avatarDrawable != null) {
+ avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
+ }
+ if (imageReceiver != null) {
+ imageReceiver.setForUserOrChat(null, avatarDrawable);
+ }
+ } else if (UserObject.isUserSelf(user)) {
+ title = LocaleController.getString("SavedMessages", R.string.SavedMessages);
+ if (avatarDrawable != null) {
+ avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
+ }
+ if (imageReceiver != null) {
+ imageReceiver.setForUserOrChat(null, avatarDrawable);
+ }
+ } else {
+ title = UserObject.getUserName(user);
+ if (avatarDrawable != null) {
+ avatarDrawable.setInfo(user);
+ }
+ if (imageReceiver != null) {
+ imageReceiver.setForUserOrChat(dialog, avatarDrawable);
+ }
+ }
+ } else if (dialog instanceof TLRPC.Chat) {
+ TLRPC.Chat chat = (TLRPC.Chat) dialog;
+ title = chat.title;
+ if (avatarDrawable != null) {
+ avatarDrawable.setInfo(chat);
+ }
+ if (imageReceiver != null) {
+ imageReceiver.setForUserOrChat(dialog, avatarDrawable);
+ }
+ }
+ return title;
+ }
+
+ public static String setDialogPhotoTitle(BackupImageView imageView, TLObject dialog) {
+ if (imageView != null) {
+ return setDialogPhotoTitle(imageView.getImageReceiver(), imageView.getAvatarDrawable(), dialog);
+ }
+ return setDialogPhotoTitle(null, null, dialog);
+ }
+
+ public static String getPublicUsername(TLObject dialog) {
+ if (dialog instanceof TLRPC.Chat) {
+ return ChatObject.getPublicUsername((TLRPC.Chat) dialog);
+ } else if (dialog instanceof TLRPC.User) {
+ return UserObject.getPublicUsername((TLRPC.User) dialog);
+ }
+ return null;
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java b/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java
index 06b79e162..b943fd284 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java
@@ -1108,14 +1108,26 @@ public class DownloadController extends BaseController implements NotificationCe
public void startDownloadFile(TLRPC.Document document, MessageObject parentObject) {
- if (parentObject.getDocument() == null) {
+ if (parentObject == null) {
+ return;
+ }
+ TLRPC.Document parentDocument = parentObject.getDocument();
+ if (parentDocument == null) {
return;
}
AndroidUtilities.runOnUIThread(() -> {
+ if (parentDocument == null) {
+ return;
+ }
boolean contains = false;
for (int i = 0; i < recentDownloadingFiles.size(); i++) {
- if (recentDownloadingFiles.get(i).getDocument() != null && recentDownloadingFiles.get(i).getDocument().id == parentObject.getDocument().id) {
+ MessageObject messageObject = recentDownloadingFiles.get(i);
+ if (messageObject == null) {
+ continue;
+ }
+ TLRPC.Document document1 = messageObject.getDocument();
+ if (document1 != null && document1.id == parentDocument.id) {
contains = true;
break;
}
@@ -1123,7 +1135,12 @@ public class DownloadController extends BaseController implements NotificationCe
if (!contains) {
for (int i = 0; i < downloadingFiles.size(); i++) {
- if (downloadingFiles.get(i).getDocument() != null && downloadingFiles.get(i).getDocument().id == parentObject.getDocument().id) {
+ MessageObject messageObject = downloadingFiles.get(i);
+ if (messageObject == null) {
+ continue;
+ }
+ TLRPC.Document document1 = messageObject.getDocument();
+ if (document1 != null && document1.id == parentDocument.id) {
contains = true;
break;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
index 59c99d67b..6e385e255 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
@@ -24,7 +24,6 @@ import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;
-import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -330,9 +329,9 @@ public class Emoji {
this.end = end;
this.code = code;
}
- int start;
- int end;
- CharSequence code;
+ public int start;
+ public int end;
+ public CharSequence code;
}
public static boolean fullyConsistsOfEmojis(CharSequence cs) {
@@ -505,10 +504,14 @@ public class Emoji {
s = Spannable.Factory.getInstance().newSpannable(cs.toString());
}
ArrayList emojis = parseEmojis(s, emojiOnly);
+ if (emojis.isEmpty()) {
+ return cs;
+ }
AnimatedEmojiSpan[] animatedEmojiSpans = s.getSpans(0, s.length(), AnimatedEmojiSpan.class);
EmojiSpan span;
Drawable drawable;
+ int limitCount = SharedConfig.getDevicePerformanceClass() >= SharedConfig.PERFORMANCE_CLASS_HIGH ? 100 : 50;
for (int i = 0; i < emojis.size(); ++i) {
try {
EmojiSpanRange emojiRange = emojis.get(i);
@@ -534,7 +537,6 @@ public class Emoji {
} catch (Exception e) {
FileLog.e(e);
}
- int limitCount = SharedConfig.getDevicePerformanceClass() >= SharedConfig.PERFORMANCE_CLASS_HIGH ? 100 : 50;
if ((Build.VERSION.SDK_INT < 23 || Build.VERSION.SDK_INT >= 29)/* && !BuildVars.DEBUG_PRIVATE_VERSION*/ && (i + 1) >= limitCount) {
break;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
index 3681d9c60..f200a952f 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java
@@ -16,6 +16,7 @@ import org.telegram.ui.LaunchActivity;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
@@ -186,6 +187,7 @@ public class FileLoadOperation {
private File tempPath;
private boolean isForceRequest;
private int priority;
+ private long fileDialogId;
private boolean ungzip;
@@ -218,6 +220,7 @@ public class FileLoadOperation {
public FileLoadOperation(ImageLocation imageLocation, Object parent, String extension, long size) {
updateParams();
parentObject = parent;
+ fileDialogId = FileLoader.getDialogIdFromParent(currentAccount, parentObject);
isStream = imageLocation.imageType == FileLoader.IMAGE_TYPE_ANIMATION;
if (imageLocation.isEncrypted()) {
location = new TLRPC.TL_inputEncryptedFileLocation();
@@ -324,6 +327,7 @@ public class FileLoadOperation {
updateParams();
try {
parentObject = parent;
+ fileDialogId = FileLoader.getDialogIdFromParent(currentAccount, parentObject);
if (documentLocation instanceof TLRPC.TL_documentEncrypted) {
location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = documentLocation.id;
@@ -827,6 +831,7 @@ public class FileLoadOperation {
finalFileExist = false;
}
+
if (!finalFileExist) {
cacheFileTemp = new File(tempPath, fileNameTemp);
if (ungzip) {
@@ -964,6 +969,11 @@ public class FileLoadOperation {
}
}
+ if (fileDialogId != 0) {
+ FileLoader.getInstance(currentAccount).getFileDatabase().saveFileDialogId(cacheFileParts, fileDialogId);
+ FileLoader.getInstance(currentAccount).getFileDatabase().saveFileDialogId(cacheFileTemp, fileDialogId);
+ }
+
if (cacheFileTemp.exists()) {
if (newKeyGenerated) {
cacheFileTemp.delete();
@@ -1281,6 +1291,14 @@ public class FileLoadOperation {
if (BuildVars.DEBUG_VERSION) {
FileLog.d("finished preloading file to " + cacheFileTemp + " loaded " + totalPreloadedBytes + " of " + totalBytesCount);
}
+ if (fileDialogId != 0) {
+ if (cacheFileTemp != null) {
+ FileLoader.getInstance(currentAccount).getFileDatabase().removeFiles(Collections.singletonList(cacheFileTemp));
+ }
+ if (cacheFileParts != null) {
+ FileLoader.getInstance(currentAccount).getFileDatabase().removeFiles(Collections.singletonList(cacheFileParts));
+ }
+ }
delegate.didFinishLoadingFile(FileLoadOperation.this, cacheFileFinal);
} else {
final File cacheIvTempFinal = cacheIvTemp;
@@ -1310,7 +1328,7 @@ public class FileLoadOperation {
} catch (ZipException zipException) {
ungzip = false;
} catch (Throwable e) {
- FileLog.e(e);
+ FileLog.e(e, !(e instanceof FileNotFoundException));
if (BuildVars.LOGS_ENABLED) {
FileLog.e("unable to ungzip temp = " + cacheFileTempFinal + " to final = " + cacheFileFinal);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
index 296df15e1..c3a075f51 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
@@ -19,11 +19,14 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class FileLoader extends BaseController {
@@ -35,6 +38,30 @@ public class FileLoader extends BaseController {
private int priorityIncreasePointer;
+ private static Pattern sentPattern;
+
+ public static long getDialogIdFromParent(int currentAccount, Object parentObject) {
+ if (parentObject instanceof String) {
+ String str = (String) parentObject;
+ if (str.startsWith("sent_")) {
+ if (sentPattern == null) {
+ sentPattern = Pattern.compile("sent_.*_.*_([0-9]+)");
+ }
+ try {
+ Matcher matcher = sentPattern.matcher(str);
+ if (matcher.matches()) {
+ return Long.parseLong(matcher.group(1));
+ }
+ } catch (Exception e) {
+ FileLog.e(e);
+ }
+ }
+ } else if (parentObject instanceof MessageObject) {
+ return ((MessageObject) parentObject).getDialogId();
+ }
+ return 0;
+ }
+
private int getPriorityValue(int priorityType) {
if (priorityType == PRIORITY_STREAM) {
return Integer.MAX_VALUE;
@@ -51,6 +78,10 @@ public class FileLoader extends BaseController {
}
}
+ public DispatchQueue getFileLoaderQueue() {
+ return fileLoaderQueue;
+ }
+
public interface FileLoaderDelegate {
void fileUploadProgressChanged(FileUploadOperation operation, String location, long uploadedSize, long totalSize, boolean isEncrypted);
@@ -104,7 +135,6 @@ public class FileLoader extends BaseController {
private ConcurrentHashMap loadOperationPaths = new ConcurrentHashMap<>();
- private ArrayList activeFileLoadOperation = new ArrayList<>();
private ConcurrentHashMap loadOperationPathsUI = new ConcurrentHashMap<>(10, 1, 2);
private HashMap uploadSizes = new HashMap<>();
@@ -498,6 +528,30 @@ public class FileLoader extends BaseController {
}
}
+
+ public void cancelLoadAllFiles() {
+ for (String fileName : loadOperationPathsUI.keySet()) {
+ LoadOperationUIObject uiObject = loadOperationPathsUI.get(fileName);
+ Runnable runnable = uiObject != null ? uiObject.loadInternalRunnable : null;
+ boolean removed = uiObject != null;
+ if (runnable != null) {
+ fileLoaderQueue.cancelRunnable(runnable);
+ }
+ fileLoaderQueue.postRunnable(() -> {
+ FileLoadOperation operation = loadOperationPaths.remove(fileName);
+ if (operation != null) {
+ FileLoaderPriorityQueue queue = operation.getQueue();
+ queue.cancel(operation);
+ }
+ });
+// if (removed && document != null) {
+// AndroidUtilities.runOnUIThread(() -> {
+// getNotificationCenter().postNotificationName(NotificationCenter.onDownloadingFilesChanged);
+// });
+// }
+ }
+ }
+
public boolean isLoadingFile(final String fileName) {
return fileName != null && loadOperationPathsUI.containsKey(fileName);
}
@@ -713,8 +767,15 @@ public class FileLoader extends BaseController {
if (!operation.isPreloadVideoOperation() && operation.isPreloadFinished()) {
return;
}
- if (document != null && parentObject instanceof MessageObject && ((MessageObject) parentObject).putInDownloadsStore) {
- getDownloadController().onDownloadComplete((MessageObject) parentObject);
+ long dialogId = getDialogIdFromParent(currentAccount, parentObject);
+ if (dialogId != 0) {
+ getFileLoader().getFileDatabase().saveFileDialogId(finalFile, dialogId);
+ }
+ if (parentObject instanceof MessageObject) {
+ MessageObject messageObject = (MessageObject) parentObject;
+ if (document != null && messageObject.putInDownloadsStore) {
+ getDownloadController().onDownloadComplete(messageObject);
+ }
}
if (!operation.isPreloadVideoOperation()) {
@@ -915,7 +976,7 @@ public class FileLoader extends BaseController {
}
}
} else if (MessageObject.getMedia(message) instanceof TLRPC.TL_messageMediaInvoice) {
- TLRPC.WebDocument document = ((TLRPC.TL_messageMediaInvoice) MessageObject.getMedia(message)).photo;
+ TLRPC.WebDocument document = ((TLRPC.TL_messageMediaInvoice) MessageObject.getMedia(message)).webPhoto;
if (document != null) {
return Utilities.MD5(document.url) + "." + ImageLoader.getHttpUrlExtension(document.url, getMimeTypePart(document.mime_type));
}
@@ -1087,7 +1148,7 @@ public class FileLoader extends BaseController {
return new File(dir, getAttachFileName(attach, ext));
}
- private FilePathDatabase getFileDatabase() {
+ public FilePathDatabase getFileDatabase() {
return filePathDatabase;
}
@@ -1498,4 +1559,19 @@ public class FileLoader extends BaseController {
private static class LoadOperationUIObject {
Runnable loadInternalRunnable;
}
+
+ public static byte[] longToBytes(long x) {
+ ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
+ buffer.putLong(x);
+ return buffer.array();
+ }
+
+ public static long bytesToLong(byte[] bytes) {
+ long l = 0;
+ for (int i = 0; i < 8; i++) {
+ l <<= 8;
+ l ^= bytes[i] & 0xFF;
+ }
+ return l;
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
index 7cf4f94b8..200ad3bfe 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java
@@ -37,6 +37,7 @@ public class FileLog {
private File networkFile = null;
private File tonlibFile = null;
private boolean initied;
+ public static boolean databaseIsMalformed = false;
private OutputStreamWriter tlStreamWriter = null;
private File tlRequestsFile = null;
@@ -311,7 +312,7 @@ public class FileLog {
AndroidUtilities.appCenterLog(e);
}
if (BuildVars.DEBUG_VERSION && e instanceof SQLiteException && e.getMessage() != null && e.getMessage().contains("disk image is malformed")) {
-
+ databaseIsMalformed = true;
}
ensureInitied();
e.printStackTrace();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FilePathDatabase.java b/TMessagesProj/src/main/java/org/telegram/messenger/FilePathDatabase.java
index e1a65d098..8b0bbbc7e 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FilePathDatabase.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FilePathDatabase.java
@@ -10,6 +10,7 @@ import org.telegram.SQLite.SQLitePreparedStatement;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.CountDownLatch;
public class FilePathDatabase {
@@ -21,7 +22,7 @@ public class FilePathDatabase {
private File cacheFile;
private File shmCacheFile;
- private final static int LAST_DB_VERSION = 2;
+ private final static int LAST_DB_VERSION = 3;
private final static String DATABASE_NAME = "file_to_path";
private final static String DATABASE_BACKUP_NAME = "file_to_path_backup";
@@ -56,6 +57,9 @@ public class FilePathDatabase {
if (createTable) {
database.executeFast("CREATE TABLE paths(document_id INTEGER, dc_id INTEGER, type INTEGER, path TEXT, PRIMARY KEY(document_id, dc_id, type));").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS path_in_paths ON paths(path);").stepThis().dispose();
+
+ database.executeFast("CREATE TABLE paths_by_dialog_id(path TEXT PRIMARY KEY, dialog_id INTEGER);").stepThis().dispose();
+
database.executeFast("PRAGMA user_version = " + LAST_DB_VERSION).stepThis().dispose();
} else {
int version = database.executeInt("PRAGMA user_version");
@@ -95,6 +99,11 @@ public class FilePathDatabase {
database.executeFast("PRAGMA user_version = " + 2).stepThis().dispose();
version = 2;
}
+ if (version == 2) {
+ database.executeFast("CREATE TABLE paths_by_dialog_id(path TEXT PRIMARY KEY, dialog_id INTEGER);").stepThis().dispose();
+ database.executeFast("PRAGMA user_version = " + 3).stepThis().dispose();
+ version = 3;
+ }
}
private void createBackup() {
@@ -271,6 +280,7 @@ public class FilePathDatabase {
dispatchQueue.postRunnable(() -> {
try {
database.executeFast("DELETE FROM paths WHERE 1").stepThis().dispose();
+ database.executeFast("DELETE FROM paths_by_dialog_id WHERE 1").stepThis().dispose();
} catch (Exception e) {
FileLog.e(e);
}
@@ -300,6 +310,68 @@ public class FilePathDatabase {
return res[0];
}
+ public void saveFileDialogId(File file, long dialogId) {
+ if (file == null) {
+ return;
+ }
+ dispatchQueue.postRunnable(() -> {
+ SQLitePreparedStatement state = null;
+ try {
+ state = database.executeFast("REPLACE INTO paths_by_dialog_id VALUES(?, ?)");
+ state.requery();
+ state.bindString(1, file.getPath());
+ state.bindLong(2, dialogId);
+ state.step();
+ } catch (Exception e) {
+ FileLog.e(e);
+ } finally {
+ if (state != null) {
+ state.dispose();
+ }
+ }
+ });
+ }
+
+ public long getFileDialogId(File file) {
+ if (file == null) {
+ return 0;
+ }
+ long dialogId = 0;
+ SQLiteCursor cursor = null;
+ try {
+ cursor = database.queryFinalized("SELECT dialog_id FROM paths_by_dialog_id WHERE path = '" + file.getPath() + "'");
+ if (cursor.next()) {
+ dialogId = cursor.longValue(0);
+ }
+ } catch (Exception e) {
+ FileLog.e(e);
+ } finally {
+ if (cursor != null) {
+ cursor.dispose();
+ }
+ }
+ return dialogId;
+ }
+
+ public DispatchQueue getQueue() {
+ return dispatchQueue;
+ }
+
+ public void removeFiles(List filesToRemove) {
+ dispatchQueue.postRunnable(() -> {
+ try {
+ database.beginTransaction();
+ for (int i = 0; i < filesToRemove.size(); i++) {
+ database.executeFast("DELETE FROM paths_by_dialog_id WHERE path = '" + filesToRemove.get(i).getPath() + "'").stepThis().dispose();
+ }
+ } catch (Exception e) {
+ FileLog.e(e);
+ } finally {
+ database.commitTransaction();
+ }
+ });
+ }
+
public static class PathData {
public final long id;
public final int dc;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileRefController.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileRefController.java
index d52dd1830..aa9a3bb02 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileRefController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileRefController.java
@@ -458,7 +458,7 @@ public class FileRefController extends BaseController {
}
} else if (string.startsWith("sent_")) {
String[] params = string.split("_");
- if (params.length == 3) {
+ if (params.length >= 3) {
long channelId = Utilities.parseLong(params[1]);
if (channelId != 0) {
TLRPC.TL_channels_getMessages req = new TLRPC.TL_channels_getMessages();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
index 6ead2534c..f208907fe 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java
@@ -257,7 +257,7 @@ public class FileUploadOperation {
if (stream == null) {
File cacheFile = new File(uploadingFilePath);
if (AndroidUtilities.isInternalUri(Uri.fromFile(cacheFile))) {
- throw new Exception("trying to upload internal file");
+ throw new FileLog.IgnoreSentException("trying to upload internal file");
}
stream = new RandomAccessFile(cacheFile, "r");
boolean isInternalFile = false;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/GoogleLocationProvider.java b/TMessagesProj/src/main/java/org/telegram/messenger/GoogleLocationProvider.java
index 42f9adfb0..237f27e55 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/GoogleLocationProvider.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/GoogleLocationProvider.java
@@ -29,7 +29,7 @@ public class GoogleLocationProvider implements ILocationServiceProvider {
@Override
public void init(Context context) {
locationProviderClient = LocationServices.getFusedLocationProviderClient(context);
- settingsClient = new SettingsClient(context);
+ settingsClient = LocationServices.getSettingsClient(context);
}
@Override
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java
index 862ef50cc..e3af7cb76 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java
@@ -28,7 +28,6 @@ import android.os.Environment;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.text.TextUtils;
-import android.util.Log;
import android.util.SparseArray;
import androidx.exifinterface.media.ExifInterface;
@@ -1354,7 +1353,7 @@ public class ImageLoader {
}
}
} catch (Throwable e) {
- FileLog.e(e);
+ FileLog.e(e, !(e instanceof FileNotFoundException));
}
} else {
try {
@@ -1399,7 +1398,8 @@ public class ImageLoader {
Utilities.loadWebpImage(image, buffer, buffer.limit(), null, !opts.inPurgeable);
file.close();
} else {
- if (opts.inPurgeable || secureDocumentKey != null || Build.VERSION.SDK_INT <= 29) {
+ try {
+
RandomAccessFile f = new RandomAccessFile(cacheFileFinal, "r");
int len = (int) f.length();
int offset = 0;
@@ -1426,7 +1426,11 @@ public class ImageLoader {
if (!error) {
image = BitmapFactory.decodeByteArray(data, offset, len, opts);
}
- } else {
+ } catch (Throwable e) {
+
+ }
+
+ if (image == null) {
FileInputStream is;
if (inEncryptedFile) {
is = new EncryptedFileInputStream(cacheFileFinal, cacheImage.encryptionKeyPath);
@@ -1623,7 +1627,7 @@ public class ImageLoader {
toSet = bitmapDrawable;
} else {
Bitmap image = bitmapDrawable.getBitmap();
- image.recycle();
+ AndroidUtilities.recycleBitmap(image);
}
if (toSet != null && incrementUseCount) {
incrementUseCount(cacheImage.key);
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ImageReceiver.java b/TMessagesProj/src/main/java/org/telegram/messenger/ImageReceiver.java
index 619f54a8b..ef5264ba6 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/ImageReceiver.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/ImageReceiver.java
@@ -44,6 +44,17 @@ import java.util.ArrayList;
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
+ public boolean updateThumbShaderMatrix() {
+ if (currentThumbDrawable != null && thumbShader != null) {
+ drawDrawable(null, currentThumbDrawable, 255, thumbShader, 0, 0, null);
+ return true;
+ } if (staticThumbDrawable != null && thumbShader != null) {
+ drawDrawable(null, staticThumbDrawable, 255, thumbShader, 0, 0, null);
+ return true;
+ }
+ return false;
+ }
+
public interface ImageReceiverDelegate {
void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb, boolean memCache);
@@ -208,7 +219,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
private String currentThumbKey;
private int thumbTag;
private Drawable currentThumbDrawable;
- private BitmapShader thumbShader;
+ public BitmapShader thumbShader;
private int thumbOrientation;
private ImageLocation currentMediaLocation;
@@ -378,13 +389,15 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
if (userFull == null) {
MessagesController.getInstance(currentAccount).loadFullUser(user, currentGuid, false);
} else {
- if (userFull.profile_photo != null) {
- TLRPC.Photo photo = userFull.profile_photo;
- if (photo != null && photo.video_sizes != null && !photo.video_sizes.isEmpty()) {
- TLRPC.VideoSize videoSize = photo.video_sizes.get(0);
- for (int i = 0; i < photo.video_sizes.size(); i++) {
- if ("p".equals(photo.video_sizes.get(i).type)) {
- videoSize = photo.video_sizes.get(i);
+ TLRPC.Photo photo = userFull.profile_photo;
+ if (photo != null) {
+ ArrayList videoSizes = photo.video_sizes;
+ if (videoSizes != null && !videoSizes.isEmpty()) {
+ TLRPC.VideoSize videoSize = videoSizes.get(0);
+ for (int i = 0; i < videoSizes.size(); i++) {
+ TLRPC.VideoSize videoSize1 = videoSizes.get(i);
+ if ("p".equals(videoSize1.type)) {
+ videoSize = videoSize1;
break;
}
}
@@ -1170,10 +1183,12 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
if (isRoundRect) {
try {
- if (roundRadius[0] == 0) {
- canvas.drawRect(roundRect, roundPaint);
- } else {
- canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
+ if (canvas != null) {
+ if (roundRadius[0] == 0) {
+ canvas.drawRect(roundRect, roundPaint);
+ } else {
+ canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
+ }
}
} catch (Exception e) {
onBitmapException(bitmapDrawable);
@@ -1187,7 +1202,9 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
roundPath.reset();
roundPath.addRoundRect(roundRect, radii, Path.Direction.CW);
roundPath.close();
- canvas.drawPath(roundPath, roundPaint);
+ if (canvas != null) {
+ canvas.drawPath(roundPath, roundPaint);
+ }
}
}
} else {
@@ -1273,16 +1290,18 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
if (isRoundRect) {
try {
- if (roundRadius[0] == 0) {
- if (reactionLastFrame) {
- AndroidUtilities.rectTmp.set(roundRect);
- AndroidUtilities.rectTmp.inset(-(drawRegion.width() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.width()) / 2f, -(drawRegion.height() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.height()) / 2f);
- canvas.drawRect(AndroidUtilities.rectTmp, roundPaint);
+ if (canvas != null) {
+ if (roundRadius[0] == 0) {
+ if (reactionLastFrame) {
+ AndroidUtilities.rectTmp.set(roundRect);
+ AndroidUtilities.rectTmp.inset(-(drawRegion.width() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.width()) / 2f, -(drawRegion.height() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.height()) / 2f);
+ canvas.drawRect(AndroidUtilities.rectTmp, roundPaint);
+ } else {
+ canvas.drawRect(roundRect, roundPaint);
+ }
} else {
- canvas.drawRect(roundRect, roundPaint);
+ canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
}
- } else {
- canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
}
} catch (Exception e) {
if (backgroundThreadDrawHolder == null) {
@@ -1298,7 +1317,9 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
roundPath.reset();
roundPath.addRoundRect(roundRect, radii, Path.Direction.CW);
roundPath.close();
- canvas.drawPath(roundPath, roundPaint);
+ if (canvas != null) {
+ canvas.drawPath(roundPath, roundPaint);
+ }
}
}
}
@@ -1339,104 +1360,106 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
canvas.restore();
}
} else {
- if (Math.abs(scaleW - scaleH) > 0.00001f) {
- canvas.save();
- if (clip) {
- canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
- }
-
- if (orientation % 360 != 0) {
- if (centerRotation) {
- canvas.rotate(orientation, imageW / 2, imageH / 2);
- } else {
- canvas.rotate(orientation, 0, 0);
+ if (canvas != null) {
+ if (Math.abs(scaleW - scaleH) > 0.00001f) {
+ canvas.save();
+ if (clip) {
+ canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
}
- }
- if (bitmapW / scaleH > imageW) {
- bitmapW /= scaleH;
- drawRegion.set(imageX - (bitmapW - imageW) / 2.0f, imageY, imageX + (bitmapW + imageW) / 2.0f, imageY + imageH);
+ if (orientation % 360 != 0) {
+ if (centerRotation) {
+ canvas.rotate(orientation, imageW / 2, imageH / 2);
+ } else {
+ canvas.rotate(orientation, 0, 0);
+ }
+ }
+
+ if (bitmapW / scaleH > imageW) {
+ bitmapW /= scaleH;
+ drawRegion.set(imageX - (bitmapW - imageW) / 2.0f, imageY, imageX + (bitmapW + imageW) / 2.0f, imageY + imageH);
+ } else {
+ bitmapH /= scaleW;
+ drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2.0f, imageX + imageW, imageY + (bitmapH + imageH) / 2.0f);
+ }
+ if (bitmapDrawable instanceof AnimatedFileDrawable) {
+ ((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
+ }
+ if (backgroundThreadDrawHolder == null) {
+ if (orientation % 360 == 90 || orientation % 360 == 270) {
+ float width = drawRegion.width() / 2;
+ float height = drawRegion.height() / 2;
+ float centerX = drawRegion.centerX();
+ float centerY = drawRegion.centerY();
+ bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
+ } else {
+ bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
+ }
+ }
+ if (isVisible) {
+ try {
+ if (Build.VERSION.SDK_INT >= 29) {
+ if (blendMode != null) {
+ bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
+ } else {
+ bitmapDrawable.getPaint().setBlendMode(null);
+ }
+ }
+ drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
+ } catch (Exception e) {
+ if (backgroundThreadDrawHolder == null) {
+ onBitmapException(bitmapDrawable);
+ }
+ FileLog.e(e);
+ }
+ }
+
+ canvas.restore();
} else {
- bitmapH /= scaleW;
- drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2.0f, imageX + imageW, imageY + (bitmapH + imageH) / 2.0f);
- }
- if (bitmapDrawable instanceof AnimatedFileDrawable) {
- ((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
- }
- if (backgroundThreadDrawHolder == null) {
- if (orientation % 360 == 90 || orientation % 360 == 270) {
- float width = drawRegion.width() / 2;
- float height = drawRegion.height() / 2;
- float centerX = drawRegion.centerX();
- float centerY = drawRegion.centerY();
- bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
- } else {
- bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
- }
- }
- if (isVisible) {
- try {
- if (Build.VERSION.SDK_INT >= 29) {
- if (blendMode != null) {
- bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
- } else {
- bitmapDrawable.getPaint().setBlendMode(null);
- }
+ canvas.save();
+ if (orientation % 360 != 0) {
+ if (centerRotation) {
+ canvas.rotate(orientation, imageW / 2, imageH / 2);
+ } else {
+ canvas.rotate(orientation, 0, 0);
}
- drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
- } catch (Exception e) {
- if (backgroundThreadDrawHolder == null) {
+ }
+ drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
+ if (isRoundVideo) {
+ drawRegion.inset(-AndroidUtilities.roundMessageInset, -AndroidUtilities.roundMessageInset);
+ }
+ if (bitmapDrawable instanceof AnimatedFileDrawable) {
+ ((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
+ }
+ if (backgroundThreadDrawHolder == null) {
+ if (orientation % 360 == 90 || orientation % 360 == 270) {
+ float width = drawRegion.width() / 2;
+ float height = drawRegion.height() / 2;
+ float centerX = drawRegion.centerX();
+ float centerY = drawRegion.centerY();
+ bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
+ } else {
+ bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
+ }
+ }
+ if (isVisible) {
+ try {
+ if (Build.VERSION.SDK_INT >= 29) {
+ if (blendMode != null) {
+ bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
+ } else {
+ bitmapDrawable.getPaint().setBlendMode(null);
+ }
+ }
+
+ drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
+ } catch (Exception e) {
onBitmapException(bitmapDrawable);
+ FileLog.e(e);
}
- FileLog.e(e);
}
+ canvas.restore();
}
-
- canvas.restore();
- } else {
- canvas.save();
- if (orientation % 360 != 0) {
- if (centerRotation) {
- canvas.rotate(orientation, imageW / 2, imageH / 2);
- } else {
- canvas.rotate(orientation, 0, 0);
- }
- }
- drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
- if (isRoundVideo) {
- drawRegion.inset(-AndroidUtilities.roundMessageInset, -AndroidUtilities.roundMessageInset);
- }
- if (bitmapDrawable instanceof AnimatedFileDrawable) {
- ((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
- }
- if (backgroundThreadDrawHolder == null) {
- if (orientation % 360 == 90 || orientation % 360 == 270) {
- float width = drawRegion.width() / 2;
- float height = drawRegion.height() / 2;
- float centerX = drawRegion.centerX();
- float centerY = drawRegion.centerY();
- bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
- } else {
- bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
- }
- }
- if (isVisible) {
- try {
- if (Build.VERSION.SDK_INT >= 29) {
- if (blendMode != null) {
- bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
- } else {
- bitmapDrawable.getPaint().setBlendMode(null);
- }
- }
-
- drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
- } catch (Exception e) {
- onBitmapException(bitmapDrawable);
- FileLog.e(e);
- }
- }
- canvas.restore();
}
}
}
@@ -1464,7 +1487,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
}
drawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
}
- if (isVisible) {
+ if (isVisible && canvas != null) {
try {
drawable.setAlpha(alpha);
if (backgroundThreadDrawHolder != null) {
@@ -1511,7 +1534,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
} else {
bitmapDrawable.setAlpha(alpha);
if (bitmapDrawable instanceof RLottieDrawable) {
- ((RLottieDrawable) bitmapDrawable).drawInternal(canvas, false, currentTime, 0);
+ ((RLottieDrawable) bitmapDrawable).drawInternal(canvas, null, false, currentTime, 0);
} else if (bitmapDrawable instanceof AnimatedFileDrawable) {
((AnimatedFileDrawable) bitmapDrawable).drawInternal(canvas, false, currentTime, 0);
} else {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java
index adac600ff..e33a1a7aa 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java
@@ -414,7 +414,9 @@ public class LocaleController {
public static String getLanguageFlag(String countryCode) {
if (countryCode.length() != 2 || countryCode.equals("YL")) return null;
- if (countryCode.equals("XG")) {
+ if (countryCode.equals("FT")) {
+ return "\uD83C\uDFF4\u200D\u2620\uFE0F";
+ } else if (countryCode.equals("XG")) {
return "\uD83D\uDEF0";
} else if (countryCode.equals("XV")){
return "\uD83C\uDF0D";
@@ -1056,10 +1058,11 @@ public class LocaleController {
String param = getInstance().stringForQuantity(getInstance().currentPluralRules.quantityForNumber(plural));
param = key + "_" + param;
int resourceId = ApplicationLoader.applicationContext.getResources().getIdentifier(param, "string", ApplicationLoader.applicationContext.getPackageName());
+ int fallbackResourceId = ApplicationLoader.applicationContext.getResources().getIdentifier(key + "_other", "string", ApplicationLoader.applicationContext.getPackageName());
Object[] argsWithPlural = new Object[args.length + 1];
argsWithPlural[0] = plural;
System.arraycopy(args, 0, argsWithPlural, 1, args.length);
- return formatString(param, key + "_other", resourceId, argsWithPlural);
+ return formatString(param, key + "_other", resourceId, fallbackResourceId, argsWithPlural);
}
public static String formatPluralStringComma(String key, int plural) {
@@ -1108,10 +1111,10 @@ public class LocaleController {
}
public static String formatString(String key, int res, Object... args) {
- return formatString(key, null, res, args);
+ return formatString(key, null, res, 0, args);
}
- public static String formatString(String key, String fallback, int res, Object... args) {
+ public static String formatString(String key, String fallback, int res, int fallbackRes, Object... args) {
try {
String value = BuildVars.USE_CLOUD_STRINGS ? getInstance().localeValues.get(key) : null;
if (value == null) {
@@ -1119,7 +1122,15 @@ public class LocaleController {
value = getInstance().localeValues.get(fallback);
}
if (value == null) {
- value = ApplicationLoader.applicationContext.getString(res);
+ try {
+ value = ApplicationLoader.applicationContext.getString(res);
+ } catch (Exception e) {
+ if (fallbackRes != 0) {
+ try {
+ value = ApplicationLoader.applicationContext.getString(fallbackRes);
+ } catch (Exception ignored) {}
+ }
+ }
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/LocationSharingService.java b/TMessagesProj/src/main/java/org/telegram/messenger/LocationSharingService.java
index aaf5a60dc..91f68f78f 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/LocationSharingService.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/LocationSharingService.java
@@ -128,25 +128,29 @@ public class LocationSharingService extends Service implements NotificationCente
if (getInfos().isEmpty()) {
stopSelf();
}
- if (builder == null) {
- Intent intent2 = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
- intent2.setAction("org.tmessages.openlocations");
- intent2.addCategory(Intent.CATEGORY_LAUNCHER);
- PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent2, PendingIntent.FLAG_MUTABLE);
+ try {
+ if (builder == null) {
+ Intent intent2 = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
+ intent2.setAction("org.tmessages.openlocations");
+ intent2.addCategory(Intent.CATEGORY_LAUNCHER);
+ PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent2, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
- builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
- builder.setWhen(System.currentTimeMillis());
- builder.setSmallIcon(R.drawable.live_loc);
- builder.setContentIntent(contentIntent);
- NotificationsController.checkOtherNotificationsChannel();
- builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
- builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
- Intent stopIntent = new Intent(ApplicationLoader.applicationContext, StopLiveLocationReceiver.class);
- builder.addAction(0, LocaleController.getString("StopLiveLocation", R.string.StopLiveLocation), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 2, stopIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
+ builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
+ builder.setWhen(System.currentTimeMillis());
+ builder.setSmallIcon(R.drawable.live_loc);
+ builder.setContentIntent(contentIntent);
+ NotificationsController.checkOtherNotificationsChannel();
+ builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
+ builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
+ Intent stopIntent = new Intent(ApplicationLoader.applicationContext, StopLiveLocationReceiver.class);
+ builder.addAction(0, LocaleController.getString("StopLiveLocation", R.string.StopLiveLocation), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 2, stopIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
+ }
+
+ updateNotification(false);
+ startForeground(6, builder.build());
+ } catch (Throwable e) {
+ FileLog.e(e);
}
-
- updateNotification(false);
- startForeground(6, builder.build());
return Service.START_NOT_STICKY;
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
index b46b1025c..8d878c024 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
@@ -1071,16 +1071,23 @@ public class MediaDataController extends BaseController {
return getStickerSet(inputStickerSet, cacheOnly, null);
}
- public TLRPC.TL_messages_stickerSet getStickerSet(TLRPC.InputStickerSet inputStickerSet, boolean cacheOnly, Runnable onNotFound) {
+ public TLRPC.TL_messages_stickerSet getStickerSet(TLRPC.InputStickerSet inputStickerSet, boolean cacheOnly, Utilities.Callback onResponse) {
if (inputStickerSet == null) {
return null;
}
+ TLRPC.TL_messages_stickerSet cacheSet = null;
if (inputStickerSet instanceof TLRPC.TL_inputStickerSetID && stickerSetsById.containsKey(inputStickerSet.id)) {
- return stickerSetsById.get(inputStickerSet.id);
+ cacheSet = stickerSetsById.get(inputStickerSet.id);
} else if (inputStickerSet instanceof TLRPC.TL_inputStickerSetShortName && inputStickerSet.short_name != null && stickerSetsByName.containsKey(inputStickerSet.short_name.toLowerCase())) {
- return stickerSetsByName.get(inputStickerSet.short_name.toLowerCase());
+ cacheSet = stickerSetsByName.get(inputStickerSet.short_name.toLowerCase());
} else if (inputStickerSet instanceof TLRPC.TL_inputStickerSetEmojiDefaultStatuses && stickerSetDefaultStatuses != null) {
- return stickerSetDefaultStatuses;
+ cacheSet = stickerSetDefaultStatuses;
+ }
+ if (cacheSet != null) {
+ if (onResponse != null) {
+ onResponse.run(cacheSet);
+ }
+ return cacheSet;
}
if (cacheOnly) {
return null;
@@ -1100,11 +1107,16 @@ public class MediaDataController extends BaseController {
stickerSetDefaultStatuses = set;
}
getNotificationCenter().postNotificationName(NotificationCenter.groupStickersDidLoad, set.set.id, set);
+ if (onResponse != null) {
+ onResponse.run(set);
+ }
});
} else {
- if (onNotFound != null) {
- onNotFound.run();
- }
+ AndroidUtilities.runOnUIThread(() -> {
+ if (onResponse != null) {
+ onResponse.run(null);
+ }
+ });
}
});
return null;
@@ -2713,27 +2725,31 @@ public class MediaDataController extends BaseController {
}
public void preloadStickerSetThumb(TLRPC.TL_messages_stickerSet stickerSet) {
- TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
- if (thumb != null) {
- ArrayList documents = stickerSet.documents;
- if (documents != null && !documents.isEmpty()) {
- loadStickerSetThumbInternal(thumb, stickerSet, documents.get(0), stickerSet.set.thumb_version);
+ if (stickerSet != null && stickerSet.set != null) {
+ TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
+ if (thumb != null) {
+ ArrayList documents = stickerSet.documents;
+ if (documents != null && !documents.isEmpty()) {
+ loadStickerSetThumbInternal(thumb, stickerSet, documents.get(0), stickerSet.set.thumb_version);
+ }
}
}
}
public void preloadStickerSetThumb(TLRPC.StickerSetCovered stickerSet) {
- TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
- if (thumb != null) {
- TLRPC.Document sticker;
- if (stickerSet.cover != null) {
- sticker = stickerSet.cover;
- } else if (!stickerSet.covers.isEmpty()) {
- sticker = stickerSet.covers.get(0);
- } else {
- return;
+ if (stickerSet != null && stickerSet.set != null) {
+ TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
+ if (thumb != null) {
+ TLRPC.Document sticker;
+ if (stickerSet.cover != null) {
+ sticker = stickerSet.cover;
+ } else if (!stickerSet.covers.isEmpty()) {
+ sticker = stickerSet.covers.get(0);
+ } else {
+ return;
+ }
+ loadStickerSetThumbInternal(thumb, stickerSet, sticker, stickerSet.set.thumb_version);
}
- loadStickerSetThumbInternal(thumb, stickerSet, sticker, stickerSet.set.thumb_version);
}
}
@@ -6923,14 +6939,14 @@ public class MediaDataController extends BaseController {
}
public void getEmojiSuggestions(String[] langCodes, String keyword, boolean fullMatch, KeywordResultCallback callback, boolean allowAnimated) {
- getEmojiSuggestions(langCodes, keyword, fullMatch, callback, null, allowAnimated, null);
+ getEmojiSuggestions(langCodes, keyword, fullMatch, callback, null, allowAnimated, false, null);
}
public void getEmojiSuggestions(String[] langCodes, String keyword, boolean fullMatch, KeywordResultCallback callback, final CountDownLatch sync, boolean allowAnimated) {
- getEmojiSuggestions(langCodes, keyword, fullMatch, callback, sync, allowAnimated, null);
+ getEmojiSuggestions(langCodes, keyword, fullMatch, callback, sync, allowAnimated, false, null);
}
- public void getEmojiSuggestions(String[] langCodes, String keyword, boolean fullMatch, KeywordResultCallback callback, final CountDownLatch sync, boolean allowAnimated, Integer maxAnimatedPerEmoji) {
+ public void getEmojiSuggestions(String[] langCodes, String keyword, boolean fullMatch, KeywordResultCallback callback, final CountDownLatch sync, boolean allowAnimated, boolean allowTopicIcons, Integer maxAnimatedPerEmoji) {
if (callback == null) {
return;
}
@@ -7042,7 +7058,7 @@ public class MediaDataController extends BaseController {
});
String aliasFinal = alias;
if (allowAnimated && SharedConfig.suggestAnimatedEmoji) {
- fillWithAnimatedEmoji(result, maxAnimatedPerEmoji, () -> {
+ fillWithAnimatedEmoji(result, maxAnimatedPerEmoji, allowTopicIcons, () -> {
if (sync != null) {
callback.run(result, aliasFinal);
sync.countDown();
@@ -7070,14 +7086,14 @@ public class MediaDataController extends BaseController {
private boolean triedLoadingEmojipacks = false;
- public void fillWithAnimatedEmoji(ArrayList result, Integer maxAnimatedPerEmojiInput, Runnable onDone) {
+ public void fillWithAnimatedEmoji(ArrayList result, Integer maxAnimatedPerEmojiInput, boolean allowTopicIcons, Runnable onDone) {
if (result == null || result.isEmpty()) {
if (onDone != null) {
onDone.run();
}
return;
}
- final ArrayList[] emojiPacks = new ArrayList[2];
+ final ArrayList[] emojiPacks = new ArrayList[1];
emojiPacks[0] = getStickerSets(TYPE_EMOJIPACKS);
final Runnable fillRunnable = () -> {
ArrayList featuredSets = getFeaturedEmojiSets();
@@ -7085,13 +7101,29 @@ public class MediaDataController extends BaseController {
ArrayList animatedEmoji = new ArrayList<>();
final int maxAnimatedPerEmoji = maxAnimatedPerEmojiInput == null ? (result.size() > 5 ? 1 : (result.size() > 2 ? 2 : 3)) : maxAnimatedPerEmojiInput;
int len = maxAnimatedPerEmojiInput == null ? Math.min(15, result.size()) : result.size();
+ boolean isPremium = UserConfig.getInstance(currentAccount).isPremium();
+ String topicIconsName = null;
+ if (allowTopicIcons) {
+ topicIconsName = UserConfig.getInstance(currentAccount).defaultTopicIcons;
+ if (emojiPacks[0] != null) {
+ TLRPC.TL_messages_stickerSet set = null;
+ if (topicIconsName != null) {
+ set = MediaDataController.getInstance(currentAccount).getStickerSetByName(topicIconsName);
+ if (set == null) {
+ set = MediaDataController.getInstance(currentAccount).getStickerSetByEmojiOrName(topicIconsName);
+ }
+ }
+ if (set != null) {
+ emojiPacks[0].add(set);
+ }
+ }
+ }
for (int i = 0; i < len; ++i) {
String emoji = result.get(i).emoji;
if (emoji == null) {
continue;
}
animatedEmoji.clear();
- boolean isPremium = UserConfig.getInstance(currentAccount).isPremium();
if (Emoji.recentEmoji != null) {
for (int j = 0; j < Emoji.recentEmoji.size(); ++j) {
if (Emoji.recentEmoji.get(j).startsWith("animated_")) {
@@ -7099,8 +7131,9 @@ public class MediaDataController extends BaseController {
long documentId = Long.parseLong(Emoji.recentEmoji.get(j).substring(9));
TLRPC.Document document = AnimatedEmojiDrawable.findDocument(currentAccount, documentId);
if (document != null &&
- (isPremium || MessageObject.isFreeEmoji(document)) &&
- emoji.equals(MessageObject.findAnimatedEmojiEmoticon(document, null))) {
+ emoji.equals(MessageObject.findAnimatedEmojiEmoticon(document, null)) &&
+ (isPremium || MessageObject.isFreeEmoji(document))
+ ) {
animatedEmoji.add(document);
}
} catch (Exception ignore) {
@@ -7127,7 +7160,7 @@ public class MediaDataController extends BaseController {
}
}
- if (attribute != null && emoji.equals(attribute.alt) && (isPremium || attribute.free)) {
+ if (attribute != null && emoji.equals(attribute.alt) && (isPremium || attribute.free || set.set != null && set.set.short_name != null && set.set.short_name.equals(topicIconsName))) {
boolean duplicate = false;
for (int l = 0; l < animatedEmoji.size(); ++l) {
if (animatedEmoji.get(l).id == document.id) {
@@ -7172,7 +7205,7 @@ public class MediaDataController extends BaseController {
}
}
- if (attribute != null && emoji.equals(attribute.alt) && (isPremium || attribute.free)) {
+ if (attribute != null && emoji.equals(attribute.alt) && (isPremium || attribute.free || set.set != null && set.set.short_name != null && set.set.short_name.equals(topicIconsName))) {
boolean duplicate = false;
for (int l = 0; l < animatedEmoji.size(); ++l) {
if (animatedEmoji.get(l).id == document.id) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java
index 2cdae265c..04ac68ef2 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java
@@ -28,7 +28,6 @@ import android.text.style.URLSpan;
import android.text.util.Linkify;
import android.util.Base64;
-import androidx.annotation.IntDef;
import androidx.collection.LongSparseArray;
import org.telegram.PhoneFormat.PhoneFormat;
@@ -42,7 +41,6 @@ import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.ChatMessageCell;
import org.telegram.ui.Components.AnimatedEmojiDrawable;
import org.telegram.ui.Components.AnimatedEmojiSpan;
-import org.telegram.ui.Components.EmojiView;
import org.telegram.ui.Components.Forum.ForumBubbleDrawable;
import org.telegram.ui.Components.Forum.ForumUtilities;
import org.telegram.ui.Components.Reactions.ReactionsLayoutInBubble;
@@ -62,8 +60,6 @@ import org.telegram.ui.Components.spoilers.SpoilerEffect;
import java.io.BufferedReader;
import java.io.File;
import java.io.StringReader;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
import java.net.URLEncoder;
import java.util.AbstractMap;
import java.util.ArrayList;
@@ -252,7 +248,7 @@ public class MessageObject {
// forwarding preview params
public boolean hideSendersName;
public TLRPC.Peer sendAsPeer;
- public ForumBubbleDrawable[] topicIconDrawable = new ForumBubbleDrawable[1];
+ public Drawable[] topicIconDrawable = new Drawable[1];
static final String[] excludeWords = new String[]{
" vs. ",
@@ -273,6 +269,7 @@ public class MessageObject {
public Drawable customAvatarDrawable;
private byte[] randomWaveform;
+ public boolean drawServiceWithDefaultTypeface;
public static boolean hasUnreadReactions(TLRPC.Message message) {
if (message == null) {
@@ -305,12 +302,16 @@ public class MessageObject {
return false;
}
- public static int getTopicId(TLRPC.Message message) {
+ private static int getTopicId(TLRPC.Message message) {
+ return getTopicId(message, false);
+ }
+
+ public static int getTopicId(TLRPC.Message message, boolean sureIsForum) {
if (message != null && message.action instanceof TLRPC.TL_messageActionTopicCreate) {
return message.id;
}
if (message == null || message.reply_to == null || !message.reply_to.forum_topic) {
- return 0;
+ return sureIsForum ? 1 : 0; // 1 = general topic
}
if (message instanceof TLRPC.TL_messageService && !(message.action instanceof TLRPC.TL_messageActionPinMessage)) {
int topicId = message.reply_to.reply_to_msg_id;
@@ -1334,12 +1335,9 @@ public class MessageObject {
boolean large = emojiOnlyCount == animatedEmojiCount;
int cacheType = -1;
TextPaint emojiPaint;
- switch (emojiOnlyCount) {
+ switch (Math.max(emojiOnlyCount, animatedEmojiCount)) {
case 0:
case 1:
- cacheType = AnimatedEmojiDrawable.CACHE_TYPE_MESSAGES_LARGE;
- emojiPaint = large ? Theme.chat_msgTextPaintEmoji[0] : Theme.chat_msgTextPaintEmoji[2];
- break;
case 2:
cacheType = AnimatedEmojiDrawable.CACHE_TYPE_MESSAGES_LARGE;
emojiPaint = large ? Theme.chat_msgTextPaintEmoji[0] : Theme.chat_msgTextPaintEmoji[2];
@@ -1855,7 +1853,11 @@ public class MessageObject {
}
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionDeleteMessage) {
message = ((TLRPC.TL_channelAdminLogEventActionDeleteMessage) event.action).message;
- messageText = replaceWithLink(LocaleController.getString("EventLogDeletedMessages", R.string.EventLogDeletedMessages), "un1", fromUser);
+ if (fromUser != null && fromUser.id == MessagesController.getInstance(currentAccount).telegramAntispamUserId) {
+ messageText = LocaleController.getString("EventLogDeletedMessages", R.string.EventLogDeletedMessages).replace("un1", UserObject.getUserName(fromUser));
+ } else {
+ messageText = replaceWithLink(LocaleController.getString("EventLogDeletedMessages", R.string.EventLogDeletedMessages), "un1", fromUser);
+ }
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) {
long newChatId = ((TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) event.action).new_value;
long oldChatId = ((TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) event.action).prev_value;
@@ -2284,12 +2286,18 @@ public class MessageObject {
messageText = replaceWithLink(messageText, "un2", createTopic.topic);
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionEditTopic) {
TLRPC.TL_channelAdminLogEventActionEditTopic editTopic = (TLRPC.TL_channelAdminLogEventActionEditTopic) event.action;
- messageText = replaceWithLink(
- LocaleController.formatString("EventLogEditTopic", R.string.EventLogEditTopic),
- "un1", fromUser
- );
- messageText = replaceWithLink(messageText, "un2", editTopic.prev_topic);
- messageText = replaceWithLink(messageText, "un3", editTopic.new_topic);
+ if (editTopic.prev_topic instanceof TLRPC.TL_forumTopic && editTopic.new_topic instanceof TLRPC.TL_forumTopic &&
+ ((TLRPC.TL_forumTopic) editTopic.prev_topic).hidden != ((TLRPC.TL_forumTopic) editTopic.new_topic).hidden) {
+ String text = ((TLRPC.TL_forumTopic) editTopic.new_topic).hidden ? LocaleController.getString("TopicHidden2", R.string.TopicHidden2) : LocaleController.getString("TopicShown2", R.string.TopicShown2);
+ messageText = replaceWithLink(text, "%s", fromUser);
+ } else {
+ messageText = replaceWithLink(
+ LocaleController.getString("EventLogEditTopic", R.string.EventLogEditTopic),
+ "un1", fromUser
+ );
+ messageText = replaceWithLink(messageText, "un2", editTopic.prev_topic);
+ messageText = replaceWithLink(messageText, "un3", editTopic.new_topic);
+ }
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionDeleteTopic) {
TLRPC.TL_channelAdminLogEventActionDeleteTopic deleteTopic = (TLRPC.TL_channelAdminLogEventActionDeleteTopic) event.action;
messageText = replaceWithLink(
@@ -2337,11 +2345,13 @@ public class MessageObject {
if (message != null) {
message.out = false;
+ message.realId = message.id;
message.id = mid[0]++;
message.flags &= ~TLRPC.MESSAGE_FLAG_REPLY;
message.reply_to = null;
message.flags = message.flags & ~TLRPC.MESSAGE_FLAG_EDITED;
MessageObject messageObject = new MessageObject(currentAccount, message, null, null, true, true, eventId);
+ messageObject.currentEvent = event;
if (messageObject.contentType >= 0) {
if (mediaController.isPlayingMessage(messageObject)) {
MessageObject player = mediaController.getPlayingMessageObject();
@@ -3081,6 +3091,7 @@ public class MessageObject {
fromChat = getChat(chats, sChats, messageOwner.from_id.channel_id);
}
TLObject fromObject = fromUser != null ? fromUser : fromChat;
+ drawServiceWithDefaultTypeface = false;
if (messageOwner instanceof TLRPC.TL_messageService) {
if (messageOwner.action != null) {
@@ -3347,6 +3358,22 @@ public class MessageObject {
} else {
messageText = LocaleController.getString("ActionTTLChannelDisabled", R.string.ActionTTLChannelDisabled);
}
+ } else if (action.auto_setting_from != 0) {
+ drawServiceWithDefaultTypeface = true;
+ if (action.auto_setting_from == UserConfig.getInstance(currentAccount).clientUserId) {
+ messageText = AndroidUtilities.replaceTags(LocaleController.formatString("AutoDeleteGlobalActionFromYou", R.string.AutoDeleteGlobalActionFromYou, LocaleController.formatTTLString(action.period)));
+ } else {
+ TLObject object = null;
+ if (users != null) {
+ users.get(action.auto_setting_from);
+ }
+ if (object == null && chats != null) {
+ object = chats.get(action.auto_setting_from);
+ } else {
+ object = fromObject;
+ }
+ messageText = replaceWithLink(AndroidUtilities.replaceTags(LocaleController.formatString("AutoDeleteGlobalAction", R.string.AutoDeleteGlobalAction, LocaleController.formatTTLString(action.period))), "un1", object);
+ }
} else if (action.period != 0) {
if (isOut()) {
messageText = LocaleController.formatString("ActionTTLYouChanged", R.string.ActionTTLYouChanged, LocaleController.formatTTLString(action.period));
@@ -3458,7 +3485,15 @@ public class MessageObject {
name = "DELETED";
}
- if ((messageOwner.action.flags & 4) > 0) {
+ if ((messageOwner.action.flags & 8) > 0) {
+ if (((TLRPC.TL_messageActionTopicEdit) messageOwner.action).hidden) {
+ messageText = replaceWithLink(LocaleController.getString("TopicHidden2", R.string.TopicHidden2), "%s", object);
+ messageTextShort = LocaleController.getString("TopicHidden", R.string.TopicHidden);
+ } else {
+ messageText = replaceWithLink(LocaleController.getString("TopicShown2", R.string.TopicShown2), "%s", object);
+ messageTextShort = LocaleController.getString("TopicShown", R.string.TopicShown);
+ }
+ } else if ((messageOwner.action.flags & 4) > 0) {
if (((TLRPC.TL_messageActionTopicEdit) messageOwner.action).closed) {
messageText = replaceWithLink(LocaleController.getString("TopicClosed2", R.string.TopicClosed2), "%s", object);
messageTextShort = LocaleController.getString("TopicClosed", R.string.TopicClosed);
@@ -3905,7 +3940,7 @@ public class MessageObject {
if (document != null) {
return document.mime_type;
} else if (getMedia(messageOwner) instanceof TLRPC.TL_messageMediaInvoice) {
- TLRPC.WebDocument photo = ((TLRPC.TL_messageMediaInvoice) getMedia(messageOwner)).photo;
+ TLRPC.WebDocument photo = ((TLRPC.TL_messageMediaInvoice) getMedia(messageOwner)).webPhoto;
if (photo != null) {
return photo.mime_type;
}
@@ -5448,23 +5483,27 @@ public class MessageObject {
return messageOwner.out;
}
+ Boolean isOutOwnerCached;
public boolean isOutOwner() {
if (preview) {
return true;
}
+ if (isOutOwnerCached != null) {
+ return isOutOwnerCached;
+ }
TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(null, null, messageOwner.peer_id.channel_id) : null;
if (!messageOwner.out || !(messageOwner.from_id instanceof TLRPC.TL_peerUser) && (!(messageOwner.from_id instanceof TLRPC.TL_peerChannel) || ChatObject.isChannel(chat) && !chat.megagroup) || messageOwner.post) {
- return false;
+ return isOutOwnerCached = false;
}
if (messageOwner.fwd_from == null) {
- return true;
+ return isOutOwnerCached= true;
}
long selfUserId = UserConfig.getInstance(currentAccount).getClientUserId();
if (getDialogId() == selfUserId) {
- return messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerUser && messageOwner.fwd_from.from_id.user_id == selfUserId && (messageOwner.fwd_from.saved_from_peer == null || messageOwner.fwd_from.saved_from_peer.user_id == selfUserId)
+ return isOutOwnerCached = messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerUser && messageOwner.fwd_from.from_id.user_id == selfUserId && (messageOwner.fwd_from.saved_from_peer == null || messageOwner.fwd_from.saved_from_peer.user_id == selfUserId)
|| messageOwner.fwd_from.saved_from_peer != null && messageOwner.fwd_from.saved_from_peer.user_id == selfUserId && (messageOwner.fwd_from.from_id == null || messageOwner.fwd_from.from_id.user_id == selfUserId);
}
- return messageOwner.fwd_from.saved_from_peer == null || messageOwner.fwd_from.saved_from_peer.user_id == selfUserId;
+ return isOutOwnerCached = messageOwner.fwd_from.saved_from_peer == null || messageOwner.fwd_from.saved_from_peer.user_id == selfUserId;
}
public boolean needDrawAvatar() {
@@ -5481,6 +5520,9 @@ public class MessageObject {
if (customAvatarDrawable != null) {
return true;
}
+ if (isSponsored() && (isFromChat() || sponsoredShowPeerPhoto)) {
+ return true;
+ }
return !isSponsored() && (isFromChat() && isFromUser() || isFromGroup() || eventId != 0 || messageOwner.fwd_from != null && messageOwner.fwd_from.saved_from_peer != null);
}
@@ -5563,6 +5605,35 @@ public class MessageObject {
return 0;
}
+ public TLObject getFromPeerObject() {
+ if (messageOwner != null) {
+ if (messageOwner.from_id instanceof TLRPC.TL_peerChannel_layer131 ||
+ messageOwner.from_id instanceof TLRPC.TL_peerChannel) {
+ return MessagesController.getInstance(currentAccount).getChat(messageOwner.from_id.channel_id);
+ } else if (
+ messageOwner.from_id instanceof TLRPC.TL_peerUser_layer131 ||
+ messageOwner.from_id instanceof TLRPC.TL_peerUser
+ ) {
+ return MessagesController.getInstance(currentAccount).getUser(messageOwner.from_id.user_id);
+ } else if (
+ messageOwner.from_id instanceof TLRPC.TL_peerChat_layer131 ||
+ messageOwner.from_id instanceof TLRPC.TL_peerChat
+ ) {
+ return MessagesController.getInstance(currentAccount).getChat(messageOwner.from_id.chat_id);
+ }
+ }
+ return null;
+ }
+
+ public static String getPeerObjectName(TLObject object) {
+ if (object instanceof TLRPC.User) {
+ return UserObject.getUserName((TLRPC.User) object);
+ } else if (object instanceof TLRPC.Chat) {
+ return ((TLRPC.Chat) object).title;
+ }
+ return "DELETED";
+ }
+
public boolean isFromUser() {
return messageOwner.from_id instanceof TLRPC.TL_peerUser && !messageOwner.post;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
index 573470e8d..9268e6772 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java
@@ -371,6 +371,8 @@ public class MessagesController extends BaseController implements NotificationCe
public int reactionsInChatMax;
public int forumUpgradeParticipantsMin;
public int topicsPinnedLimit;
+ public long telegramAntispamUserId;
+ public int telegramAntispamGroupSizeMin;
public int uploadMaxFileParts;
public int uploadMaxFilePartsPremium;
@@ -588,6 +590,14 @@ public class MessagesController extends BaseController implements NotificationCe
return chatLocal != null && chatLocal.forum;
}
+ public boolean isForum(MessageObject msg) {
+ return msg != null && isForum(msg.getDialogId());
+ }
+
+ public boolean isForum(TLRPC.Message msg) {
+ return msg != null && isForum(MessageObject.getDialogId(msg));
+ }
+
public void markAllTopicsAsRead(long did) {
getMessagesStorage().loadTopics(did, topics -> {
AndroidUtilities.runOnUIThread(() -> {
@@ -1117,6 +1127,8 @@ public class MessagesController extends BaseController implements NotificationCe
transcribeButtonPressed = mainPreferences.getInt("transcribeButtonPressed", 0);
forumUpgradeParticipantsMin = mainPreferences.getInt("forumUpgradeParticipantsMin", 200);
topicsPinnedLimit = mainPreferences.getInt("topicsPinnedLimit", 3);
+ telegramAntispamUserId = mainPreferences.getLong("telegramAntispamUserId", -1);
+ telegramAntispamGroupSizeMin = mainPreferences.getInt("telegramAntispamGroupSizeMin", 100);
BuildVars.GOOGLE_AUTH_CLIENT_ID = mainPreferences.getString("googleAuthClientId", BuildVars.GOOGLE_AUTH_CLIENT_ID);
Set currencySet = mainPreferences.getStringSet("directPaymentsCurrency", null);
@@ -1335,7 +1347,6 @@ public class MessagesController extends BaseController implements NotificationCe
sendLoadPeersRequest(req3, requests, pinnedDialogs, pinnedRemoteDialogs, users, chats, filtersToSave, filtersToDelete, filtersOrder, filterDialogRemovals, filterUserRemovals, filtersUnreadCounterReset);
}
- //no
TLRPC.TL_messages_getPeerDialogs req4 = null;
for (HashMap.Entry entry : dialogsToLoadMap.entrySet()) {
if (req4 == null) {
@@ -2644,6 +2655,31 @@ public class MessagesController extends BaseController implements NotificationCe
}
}
}
+ case "telegram_antispam_user_id": {
+ if (value.value instanceof TLRPC.TL_jsonString) {
+ TLRPC.TL_jsonString string = (TLRPC.TL_jsonString) value.value;
+ try {
+ long number = Long.parseLong(string.value);
+ if (number != telegramAntispamUserId) {
+ telegramAntispamUserId = number;
+ editor.putLong("telegramAntispamUserId", telegramAntispamUserId);
+ changed = true;
+ }
+ } catch (Exception e) {
+ FileLog.e(e);
+ }
+ }
+ }
+ case "telegram_antispam_group_size_min": {
+ if (value.value instanceof TLRPC.TL_jsonNumber) {
+ TLRPC.TL_jsonNumber number = (TLRPC.TL_jsonNumber) value.value;
+ if (number.value != telegramAntispamGroupSizeMin) {
+ telegramAntispamGroupSizeMin = (int) number.value;
+ editor.putInt("telegramAntispamGroupSizeMin", telegramAntispamGroupSizeMin);
+ changed = true;
+ }
+ }
+ }
}
}
if (changed) {
@@ -3029,7 +3065,6 @@ public class MessagesController extends BaseController implements NotificationCe
inputPeer.chat_id = -id;
}
} else {
- TLRPC.User user = getUser(id);
inputPeer = new TLRPC.TL_peerUser();
inputPeer.user_id = id;
}
@@ -3618,6 +3653,15 @@ public class MessagesController extends BaseController implements NotificationCe
return users.get(id);
}
+ public TLObject getUserOrChat(long dialogId) {
+ if (users.containsKey(dialogId)) {
+ return users.get(dialogId);
+ } else if (chats.containsKey(-dialogId)) {
+ return chats.get(-dialogId);
+ }
+ return null;
+ }
+
public TLObject getUserOrChat(String username) {
if (username == null || username.length() == 0) {
return null;
@@ -3982,7 +4026,9 @@ public class MessagesController extends BaseController implements NotificationCe
addOrRemoveActiveVoiceChat(chat);
}
if (oldChat != null && oldChat.forum != chat.forum) {
- getNotificationCenter().postNotificationName(NotificationCenter.chatSwithcedToForum, chat.id);
+ AndroidUtilities.runOnUIThread(() -> {
+ getNotificationCenter().postNotificationName(NotificationCenter.chatSwithcedToForum, chat.id);
+ });
}
}
@@ -4133,7 +4179,6 @@ public class MessagesController extends BaseController implements NotificationCe
if (did == 0 && (dialogs == null || dialogs.isEmpty())) {
return;
}
- //probably
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
if (dialogs != null) {
for (int a = 0; a < dialogs.size(); a++) {
@@ -4376,11 +4421,18 @@ public class MessagesController extends BaseController implements NotificationCe
getMediaDataController().getGroupStickerSetById(res.full_chat.stickerset);
}
getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, res.full_chat, classGuid, false, true);
- if ((res.full_chat.flags & 2048) != 0) {
- TLRPC.Dialog dialog = dialogs_dict.get(-chatId);
- if (dialog != null && dialog.folder_id != res.full_chat.folder_id) {
- dialog.folder_id = res.full_chat.folder_id;
- sortDialogs(null);
+
+ TLRPC.Dialog dialog = dialogs_dict.get(-chatId);
+ if (dialog != null) {
+ if ((res.full_chat.flags & 2048) != 0) {
+ if (dialog.folder_id != res.full_chat.folder_id) {
+ dialog.folder_id = res.full_chat.folder_id;
+ sortDialogs(null);
+ getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
+ }
+ }
+ if (dialog.ttl_period != res.full_chat.ttl_period) {
+ dialog.ttl_period = res.full_chat.ttl_period;
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
}
}
@@ -4456,13 +4508,18 @@ public class MessagesController extends BaseController implements NotificationCe
getNotificationCenter().postNotificationName(NotificationCenter.botInfoDidLoad, userFull.bot_info, classGuid);
}
getNotificationCenter().postNotificationName(NotificationCenter.userInfoDidLoad, user.id, userFull);
- if ((userFull.flags & 2048) != 0) {
- TLRPC.Dialog dialog = dialogs_dict.get(user.id);
- if (dialog != null && dialog.folder_id != userFull.folder_id) {
+
+ TLRPC.Dialog dialog = dialogs_dict.get(user.id);
+ if (dialog != null) {
+ if ((userFull.flags & 2048) != 0 && dialog.folder_id != userFull.folder_id) {
dialog.folder_id = userFull.folder_id;
sortDialogs(null);
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
}
+ if ((userFull.flags & 16384) != 0 && dialog.ttl_period != userFull.ttl_period) {
+ dialog.ttl_period = userFull.ttl_period;
+ getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
+ }
}
});
} else {
@@ -5892,28 +5949,31 @@ public class MessagesController extends BaseController implements NotificationCe
});
TLRPC.ChatFull chatFull = null;
TLRPC.UserFull userFull = null;
+ TLRPC.Dialog dialog = getMessagesController().dialogs_dict.get(did);
+ if (dialog != null) {
+ dialog.ttl_period = ttl;
+ }
+ getMessagesStorage().setDialogTtl(did, ttl);
if (did > 0) {
userFull = getUserFull(did);
- if (userFull == null) {
- return;
+ if (userFull != null) {
+ userFull.ttl_period = ttl;
+ userFull.flags |= 16384;
}
- userFull.ttl_period = ttl;
- userFull.flags |= 16384;
} else {
chatFull = getChatFull(-did);
- if (chatFull == null) {
- return;
- }
- chatFull.ttl_period = ttl;
- if (chatFull instanceof TLRPC.TL_channelFull) {
- chatFull.flags |= 16777216;
- } else {
- chatFull.flags |= 16384;
+ if (chatFull != null) {
+ chatFull.ttl_period = ttl;
+ if (chatFull instanceof TLRPC.TL_channelFull) {
+ chatFull.flags |= 16777216;
+ } else {
+ chatFull.flags |= 16384;
+ }
}
}
if (chatFull != null) {
getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, chatFull, 0, false, false);
- } else {
+ } else if (userFull != null) {
getNotificationCenter().postNotificationName(NotificationCenter.userInfoDidLoad, did, userFull);
}
}
@@ -6761,7 +6821,6 @@ public class MessagesController extends BaseController implements NotificationCe
chatsDict.put(c.id, c);
}
- //no
TLRPC.TL_messages_getPeerDialogs req1 = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer peer = new TLRPC.TL_inputDialogPeer();
if (res.peer.user_id != 0) {
@@ -7359,7 +7418,6 @@ public class MessagesController extends BaseController implements NotificationCe
getConnectionsManager().bindRequestToGuid(reqId, classGuid);
} else {
if (loadDialog && (load_type == 3 || load_type == 2) && last_message_id == 0) {
- //probably--
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.InputPeer inputPeer = getInputPeer(dialogId);
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
@@ -8126,7 +8184,6 @@ public class MessagesController extends BaseController implements NotificationCe
FileLog.d("load unknown dialog " + dialogId);
}
- //probably--
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = peer;
@@ -10162,10 +10219,14 @@ public class MessagesController extends BaseController implements NotificationCe
}
}
- public int createChat(String title, ArrayList selectedContacts, String about, int type, boolean forImport, Location location, String locationAddress, BaseFragment fragment) {
+ public int createChat(String title, ArrayList selectedContacts, String about, int type, boolean forImport, Location location, String locationAddress, int ttlPeriod, BaseFragment fragment) {
if (type == ChatObject.CHAT_TYPE_CHAT && !forImport) {
TLRPC.TL_messages_createChat req = new TLRPC.TL_messages_createChat();
req.title = title;
+ if (ttlPeriod > 0) {
+ req.ttl_period = ttlPeriod;
+ req.flags |= 1;
+ }
for (int a = 0; a < selectedContacts.size(); a++) {
TLRPC.User user = getUser(selectedContacts.get(a));
if (user == null) {
@@ -10690,6 +10751,78 @@ public class MessagesController extends BaseController implements NotificationCe
deleteParticipantFromChat(chatId, user, null, false, false);
}
+ public void deleteParticipantFromChat(long chatId, TLRPC.InputPeer peer) {
+ deleteParticipantFromChat(chatId, peer, false, false);
+ }
+
+ public void deleteParticipantFromChat(long chatId, TLRPC.InputPeer peer, boolean forceDelete, boolean revoke) {
+ if (peer == null) {
+ return;
+ }
+ TLObject request;
+ TLRPC.Chat ownerChat = getChat(chatId);
+ boolean self = peer instanceof TLRPC.TL_inputPeerUser && UserObject.isUserSelf(getMessagesController().getUser(peer.user_id));
+ boolean isChannel = ChatObject.isChannel(ownerChat);
+ if (isChannel) {
+ if (self) {
+ if (ownerChat.creator && forceDelete) {
+ TLRPC.TL_channels_deleteChannel req = new TLRPC.TL_channels_deleteChannel();
+ req.channel = getInputChannel(ownerChat);
+ request = req;
+ } else {
+ TLRPC.TL_channels_leaveChannel req = new TLRPC.TL_channels_leaveChannel();
+ req.channel = getInputChannel(ownerChat);
+ request = req;
+ }
+ } else {
+ TLRPC.TL_channels_editBanned req = new TLRPC.TL_channels_editBanned();
+ req.channel = getInputChannel(ownerChat);
+ req.participant = peer;
+ req.banned_rights = new TLRPC.TL_chatBannedRights();
+ req.banned_rights.view_messages = true;
+ req.banned_rights.send_media = true;
+ req.banned_rights.send_messages = true;
+ req.banned_rights.send_stickers = true;
+ req.banned_rights.send_gifs = true;
+ req.banned_rights.send_games = true;
+ req.banned_rights.send_inline = true;
+ req.banned_rights.embed_links = true;
+ req.banned_rights.pin_messages = true;
+ req.banned_rights.send_polls = true;
+ req.banned_rights.invite_users = true;
+ req.banned_rights.change_info = true;
+ request = req;
+ }
+ } else {
+ if (forceDelete) {
+ TLRPC.TL_messages_deleteChat req = new TLRPC.TL_messages_deleteChat();
+ req.chat_id = chatId;
+ getConnectionsManager().sendRequest(req, (response, error) -> {
+
+ });
+ return;
+ }
+ TLRPC.TL_messages_deleteChatUser req = new TLRPC.TL_messages_deleteChatUser();
+ req.chat_id = chatId;
+ req.user_id = (TLRPC.InputUser) getInputUser(peer);
+ req.revoke_history = true;
+ request = req;
+ }
+ if (self) {
+ deleteDialog(-chatId, 0, revoke);
+ }
+ getConnectionsManager().sendRequest(request, (response, error) -> {
+ if (error != null) {
+ return;
+ }
+ TLRPC.Updates updates = (TLRPC.Updates) response;
+ processUpdates(updates, false);
+ if (isChannel && !self) {
+ AndroidUtilities.runOnUIThread(() -> loadFullChat(chatId, 0, true), 1000);
+ }
+ }, ConnectionsManager.RequestFlagInvokeAfter);
+ }
+
public void deleteParticipantFromChat(long chatId, TLRPC.User user, TLRPC.Chat chat, boolean forceDelete, boolean revoke) {
if (user == null && chat == null) {
return;
@@ -11272,7 +11405,6 @@ public class MessagesController extends BaseController implements NotificationCe
gettingUnknownChannels.put(channel.id, true);
- //no
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = inputPeer;
@@ -15047,6 +15179,7 @@ public class MessagesController extends BaseController implements NotificationCe
long peerId = MessageObject.getPeerId(updatePeerHistoryTTL.peer);
TLRPC.ChatFull chatFull = null;
TLRPC.UserFull userFull = null;
+
if (peerId > 0) {
userFull = getUserFull(peerId);
if (userFull != null) {
@@ -15083,6 +15216,12 @@ public class MessagesController extends BaseController implements NotificationCe
getNotificationCenter().postNotificationName(NotificationCenter.userInfoDidLoad, peerId, userFull);
getMessagesStorage().updateUserInfo(userFull, false);
}
+ getMessagesStorage().setDialogTtl(peerId, updatePeerHistoryTTL.ttl_period);
+ TLRPC.Dialog dialog = dialogs_dict.get(peerId);
+ if (dialog != null) {
+ dialog.ttl_period = updatePeerHistoryTTL.ttl_period;
+ getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, 0);
+ }
} else if (baseUpdate instanceof TLRPC.TL_updatePendingJoinRequests) {
TLRPC.TL_updatePendingJoinRequests update = (TLRPC.TL_updatePendingJoinRequests) baseUpdate;
getMemberRequestsController().onPendingRequestsUpdated(update);
@@ -15573,7 +15712,6 @@ public class MessagesController extends BaseController implements NotificationCe
}
if (needReload) {
if (topicId == 0) {
- //no
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = getInputPeer(dialogId);
@@ -16744,7 +16882,7 @@ public class MessagesController extends BaseController implements NotificationCe
});
}
- public void checkIsInChat(TLRPC.Chat chat, TLRPC.User user, IsInChatCheckedCallback callback) {
+ public void checkIsInChat(boolean tryCacheFirst, TLRPC.Chat chat, TLRPC.User user, IsInChatCheckedCallback callback) {
if (chat == null || user == null) {
if (callback != null) {
callback.run(false, null, null);
@@ -16752,6 +16890,30 @@ public class MessagesController extends BaseController implements NotificationCe
return;
}
if (chat.megagroup || ChatObject.isChannel(chat)) {
+ if (tryCacheFirst) {
+ TLRPC.ChatFull chatFull = getChatFull(chat.id);
+ if (chatFull != null) {
+ TLRPC.ChatParticipant userParticipant = null;
+ if (chatFull.participants != null && chatFull.participants.participants != null) {
+ final int count = chatFull.participants.participants.size();
+ for (int i = 0; i < count; ++i) {
+ TLRPC.ChatParticipant participant = chatFull.participants.participants.get(i);
+ if (participant != null && participant.user_id == user.id) {
+ userParticipant = participant;
+ break;
+ }
+ }
+ }
+ if (callback != null && userParticipant != null) {
+ callback.run(
+ userParticipant != null,
+ chatFull.participants != null && chatFull.participants.admin_id == user.id ? ChatRightsEditActivity.emptyAdminRights(true) : null,
+ null
+ );
+ return;
+ }
+ }
+ }
TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
req.channel = getInputChannel(chat.id);
req.participant = getInputPeer(user);
@@ -16781,9 +16943,9 @@ public class MessagesController extends BaseController implements NotificationCe
}
if (callback != null) {
callback.run(
- userParticipant != null,
- chatFull.participants != null && chatFull.participants.admin_id == user.id ? ChatRightsEditActivity.emptyAdminRights(true) : null,
- null
+ userParticipant != null,
+ chatFull.participants != null && chatFull.participants.admin_id == user.id ? ChatRightsEditActivity.emptyAdminRights(true) : null,
+ null
);
}
} else {
@@ -16874,4 +17036,38 @@ public class MessagesController extends BaseController implements NotificationCe
return unreadCount;
}
+ private boolean requestingContactToken;
+ private TLRPC.TL_exportedContactToken cachedContactToken;
+ public TLRPC.TL_exportedContactToken getCachedContactToken() {
+ if (cachedContactToken != null && cachedContactToken.expires > System.currentTimeMillis() / 1000) {
+ return cachedContactToken;
+ }
+ return null;
+ }
+ public void requestContactToken(Utilities.Callback callback) {
+ requestContactToken(0, callback);
+ }
+ public void requestContactToken(long minDuration, Utilities.Callback callback) {
+ if (callback == null || requestingContactToken) {
+ return;
+ }
+ if (cachedContactToken != null && cachedContactToken.expires > System.currentTimeMillis() / 1000) {
+ callback.run(cachedContactToken);
+ return;
+ }
+ requestingContactToken = true;
+ final long start = System.currentTimeMillis();
+ getConnectionsManager().sendRequest(new TLRPC.TL_contacts_exportContactToken(), (res, err) -> {
+ if (res instanceof TLRPC.TL_exportedContactToken) {
+ cachedContactToken = (TLRPC.TL_exportedContactToken) res;
+ AndroidUtilities.runOnUIThread(() -> {
+ callback.run(cachedContactToken);
+ requestingContactToken = false;
+ }, Math.max(0, minDuration - (System.currentTimeMillis() - start)));
+ } else {
+ requestingContactToken = false;
+ }
+ });
+ }
+
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java
index 3d0c6eb00..6d89856d6 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java
@@ -93,7 +93,7 @@ public class MessagesStorage extends BaseController {
}
}
- private final static int LAST_DB_VERSION = 107;
+ private final static int LAST_DB_VERSION = 110;
private boolean databaseMigrationInProgress;
public boolean showClearDatabaseAlert;
private LongSparseIntArray dialogIsForum = new LongSparseIntArray();
@@ -200,7 +200,6 @@ public class MessagesStorage extends BaseController {
public MessagesStorage(int instance) {
super(instance);
storageQueue = new DispatchQueue("storageQueue_" + instance);
- //storageQueue.setPriority(Thread.MAX_PRIORITY);
storageQueue.postRunnable(() -> openDatabase(1));
}
@@ -315,7 +314,7 @@ public class MessagesStorage extends BaseController {
database.executeFast("CREATE TABLE user_phones_v7(key TEXT, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (key, phone))").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v7(sphone, deleted);").stepThis().dispose();
- database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER, inbox_max INTEGER, outbox_max INTEGER, last_mid_i INTEGER, unread_count_i INTEGER, pts INTEGER, date_i INTEGER, pinned INTEGER, flags INTEGER, folder_id INTEGER, data BLOB, unread_reactions INTEGER, last_mid_group INTEGER)").stepThis().dispose();
+ database.executeFast("CREATE TABLE dialogs(did INTEGER PRIMARY KEY, date INTEGER, unread_count INTEGER, last_mid INTEGER, inbox_max INTEGER, outbox_max INTEGER, last_mid_i INTEGER, unread_count_i INTEGER, pts INTEGER, date_i INTEGER, pinned INTEGER, flags INTEGER, folder_id INTEGER, data BLOB, unread_reactions INTEGER, last_mid_group INTEGER, ttl_period INTEGER)").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_dialogs ON dialogs(date);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_idx_dialogs ON dialogs(last_mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose();
@@ -438,7 +437,7 @@ public class MessagesStorage extends BaseController {
database.executeFast("CREATE TABLE media_holes_topics(uid INTEGER, topic_id INTEGER, type INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, topic_id, type, start));").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_media_holes_topics ON media_holes_topics(uid, topic_id, type, end);").stepThis().dispose();
- database.executeFast("CREATE TABLE topics(did INTEGER, topic_id INTEGER, data BLOB, top_message INTEGER, topic_message BLOB, unread_count INTEGER, max_read_id INTEGER, unread_mentions INTEGER, unread_reactions INTEGER, read_outbox INTEGER, pinned INTEGER, PRIMARY KEY(did, topic_id));").stepThis().dispose();
+ database.executeFast("CREATE TABLE topics(did INTEGER, topic_id INTEGER, data BLOB, top_message INTEGER, topic_message BLOB, unread_count INTEGER, max_read_id INTEGER, unread_mentions INTEGER, unread_reactions INTEGER, read_outbox INTEGER, pinned INTEGER, total_messages_count INTEGER, hidden INTEGER, PRIMARY KEY(did, topic_id));").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS did_top_message_topics ON topics(did, top_message);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS did_topics ON topics(did);").stepThis().dispose();
@@ -554,1196 +553,16 @@ public class MessagesStorage extends BaseController {
int version = currentVersion;
FileLog.d("MessagesStorage start db migration from " + version + " to " + LAST_DB_VERSION);
- if (version < 4) {
- database.executeFast("CREATE TABLE IF NOT EXISTS user_photos(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose();
+ version = DatabaseMigrationHelper.migrate(MessagesStorage.this, version);
- database.executeFast("DROP INDEX IF EXISTS read_state_out_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS ttl_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS date_idx_messages;").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages ON messages(mid, out);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages ON messages(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages ON messages(uid, date, mid);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS sent_files_v2(uid TEXT, type INTEGER, data BLOB, PRIMARY KEY (uid, type))").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS download_queue(uid INTEGER, type INTEGER, date INTEGER, data BLOB, PRIMARY KEY (uid, type));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS type_date_idx_download_queue ON download_queue(type, date);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS dialog_settings(did INTEGER PRIMARY KEY, flags INTEGER);").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose();
-
- database.executeFast("UPDATE messages SET send_state = 2 WHERE mid < 0 AND send_state = 1").stepThis().dispose();
-
- fixNotificationSettings();
- database.executeFast("PRAGMA user_version = 4").stepThis().dispose();
- version = 4;
- }
- if (version == 4) {
- database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v2(mid INTEGER PRIMARY KEY, date INTEGER)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v2 ON enc_tasks_v2(date);").stepThis().dispose();
- database.beginTransaction();
- SQLiteCursor cursor = database.queryFinalized("SELECT date, data FROM enc_tasks WHERE 1");
- SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_tasks_v2 VALUES(?, ?)");
- if (cursor.next()) {
- int date = cursor.intValue(0);
- NativeByteBuffer data = cursor.byteBufferValue(1);
- if (data != null) {
- int length = data.limit();
- for (int a = 0; a < length / 4; a++) {
- state.requery();
- state.bindInteger(1, data.readInt32(false));
- state.bindInteger(2, date);
- state.step();
- }
- data.reuse();
- }
- }
- state.dispose();
- cursor.dispose();
- database.commitTransaction();
-
- database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS enc_tasks;").stepThis().dispose();
-
- database.executeFast("ALTER TABLE messages ADD COLUMN media INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 6").stepThis().dispose();
- version = 6;
- }
- if (version == 6) {
- database.executeFast("CREATE TABLE IF NOT EXISTS messages_seq(mid INTEGER PRIMARY KEY, seq_in INTEGER, seq_out INTEGER);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS seq_idx_messages_seq ON messages_seq(seq_in, seq_out);").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN layer INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_in INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN seq_out INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 7").stepThis().dispose();
- version = 7;
- }
- if (version == 7 || version == 8 || version == 9) {
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN use_count INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN exchange_id INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN key_date INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN fprint INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN fauthkey BLOB default NULL").stepThis().dispose();
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN khash BLOB default NULL").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 10").stepThis().dispose();
- version = 10;
- }
- if (version == 10) {
- database.executeFast("CREATE TABLE IF NOT EXISTS web_recent_v3(id TEXT, type INTEGER, image_url TEXT, thumb_url TEXT, local_url TEXT, width INTEGER, height INTEGER, size INTEGER, date INTEGER, PRIMARY KEY (id, type));").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 11").stepThis().dispose();
- version = 11;
- }
- if (version == 11 || version == 12) {
- database.executeFast("DROP INDEX IF EXISTS uid_mid_idx_media;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS mid_idx_media;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_date_mid_idx_media;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS media;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS media_counts;").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS media_v2(mid INTEGER PRIMARY KEY, uid INTEGER, date INTEGER, type INTEGER, data BLOB)").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS media_counts_v2(uid INTEGER, type INTEGER, count INTEGER, PRIMARY KEY(uid, type))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media ON media_v2(uid, mid, type, date);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
- version = 13;
- }
- if (version == 13) {
- database.executeFast("ALTER TABLE messages ADD COLUMN replydata BLOB default NULL").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 14").stepThis().dispose();
- version = 14;
- }
- if (version == 14) {
- database.executeFast("CREATE TABLE IF NOT EXISTS hashtag_recent_v2(id TEXT PRIMARY KEY, date INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 15").stepThis().dispose();
- version = 15;
- }
- if (version == 15) {
- database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
- version = 16;
- }
- if (version == 16) {
- database.executeFast("ALTER TABLE dialogs ADD COLUMN inbox_max INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN outbox_max INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 17").stepThis().dispose();
- version = 17;
- }
- if (version == 17) {
- database.executeFast("PRAGMA user_version = 18").stepThis().dispose();
- version = 18;
- }
- if (version == 18) {
- database.executeFast("DROP TABLE IF EXISTS stickers;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS stickers_v2(id INTEGER PRIMARY KEY, data BLOB, date INTEGER, hash INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 19").stepThis().dispose();
- version = 19;
- }
- if (version == 19) {
- database.executeFast("CREATE TABLE IF NOT EXISTS bot_keyboard(uid INTEGER PRIMARY KEY, mid INTEGER, info BLOB)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS bot_keyboard_idx_mid ON bot_keyboard(mid);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 20").stepThis().dispose();
- version = 20;
- }
- if (version == 20) {
- database.executeFast("CREATE TABLE search_recent(did INTEGER PRIMARY KEY, date INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 21").stepThis().dispose();
- version = 21;
- }
- if (version == 21) {
- database.executeFast("CREATE TABLE IF NOT EXISTS chat_settings_v2(uid INTEGER PRIMARY KEY, info BLOB)").stepThis().dispose();
-
- SQLiteCursor cursor = database.queryFinalized("SELECT uid, participants FROM chat_settings WHERE uid < 0");
- SQLitePreparedStatement state = database.executeFast("REPLACE INTO chat_settings_v2 VALUES(?, ?)");
- while (cursor.next()) {
- long chatId = cursor.intValue(0);
- NativeByteBuffer data = cursor.byteBufferValue(1);
- if (data != null) {
- TLRPC.ChatParticipants participants = TLRPC.ChatParticipants.TLdeserialize(data, data.readInt32(false), false);
- data.reuse();
- if (participants != null) {
- TLRPC.TL_chatFull chatFull = new TLRPC.TL_chatFull();
- chatFull.id = chatId;
- chatFull.chat_photo = new TLRPC.TL_photoEmpty();
- chatFull.notify_settings = new TLRPC.TL_peerNotifySettingsEmpty_layer77();
- chatFull.exported_invite = null;
- chatFull.participants = participants;
- NativeByteBuffer data2 = new NativeByteBuffer(chatFull.getObjectSize());
- chatFull.serializeToStream(data2);
- state.requery();
- state.bindLong(1, chatId);
- state.bindByteBuffer(2, data2);
- state.step();
- data2.reuse();
- }
- }
- }
- state.dispose();
- cursor.dispose();
-
- database.executeFast("DROP TABLE IF EXISTS chat_settings;").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN last_mid_i INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN unread_count_i INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN pts INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN date_i INTEGER default 0").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_i_idx_dialogs ON dialogs(last_mid_i);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_i_idx_dialogs ON dialogs(unread_count_i);").stepThis().dispose();
- database.executeFast("ALTER TABLE messages ADD COLUMN imp INTEGER default 0").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS messages_holes(uid INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, start));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_messages_holes ON messages_holes(uid, end);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 22").stepThis().dispose();
- version = 22;
- }
- if (version == 22) {
- database.executeFast("CREATE TABLE IF NOT EXISTS media_holes_v2(uid INTEGER, type INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, type, start));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_media_holes_v2 ON media_holes_v2(uid, type, end);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 23").stepThis().dispose();
- version = 23;
- }
- if (version == 23 || version == 24) {
- database.executeFast("DELETE FROM media_holes_v2 WHERE uid != 0 AND type >= 0 AND start IN (0, 1)").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 25").stepThis().dispose();
- version = 25;
- }
- if (version == 25 || version == 26) {
- database.executeFast("CREATE TABLE IF NOT EXISTS channel_users_v2(did INTEGER, uid INTEGER, date INTEGER, data BLOB, PRIMARY KEY(did, uid))").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 27").stepThis().dispose();
- version = 27;
- }
- if (version == 27) {
- database.executeFast("ALTER TABLE web_recent_v3 ADD COLUMN document BLOB default NULL").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 28").stepThis().dispose();
- version = 28;
- }
- if (version == 28 || version == 29) {
- database.executeFast("DELETE FROM sent_files_v2 WHERE 1").stepThis().dispose();
- database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 30").stepThis().dispose();
- version = 30;
- }
- if (version == 30) {
- database.executeFast("ALTER TABLE chat_settings_v2 ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS chat_settings_pinned_idx ON chat_settings_v2(uid, pinned) WHERE pinned != 0;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS users_data(uid INTEGER PRIMARY KEY, about TEXT)").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 31").stepThis().dispose();
- version = 31;
- }
- if (version == 31) {
- database.executeFast("DROP TABLE IF EXISTS bot_recent;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS chat_hints(did INTEGER, type INTEGER, rating REAL, date INTEGER, PRIMARY KEY(did, type))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS chat_hints_rating_idx ON chat_hints(rating);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 32").stepThis().dispose();
- version = 32;
- }
- if (version == 32) {
- database.executeFast("DROP INDEX IF EXISTS uid_mid_idx_imp_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_date_mid_imp_idx_messages;").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 33").stepThis().dispose();
- version = 33;
- }
- if (version == 33) {
- database.executeFast("CREATE TABLE IF NOT EXISTS pending_tasks(id INTEGER PRIMARY KEY, data BLOB);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 34").stepThis().dispose();
- version = 34;
- }
- if (version == 34) {
- database.executeFast("CREATE TABLE IF NOT EXISTS stickers_featured(id INTEGER PRIMARY KEY, data BLOB, unread BLOB, date INTEGER, hash INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 35").stepThis().dispose();
- version = 35;
- }
- if (version == 35) {
- database.executeFast("CREATE TABLE IF NOT EXISTS requested_holes(uid INTEGER, seq_out_start INTEGER, seq_out_end INTEGER, PRIMARY KEY (uid, seq_out_start, seq_out_end));").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 36").stepThis().dispose();
- version = 36;
- }
- if (version == 36) {
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN in_seq_no INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 37").stepThis().dispose();
- version = 37;
- }
- if (version == 37) {
- database.executeFast("CREATE TABLE IF NOT EXISTS botcache(id TEXT PRIMARY KEY, date INTEGER, data BLOB)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS botcache_date_idx ON botcache(date);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 38").stepThis().dispose();
- version = 38;
- }
- if (version == 38) {
- database.executeFast("ALTER TABLE dialogs ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 39").stepThis().dispose();
- version = 39;
- }
- if (version == 39) {
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN admin_id INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 40").stepThis().dispose();
- version = 40;
- }
- if (version == 40) {
- fixNotificationSettings();
- database.executeFast("PRAGMA user_version = 41").stepThis().dispose();
- version = 41;
- }
- if (version == 41) {
- database.executeFast("ALTER TABLE messages ADD COLUMN mention INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE user_contacts_v6 ADD COLUMN imported INTEGER default 0").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages ON messages(uid, mention, read_state);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 42").stepThis().dispose();
- version = 42;
- }
- if (version == 42) {
- database.executeFast("CREATE TABLE IF NOT EXISTS sharing_locations(uid INTEGER PRIMARY KEY, mid INTEGER, date INTEGER, period INTEGER, message BLOB);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 43").stepThis().dispose();
- version = 43;
- }
- if (version == 43) {
- database.executeFast("PRAGMA user_version = 44").stepThis().dispose();
- version = 44;
- }
- if (version == 44) {
- database.executeFast("CREATE TABLE IF NOT EXISTS user_contacts_v7(key TEXT PRIMARY KEY, uid INTEGER, fname TEXT, sname TEXT, imported INTEGER)").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS user_phones_v7(key TEXT, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (key, phone))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v7(sphone, deleted);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 45").stepThis().dispose();
- version = 45;
- }
- if (version == 45) {
- database.executeFast("ALTER TABLE enc_chats ADD COLUMN mtproto_seq INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 46").stepThis().dispose();
- version = 46;
- }
- if (version == 46) {
- database.executeFast("DELETE FROM botcache WHERE 1").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 47").stepThis().dispose();
- version = 47;
- }
- if (version == 47) {
- database.executeFast("ALTER TABLE dialogs ADD COLUMN flags INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 48").stepThis().dispose();
- version = 48;
- }
- if (version == 48) {
- database.executeFast("CREATE TABLE IF NOT EXISTS unread_push_messages(uid INTEGER, mid INTEGER, random INTEGER, date INTEGER, data BLOB, fm TEXT, name TEXT, uname TEXT, flags INTEGER, PRIMARY KEY(uid, mid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS unread_push_messages_idx_date ON unread_push_messages(date);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS unread_push_messages_idx_random ON unread_push_messages(random);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 49").stepThis().dispose();
- version = 49;
- }
- if (version == 49) {
- database.executeFast("CREATE TABLE IF NOT EXISTS user_settings(uid INTEGER PRIMARY KEY, info BLOB, pinned INTEGER)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS user_settings_pinned_idx ON user_settings(uid, pinned) WHERE pinned != 0;").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 50").stepThis().dispose();
- version = 50;
- }
- if (version == 50) {
- database.executeFast("DELETE FROM sent_files_v2 WHERE 1").stepThis().dispose();
- database.executeFast("ALTER TABLE sent_files_v2 ADD COLUMN parent TEXT").stepThis().dispose();
- database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
- database.executeFast("ALTER TABLE download_queue ADD COLUMN parent TEXT").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 51").stepThis().dispose();
- version = 51;
- }
- if (version == 51) {
- database.executeFast("ALTER TABLE media_counts_v2 ADD COLUMN old INTEGER").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 52").stepThis().dispose();
- version = 52;
- }
- if (version == 52) {
- database.executeFast("CREATE TABLE IF NOT EXISTS polls_v2(mid INTEGER, uid INTEGER, id INTEGER, PRIMARY KEY (mid, uid));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS polls_id ON polls_v2(id);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 53").stepThis().dispose();
- version = 53;
- }
- if (version == 53) {
- database.executeFast("ALTER TABLE chat_settings_v2 ADD COLUMN online INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 54").stepThis().dispose();
- version = 54;
- }
- if (version == 54) {
- database.executeFast("DROP TABLE IF EXISTS wallpapers;").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 55").stepThis().dispose();
- version = 55;
- }
- if (version == 55) {
- database.executeFast("CREATE TABLE IF NOT EXISTS wallpapers2(uid INTEGER PRIMARY KEY, data BLOB, num INTEGER)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS wallpapers_num ON wallpapers2(num);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 56").stepThis().dispose();
- version = 56;
- }
- if (version == 56 || version == 57) {
- database.executeFast("CREATE TABLE IF NOT EXISTS emoji_keywords_v2(lang TEXT, keyword TEXT, emoji TEXT, PRIMARY KEY(lang, keyword, emoji));").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS emoji_keywords_info_v2(lang TEXT PRIMARY KEY, alias TEXT, version INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 58").stepThis().dispose();
- version = 58;
- }
- if (version == 58) {
- database.executeFast("CREATE INDEX IF NOT EXISTS emoji_keywords_v2_keyword ON emoji_keywords_v2(keyword);").stepThis().dispose();
- database.executeFast("ALTER TABLE emoji_keywords_info_v2 ADD COLUMN date INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 59").stepThis().dispose();
- version = 59;
- }
- if (version == 59) {
- database.executeFast("ALTER TABLE dialogs ADD COLUMN folder_id INTEGER default 0").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN data BLOB default NULL").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS folder_id_idx_dialogs ON dialogs(folder_id);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 60").stepThis().dispose();
- version = 60;
- }
- if (version == 60) {
- database.executeFast("DROP TABLE IF EXISTS channel_admins;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS blocked_users;").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 61").stepThis().dispose();
- version = 61;
- }
- if (version == 61) {
- database.executeFast("DROP INDEX IF EXISTS send_state_idx_messages;").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages2 ON messages(mid, send_state, date);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 62").stepThis().dispose();
- version = 62;
- }
- if (version == 62) {
- database.executeFast("CREATE TABLE IF NOT EXISTS scheduled_messages(mid INTEGER PRIMARY KEY, uid INTEGER, send_state INTEGER, date INTEGER, data BLOB, ttl INTEGER, replydata BLOB)").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_scheduled_messages ON scheduled_messages(mid, send_state, date);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_idx_scheduled_messages ON scheduled_messages(uid, date);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 63").stepThis().dispose();
- version = 63;
- }
- if (version == 63) {
- database.executeFast("DELETE FROM download_queue WHERE 1").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 64").stepThis().dispose();
- version = 64;
- }
- if (version == 64) {
- database.executeFast("CREATE TABLE IF NOT EXISTS dialog_filter(id INTEGER PRIMARY KEY, ord INTEGER, unread_count INTEGER, flags INTEGER, title TEXT)").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS dialog_filter_ep(id INTEGER, peer INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 65").stepThis().dispose();
- version = 65;
- }
- if (version == 65) {
- database.executeFast("CREATE INDEX IF NOT EXISTS flags_idx_dialogs ON dialogs(flags);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 66").stepThis().dispose();
- version = 66;
- }
- if (version == 66) {
- database.executeFast("CREATE TABLE dialog_filter_pin_v2(id INTEGER, peer INTEGER, pin INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 67").stepThis().dispose();
- version = 67;
- }
- if (version == 67) {
- database.executeFast("CREATE TABLE IF NOT EXISTS stickers_dice(emoji TEXT PRIMARY KEY, data BLOB, date INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 68").stepThis().dispose();
- version = 68;
- }
- if (version == 68) {
- executeNoException("ALTER TABLE messages ADD COLUMN forwards INTEGER default 0");
- database.executeFast("PRAGMA user_version = 69").stepThis().dispose();
- version = 69;
- }
- if (version == 69) {
- executeNoException("ALTER TABLE messages ADD COLUMN replies_data BLOB default NULL");
- executeNoException("ALTER TABLE messages ADD COLUMN thread_reply_id INTEGER default 0");
- database.executeFast("PRAGMA user_version = 70").stepThis().dispose();
- version = 70;
- }
- if (version == 70) {
- database.executeFast("CREATE TABLE IF NOT EXISTS chat_pinned_v2(uid INTEGER, mid INTEGER, data BLOB, PRIMARY KEY (uid, mid));").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 71").stepThis().dispose();
- version = 71;
- }
- if (version == 71) {
- executeNoException("ALTER TABLE sharing_locations ADD COLUMN proximity INTEGER default 0");
- database.executeFast("PRAGMA user_version = 72").stepThis().dispose();
- version = 72;
- }
- if (version == 72) {
- database.executeFast("CREATE TABLE IF NOT EXISTS chat_pinned_count(uid INTEGER PRIMARY KEY, count INTEGER, end INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 73").stepThis().dispose();
- version = 73;
- }
- if (version == 73) {
- executeNoException("ALTER TABLE chat_settings_v2 ADD COLUMN inviter INTEGER default 0");
- database.executeFast("PRAGMA user_version = 74").stepThis().dispose();
- version = 74;
- }
- if (version == 74) {
- database.executeFast("CREATE TABLE IF NOT EXISTS shortcut_widget(id INTEGER, did INTEGER, ord INTEGER, PRIMARY KEY (id, did));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS shortcut_widget_did ON shortcut_widget(did);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 75").stepThis().dispose();
- version = 75;
- }
- if (version == 75) {
- executeNoException("ALTER TABLE chat_settings_v2 ADD COLUMN links INTEGER default 0");
- database.executeFast("PRAGMA user_version = 76").stepThis().dispose();
- version = 76;
- }
- if (version == 76) {
- executeNoException("ALTER TABLE enc_tasks_v2 ADD COLUMN media INTEGER default -1");
- database.executeFast("PRAGMA user_version = 77").stepThis().dispose();
- version = 77;
- }
- if (version == 77) {
- database.executeFast("DROP TABLE IF EXISTS channel_admins_v2;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS channel_admins_v3(did INTEGER, uid INTEGER, data BLOB, PRIMARY KEY(did, uid))").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 78").stepThis().dispose();
- version = 78;
- }
- if (version == 78) {
- database.executeFast("DROP TABLE IF EXISTS bot_info;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS bot_info_v2(uid INTEGER, dialogId INTEGER, info BLOB, PRIMARY KEY(uid, dialogId))").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 79").stepThis().dispose();
- version = 79;
- }
- if (version == 79) {
- database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v3(mid INTEGER, date INTEGER, media INTEGER, PRIMARY KEY(mid, media))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v3 ON enc_tasks_v3(date);").stepThis().dispose();
-
- database.beginTransaction();
- SQLiteCursor cursor = database.queryFinalized("SELECT mid, date, media FROM enc_tasks_v2 WHERE 1");
- SQLitePreparedStatement state = database.executeFast("REPLACE INTO enc_tasks_v3 VALUES(?, ?, ?)");
- if (cursor.next()) {
- long mid = cursor.longValue(0);
- int date = cursor.intValue(1);
- int media = cursor.intValue(2);
-
- state.requery();
- state.bindLong(1, mid);
- state.bindInteger(2, date);
- state.bindInteger(3, media);
- state.step();
- }
- state.dispose();
- cursor.dispose();
- database.commitTransaction();
-
- database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks_v2;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS enc_tasks_v2;").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 80").stepThis().dispose();
- version = 80;
- }
- if (version == 80) {
- database.executeFast("CREATE TABLE IF NOT EXISTS scheduled_messages_v2(mid INTEGER, uid INTEGER, send_state INTEGER, date INTEGER, data BLOB, ttl INTEGER, replydata BLOB, PRIMARY KEY(mid, uid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_scheduled_messages_v2 ON scheduled_messages_v2(mid, send_state, date);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_idx_scheduled_messages_v2 ON scheduled_messages_v2(uid, date);").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS bot_keyboard_idx_mid_v2 ON bot_keyboard(mid, uid);").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS bot_keyboard_idx_mid;").stepThis().dispose();
-
- database.beginTransaction();
- SQLiteCursor cursor;
- try {
- cursor = database.queryFinalized("SELECT mid, uid, send_state, date, data, ttl, replydata FROM scheduled_messages_v2 WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO scheduled_messages_v2 VALUES(?, ?, ?, ?, ?, ?, ?)");
- while (cursor.next()) {
- NativeByteBuffer data = cursor.byteBufferValue(4);
- if (data == null) {
- continue;
- }
- int mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- int sendState = cursor.intValue(2);
- int date = cursor.intValue(3);
- int ttl = cursor.intValue(5);
- NativeByteBuffer replydata = cursor.byteBufferValue(6);
-
- statement.requery();
- statement.bindInteger(1, mid);
- statement.bindLong(2, uid);
- statement.bindInteger(3, sendState);
- statement.bindByteBuffer(4, data);
- statement.bindInteger(5, date);
- statement.bindInteger(6, ttl);
- if (replydata != null) {
- statement.bindByteBuffer(7, replydata);
- } else {
- statement.bindNull(7);
- }
- statement.step();
- if (replydata != null) {
- replydata.reuse();
- }
- data.reuse();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- database.executeFast("DROP INDEX IF EXISTS send_state_idx_scheduled_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_date_idx_scheduled_messages;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS scheduled_messages;").stepThis().dispose();
-
- database.commitTransaction();
- database.executeFast("PRAGMA user_version = 81").stepThis().dispose();
- version = 81;
- }
- if (version == 81) {
- database.executeFast("CREATE TABLE IF NOT EXISTS media_v3(mid INTEGER, uid INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_v3 ON media_v3(uid, mid, type, date);").stepThis().dispose();
-
- database.beginTransaction();
- SQLiteCursor cursor;
- try {
- cursor = database.queryFinalized("SELECT mid, uid, date, type, data FROM media_v2 WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO media_v3 VALUES(?, ?, ?, ?, ?)");
- while (cursor.next()) {
- NativeByteBuffer data = cursor.byteBufferValue(4);
- if (data == null) {
- continue;
- }
- int mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
- int date = cursor.intValue(2);
- int type = cursor.intValue(3);
-
- statement.requery();
- statement.bindInteger(1, mid);
- statement.bindLong(2, uid);
- statement.bindInteger(3, date);
- statement.bindInteger(4, type);
- statement.bindByteBuffer(5, data);
- statement.step();
- data.reuse();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- database.executeFast("DROP INDEX IF EXISTS uid_mid_type_date_idx_media;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS media_v2;").stepThis().dispose();
- database.commitTransaction();
-
- database.executeFast("PRAGMA user_version = 82").stepThis().dispose();
- version = 82;
- }
- if (version == 82) {
- database.executeFast("CREATE TABLE IF NOT EXISTS randoms_v2(random_id INTEGER, mid INTEGER, uid INTEGER, PRIMARY KEY (random_id, mid, uid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms_v2 ON randoms_v2(mid, uid);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v4(mid INTEGER, uid INTEGER, date INTEGER, media INTEGER, PRIMARY KEY(mid, uid, media))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v4 ON enc_tasks_v4(date);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS polls_v2(mid INTEGER, uid INTEGER, id INTEGER, PRIMARY KEY (mid, uid));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS polls_id_v2 ON polls_v2(id);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending_v2(id INTEGER, mid INTEGER, uid INTEGER, PRIMARY KEY (id, mid, uid));").stepThis().dispose();
-
- database.beginTransaction();
-
- SQLiteCursor cursor;
- try {
- cursor = database.queryFinalized("SELECT r.random_id, r.mid, m.uid FROM randoms as r INNER JOIN messages as m ON r.mid = m.mid WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO randoms_v2 VALUES(?, ?, ?)");
- while (cursor.next()) {
- long randomId = cursor.longValue(0);
- int mid = cursor.intValue(1);
- long uid = cursor.longValue(2);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
-
- statement.requery();
- statement.bindLong(1, randomId);
- statement.bindInteger(2, mid);
- statement.bindLong(3, uid);
- statement.step();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- try {
- cursor = database.queryFinalized("SELECT p.mid, m.uid, p.id FROM polls as p INNER JOIN messages as m ON p.mid = m.mid WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO polls_v2 VALUES(?, ?, ?)");
- while (cursor.next()) {
- int mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- long id = cursor.longValue(2);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
-
- statement.requery();
- statement.bindInteger(1, mid);
- statement.bindLong(2, uid);
- statement.bindLong(3, id);
- statement.step();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- try {
- cursor = database.queryFinalized("SELECT wp.id, wp.mid, m.uid FROM webpage_pending as wp INNER JOIN messages as m ON wp.mid = m.mid WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO webpage_pending_v2 VALUES(?, ?, ?)");
- while (cursor.next()) {
- long id = cursor.longValue(0);
- int mid = cursor.intValue(1);
- long uid = cursor.longValue(2);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
-
- statement.requery();
- statement.bindLong(1, id);
- statement.bindInteger(2, mid);
- statement.bindLong(3, uid);
- statement.step();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- try {
- cursor = database.queryFinalized("SELECT et.mid, m.uid, et.date, et.media FROM enc_tasks_v3 as et INNER JOIN messages as m ON et.mid = m.mid WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO enc_tasks_v4 VALUES(?, ?, ?, ?)");
- while (cursor.next()) {
- int mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- int date = cursor.intValue(2);
- int media = cursor.intValue(3);
-
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
-
- statement.requery();
- statement.bindInteger(1, mid);
- statement.bindLong(2, uid);
- statement.bindInteger(3, date);
- statement.bindInteger(4, media);
- statement.step();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- database.executeFast("DROP INDEX IF EXISTS mid_idx_randoms;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS randoms;").stepThis().dispose();
-
- database.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks_v3;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS enc_tasks_v3;").stepThis().dispose();
-
- database.executeFast("DROP INDEX IF EXISTS polls_id;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS polls;").stepThis().dispose();
-
- database.executeFast("DROP TABLE IF EXISTS webpage_pending;").stepThis().dispose();
- database.commitTransaction();
-
- database.executeFast("PRAGMA user_version = 83").stepThis().dispose();
- version = 83;
- }
- if (version == 83) {
- database.executeFast("CREATE TABLE IF NOT EXISTS messages_v2(mid INTEGER, uid INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER, replydata BLOB, imp INTEGER, mention INTEGER, forwards INTEGER, replies_data BLOB, thread_reply_id INTEGER, is_channel INTEGER, PRIMARY KEY(mid, uid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_v2 ON messages_v2(uid, mid, read_state, out);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages_v2 ON messages_v2(uid, date, mid);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages_v2 ON messages_v2(mid, out);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages_v2 ON messages_v2(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages_v2 ON messages_v2(mid, send_state, date);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_v2 ON messages_v2(uid, mention, read_state);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS is_channel_idx_messages_v2 ON messages_v2(mid, is_channel);").stepThis().dispose();
-
- database.beginTransaction();
-
- SQLiteCursor cursor;
-
- try {
- cursor = database.queryFinalized("SELECT mid, uid, read_state, send_state, date, data, out, ttl, media, replydata, imp, mention, forwards, replies_data, thread_reply_id FROM messages WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO messages_v2 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- int num = 0;
- while (cursor.next()) {
- NativeByteBuffer data = cursor.byteBufferValue(5);
- if (data == null) {
- continue;
- }
- num++;
- long mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
- int readState = cursor.intValue(2);
- int sendState = cursor.intValue(3);
- int date = cursor.intValue(4);
- int out = cursor.intValue(6);
- int ttl = cursor.intValue(7);
- int media = cursor.intValue(8);
- NativeByteBuffer replydata = cursor.byteBufferValue(9);
- int imp = cursor.intValue(10);
- int mention = cursor.intValue(11);
- int forwards = cursor.intValue(12);
- NativeByteBuffer repliesdata = cursor.byteBufferValue(13);
- int thread_reply_id = cursor.intValue(14);
- int channelId = (int) (uid >> 32);
- if (ttl < 0) {
- TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
- if (message != null) {
- message.readAttachPath(data, getUserConfig().clientUserId);
- if (message.params == null) {
- message.params = new HashMap<>();
- message.params.put("fwd_peer", "" + ttl);
- }
- data.reuse();
- data = new NativeByteBuffer(message.getObjectSize());
- message.serializeToStream(data);
- }
- ttl = 0;
- }
-
- statement.requery();
- statement.bindInteger(1, (int) mid);
- statement.bindLong(2, uid);
- statement.bindInteger(3, readState);
- statement.bindInteger(4, sendState);
- statement.bindInteger(5, date);
- statement.bindByteBuffer(6, data);
- statement.bindInteger(7, out);
- statement.bindInteger(8, ttl);
- statement.bindInteger(9, media);
- if (replydata != null) {
- statement.bindByteBuffer(10, replydata);
- } else {
- statement.bindNull(10);
- }
- statement.bindInteger(11, imp);
- statement.bindInteger(12, mention);
- statement.bindInteger(13, forwards);
- if (repliesdata != null) {
- statement.bindByteBuffer(14, repliesdata);
- } else {
- statement.bindNull(14);
- }
- statement.bindInteger(15, thread_reply_id);
- statement.bindInteger(16, channelId > 0 ? 1 : 0);
- statement.step();
- if (replydata != null) {
- replydata.reuse();
- }
- if (repliesdata != null) {
- repliesdata.reuse();
- }
- data.reuse();
- }
- cursor.dispose();
- statement.dispose();
- }
-
- ArrayList secretChatsToUpdate = null;
- ArrayList foldersToUpdate = null;
- cursor = database.queryFinalized("SELECT did, last_mid, last_mid_i FROM dialogs WHERE 1");
- SQLitePreparedStatement statement4 = database.executeFast("UPDATE dialogs SET last_mid = ?, last_mid_i = ? WHERE did = ?");
- while (cursor.next()) {
- long did = cursor.longValue(0);
- int lowerId = (int) did;
- int highId = (int) (did >> 32);
- if (lowerId == 0) {
- if (secretChatsToUpdate == null) {
- secretChatsToUpdate = new ArrayList<>();
- }
- secretChatsToUpdate.add(highId);
- } else if (highId == 2) {
- if (foldersToUpdate == null) {
- foldersToUpdate = new ArrayList<>();
- }
- foldersToUpdate.add(lowerId);
- }
-
- statement4.requery();
- statement4.bindInteger(1, cursor.intValue(1));
- statement4.bindInteger(2, cursor.intValue(2));
- statement4.bindLong(3, did);
- statement4.step();
- }
- statement4.dispose();
- cursor.dispose();
-
- cursor = database.queryFinalized("SELECT uid, mid FROM unread_push_messages WHERE 1");
- statement4 = database.executeFast("UPDATE unread_push_messages SET mid = ? WHERE uid = ? AND mid = ?");
- while (cursor.next()) {
- long did = cursor.longValue(0);
- int mid = cursor.intValue(1);
- statement4.requery();
- statement4.bindInteger(1, mid);
- statement4.bindLong(2, did);
- statement4.bindInteger(3, mid);
- statement4.step();
- }
- statement4.dispose();
- cursor.dispose();
-
- if (secretChatsToUpdate != null) {
- SQLitePreparedStatement statement = database.executeFast("UPDATE dialogs SET did = ? WHERE did = ?");
- SQLitePreparedStatement statement2 = database.executeFast("UPDATE dialog_filter_pin_v2 SET peer = ? WHERE peer = ?");
- SQLitePreparedStatement statement3 = database.executeFast("UPDATE dialog_filter_ep SET peer = ? WHERE peer = ?");
- for (int a = 0, N = secretChatsToUpdate.size(); a < N; a++) {
- int sid = secretChatsToUpdate.get(a);
-
- long newId = DialogObject.makeEncryptedDialogId(sid);
- long oldId = ((long) sid) << 32;
- statement.requery();
- statement.bindLong(1, newId);
- statement.bindLong(2, oldId);
- statement.step();
-
- statement2.requery();
- statement2.bindLong(1, newId);
- statement2.bindLong(2, oldId);
- statement2.step();
-
- statement3.requery();
- statement3.bindLong(1, newId);
- statement3.bindLong(2, oldId);
- statement3.step();
- }
- statement.dispose();
- statement2.dispose();
- statement3.dispose();
- }
- if (foldersToUpdate != null) {
- SQLitePreparedStatement statement = database.executeFast("UPDATE dialogs SET did = ? WHERE did = ?");
- for (int a = 0, N = foldersToUpdate.size(); a < N; a++) {
- int fid = foldersToUpdate.get(a);
-
- long newId = DialogObject.makeFolderDialogId(fid);
- long oldId = (((long) 2) << 32) | fid;
- statement.requery();
- statement.bindLong(1, newId);
- statement.bindLong(2, oldId);
- statement.step();
- }
- statement.dispose();
- }
-
- database.executeFast("DROP INDEX IF EXISTS uid_mid_read_out_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_date_mid_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS mid_out_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS task_idx_messages;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS send_state_idx_messages2;").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_mention_idx_messages;").stepThis().dispose();
- database.executeFast("DROP TABLE IF EXISTS messages;").stepThis().dispose();
- database.commitTransaction();
-
- database.executeFast("PRAGMA user_version = 84").stepThis().dispose();
- version = 84;
- }
- if (version == 84) {
- database.executeFast("CREATE TABLE IF NOT EXISTS media_v4(mid INTEGER, uid INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid, type))").stepThis().dispose();
- database.beginTransaction();
- SQLiteCursor cursor;
- try {
- cursor = database.queryFinalized("SELECT mid, uid, date, type, data FROM media_v3 WHERE 1");
- } catch (Exception e) {
- cursor = null;
- FileLog.e(e);
- }
- if (cursor != null) {
- SQLitePreparedStatement statement = database.executeFast("REPLACE INTO media_v4 VALUES(?, ?, ?, ?, ?)");
- while (cursor.next()) {
- NativeByteBuffer data = cursor.byteBufferValue(4);
- if (data == null) {
- continue;
- }
- int mid = cursor.intValue(0);
- long uid = cursor.longValue(1);
- int lowerId = (int) uid;
- if (lowerId == 0) {
- int highId = (int) (uid >> 32);
- uid = DialogObject.makeEncryptedDialogId(highId);
- }
- int date = cursor.intValue(2);
- int type = cursor.intValue(3);
-
- statement.requery();
- statement.bindInteger(1, mid);
- statement.bindLong(2, uid);
- statement.bindInteger(3, date);
- statement.bindInteger(4, type);
- statement.bindByteBuffer(5, data);
- statement.step();
- data.reuse();
- }
- cursor.dispose();
- statement.dispose();
- }
- database.commitTransaction();
-
- database.executeFast("DROP TABLE IF EXISTS media_v3;").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 85").stepThis().dispose();
- version = 85;
- }
- if (version == 85) {
- executeNoException("ALTER TABLE messages_v2 ADD COLUMN reply_to_message_id INTEGER default 0");
- executeNoException("ALTER TABLE scheduled_messages_v2 ADD COLUMN reply_to_message_id INTEGER default 0");
-
- database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_messages_v2 ON messages_v2(mid, reply_to_message_id);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_scheduled_messages_v2 ON scheduled_messages_v2(mid, reply_to_message_id);").stepThis().dispose();
-
- executeNoException("UPDATE messages_v2 SET replydata = NULL");
- executeNoException("UPDATE scheduled_messages_v2 SET replydata = NULL");
- database.executeFast("PRAGMA user_version = 86").stepThis().dispose();
- version = 86;
- }
-
- if (version == 86) {
- database.executeFast("CREATE TABLE IF NOT EXISTS reactions(data BLOB, hash INTEGER, date INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 87").stepThis().dispose();
- version = 87;
- }
-
- if (version == 87) {
- database.executeFast("ALTER TABLE dialogs ADD COLUMN unread_reactions INTEGER default 0").stepThis().dispose();
- database.executeFast("CREATE TABLE reaction_mentions(message_id INTEGER PRIMARY KEY, state INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 88").stepThis().dispose();
- version = 88;
- }
-
- if (version == 88 || version == 89) {
- database.executeFast("DROP TABLE IF EXISTS reaction_mentions;").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS reaction_mentions(message_id INTEGER, state INTEGER, dialog_id INTEGER, PRIMARY KEY(dialog_id, message_id));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS reaction_mentions_did ON reaction_mentions(dialog_id);").stepThis().dispose();
-
- database.executeFast("DROP INDEX IF EXISTS uid_mid_type_date_idx_media_v3").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_v4 ON media_v4(uid, mid, type, date);").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 90").stepThis().dispose();
-
- version = 90;
- }
-
- if (version == 90 || version == 91) {
- database.executeFast("DROP TABLE IF EXISTS downloading_documents;").stepThis().dispose();
- database.executeFast("CREATE TABLE downloading_documents(data BLOB, hash INTEGER, id INTEGER, state INTEGER, date INTEGER, PRIMARY KEY(hash, id));").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 92").stepThis().dispose();
- version = 92;
- }
-
- if (version == 92) {
- database.executeFast("CREATE TABLE IF NOT EXISTS attach_menu_bots(data BLOB, hash INTEGER, date INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 93").stepThis().dispose();
- version = 95;
- }
-
- if (version == 95 || version == 93) {
- executeNoException("ALTER TABLE messages_v2 ADD COLUMN custom_params BLOB default NULL");
- database.executeFast("PRAGMA user_version = 96").stepThis().dispose();
- version = 96;
- }
-
- // skip 94, 95. private beta db rollback
- if (version == 96) {
- database.executeFast("CREATE TABLE IF NOT EXISTS premium_promo(data BLOB, date INTEGER);").stepThis().dispose();
- database.executeFast("UPDATE stickers_v2 SET date = 0");
- database.executeFast("PRAGMA user_version = 97").stepThis().dispose();
- version = 97;
- }
-
- if (version == 97) {
- database.executeFast("DROP TABLE IF EXISTS stickers_featured;").stepThis().dispose();
- database.executeFast("CREATE TABLE stickers_featured(id INTEGER PRIMARY KEY, data BLOB, unread BLOB, date INTEGER, hash INTEGER, premium INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 98").stepThis().dispose();
- version = 98;
- }
-
- if (version == 98) {
- database.executeFast("CREATE TABLE animated_emoji(document_id INTEGER PRIMARY KEY, data BLOB);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 99").stepThis().dispose();
- version = 99;
- }
-
- if (version == 99) {
- database.executeFast("ALTER TABLE stickers_featured ADD COLUMN emoji INTEGER default 0").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 100").stepThis().dispose();
- version = 100;
- }
-
- if (version == 100) {
- database.executeFast("CREATE TABLE emoji_statuses(data BLOB, type INTEGER);").stepThis().dispose();
- database.executeFast("PRAGMA user_version = 101").stepThis().dispose();
- version = 101;
- }
-
- if (version == 101) {
- database.executeFast("ALTER TABLE messages_v2 ADD COLUMN group_id INTEGER default NULL").stepThis().dispose();
- database.executeFast("ALTER TABLE dialogs ADD COLUMN last_mid_group INTEGER default NULL").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_groupid_messages_v2 ON messages_v2(uid, mid, group_id);").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 102").stepThis().dispose();
- version = 102;
- }
-
- if (version == 102) {
- database.executeFast("CREATE TABLE messages_holes_topics(uid INTEGER, topic_id INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, topic_id, start));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_messages_holes ON messages_holes_topics(uid, topic_id, end);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE messages_topics(mid INTEGER, uid INTEGER, topic_id INTEGER, read_state INTEGER, send_state INTEGER, date INTEGER, data BLOB, out INTEGER, ttl INTEGER, media INTEGER, replydata BLOB, imp INTEGER, mention INTEGER, forwards INTEGER, replies_data BLOB, thread_reply_id INTEGER, is_channel INTEGER, reply_to_message_id INTEGER, custom_params BLOB, PRIMARY KEY(mid, topic_id, uid))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_topics ON messages_topics(uid, mid, read_state, out);").stepThis().dispose();//move to topic id
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages_topics ON messages_topics(uid, date, mid);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages_topics ON messages_topics(mid, out);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS task_idx_messages_topics ON messages_topics(uid, out, read_state, ttl, date, send_state);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS send_state_idx_messages_topics ON messages_topics(mid, send_state, date);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_topics ON messages_topics(uid, mention, read_state);").stepThis().dispose();//move to uid, topic_id, mentiin_read_state
- database.executeFast("CREATE INDEX IF NOT EXISTS is_channel_idx_messages_topics ON messages_topics(mid, is_channel);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS reply_to_idx_messages_topics ON messages_topics(mid, reply_to_message_id);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_uid_messages_topics ON messages_topics(mid, uid);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS mid_uid_topic_id_messages_topics ON messages_topics(mid, topic_id, uid);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE media_topics(mid INTEGER, uid INTEGER, topic_id INTEGER, date INTEGER, type INTEGER, data BLOB, PRIMARY KEY(mid, uid, topic_id, type))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media_topics ON media_topics(uid, topic_id, mid, type, date);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE media_holes_topics(uid INTEGER, topic_id INTEGER, type INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, topic_id, type, start));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_end_media_holes_topics ON media_holes_topics(uid, topic_id, type, end);").stepThis().dispose();
-
- database.executeFast("CREATE TABLE topics(did INTEGER, topic_id INTEGER, data BLOB, top_message INTEGER, topic_message BLOB, unread_count INTEGER, max_read_id INTEGER, unread_mentions INTEGER, unread_reactions INTEGER, PRIMARY KEY(did, topic_id));").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS did_top_message_topics ON topics(did, top_message);").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 103").stepThis().dispose();
- version = 103;
- }
-
- if (version == 103) {
- database.executeFast("CREATE TABLE IF NOT EXISTS media_counts_topics(uid INTEGER, topic_id INTEGER, type INTEGER, count INTEGER, old INTEGER, PRIMARY KEY(uid, topic_id, type))").stepThis().dispose();
- database.executeFast("CREATE TABLE IF NOT EXISTS reaction_mentions_topics(message_id INTEGER, state INTEGER, dialog_id INTEGER, topic_id INTEGER, PRIMARY KEY(message_id, dialog_id, topic_id))").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS reaction_mentions_topics_did ON reaction_mentions_topics(dialog_id, topic_id);").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 104").stepThis().dispose();
- version = 104;
- }
-
- if (version == 104) {
- database.executeFast("ALTER TABLE topics ADD COLUMN read_outbox INTEGER default 0").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 105").stepThis().dispose();
- version = 105;
- }
-
- if (version == 105) {
- database.executeFast("ALTER TABLE topics ADD COLUMN pinned INTEGER default 0").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 106").stepThis().dispose();
- version = 106;
- }
-
- if (version == 106) {
- database.executeFast("DROP INDEX IF EXISTS uid_mid_read_out_idx_messages_topics").stepThis().dispose();
- database.executeFast("DROP INDEX IF EXISTS uid_mention_idx_messages_topics").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_read_out_idx_messages_topics ON messages_topics(uid, topic_id, mid, read_state, out);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_mention_idx_messages_topics ON messages_topics(uid, topic_id, mention, read_state);").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_messages_topics ON messages_topics(uid, topic_id);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_date_mid_messages_topics ON messages_topics(uid, topic_id, date, mid);").stepThis().dispose();
- database.executeFast("CREATE INDEX IF NOT EXISTS uid_topic_id_mid_messages_topics ON messages_topics(uid, topic_id, mid);").stepThis().dispose();
-
- database.executeFast("CREATE INDEX IF NOT EXISTS did_topics ON topics(did);").stepThis().dispose();
-
- database.executeFast("PRAGMA user_version = 107").stepThis().dispose();
- version = 107;
- }
-
- FileLog.d("MessagesStorage db migration finished");
+ FileLog.d("MessagesStorage db migration finished to varsion " + version);
AndroidUtilities.runOnUIThread(() -> {
databaseMigrationInProgress = false;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.onDatabaseMigration, false);
});
}
- private void executeNoException(String query) {
+ void executeNoException(String query) {
try {
database.executeFast(query).stepThis().dispose();
} catch (Exception e) {
@@ -1822,7 +641,7 @@ public class MessagesStorage extends BaseController {
});
}
- private void fixNotificationSettings() {
+ public void fixNotificationSettings() {
storageQueue.postRunnable(() -> {
try {
LongSparseArray ids = new LongSparseArray<>();
@@ -2400,7 +1219,7 @@ public class MessagesStorage extends BaseController {
if (replace) {
database.executeFast("DELETE FROM topics WHERE did = " + dialogId).stepThis().dispose();
}
- state = database.executeFast("REPLACE INTO topics VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ state = database.executeFast("REPLACE INTO topics VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if (inTransaction) {
database.beginTransaction();
}
@@ -2431,6 +1250,8 @@ public class MessagesStorage extends BaseController {
} else {
state.bindInteger(11, topic.pinned ? 1 + topic.pinnedOrder : 0);
}
+ state.bindInteger(12, topic.totalMessagesCount);
+ state.bindInteger(13, topic.hidden ? 1 : 0);
state.step();
messageData.reuse();
@@ -2473,6 +1294,18 @@ public class MessagesStorage extends BaseController {
SQLitePreparedStatement state = null;
SQLiteCursor cursor = null;
try {
+ if ((flags & TopicsController.TOPIC_FLAG_TOTAL_MESSAGES_COUNT) != 0) {
+ state = database.executeFast("UPDATE topics SET total_messages_count = ? WHERE did = ? AND topic_id = ?");
+ state.requery();
+ state.bindInteger(1, fromTopic.totalMessagesCount);
+ state.bindLong(2, dialogId);
+ state.bindInteger(3, fromTopic.id);
+ state.step();
+ state.dispose();
+ if (flags == TopicsController.TOPIC_FLAG_TOTAL_MESSAGES_COUNT) {
+ return;
+ }
+ }
TLRPC.TL_forumTopic topicToUpdate = null;
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM topics WHERE did = %d AND topic_id = %d", dialogId, fromTopic.id));
if (cursor.next()) {
@@ -2501,14 +1334,18 @@ public class MessagesStorage extends BaseController {
if ((flags & TopicsController.TOPIC_FLAG_CLOSE) != 0) {
topicToUpdate.closed = fromTopic.closed;
}
- state = database.executeFast("UPDATE topics SET data = ?, pinned = ? WHERE did = ? AND topic_id = ?");
+ if ((flags & TopicsController.TOPIC_FLAG_HIDE) != 0) {
+ topicToUpdate.hidden = fromTopic.hidden;
+ }
+ state = database.executeFast("UPDATE topics SET data = ?, pinned = ?, hidden = ? WHERE did = ? AND topic_id = ?");
database.beginTransaction();
NativeByteBuffer data = new NativeByteBuffer(topicToUpdate.getObjectSize());
topicToUpdate.serializeToStream(data);
state.bindByteBuffer(1, data);
state.bindInteger(2, pinnedOrder);
- state.bindLong(3, dialogId);
- state.bindInteger(4, topicToUpdate.id);
+ state.bindInteger(3, topicToUpdate.hidden ? 1 : 0);
+ state.bindLong(4, dialogId);
+ state.bindInteger(5, topicToUpdate.id);
state.step();
data.reuse();
}
@@ -2531,7 +1368,7 @@ public class MessagesStorage extends BaseController {
ArrayList topics = null;
SQLiteCursor cursor = null;
try {
- cursor = database.queryFinalized(String.format(Locale.US, "SELECT top_message, data, topic_message, unread_count, max_read_id, unread_mentions, unread_reactions, read_outbox, pinned FROM topics WHERE did = %d ORDER BY pinned ASC", dialogId));
+ cursor = database.queryFinalized(String.format(Locale.US, "SELECT top_message, data, topic_message, unread_count, max_read_id, unread_mentions, unread_reactions, read_outbox, pinned, total_messages_count FROM topics WHERE did = %d ORDER BY pinned ASC", dialogId));
SparseArray> topicsByTopMessageId = null;
HashSet topMessageIds = null;
@@ -2570,6 +1407,7 @@ public class MessagesStorage extends BaseController {
topic.read_outbox_max_id = cursor.intValue(7);
topic.pinnedOrder = cursor.intValue(8) - 1;
topic.pinned = topic.pinnedOrder >= 0;
+ topic.totalMessagesCount = cursor.intValue(9);
}
data.reuse();
@@ -2818,6 +1656,24 @@ public class MessagesStorage extends BaseController {
});
}
+ public void setDialogTtl(long did, int ttl) {
+ storageQueue.postRunnable(() -> {
+ try {
+ database.executeFast(String.format(Locale.US, "UPDATE dialogs SET ttl_period = %d WHERE did = %d", ttl, did)).stepThis().dispose();
+ } catch (SQLiteException e) {
+ FileLog.e(e);
+ }
+ });
+ }
+
+ public ArrayList getDatabaseFiles() {
+ ArrayList files = new ArrayList<>();
+ files.add(cacheFile);
+ files.add(walCacheFile);
+ files.add(shmCacheFile);
+ return files;
+ }
+
private static class ReadDialog {
public int lastMid;
public int date;
@@ -2907,7 +1763,7 @@ public class MessagesStorage extends BaseController {
LongSparseArray groupsToLoad = new LongSparseArray<>();
SQLiteCursor cursor = null;
try {
- cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date, d.pts, d.inbox_max, d.outbox_max, m.replydata, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid LEFT JOIN dialog_settings as s ON d.did = s.did WHERE d.did IN (%s) ORDER BY d.pinned DESC, d.date DESC", ids));
+ cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date, d.pts, d.inbox_max, d.outbox_max, m.replydata, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group, d.ttl_period FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid LEFT JOIN dialog_settings as s ON d.did = s.did WHERE d.did IN (%s) ORDER BY d.pinned DESC, d.date DESC", ids));
while (cursor.next()) {
long dialogId = cursor.longValue(0);
TLRPC.Dialog dialog = new TLRPC.TL_dialog();
@@ -2935,9 +1791,11 @@ public class MessagesStorage extends BaseController {
}
dialog.folder_id = cursor.intValue(17);
dialog.unread_reactions_count = cursor.intValue(19);
- if (!cursor.isNull(20)) {
- groupsToLoad.append(dialogId, cursor.longValue(20));
+ long groupMessagesId = cursor.longValue(20);
+ if (groupMessagesId != 0) {
+ groupsToLoad.append(dialogId, groupMessagesId);
}
+ dialog.ttl_period = cursor.intValue(21);
dialogs.dialogs.add(dialog);
NativeByteBuffer data = cursor.byteBufferValue(4);
@@ -5666,7 +4524,7 @@ public class MessagesStorage extends BaseController {
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
- topicId = MessageObject.getTopicId(message);
+ topicId = MessageObject.getTopicId(message, isForum(dialogId));
}
}
cursor.dispose();
@@ -7050,6 +5908,14 @@ public class MessagesStorage extends BaseController {
state = null;
unknownDialogsIds.remove(info.user.id);
}
+ if ((info.flags & 16384) != 0) {
+ state = database.executeFast("UPDATE dialogs SET ttl_period = ? WHERE did = ?");
+ state.bindInteger(1, info.ttl_period);
+ state.bindLong(2, info.user.id);
+ state.step();
+ state.dispose();
+ state = null;
+ }
} catch (Exception e) {
FileLog.e(e);
} finally {
@@ -7174,6 +6040,13 @@ public class MessagesStorage extends BaseController {
state = null;
unknownDialogsIds.remove(-info.id);
}
+
+ state = database.executeFast("UPDATE dialogs SET ttl_period = ? WHERE did = ?");
+ state.bindInteger(1, info.ttl_period);
+ state.bindLong(2, -info.id);
+ state.step();
+ state.dispose();
+ state = null;
} catch (Exception e) {
FileLog.e(e);
} finally {
@@ -9952,7 +8825,7 @@ public class MessagesStorage extends BaseController {
data4.reuse();
data5.reuse();
if (dialog != null) {
- state = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)");
+ state = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
state.bindLong(1, dialog.id);
state.bindInteger(2, dialog.last_message_date);
state.bindInteger(3, dialog.unread_count);
@@ -9968,6 +8841,8 @@ public class MessagesStorage extends BaseController {
state.bindInteger(13, dialog.folder_id);
state.bindNull(14);
state.bindInteger(15, dialog.unread_reactions_count);
+ state.bindInteger(16, 0);
+ state.bindInteger(17, dialog.ttl_period);
state.step();
state.dispose();
state = null;
@@ -11123,6 +9998,7 @@ public class MessagesStorage extends BaseController {
HashMap topicsReadMax = new HashMap<>();
HashMap topicsNewUnreadMessages = new HashMap<>();
+ HashMap topicsNewMessages = new HashMap<>();
HashMap topicMessagesMap = new HashMap<>();
HashMap> topicMentionsIdsMap = new HashMap<>();
HashMap topicsMentions = new HashMap<>();
@@ -11146,7 +10022,7 @@ public class MessagesStorage extends BaseController {
int messageId = message.id;
MessageObject.getDialogId(message);
- int topicId = MessageObject.getTopicId(message);
+ int topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
if (message.mentioned && message.media_unread) {
ArrayList ids = dialogMentionsIdsMap.get(message.dialog_id);
@@ -11156,6 +10032,7 @@ public class MessagesStorage extends BaseController {
}
ids.add(messageId);
if (topicId != 0) {
+ FileLog.d("add message with message to " + message.dialog_id + " " + topicId);
TopicKey topicKey = TopicKey.of(message.dialog_id, topicId);
ArrayList ids2 = topicMentionsIdsMap.get(topicKey);
if (ids2 == null) {
@@ -11222,6 +10099,14 @@ public class MessagesStorage extends BaseController {
newUnread++;
topicsNewUnreadMessages.put(topicKey, newUnread);
}
+ if (currentTopicMaxId < message.id) {
+ Integer newMessages = topicsNewMessages.get(topicKey);
+ if (newMessages == null) {
+ newMessages = 0;
+ }
+ newMessages++;
+ topicsNewMessages.put(topicKey, newMessages);
+ }
}
}
if (MediaDataController.canAddMessageToMedia(message)) {
@@ -11523,7 +10408,7 @@ public class MessagesStorage extends BaseController {
continue;
}
fixUnsupportedMedia(message);
- int topicId = MessageObject.getTopicId(message);
+ int topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
state_messages.requery();
int messageId = message.id;
@@ -11773,7 +10658,7 @@ public class MessagesStorage extends BaseController {
state_download.bindInteger(2, type);
state_download.bindInteger(3, message.date);
state_download.bindByteBuffer(4, data);
- state_download.bindString(5, "sent_" + (message.peer_id != null ? message.peer_id.channel_id : 0) + "_" + message.id);
+ state_download.bindString(5, "sent_" + (message.peer_id != null ? message.peer_id.channel_id : 0) + "_" + message.id + "_" + DialogObject.getPeerDialogId(message.peer_id));
state_download.step();
data.reuse();
}
@@ -11809,9 +10694,9 @@ public class MessagesStorage extends BaseController {
}
}
- state_dialogs_replace = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ state_dialogs_replace = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
state_dialogs_update = database.executeFast("UPDATE dialogs SET date = ?, unread_count = ?, last_mid = ?, last_mid_group = ?, unread_count_i = ? WHERE did = ?");
- state_topics_update = database.executeFast("UPDATE topics SET unread_count = ?, top_message = ?, unread_mentions = ? WHERE did = ? AND topic_id = ?");
+ state_topics_update = database.executeFast("UPDATE topics SET unread_count = ?, top_message = ?, unread_mentions = ?, total_messages_count = ? WHERE did = ? AND topic_id = ?");
ArrayList dids = new ArrayList<>();
for (int a = 0; a < messagesMap.size(); a++) {
@@ -11903,6 +10788,7 @@ public class MessagesStorage extends BaseController {
} else {
state_dialogs_replace.bindNull(16);
}
+ state_dialogs_replace.bindInteger(17, 0);
state_dialogs_replace.step();
unknownDialogsIds.put(key, true);
}
@@ -11923,12 +10809,14 @@ public class MessagesStorage extends BaseController {
TLRPC.Message message = topicMessagesMap.get(topicKey);
- cursor = database.queryFinalized("SELECT unread_count, top_message, unread_mentions FROM topics WHERE did = " + topicKey.dialogId + " AND topic_id = " + topicKey.topicId);
+ cursor = database.queryFinalized("SELECT unread_count, top_message, unread_mentions, total_messages_count FROM topics WHERE did = " + topicKey.dialogId + " AND topic_id = " + topicKey.topicId);
int oldUnreadCount = 0;
int oldMentions = 0;
+ int oldTotalCount = 0;
int topMessage = 0;
int newMentions = 0;
int newUnreadMessages = 0;
+ int newMessages = 0;
boolean exist = false;
if (cursor.next()) {
@@ -11936,6 +10824,7 @@ public class MessagesStorage extends BaseController {
oldUnreadCount = cursor.intValue(0);
topMessage = cursor.intValue(1);
oldMentions = cursor.intValue(2);
+ oldTotalCount = cursor.intValue(3);
}
cursor.dispose();
cursor = null;
@@ -11953,6 +10842,7 @@ public class MessagesStorage extends BaseController {
}
Integer newMessagesInteger = topicsNewUnreadMessages.get(topicKey);
Integer newMentionsInteger = topicsMentions.get(topicKey);
+ Integer newMessagesTotalInteger = topicsNewMessages.get(topicKey);
int messageId = message != null ? message.id : topMessage;
if (message != null) {
@@ -11963,19 +10853,23 @@ public class MessagesStorage extends BaseController {
if (newMessagesInteger != null) {
newUnreadMessages = newMessagesInteger;
}
-
if (newMentionsInteger != null) {
newMentions = newMentionsInteger;
}
+ if (newMessagesTotalInteger != null) {
+ newMessages = newMessagesTotalInteger;
+ }
int newUnreadCount = oldUnreadCount + newUnreadMessages;
int newUnreadMentions = oldMentions + newMentions;
+ int newTotalMessagesCount = oldTotalCount == 0 ? 0 : oldTotalCount + newMessages;
state_topics_update.requery();
state_topics_update.bindInteger(1, newUnreadCount);
state_topics_update.bindInteger(2, messageId);
state_topics_update.bindInteger(3, newUnreadMentions);
- state_topics_update.bindLong(4, topicKey.dialogId);
- state_topics_update.bindInteger(5, topicKey.topicId);
+ state_topics_update.bindInteger(4, newTotalMessagesCount);
+ state_topics_update.bindLong(5, topicKey.dialogId);
+ state_topics_update.bindInteger(6, topicKey.topicId);
state_topics_update.step();
if (isForum(topicKey.dialogId)) {
@@ -11999,6 +10893,7 @@ public class MessagesStorage extends BaseController {
topicUpdate.unreadMentions = oldMentions + newMentions;
topicUpdate.topMessageId = messageId;
topicUpdate.unreadCount = oldUnreadCount + newUnreadMessages;
+ topicUpdate.totalMessagesCount = newTotalMessagesCount;
topicUpdatesInUi.add(topicUpdate);
}
}
@@ -12161,7 +11056,7 @@ public class MessagesStorage extends BaseController {
});
} else if (message.action instanceof TLRPC.TL_messageActionTopicEdit) {
TLRPC.TL_messageActionTopicEdit action = (TLRPC.TL_messageActionTopicEdit) message.action;
- forumTopic.id = MessageObject.getTopicId(message);
+ forumTopic.id = MessageObject.getTopicId(message, true);
forumTopic.icon_emoji_id = action.icon_emoji_id;
forumTopic.title = action.title;
forumTopic.closed = action.closed;
@@ -12873,18 +11768,19 @@ public class MessagesStorage extends BaseController {
}
topicsToDelete.add(TopicKey.of(did, message.id));
}
- topicId = MessageObject.getTopicId(message);
+ topicId = MessageObject.getTopicId(message, isForum(did));
}
if (topicId != 0) {
TopicKey topicKey = TopicKey.of(dialogId, topicId);
int read_state = cursor.intValue(2);
+ int[] count = topicsMessagesToUpdate.get(topicKey);
+ if (count == null) {
+ count = new int[3];
+ topicsMessagesToUpdate.put(topicKey, count);
+ }
+ count[2]++;
if (cursor.intValue(3) == 0) {
- int[] count = topicsMessagesToUpdate.get(topicKey);
- if (count == null) {
- count = new int[2];
- topicsMessagesToUpdate.put(topicKey, count);
- }
if (read_state < 2) {
count[1]++;
}
@@ -12970,12 +11866,14 @@ public class MessagesStorage extends BaseController {
if (!topicsMessagesToUpdate.isEmpty()) {
HashSet dialogsToCheck = null;
for (TopicKey topicKey : topicsMessagesToUpdate.keySet()) {
- cursor = database.queryFinalized(String.format(Locale.US, "SELECT unread_count, unread_mentions FROM topics WHERE did = %d AND topic_id = %d", topicKey.dialogId, topicKey.topicId));
+ cursor = database.queryFinalized(String.format(Locale.US, "SELECT unread_count, unread_mentions, total_messages_count FROM topics WHERE did = %d AND topic_id = %d", topicKey.dialogId, topicKey.topicId));
int old_unread_count = 0;
int old_mentions_count = 0;
+ int old_total_count = 0;
if (cursor.next()) {
old_unread_count = cursor.intValue(0);
old_mentions_count = cursor.intValue(1);
+ old_total_count = cursor.intValue(2);
}
cursor.dispose();
cursor = null;
@@ -12983,12 +11881,15 @@ public class MessagesStorage extends BaseController {
int[] counts = topicsMessagesToUpdate.get(topicKey);
int newUnreadCount = Math.max(0, old_unread_count - counts[0]);
int newUnreadMentionsCount = Math.max(0, old_mentions_count - counts[1]);
- state = database.executeFast("UPDATE topics SET unread_count = ?, unread_mentions = ? WHERE did = ? AND topic_id = ?");
+ int newTotalCount = Math.max(0, old_total_count - counts[2]);
+ state = database.executeFast("UPDATE topics SET unread_count = ?, unread_mentions = ?, total_messages_count = ? WHERE did = ? AND topic_id = ?");
state.requery();
state.bindInteger(1, newUnreadCount);
state.bindInteger(2, newUnreadMentionsCount);
- state.bindLong(3, topicKey.dialogId);
- state.bindLong(4, topicKey.topicId);
+ state.bindLong(3, newTotalCount);
+ state.bindLong(4, topicKey.dialogId);
+ state.bindLong(5, topicKey.topicId);
+
state.step();
state.dispose();
state = null;
@@ -13004,6 +11905,7 @@ public class MessagesStorage extends BaseController {
topicUpdate.dialogId = topicKey.dialogId;
topicUpdate.topicId = topicKey.topicId;
topicUpdate.unreadCount = newUnreadCount;
+ topicUpdate.totalMessagesCount = newTotalCount;
topicUpdate.onlyCounters = true;
if (topicUpdatesInUi == null) {
topicUpdatesInUi = new ArrayList<>();
@@ -13278,7 +12180,7 @@ public class MessagesStorage extends BaseController {
ArrayList encryptedToLoad = new ArrayList<>();
LongSparseArray groupsToLoad = new LongSparseArray<>();
- cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, m.date, d.pts, d.inbox_max, d.outbox_max, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid AND d.last_mid_group IS NULL WHERE d.did IN(%s)", ids));
+ cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, m.date, d.pts, d.inbox_max, d.outbox_max, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group, d.ttl_period FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid AND d.last_mid_group IS NULL WHERE d.did IN(%s)", ids));
while (cursor.next()) {
long dialogId = cursor.longValue(0);
TLRPC.Dialog dialog;
@@ -13313,10 +12215,11 @@ public class MessagesStorage extends BaseController {
dialog.unread_mark = (dialog_flags & 1) != 0;
dialog.folder_id = cursor.intValue(15);
dialog.unread_reactions_count = cursor.intValue(17);
-
- if (!cursor.isNull(18)) {
- groupsToLoad.put(dialogId, cursor.longValue(18));
+ long groupMessagesId = cursor.longValue(18);
+ if (groupMessagesId != 0) {
+ groupsToLoad.put(dialogId, groupMessagesId);
}
+ dialog.ttl_period = cursor.intValue(19);
dialogs.dialogs.add(dialog);
@@ -13991,7 +12894,7 @@ public class MessagesStorage extends BaseController {
for (int i = 0; i < 2; i++) {
boolean isTopic = i == 1;
- int topicId = MessageObject.getTopicId(message);
+ int topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
if (isTopic && topicId == 0) {
continue;
}
@@ -14065,7 +12968,7 @@ public class MessagesStorage extends BaseController {
if (MediaDataController.canAddMessageToMedia(message)) {
for (int i = 0; i < 2; i++) {
boolean isTopic = i == 1;
- int topicId = MessageObject.getTopicId(message);
+ int topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
if (isTopic && topicId == 0) {
continue;
}
@@ -14322,7 +13225,7 @@ public class MessagesStorage extends BaseController {
state3.bindInteger(7, message.date);
state3.bindLong(8, dialogId);
} else {
- state3 = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ state3 = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
state3.bindLong(1, dialogId);
state3.bindInteger(2, message.date);
state3.bindInteger(3, 0);
@@ -14343,6 +13246,7 @@ public class MessagesStorage extends BaseController {
} else {
state3.bindNull(16);
}
+ state3.bindInteger(17, 0);
unknownDialogsIds.put(dialogId, true);
}
state3.step();
@@ -14358,7 +13262,7 @@ public class MessagesStorage extends BaseController {
boolean isTopicMessage = i == 1;
int topicId = threadMessageId;
if (isTopicMessage && topicId == 0) {
- topicId = MessageObject.getTopicId(message);
+ topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
}
if (isTopicMessage && topicId == 0) {
continue;
@@ -14448,7 +13352,7 @@ public class MessagesStorage extends BaseController {
}
}
}
- int topicId = MessageObject.getTopicId(message);
+ int topicId = MessageObject.getTopicId(message, isForum(message.dialog_id));
if (threadMessageId != 0 || (load_type == -2 && topicId != 0)) {
if (MediaDataController.canAddMessageToMedia(message)) {
state_media_topics.requery();
@@ -14776,7 +13680,7 @@ public class MessagesStorage extends BaseController {
}
ArrayList> dialogsToLoadGroupMessages = new ArrayList<>();
- cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date, d.pts, d.inbox_max, d.outbox_max, m.replydata, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid AND d.last_mid_group IS NULL LEFT JOIN dialog_settings as s ON d.did = s.did WHERE d.folder_id = %d ORDER BY d.pinned DESC, d.date DESC LIMIT %d,%d", fid, off, cnt));
+ cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags, m.date, d.pts, d.inbox_max, d.outbox_max, m.replydata, d.pinned, d.unread_count_i, d.flags, d.folder_id, d.data, d.unread_reactions, d.last_mid_group, d.ttl_period FROM dialogs as d LEFT JOIN messages_v2 as m ON d.last_mid = m.mid AND d.did = m.uid AND d.last_mid_group IS NULL LEFT JOIN dialog_settings as s ON d.did = s.did WHERE d.folder_id = %d ORDER BY d.pinned DESC, d.date DESC LIMIT %d,%d", fid, off, cnt));
while (cursor.next()) {
long dialogId = cursor.longValue(0);
TLRPC.Dialog dialog;
@@ -14823,9 +13727,11 @@ public class MessagesStorage extends BaseController {
}
dialog.folder_id = cursor.intValue(17);
dialog.unread_reactions_count = cursor.intValue(19);
- if (!cursor.isNull(20)) {
- dialogsToLoadGroupMessages.add(new Pair<>(dialogId, cursor.longValue(20)));
+ long groupMessagesId = cursor.longValue(20);
+ if (groupMessagesId != 0) {
+ dialogsToLoadGroupMessages.add(new Pair<>(dialogId, groupMessagesId));
}
+ dialog.ttl_period = cursor.intValue(21);
dialogs.dialogs.add(dialog);
if (draftsDialogIds != null) {
@@ -15100,7 +14006,7 @@ public class MessagesStorage extends BaseController {
if (!dialogs.dialogs.isEmpty()) {
state_messages = database.executeFast("REPLACE INTO messages_v2 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, 0, NULL, ?)");
- state_dialogs = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ state_dialogs = database.executeFast("REPLACE INTO dialogs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
state_media = database.executeFast("REPLACE INTO media_v4 VALUES(?, ?, ?, ?, ?)");
state_settings = database.executeFast("REPLACE INTO dialog_settings VALUES(?, ?)");
state_holes = database.executeFast("REPLACE INTO messages_holes VALUES(?, ?, ?)");
@@ -15280,6 +14186,7 @@ public class MessagesStorage extends BaseController {
} else {
state_dialogs.bindNull(16);
}
+ state_dialogs.bindInteger(17, dialog.ttl_period);
state_dialogs.step();
if (data != null) {
data.reuse();
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java
index 2cb0024c2..c79e99067 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java
@@ -10,6 +10,7 @@ package org.telegram.messenger;
import android.os.SystemClock;
import android.util.SparseArray;
+import android.view.View;
import androidx.annotation.UiThread;
@@ -264,6 +265,7 @@ public class NotificationCenter {
public static final int permissionsGranted = totalEvents++;
public static int topicsDidLoaded = totalEvents++;
public static int chatSwithcedToForum = totalEvents++;
+ public static int didUpdateGlobalAutoDeleteTimer = totalEvents++;
private SparseArray> observers = new SparseArray<>();
private SparseArray> removeAfterBroadcast = new SparseArray<>();
@@ -510,9 +512,6 @@ public class NotificationCenter {
if (!allowDuringAnimation && isAnimationInProgress()) {
DelayedPost delayedPost = new DelayedPost(id, args);
delayedPosts.add(delayedPost);
- if (BuildVars.LOGS_ENABLED) {
- FileLog.e("delay post notification " + id + " with args count = " + args.length);
- }
return;
}
if (!postponeCallbackList.isEmpty()) {
@@ -653,4 +652,29 @@ public class NotificationCenter {
time = SystemClock.elapsedRealtime();
}
}
+
+ public static void listenEmojiLoading(View view) {
+ if (view == null) {
+ return;
+ }
+
+ final NotificationCenterDelegate delegate = (id, account, args) -> {
+ if (id == NotificationCenter.emojiLoaded) {
+ if (view != null && view.isAttachedToWindow()) {
+ view.invalidate();
+ }
+ }
+ };
+ view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
+ @Override
+ public void onViewAttachedToWindow(View view) {
+ NotificationCenter.getGlobalInstance().addObserver(delegate, NotificationCenter.emojiLoaded);
+ }
+
+ @Override
+ public void onViewDetachedFromWindow(View view) {
+ NotificationCenter.getGlobalInstance().removeObserver(delegate, NotificationCenter.emojiLoaded);
+ }
+ });
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java
index 74abe4ee0..2ebb767ed 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java
@@ -856,7 +856,7 @@ public class NotificationsController extends BaseController {
}
long originalDialogId = dialogId;
- int topicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(messageObject));
if (dialogId == openedDialogId && ApplicationLoader.isScreenOn) {
if (!isFcm) {
playInChatSound();
@@ -919,7 +919,7 @@ public class NotificationsController extends BaseController {
if (messageObject.isReactionPush) {
SparseBooleanArray sparseBooleanArray = new SparseBooleanArray();
sparseBooleanArray.put(mid, true);
- getMessagesController().checkUnreadReactions(dialogId, MessageObject.getTopicId(messageObject.messageOwner), sparseBooleanArray);
+ getMessagesController().checkUnreadReactions(dialogId, topicId, sparseBooleanArray);
}
}
@@ -951,7 +951,7 @@ public class NotificationsController extends BaseController {
} else if (added) {
MessageObject messageObject = messageObjects.get(0);
long dialog_id = messageObject.getDialogId();
- int topicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(dialog_id));
Boolean isChannel;
if (messageObject.isFcmMessage()) {
isChannel = messageObject.localChannel;
@@ -1182,7 +1182,7 @@ public class NotificationsController extends BaseController {
}
long dialog_id = messageObject.getDialogId();
long original_dialog_id = dialog_id;
- int topicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(messageObject));
if (messageObject.messageOwner.mentioned) {
dialog_id = messageObject.getFromChatId();
}
@@ -1254,7 +1254,7 @@ public class NotificationsController extends BaseController {
}
long dialogId = messageObject.getDialogId();
long originalDialogId = dialogId;
- int topicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(messageObject));
long randomId = messageObject.messageOwner.random_id;
if (messageObject.messageOwner.mentioned) {
dialogId = messageObject.getFromChatId();
@@ -3428,7 +3428,7 @@ public class NotificationsController extends BaseController {
}
long dialog_id = lastMessageObject.getDialogId();
- int topicId = MessageObject.getTopicId(lastMessageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(lastMessageObject.messageOwner, getMessagesController().isForum(lastMessageObject));
boolean isChannel = false;
long override_dialog_id = dialog_id;
@@ -4016,7 +4016,7 @@ public class NotificationsController extends BaseController {
for (int a = 0; a < pushMessages.size(); a++) {
MessageObject messageObject = pushMessages.get(a);
long dialog_id = messageObject.getDialogId();
- int topicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int topicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(messageObject));
int dismissDate = preferences.getInt("dismissDate" + dialog_id, 0);
if (messageObject.messageOwner.date <= dismissDate) {
continue;
@@ -4305,7 +4305,7 @@ public class NotificationsController extends BaseController {
int rowsMid = 0;
for (int a = messageObjects.size() - 1; a >= 0; a--) {
MessageObject messageObject = messageObjects.get(a);
- int messageTopicId = MessageObject.getTopicId(messageObject.messageOwner);
+ int messageTopicId = MessageObject.getTopicId(messageObject.messageOwner, getMessagesController().isForum(messageObject));
if (topicId != messageTopicId) {
continue;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java
index ca6158704..75e8db83c 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java
@@ -1451,7 +1451,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
HashMap params = null;
if (DialogObject.isEncryptedDialog(did) && messageObject.messageOwner.peer_id != null && (messageObject.messageOwner.media.photo instanceof TLRPC.TL_photo || messageObject.messageOwner.media.document instanceof TLRPC.TL_document)) {
params = new HashMap<>();
- params.put("parentObject", "sent_" + messageObject.messageOwner.peer_id.channel_id + "_" + messageObject.getId());
+ params.put("parentObject", "sent_" + messageObject.messageOwner.peer_id.channel_id + "_" + messageObject.getId() + "_" + messageObject.getDialogId());
}
if (messageObject.messageOwner.media.photo instanceof TLRPC.TL_photo) {
sendMessage((TLRPC.TL_photo) messageObject.messageOwner.media.photo, null, did, messageObject.replyMessageObject, null, messageObject.messageOwner.message, messageObject.messageOwner.entities, null, params, true, 0, messageObject.messageOwner.media.ttl_seconds, messageObject, false);
@@ -2374,7 +2374,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
ArrayList arr = new ArrayList<>();
arr.add(newMsg);
- getMessagesStorage().putMessages(arr, false, true, false, 0, messageObject.scheduled, MessageObject.getTopicId(newMsg));
+ getMessagesStorage().putMessages(arr, false, true, false, 0, messageObject.scheduled, MessageObject.getTopicId(newMsg, getMessagesController().isForum(newMsg)));
getMessagesController().getTopicsController().processEditedMessage(newMsg);
messageObject.type = -1;
@@ -5570,7 +5570,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
LongSparseArray> channelReplies = null;
for (int a = 0; a < updatesArr.size(); a++) {
TLRPC.Update update = updatesArr.get(a);
- if (update instanceof TLRPC.TL_updateNewMessage) {
+ if (update instanceof TLRPC.TL_updateNewMessage && ((TLRPC.TL_updateNewMessage) update).message.action == null) {
final TLRPC.TL_updateNewMessage newMessage = (TLRPC.TL_updateNewMessage) update;
sentMessages.add(message = newMessage.message);
Utilities.stageQueue.postRunnable(() -> getMessagesController().processNewDifferenceParams(-1, newMessage.pts, -1, newMessage.pts_count));
@@ -5783,7 +5783,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
}
if (sentMessage.media instanceof TLRPC.TL_messageMediaPhoto && sentMessage.media.photo != null && newMsg.media instanceof TLRPC.TL_messageMediaPhoto && newMsg.media.photo != null) {
if (sentMessage.media.ttl_seconds == 0 && !newMsgObj.scheduled) {
- getMessagesStorage().putSentFile(originalPath, sentMessage.media.photo, 0, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id);
+ getMessagesStorage().putSentFile(originalPath, sentMessage.media.photo, 0, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id + "_" + DialogObject.getPeerDialogId(sentMessage.peer_id));
}
if (newMsg.media.photo.sizes.size() == 1 && newMsg.media.photo.sizes.get(0).location instanceof TLRPC.TL_fileLocationUnavailable) {
@@ -5843,13 +5843,13 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
boolean isVideo = MessageObject.isVideoMessage(sentMessage);
if ((isVideo || MessageObject.isGifMessage(sentMessage)) && MessageObject.isGifDocument(sentMessage.media.document) == MessageObject.isGifDocument(newMsg.media.document)) {
if (!newMsgObj.scheduled) {
- getMessagesStorage().putSentFile(originalPath, sentMessage.media.document, 2, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id);
+ getMessagesStorage().putSentFile(originalPath, sentMessage.media.document, 2, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id + "_" + DialogObject.getPeerDialogId(sentMessage.peer_id));
}
if (isVideo) {
sentMessage.attachPath = newMsg.attachPath;
}
} else if (!MessageObject.isVoiceMessage(sentMessage) && !MessageObject.isRoundVideoMessage(sentMessage) && !newMsgObj.scheduled) {
- getMessagesStorage().putSentFile(originalPath, sentMessage.media.document, 1, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id);
+ getMessagesStorage().putSentFile(originalPath, sentMessage.media.document, 1, "sent_" + sentMessage.peer_id.channel_id + "_" + sentMessage.id + "_" + DialogObject.getPeerDialogId(sentMessage.peer_id));
}
}
@@ -7063,7 +7063,7 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
messageMediaInvoice.title = invoice.title;
messageMediaInvoice.description = invoice.description;
if (invoice.photo != null) {
- messageMediaInvoice.photo = invoice.photo;
+ messageMediaInvoice.webPhoto = invoice.photo;
messageMediaInvoice.flags |= 1;
}
messageMediaInvoice.currency = invoice.currency;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SvgHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SvgHelper.java
index 26762b8f0..5682fb5de 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/SvgHelper.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/SvgHelper.java
@@ -164,7 +164,7 @@ public class SvgHelper {
}
float scale = getScale((int) w, (int) h);
- if (placeholderGradient != null) {
+ if (placeholderGradient[threadIndex] != null && gradientWidth > 0) {
if (drawInBackground) {
long dt = time - lastUpdateTime;
if (dt > 64) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TopicsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/TopicsController.java
index 3d9ddc8c0..92841bb4a 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/TopicsController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/TopicsController.java
@@ -1,6 +1,7 @@
package org.telegram.messenger;
import android.content.SharedPreferences;
+import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.SparseArray;
@@ -21,7 +22,6 @@ import org.telegram.ui.Components.Forum.ForumUtilities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -33,7 +33,8 @@ public class TopicsController extends BaseController {
public static final int TOPIC_FLAG_ICON = 2;
public static final int TOPIC_FLAG_PIN = 4;
public static final int TOPIC_FLAG_CLOSE = 8;
-
+ public static final int TOPIC_FLAG_TOTAL_MESSAGES_COUNT = 16;
+ public static final int TOPIC_FLAG_HIDE = 32;
private static final int MAX_PRELOAD_COUNT = 20;
@@ -67,7 +68,7 @@ public class TopicsController extends BaseController {
return;
}
- if (BuildVars.DEBUG_PRIVATE_VERSION) {
+ if (BuildVars.LOGS_ENABLED) {
FileLog.d("load topics " + chatId + " fromCache=" + fromCache + " loadType=" + loadType);
}
topicsIsLoading.put(chatId, 1);
@@ -75,7 +76,7 @@ public class TopicsController extends BaseController {
if (fromCache) {
getMessagesStorage().loadTopics(-chatId, topics -> {
AndroidUtilities.runOnUIThread(() -> {
- if (BuildVars.DEBUG_PRIVATE_VERSION) {
+ if (BuildVars.LOGS_ENABLED) {
FileLog.d("loaded from cache " + chatId + " topics_count=" + (topics == null ? 0 : topics.size()));
}
@@ -98,7 +99,7 @@ public class TopicsController extends BaseController {
getForumTopics.offset_id = loadOffsets.lastMessageId;
getForumTopics.offset_topic = loadOffsets.lastTopicId;
- if (BuildVars.DEBUG_PRIVATE_VERSION) {
+ if (BuildVars.LOGS_ENABLED) {
FileLog.d("offset_date=" + loadOffsets.lastMessageDate + " offset_id=" + loadOffsets.lastMessageId + " offset_topic=" + loadOffsets.lastTopicId);
}
}
@@ -111,7 +112,7 @@ public class TopicsController extends BaseController {
messagesMap.put(topics.messages.get(i).id, topics.messages.get(i));
}
AndroidUtilities.runOnUIThread(() -> {
- getMessagesStorage().putUsersAndChats(((TLRPC.TL_messages_forumTopics) response).users, ((TLRPC.TL_messages_forumTopics) response).chats, true, false);
+ getMessagesStorage().putUsersAndChats(((TLRPC.TL_messages_forumTopics) response).users, ((TLRPC.TL_messages_forumTopics) response).chats, true, true);
getMessagesController().putUsers(((TLRPC.TL_messages_forumTopics) response).users, false);
getMessagesController().putChats(((TLRPC.TL_messages_forumTopics) response).chats, false);
@@ -141,6 +142,9 @@ public class TopicsController extends BaseController {
}
public void processTopics(long chatId, ArrayList newTopics, SparseArray messagesMap, boolean fromCache, int loadType, int totalCount) {
+ if (BuildVars.LOGS_ENABLED) {
+ FileLog.d("processTopics=" + "new_topics_size=" + (newTopics == null ? 0 : newTopics.size()) + " fromCache=" + fromCache + " load_type=" + loadType + " totalCount=" + totalCount);
+ }
ArrayList topics = topicsByChatId.get(chatId);
ArrayList topicsToReload = null;
LongSparseArray topicsMap = topicsMapByChatId.get(chatId);
@@ -204,9 +208,10 @@ public class TopicsController extends BaseController {
if (topicsToReload != null && loadType != LOAD_TYPE_LOAD_UNKNOWN) {
reloadTopics(chatId, topicsToReload);
- } else if (loadType == LOAD_TYPE_LOAD_NEXT && topics.size() >= totalCount && totalCount >= 0) {
+ } else if (((loadType == LOAD_TYPE_PRELOAD && !fromCache) || loadType == LOAD_TYPE_LOAD_NEXT) && topics.size() >= totalCount && totalCount >= 0) {
endIsReached.put(chatId, 1);
getUserConfig().getPreferences().edit().putBoolean("topics_end_reached_" + chatId, true).apply();
+ changed = true;
}
if (changed) {
@@ -239,7 +244,19 @@ public class TopicsController extends BaseController {
ArrayList topics = topicsByChatId.get(chatId);
if (topics != null) {
if (openedTopicsBuChatId.get(chatId, 0) > 0) {
- Collections.sort(topics, Comparator.comparingInt(o -> o.topMessage == null ? Integer.MAX_VALUE : -(o.pinned ? Integer.MAX_VALUE - o.pinnedOrder : o.topMessage.date)));
+// Comparator.comparingInt(o -> o.topMessage == null ? Integer.MAX_VALUE : -(o.pinned ? Integer.MAX_VALUE - o.pinnedOrder : o.topMessage.date))
+ Collections.sort(topics, (a, b) -> {
+ if (a.hidden != b.hidden) {
+ return a.hidden ? -1 : 1;
+ }
+ if (a.pinned != b.pinned) {
+ return a.pinned ? -1 : 1;
+ }
+ if (a.pinned && b.pinned) {
+ return a.pinnedOrder - b.pinnedOrder;
+ }
+ return (b.topMessage != null ? b.topMessage.date : 0) - (a.topMessage != null ? a.topMessage.date : 0);
+ });
}
if (notify) {
getNotificationCenter().postNotificationName(NotificationCenter.topicsDidLoaded, chatId, true);
@@ -405,6 +422,10 @@ public class TopicsController extends BaseController {
}
public CharSequence getTopicIconName(TLRPC.Chat chat, MessageObject message, TextPaint paint) {
+ return getTopicIconName(chat, message, paint, null);
+ }
+
+ public CharSequence getTopicIconName(TLRPC.Chat chat, MessageObject message, TextPaint paint, Drawable[] drawableToSet) {
if (message.messageOwner.reply_to == null) {
return null;
}
@@ -415,7 +436,7 @@ public class TopicsController extends BaseController {
if (topicId != 0) {
TLRPC.TL_forumTopic topic = findTopic(chat.id, topicId);
if (topic != null) {
- return ForumUtilities.getTopicSpannedName(topic, paint);
+ return ForumUtilities.getTopicSpannedName(topic, paint, drawableToSet);
}
}
return null;
@@ -464,7 +485,7 @@ public class TopicsController extends BaseController {
}
public void onTopicEdited(long dialogId, TLRPC.TL_forumTopic forumTopic) {
- getMessagesStorage().updateTopicData(dialogId, forumTopic, TOPIC_FLAG_ICON + TOPIC_FLAG_TITLE);
+ getMessagesStorage().updateTopicData(dialogId, forumTopic, TOPIC_FLAG_ICON + TOPIC_FLAG_TITLE + TOPIC_FLAG_HIDE);
sortTopics(-dialogId);
}
@@ -590,6 +611,37 @@ public class TopicsController extends BaseController {
}
}
+ public void toggleShowTopic(long chatId, int topicId, boolean show) {
+ TLRPC.TL_channels_editForumTopic req = new TLRPC.TL_channels_editForumTopic();
+ req.channel = getMessagesController().getInputChannel(chatId);
+ req.topic_id = topicId;
+ req.flags = 8;
+ boolean wasHidden = show;
+ req.hidden = !show;
+
+ TLRPC.TL_forumTopic topic = findTopic(chatId, topicId);
+ if (topic != null) {
+ wasHidden = topic.hidden;
+ topic.hidden = req.hidden;
+ if (topic.hidden) {
+ topic.closed = true;
+// topic.pinned = true;
+// ArrayList order = getCurrentPinnedOrder(chatId);
+// order.remove((Integer) topicId);
+// order.add(0, topicId);
+// applyPinnedOrder(chatId, order);
+ }
+ updateTopicInUi(-chatId, topic, TOPIC_FLAG_PIN | TOPIC_FLAG_HIDE | TOPIC_FLAG_CLOSE);
+ getMessagesStorage().updateTopicData(-chatId, topic, TOPIC_FLAG_PIN | TOPIC_FLAG_HIDE | TOPIC_FLAG_CLOSE);
+ }
+
+ ConnectionsManager.getInstance(currentAccount).sendRequest(req, (res, err) -> {
+ if (err != null) {
+
+ }
+ });
+ }
+
public void pinTopic(long chatId, int topicId, boolean pin, BaseFragment fragment) {
TLRPC.TL_channels_updatePinnedForumTopic req = new TLRPC.TL_channels_updatePinnedForumTopic();
req.channel = getMessagesController().getInputChannel(chatId);
@@ -611,13 +663,15 @@ public class TopicsController extends BaseController {
return;
}
applyPinnedOrder(chatId, prevOrder);
- fragment.showDialog(
+ AndroidUtilities.runOnUIThread(() -> {
+ fragment.showDialog(
new AlertDialog.Builder(fragment.getContext())
- .setTitle(LocaleController.getString("LimitReached", R.string.LimitReached))
- .setMessage(LocaleController.formatString("LimitReachedPinnedTopics", R.string.LimitReachedPinnedTopics, MessagesController.getInstance(currentAccount).topicsPinnedLimit))
- .setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
- .create()
- );
+ .setTitle(LocaleController.getString("LimitReached", R.string.LimitReached))
+ .setMessage(LocaleController.formatString("LimitReachedPinnedTopics", R.string.LimitReachedPinnedTopics, MessagesController.getInstance(currentAccount).topicsPinnedLimit))
+ .setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
+ .create()
+ );
+ });
} else if ("PINNED_TOPIC_NOT_MODIFIED".equals(error.text)) {
reloadTopics(chatId, false);
}
@@ -751,6 +805,9 @@ public class TopicsController extends BaseController {
topic.unread_mentions_count = update.unreadMentions;
topicsByTopMsgId.put(messageHash(topic.top_message, -update.dialogId), topic);
}
+ if (update.totalMessagesCount > 0) {
+ topic.totalMessagesCount = update.totalMessagesCount;
+ }
changedDialogs.add(-update.dialogId);
}
}
@@ -890,6 +947,9 @@ public class TopicsController extends BaseController {
if ((flags & TOPIC_FLAG_PIN) != 0) {
topic.pinned = forumTopic.pinned;
}
+ if ((flags & TOPIC_FLAG_HIDE) != 0) {
+ topic.hidden = forumTopic.hidden;
+ }
sortTopics(-dialogId);
}
}
@@ -926,6 +986,7 @@ public class TopicsController extends BaseController {
}
public static class TopicUpdate {
+ public int totalMessagesCount = -1;
long dialogId;
int topicId;
int unreadMentions;
@@ -951,6 +1012,25 @@ public class TopicsController extends BaseController {
v = 0;
}
openedTopicsBuChatId.put(chatId, v);
+ }
+ public void getTopicRepliesCount(long dialogId, int topicId) {
+ TLRPC.TL_forumTopic topic = findTopic(-dialogId, topicId);
+ if (topic != null) {
+ if (topic.totalMessagesCount == 0) {
+ TLRPC.TL_messages_getReplies req = new TLRPC.TL_messages_getReplies();
+ req.peer = getMessagesController().getInputPeer(dialogId);
+ req.msg_id = topicId;
+ req.limit = 1;
+ getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
+ if (response != null) {
+ TLRPC.messages_Messages messages = (TLRPC.messages_Messages) response;
+ topic.totalMessagesCount = messages.count;
+ getMessagesStorage().updateTopicData(dialogId, topic, TOPIC_FLAG_TOTAL_MESSAGES_COUNT);
+ NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.topicsDidLoaded, -dialogId, true);
+ }
+ }));
+ }
+ }
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
index 41e33b371..253bdd2b1 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java
@@ -527,4 +527,34 @@ public class UserConfig extends BaseController {
}
return null;
}
+
+
+ int globalTtl = 0;
+ boolean ttlIsLoading = false;
+ long lastLoadingTime;
+
+ public int getGlobalTTl() {
+ return globalTtl;
+ }
+
+ public void loadGlobalTTl() {
+ if (ttlIsLoading || System.currentTimeMillis() - lastLoadingTime < 60 * 1000) {
+ return;
+ }
+ ttlIsLoading = true;
+ TLRPC.TL_messages_getDefaultHistoryTTL getDefaultHistoryTTL = new TLRPC.TL_messages_getDefaultHistoryTTL();
+ getConnectionsManager().sendRequest(getDefaultHistoryTTL, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
+ if (response != null) {
+ globalTtl = ((TLRPC.TL_defaultHistoryTTL) response).period / 60;
+ getNotificationCenter().postNotificationName(NotificationCenter.didUpdateGlobalAutoDeleteTimer);
+ ttlIsLoading = false;
+ lastLoadingTime = System.currentTimeMillis();
+ }
+ }));
+
+ }
+
+ public void setGlobalTtl(int ttl) {
+ globalTtl = ttl;
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/VideoEditedInfo.java b/TMessagesProj/src/main/java/org/telegram/messenger/VideoEditedInfo.java
index a023c6b5d..076d12bad 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/VideoEditedInfo.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/VideoEditedInfo.java
@@ -27,6 +27,7 @@ public class VideoEditedInfo {
public long avatarStartTime = -1;
public float start;
public float end;
+ public int compressQuality;
public int rotationValue;
public int originalWidth;
public int originalHeight;
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
index cc58fc6ff..84a6a8311 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
@@ -424,7 +424,7 @@ public class Browser {
try {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
List allActivities = ApplicationLoader.applicationContext.getPackageManager().queryIntentActivities(viewIntent, 0);
- if (allActivities != null && allActivities.size() > 1) {
+ if (allActivities != null && allActivities.size() >= 1) {
return false;
}
} catch (Exception ignore) {
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java
index 626c030df..2a1a8e0db 100755
--- a/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/voip/VoIPService.java
@@ -3059,7 +3059,11 @@ public class VoIPService extends Service implements SensorEventListener, AudioMa
}
am.abandonAudioFocus(this);
}
- am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));
+ try {
+ am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));
+ } catch (Exception e) {
+ FileLog.e(e);
+ }
if (hasAudioFocus) {
am.abandonAudioFocus(this);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java
index 1942a2ce3..a17ceb6c9 100644
--- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java
+++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java
@@ -18,7 +18,6 @@ import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.MessageObject;
-import org.telegram.messenger.MessagesController;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.Utilities;
@@ -69,7 +68,7 @@ public class TLRPC {
public static final int MESSAGE_FLAG_HAS_BOT_ID = 0x00000800;
public static final int MESSAGE_FLAG_EDITED = 0x00008000;
- public static final int LAYER = 149;
+ public static final int LAYER = 150;
public static class TL_stats_megagroupStats extends TLObject {
public static int constructor = 0xef7ff916;
@@ -3841,21 +3840,21 @@ public class TLRPC {
public static Peer TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
Peer result = null;
switch (constructor) {
+ case 0xa2a5371e:
+ result = new TL_peerChannel();
+ break;
case 0xbddde532:
result = new TL_peerChannel_layer131();
break;
case 0x59511722:
result = new TL_peerUser();
break;
- case 0xa2a5371e:
- result = new TL_peerChannel();
+ case 0x9db1bc6d:
+ result = new TL_peerUser_layer131();
break;
case 0x36c6019a:
result = new TL_peerChat();
break;
- case 0x9db1bc6d:
- result = new TL_peerUser_layer131();
- break;
case 0xbad0e5bb:
result = new TL_peerChat_layer131();
break;
@@ -4684,7 +4683,7 @@ public class TLRPC {
case 0x64199744:
result = new TL_secureFileEmpty();
break;
- case 0xe0277a62:
+ case 0x7d09c27e:
result = new TL_secureFile();
break;
}
@@ -6695,6 +6694,7 @@ public class TLRPC {
public static abstract class auth_SentCodeType extends TLObject {
public int flags;
+ public String url;
public int length;
public String pattern;
public String prefix;
@@ -6727,6 +6727,9 @@ public class TLRPC {
case 0xc000bba2:
result = new TL_auth_sentCodeTypeSms();
break;
+ case 0xd9565c39:
+ result = new TL_auth_sentCodeTypeFragmentSms();
+ break;
}
if (result == null && exception) {
throw new RuntimeException(String.format("can't parse magic %x in auth_SentCodeType", constructor));
@@ -6854,6 +6857,22 @@ public class TLRPC {
}
}
+ public static class TL_auth_sentCodeTypeFragmentSms extends auth_SentCodeType {
+ public static int constructor = 0xd9565c39;
+
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ url = stream.readString(exception);
+ length = stream.readInt32(exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeString(url);
+ stream.writeInt32(length);
+ }
+ }
+
public static abstract class messages_StickerSetInstallResult extends TLObject {
public ArrayList sets = new ArrayList<>();
@@ -7862,7 +7881,7 @@ public class TLRPC {
public static class TL_messageMediaInvoice extends MessageMedia {
public static int constructor = 0xf6a548d3;
- public WebDocument photo;
+ public WebDocument webPhoto;
public void readParams(AbstractSerializedData stream, boolean exception) {
flags = stream.readInt32(exception);
@@ -7871,7 +7890,7 @@ public class TLRPC {
title = stream.readString(exception);
description = stream.readString(exception);
if ((flags & 1) != 0) {
- photo = WebDocument.TLdeserialize(stream, stream.readInt32(exception), exception);
+ webPhoto = WebDocument.TLdeserialize(stream, stream.readInt32(exception), exception);
}
if ((flags & 4) != 0) {
receipt_msg_id = stream.readInt32(exception);
@@ -7892,7 +7911,7 @@ public class TLRPC {
stream.writeString(title);
stream.writeString(description);
if ((flags & 1) != 0) {
- photo.serializeToStream(stream);
+ webPhoto.serializeToStream(stream);
}
if ((flags & 4) != 0) {
stream.writeInt32(receipt_msg_id);
@@ -12061,6 +12080,7 @@ public class TLRPC {
public ArrayList available_reactions_legacy = new ArrayList<>();
public int flags2;
public boolean can_delete_channel;
+ public boolean antispam;
public ChatReactions available_reactions;
public long inviterId; //custom
@@ -14534,6 +14554,7 @@ public class TLRPC {
blocked = (flags & 4194304) != 0;
flags2 = stream.readInt32(exception);
can_delete_channel = (flags2 & 1) != 0;
+ antispam = (flags2 & 2) != 0;
id = stream.readInt64(exception);
about = stream.readString(exception);
if ((flags & 1) != 0) {
@@ -14669,6 +14690,7 @@ public class TLRPC {
flags = blocked ? (flags | 4194304) : (flags &~ 4194304);
stream.writeInt32(flags);
flags2 = can_delete_channel ? (flags2 | 1) : (flags2 &~ 1);
+ flags2 = antispam ? (flags2 | 2) : (flags2 &~ 2);
stream.writeInt32(flags2);
stream.writeInt64(id);
stream.writeString(about);
@@ -21139,6 +21161,37 @@ public class TLRPC {
}
}
+ public static class TL_exportedContactToken extends TLObject {
+ public static int constructor = 0x41bf109b;
+
+ public String url;
+ public int expires;
+
+ public static TL_exportedContactToken TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
+ if (TL_exportedContactToken.constructor != constructor) {
+ if (exception) {
+ throw new RuntimeException(String.format("can't parse magic %x in TL_exportedContactToken", constructor));
+ } else {
+ return null;
+ }
+ }
+ TL_exportedContactToken result = new TL_exportedContactToken();
+ result.readParams(stream, exception);
+ return result;
+ }
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ url = stream.readString(exception);
+ expires = stream.readInt32(exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeString(url);
+ stream.writeInt32(expires);
+ }
+ }
+
public static class TL_botCommand extends TLObject {
public static int constructor = 0xc27ac8c7;
@@ -21410,7 +21463,6 @@ public class TLRPC {
public static class TL_inputGroupCallStream extends InputFileLocation {
public static int constructor = 0x598a92a;
- public int flags;
public TL_inputGroupCall call;
public long time_ms;
public int scale;
@@ -22350,6 +22402,9 @@ public class TLRPC {
}
public void serializeToStream(AbstractSerializedData stream) {
+ if (username == null) {
+ flags = flags & ~8;
+ }
stream.writeInt32(constructor);
flags = self ? (flags | 1024) : (flags &~ 1024);
flags = contact ? (flags | 2048) : (flags &~ 2048);
@@ -23993,6 +24048,9 @@ public class TLRPC {
result = new TL_messageActionUserJoined();
break;
case 0xb18a431c:
+ result = new TL_messageActionTopicEdit_layer149();
+ break;
+ case 0xc0944820:
result = new TL_messageActionTopicEdit();
break;
case 0x55555551:
@@ -24004,9 +24062,12 @@ public class TLRPC {
case 0x55555552:
result = new TL_messageActionTTLChange();
break;
- case 0xaa1afbfd:
+ case 0x3c134d7b:
result = new TL_messageActionSetMessagesTTL();
break;
+ case 0xaa1afbfd:
+ result = new TL_messageActionSetMessagesTTL_layer149();
+ break;
case 0xd95c6154:
result = new TL_messageActionSecureValuesSent();
break;
@@ -24414,10 +24475,48 @@ public class TLRPC {
}
public static class TL_messageActionTopicEdit extends MessageAction {
- public static int constructor = 0xb18a431c;
+ public static int constructor = 0xc0944820;
public long icon_emoji_id;
public boolean closed;
+ public boolean hidden;
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ flags = stream.readInt32(exception);
+ if ((flags & 1) != 0) {
+ title = stream.readString(exception);
+ }
+ if ((flags & 2) != 0) {
+ icon_emoji_id = stream.readInt64(exception);
+ }
+ if ((flags & 4) != 0) {
+ closed = stream.readBool(exception);
+ }
+ if ((flags & 8) != 0) {
+ hidden = stream.readBool(exception);
+ }
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(flags);
+ if ((flags & 1) != 0) {
+ stream.writeString(title);
+ }
+ if ((flags & 2) != 0) {
+ stream.writeInt64(icon_emoji_id);
+ }
+ if ((flags & 4) != 0) {
+ stream.writeBool(closed);
+ }
+ if ((flags & 8) != 0) {
+ stream.writeBool(hidden);
+ }
+ }
+ }
+
+ public static class TL_messageActionTopicEdit_layer149 extends TL_messageActionTopicEdit {
+ public static int constructor = 0xb18a431c;
public void readParams(AbstractSerializedData stream, boolean exception) {
flags = stream.readInt32(exception);
@@ -24677,9 +24776,31 @@ public class TLRPC {
}
public static class TL_messageActionSetMessagesTTL extends MessageAction {
- public static int constructor = 0xaa1afbfd;
+ public static int constructor = 0x3c134d7b;
public int period;
+ public long auto_setting_from;
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ flags = stream.readInt32(exception);
+ period = stream.readInt32(exception);
+ if ((flags & 1) != 0) {
+ auto_setting_from = stream.readInt64(exception);
+ }
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(flags);
+ stream.writeInt32(period);
+ if ((flags & 1) != 0) {
+ stream.writeInt64(auto_setting_from);
+ }
+ }
+ }
+
+ public static class TL_messageActionSetMessagesTTL_layer149 extends TL_messageActionSetMessagesTTL {
+ public static int constructor = 0xaa1afbfd;
public void readParams(AbstractSerializedData stream, boolean exception) {
period = stream.readInt32(exception);
@@ -44148,6 +44269,9 @@ public class TLRPC {
case 0xd61ad6ee:
result = new TL_auth_codeTypeMissedCall();
break;
+ case 0x6ed998c:
+ result = new TL_auth_codeTypeFragmentSms();
+ break;
}
if (result == null && exception) {
throw new RuntimeException(String.format("can't parse magic %x in auth_CodeType", constructor));
@@ -44195,6 +44319,15 @@ public class TLRPC {
}
}
+ public static class TL_auth_codeTypeFragmentSms extends auth_CodeType {
+ public static int constructor = 0x6ed998c;
+
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
public static abstract class messages_TranslatedText extends TLObject {
public static messages_TranslatedText TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
@@ -51228,10 +51361,12 @@ public class TLRPC {
}
public static class TL_messages_createChat extends TLObject {
- public static int constructor = 0x9cb126e;
+ public static int constructor = 0x34a818;
+ public int flags;
public ArrayList users = new ArrayList<>();
public String title;
+ public int ttl_period;
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
return Updates.TLdeserialize(stream, constructor, exception);
@@ -51239,6 +51374,7 @@ public class TLRPC {
public void serializeToStream(AbstractSerializedData stream) {
stream.writeInt32(constructor);
+ stream.writeInt32(flags);
stream.writeInt32(0x1cb5c415);
int count = users.size();
stream.writeInt32(count);
@@ -51246,6 +51382,9 @@ public class TLRPC {
users.get(a).serializeToStream(stream);
}
stream.writeString(title);
+ if ((flags & 1) != 0) {
+ stream.writeInt32(ttl_period);
+ }
}
}
@@ -61607,18 +61746,24 @@ public class TLRPC {
public int pts;
public DraftMessage draft;
public int folder_id;
+ public int ttl_period;
public int last_message_date; //custom
public long id; //custom
public int pinnedNum; //custom
+ public boolean isFolder; //custom
- public static Dialog TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
+ public static Dialog TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
Dialog result = null;
switch (constructor) {
- case 0xa8edd0f5:
+ case 0xd58a08c6:
result = new TL_dialog();
break;
+ case 0xa8edd0f5:
+ result = new TL_dialog_layer149();
+ break;
case 0x71bd134c:
result = new TL_dialogFolder();
+ result.isFolder = true;
break;
}
if (result == null && exception) {
@@ -61632,8 +61777,7 @@ public class TLRPC {
}
public static class TL_dialog extends Dialog {
- public static int constructor = 0xa8edd0f5;
- public int stableId = MessagesController.stableIdPointer++;
+ public static int constructor = 0xd58a08c6;
public void readParams(AbstractSerializedData stream, boolean exception) {
flags = stream.readInt32(exception);
@@ -61646,7 +61790,7 @@ public class TLRPC {
unread_count = stream.readInt32(exception);
unread_mentions_count = stream.readInt32(exception);
unread_reactions_count = stream.readInt32(exception);
- notify_settings = PeerNotifySettings.TLdeserialize(stream, stream.readInt32(exception), exception);
+ notify_settings = TL_peerNotifySettings.TLdeserialize(stream, stream.readInt32(exception), exception);
if ((flags & 1) != 0) {
pts = stream.readInt32(exception);
}
@@ -61656,6 +61800,9 @@ public class TLRPC {
if ((flags & 16) != 0) {
folder_id = stream.readInt32(exception);
}
+ if ((flags & 32) != 0) {
+ ttl_period = stream.readInt32(exception);
+ }
}
public void serializeToStream(AbstractSerializedData stream) {
@@ -61680,6 +61827,66 @@ public class TLRPC {
if ((flags & 16) != 0) {
stream.writeInt32(folder_id);
}
+ if ((flags & 32) != 0) {
+ stream.writeInt32(ttl_period);
+ }
+ }
+ }
+
+ public static class TL_dialog_layer149 extends TL_dialog {
+ public static int constructor = 0xa8edd0f5;
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ flags = stream.readInt32(exception);
+ pinned = (flags & 4) != 0;
+ unread_mark = (flags & 8) != 0;
+ peer = Peer.TLdeserialize(stream, stream.readInt32(exception), exception);
+ top_message = stream.readInt32(exception);
+ read_inbox_max_id = stream.readInt32(exception);
+ read_outbox_max_id = stream.readInt32(exception);
+ unread_count = stream.readInt32(exception);
+ unread_mentions_count = stream.readInt32(exception);
+ unread_reactions_count = stream.readInt32(exception);
+ notify_settings = PeerNotifySettings.TLdeserialize(stream, stream.readInt32(exception), exception);
+ if ((flags & 1) != 0) {
+ pts = stream.readInt32(exception);
+ }
+ if ((flags & 2) != 0) {
+ draft = DraftMessage.TLdeserialize(stream, stream.readInt32(exception), exception);
+ }
+ if ((flags & 16) != 0) {
+ folder_id = stream.readInt32(exception);
+ }
+ if ((flags & 32) != 0) {
+ ttl_period = stream.readInt32(exception);
+ }
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ flags = pinned ? (flags | 4) : (flags &~ 4);
+ flags = unread_mark ? (flags | 8) : (flags &~ 8);
+ stream.writeInt32(flags);
+ peer.serializeToStream(stream);
+ stream.writeInt32(top_message);
+ stream.writeInt32(read_inbox_max_id);
+ stream.writeInt32(read_outbox_max_id);
+ stream.writeInt32(unread_count);
+ stream.writeInt32(unread_mentions_count);
+ stream.writeInt32(unread_reactions_count);
+ notify_settings.serializeToStream(stream);
+ if ((flags & 1) != 0) {
+ stream.writeInt32(pts);
+ }
+ if ((flags & 2) != 0) {
+ draft.serializeToStream(stream);
+ }
+ if ((flags & 16) != 0) {
+ stream.writeInt32(folder_id);
+ }
+ if ((flags & 32) != 0) {
+ stream.writeInt32(ttl_period);
+ }
}
}
@@ -64166,6 +64373,7 @@ public class TLRPC {
public boolean closed;
public boolean pinned;
public boolean isShort;
+ public boolean hidden;
public int id;
public int date;
public String title;
@@ -64185,6 +64393,7 @@ public class TLRPC {
public Message topMessage; // custom
public String searchQuery; //custom
public int pinnedOrder; // custom
+ public int totalMessagesCount; // custom
public static TL_forumTopic TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
TL_forumTopic result = null;
@@ -64214,6 +64423,7 @@ public class TLRPC {
closed = (flags & 4) != 0;
pinned = (flags & 8) != 0;
isShort = (flags & 32) != 0;
+ hidden = (flags & 64) != 0;
id = stream.readInt32(exception);
date = stream.readInt32(exception);
title = stream.readString(exception);
@@ -64240,6 +64450,7 @@ public class TLRPC {
flags = closed ? (flags | 4) : (flags &~ 4);
flags = pinned ? (flags | 8) : (flags &~ 8);
flags = isShort ? (flags | 32) : (flags &~ 32);
+ flags = hidden ? (flags | 64) : (flags &~ 64);
stream.writeInt32(flags);
stream.writeInt32(id);
stream.writeInt32(date);
@@ -64438,7 +64649,7 @@ public class TLRPC {
}
public static class TL_channels_editForumTopic extends TLObject {
- public static int constructor = 0x6c883e2d;
+ public static int constructor = 0xf4dfa185;
public int flags;
public InputChannel channel;
@@ -64446,6 +64657,7 @@ public class TLRPC {
public String title;
public long icon_emoji_id;
public boolean closed;
+ public boolean hidden;
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
return Updates.TLdeserialize(stream, constructor, exception);
@@ -64465,6 +64677,9 @@ public class TLRPC {
if ((flags & 4) != 0) {
stream.writeBool(closed);
}
+ if ((flags & 8) != 0) {
+ stream.writeBool(hidden);
+ }
}
}
@@ -64709,6 +64924,124 @@ public class TLRPC {
}
}
}
+
+ public static class TL_channels_toggleAntiSpam extends TLObject {
+ public static int constructor = 0x68f3e4eb;
+
+ public InputChannel channel;
+ public boolean enabled;
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return Updates.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ channel.serializeToStream(stream);
+ stream.writeBool(enabled);
+ }
+ }
+
+ public static class TL_channels_reportAntiSpamFalsePositive extends TLObject {
+ public static int constructor = 0xa850a693;
+
+ public InputChannel channel;
+ public int msg_id;
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return Bool.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ channel.serializeToStream(stream);
+ stream.writeInt32(msg_id);
+ }
+ }
+
+ public static class TL_messages_setDefaultHistoryTTL extends TLObject {
+ public static int constructor = 0x9eb51445;
+
+ public int period;
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return Bool.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(period);
+ }
+ }
+
+ public static class TL_messages_getDefaultHistoryTTL extends TLObject {
+ public static int constructor = 0x658b7188;
+
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return TL_defaultHistoryTTL.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
+ public static class TL_defaultHistoryTTL extends TLObject {
+ public static int constructor = 0x43b46b20;
+
+ public int period;
+
+ public static TL_defaultHistoryTTL TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
+ if (TL_defaultHistoryTTL.constructor != constructor) {
+ if (exception) {
+ throw new RuntimeException(String.format("can't parse magic %x in TL_defaultHistoryTTL", constructor));
+ } else {
+ return null;
+ }
+ }
+ TL_defaultHistoryTTL result = new TL_defaultHistoryTTL();
+ result.readParams(stream, exception);
+ return result;
+ }
+
+ public void readParams(AbstractSerializedData stream, boolean exception) {
+ period = stream.readInt32(exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeInt32(period);
+ }
+ }
+ public static class TL_contacts_exportContactToken extends TLObject {
+ public static int constructor = 0xf8654027;
+
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return TL_exportedContactToken.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ }
+ }
+
+ public static class TL_contacts_importContactToken extends TLObject {
+ public static int constructor = 0x13005788;
+
+ public String token;
+
+ public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
+ return User.TLdeserialize(stream, constructor, exception);
+ }
+
+ public void serializeToStream(AbstractSerializedData stream) {
+ stream.writeInt32(constructor);
+ stream.writeString(token);
+ }
+ }
+
//functions
public static class Vector extends TLObject {
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java
index fc443f7c6..1b1ccaaf1 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java
@@ -12,6 +12,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
@@ -48,6 +49,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.ui.Adapters.FiltersView;
import org.telegram.ui.Components.AnimatedEmojiDrawable;
+import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CubicBezierInterpolator;
import org.telegram.ui.Components.EllipsizeSpanAnimator;
import org.telegram.ui.Components.FireworksEffect;
@@ -69,8 +71,9 @@ public class ActionBar extends FrameLayout {
}
}
- private INavigationLayout.BackButtonState backButtonState;
+ private INavigationLayout.BackButtonState backButtonState = INavigationLayout.BackButtonState.BACK;
private ImageView backButtonImageView;
+ private BackupImageView avatarSearchImageView;
private Drawable backButtonDrawable;
private SimpleTextView[] titleTextView = new SimpleTextView[2];
private SimpleTextView subtitleTextView;
@@ -117,6 +120,7 @@ public class ActionBar extends FrameLayout {
private boolean castShadows = true;
protected boolean isSearchFieldVisible;
+ public float searchFieldVisibleAlpha;
protected int itemsBackgroundColor;
protected int itemsActionModeBackgroundColor;
protected int itemsColor;
@@ -130,10 +134,13 @@ public class ActionBar extends FrameLayout {
private boolean fromBottom;
private boolean centerScale;
private CharSequence subtitle;
+ private boolean drawBackButton;
private View.OnTouchListener interceptTouchEventListener;
private final Theme.ResourcesProvider resourcesProvider;
+ private PorterDuff.Mode colorFilterMode = PorterDuff.Mode.MULTIPLY;
+
SizeNotifierFrameLayout contentView;
boolean blurredBackground;
public Paint blurScrimPaint = new Paint();
@@ -158,7 +165,14 @@ public class ActionBar extends FrameLayout {
});
}
+ public void setColorFilterMode(PorterDuff.Mode colorFilterMode) {
+ this.colorFilterMode = colorFilterMode;
+ }
+
public INavigationLayout.BackButtonState getBackButtonState() {
+ if (backButtonDrawable instanceof INavigationLayout.IBackButtonDrawable) {
+ return ((INavigationLayout.IBackButtonDrawable) backButtonDrawable).getBackButtonState();
+ }
return backButtonState;
}
@@ -170,7 +184,7 @@ public class ActionBar extends FrameLayout {
backButtonImageView.setScaleType(ImageView.ScaleType.CENTER);
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsBackgroundColor));
if (itemsColor != 0) {
- backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, PorterDuff.Mode.MULTIPLY));
+ backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, colorFilterMode));
}
backButtonImageView.setPadding(AndroidUtilities.dp(1), 0, 0, 0);
addView(backButtonImageView, LayoutHelper.createFrame(54, 54, Gravity.LEFT | Gravity.TOP));
@@ -224,6 +238,23 @@ public class ActionBar extends FrameLayout {
invalidate();
}
+ public BackupImageView getSearchAvatarImageView() {
+ return avatarSearchImageView;
+ }
+
+ public void setSearchAvatarImageView(BackupImageView backupImageView) {
+ if (avatarSearchImageView == backupImageView) {
+ return;
+ }
+ if (avatarSearchImageView != null) {
+ removeView(avatarSearchImageView);
+ }
+ avatarSearchImageView = backupImageView;
+ if (avatarSearchImageView != null) {
+ addView(avatarSearchImageView);
+ }
+ }
+
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (supportsHolidayImage && !titleOverlayShown && !LocaleController.isRTL && ev.getAction() == MotionEvent.ACTION_DOWN) {
@@ -252,9 +283,12 @@ public class ActionBar extends FrameLayout {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
- if (parentFragment != null && parentFragment.getParentLayout().isActionBarInCrossfade()) {
+ if (parentFragment != null && parentFragment.getParentLayout() != null && parentFragment.getParentLayout().isActionBarInCrossfade()) {
return false;
}
+ if (drawBackButton && child == backButtonImageView) {
+ return true;
+ }
boolean clip = shouldClipChild(child);
if (clip) {
@@ -318,9 +352,6 @@ public class ActionBar extends FrameLayout {
}
backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
backButtonImageView.setImageResource(resource);
- if (resource == R.drawable.ic_ab_back) {
- backButtonState = INavigationLayout.BackButtonState.BACK;
- }
}
private void createSubtitleTextView() {
@@ -380,7 +411,12 @@ public class ActionBar extends FrameLayout {
if (titleTextView[i] != null) {
return;
}
- titleTextView[i] = new SimpleTextView(getContext());
+ titleTextView[i] = new SimpleTextView(getContext()) {
+ @Override
+ public void setAlpha(float alpha) {
+ super.setAlpha(alpha);
+ }
+ };
titleTextView[i].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
if (titleColorToSet != 0) {
titleTextView[i].setTextColor(titleColorToSet);
@@ -691,6 +727,15 @@ public class ActionBar extends FrameLayout {
}
actionModeAnimation = new AnimatorSet();
actionModeAnimation.playTogether(animators);
+ if (backgroundUpdateListener != null) {
+ ValueAnimator alphaUpdate = ValueAnimator.ofFloat(0, 1);
+ alphaUpdate.addUpdateListener(anm -> {
+ if (backgroundUpdateListener != null) {
+ backgroundUpdateListener.run();
+ }
+ });
+ actionModeAnimation.playTogether(alphaUpdate);
+ }
actionModeAnimation.setDuration(200);
actionModeAnimation.addListener(new AnimatorListenerAdapter() {
@Override
@@ -844,6 +889,15 @@ public class ActionBar extends FrameLayout {
}
actionModeAnimation = new AnimatorSet();
actionModeAnimation.playTogether(animators);
+ if (backgroundUpdateListener != null) {
+ ValueAnimator alphaUpdate = ValueAnimator.ofFloat(0, 1);
+ alphaUpdate.addUpdateListener(anm -> {
+ if (backgroundUpdateListener != null) {
+ backgroundUpdateListener.run();
+ }
+ });
+ actionModeAnimation.playTogether(alphaUpdate);
+ }
actionModeAnimation.setDuration(200);
actionModeAnimation.addListener(new AnimatorListenerAdapter() {
@Override
@@ -948,8 +1002,17 @@ public class ActionBar extends FrameLayout {
return actionMode != null && actionModeVisible && ((actionModeTag == null && tag == null) || (actionModeTag != null && actionModeTag.equals(tag)));
}
+ Runnable backgroundUpdateListener;
AnimatorSet searchVisibleAnimator;
+ public void listenToBackgroundUpdate(Runnable invalidate) {
+ backgroundUpdateListener = invalidate;
+ }
+
+ protected boolean onSearchChangedIgnoreTitles() {
+ return false;
+ }
+
public void onSearchFieldVisibilityChanged(boolean visible) {
isSearchFieldVisible = visible;
if (searchVisibleAnimator != null) {
@@ -958,14 +1021,26 @@ public class ActionBar extends FrameLayout {
searchVisibleAnimator = new AnimatorSet();
final ArrayList viewsToHide = new ArrayList<>();
- if (titleTextView[0] != null) {
- viewsToHide.add(titleTextView[0]);
+ final boolean ignoreTitles = onSearchChangedIgnoreTitles();
+ if (!ignoreTitles) {
+ if (titleTextView[0] != null) {
+ viewsToHide.add(titleTextView[0]);
+ }
+
+ if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
+ viewsToHide.add(subtitleTextView);
+ subtitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
+ }
}
- if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
- viewsToHide.add(subtitleTextView);
- subtitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
- }
+ ValueAnimator alphaUpdate = ValueAnimator.ofFloat(searchFieldVisibleAlpha, visible ? 1f : 0f);
+ alphaUpdate.addUpdateListener(anm -> {
+ searchFieldVisibleAlpha = (float) anm.getAnimatedValue();
+ if (backgroundUpdateListener != null) {
+ backgroundUpdateListener.run();
+ }
+ });
+ searchVisibleAnimator.playTogether(alphaUpdate);
for (int i = 0; i < viewsToHide.size(); i++) {
View view = viewsToHide.get(i);
@@ -979,6 +1054,10 @@ public class ActionBar extends FrameLayout {
searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(view, View.SCALE_Y, visible ? 0.95f : 1f));
searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(view, View.SCALE_X, visible ? 0.95f : 1f));
}
+ if (avatarSearchImageView != null) {
+ avatarSearchImageView.setVisibility(View.VISIBLE);
+ searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(avatarSearchImageView, View.ALPHA, visible ? 1f : 0f));
+ }
centerScale = true;
requestLayout();
searchVisibleAnimator.addListener(new AnimatorListenerAdapter() {
@@ -994,7 +1073,7 @@ public class ActionBar extends FrameLayout {
}
}
- if (visible) {
+ if (visible && !ignoreTitles) {
if (titleTextView[0] != null) {
titleTextView[0].setVisibility(View.GONE);
}
@@ -1002,16 +1081,24 @@ public class ActionBar extends FrameLayout {
titleTextView[1].setVisibility(View.GONE);
}
}
+
+ if (avatarSearchImageView != null) {
+ if (!visible) {
+ avatarSearchImageView.setVisibility(View.GONE);
+ }
+ }
}
});
searchVisibleAnimator.setDuration(150).start();
- Drawable drawable = backButtonImageView.getDrawable();
- if (drawable instanceof MenuDrawable) {
- MenuDrawable menuDrawable = (MenuDrawable) drawable;
- menuDrawable.setRotateToBack(true);
- menuDrawable.setRotation(visible ? 1 : 0, true);
+ if (backButtonImageView != null) {
+ Drawable drawable = backButtonImageView.getDrawable();
+ if (drawable instanceof MenuDrawable) {
+ MenuDrawable menuDrawable = (MenuDrawable) drawable;
+ menuDrawable.setRotateToBack(true);
+ menuDrawable.setRotation(visible ? 1 : 0, true);
+ }
}
}
@@ -1194,10 +1281,17 @@ public class ActionBar extends FrameLayout {
}
}
+ if (avatarSearchImageView != null) {
+ avatarSearchImageView.measure(
+ MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY)
+ );
+ }
+
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
- if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView) {
+ if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView || child == avatarSearchImageView) {
continue;
}
measureChildWithMargins(child, widthMeasureSpec, 0, MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY), 0);
@@ -1250,10 +1344,19 @@ public class ActionBar extends FrameLayout {
additionalSubtitleTextView.layout(textLeft, additionalTop + textTop, textLeft + additionalSubtitleTextView.getMeasuredWidth(), additionalTop + textTop + additionalSubtitleTextView.getTextHeight());
}
+ if (avatarSearchImageView != null) {
+ avatarSearchImageView.layout(
+ AndroidUtilities.dp(56 + 8),
+ additionalTop + (getCurrentActionBarHeight() - avatarSearchImageView.getMeasuredHeight()) / 2,
+ AndroidUtilities.dp(56 + 8) + avatarSearchImageView.getMeasuredWidth(),
+ additionalTop + (getCurrentActionBarHeight() + avatarSearchImageView.getMeasuredHeight()) / 2
+ );
+ }
+
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
- if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView) {
+ if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView || child == avatarSearchImageView) {
continue;
}
@@ -1476,7 +1579,7 @@ public class ActionBar extends FrameLayout {
itemsColor = color;
if (backButtonImageView != null) {
if (itemsColor != 0) {
- backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, PorterDuff.Mode.MULTIPLY));
+ backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, colorFilterMode));
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setColor(color);
@@ -1709,4 +1812,12 @@ public class ActionBar extends FrameLayout {
public void setForceSkipTouches(boolean forceSkipTouches) {
this.forceSkipTouches = forceSkipTouches;
}
+
+ public void setDrawBackButton(boolean b) {
+ this.drawBackButton = b;
+ if (backButtonImageView != null) {
+ backButtonImageView.invalidate();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java
index 1d745defb..5da7538bf 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarLayout.java
@@ -1606,6 +1606,10 @@ public class ActionBarLayout extends FrameLayout implements INavigationLayout, F
}
public void closeLastFragment(boolean animated, boolean forceNoAnimation) {
+ BaseFragment fragment = getLastFragment();
+ if (fragment != null && fragment.closeLastFragment()) {
+ return;
+ }
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
return;
}
@@ -2188,7 +2192,9 @@ public class ActionBarLayout extends FrameLayout implements INavigationLayout, F
oldFragment = null;
Runnable endRunnable = onCloseAnimationEndRunnable;
onCloseAnimationEndRunnable = null;
- endRunnable.run();
+ if (endRunnable != null) {
+ endRunnable.run();
+ }
checkNeedRebuild();
checkNeedRebuild();
}
@@ -2346,19 +2352,19 @@ public class ActionBarLayout extends FrameLayout implements INavigationLayout, F
}
}
- private View findScrollingChild(ViewGroup parent, float x, float y) {
+ public static View findScrollingChild(ViewGroup parent, float x, float y) {
int n = parent.getChildCount();
for (int i = 0; i < n; i++) {
View child = parent.getChildAt(i);
if (child.getVisibility() != View.VISIBLE) {
continue;
}
- child.getHitRect(rect);
- if (rect.contains((int) x, (int) y)) {
+ child.getHitRect(AndroidUtilities.rectTmp2);
+ if (AndroidUtilities.rectTmp2.contains((int) x, (int) y)) {
if (child.canScrollHorizontally(-1)) {
return child;
} else if (child instanceof ViewGroup) {
- View v = findScrollingChild((ViewGroup) child, x - rect.left, y - rect.top);
+ View v = findScrollingChild((ViewGroup) child, x - AndroidUtilities.rectTmp2.left, y - AndroidUtilities.rectTmp2.top);
if (v != null) {
return v;
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java
index 254fb21c5..1ce7f3974 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java
@@ -80,10 +80,10 @@ public class ActionBarMenuItem extends FrameLayout {
public void setSearchPaddingStart(int padding) {
searchItemPaddingStart = padding;
if (searchContainer != null) {
- ((MarginLayoutParams)searchContainer.getLayoutParams()).leftMargin = AndroidUtilities.dp(padding);
+ ((MarginLayoutParams) searchContainer.getLayoutParams()).leftMargin = AndroidUtilities.dp(padding);
searchContainer.setClipChildren(searchItemPaddingStart != 0);
+ searchContainer.setLayoutParams(searchContainer.getLayoutParams());
}
-
}
public static class ActionBarMenuItemSearchListener {
@@ -1837,6 +1837,17 @@ public class ActionBarMenuItem extends FrameLayout {
}
}
+ public int getVisibleSubItemsCount() {
+ int count = 0;
+ for (int i = 0; i < popupLayout.getItemsCount(); ++i) {
+ View item = popupLayout.getItemAt(i);
+ if (item != null && item.getVisibility() == View.VISIBLE) {
+ count++;
+ }
+ }
+ return count;
+ }
+
public void requestFocusOnSearchView() {
if (searchContainer.getWidth() != 0 && !searchField.isFocused()) {
searchField.requestFocus();
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java
index 7a8006a6e..e7222fc4d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarPopupWindow.java
@@ -1019,21 +1019,31 @@ public class ActionBarPopupWindow extends PopupWindow {
Theme.ResourcesProvider resourcesProvider;
String colorKey;
+ Drawable shadowDrawable;
+
+ public GapView(Context context, Theme.ResourcesProvider resourcesProvider) {
+ this(context, resourcesProvider, Theme.key_actionBarDefaultSubmenuSeparator);
+ }
+
public GapView(Context context, Theme.ResourcesProvider resourcesProvider, String colorKey) {
super(context);
this.resourcesProvider = resourcesProvider;
this.colorKey = colorKey;
-
- setBackgroundColor(getThemedColor(colorKey));
- }
-
- private int getThemedColor(String key) {
- Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
- return color != null ? color : Theme.getColor(key);
+ this.shadowDrawable = Theme.getThemedDrawable(getContext(), R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow, resourcesProvider);
+ setBackgroundColor(Theme.getColor(colorKey, resourcesProvider));
}
public void setColor(int color) {
setBackgroundColor(color);
}
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (shadowDrawable != null) {
+ shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
+ shadowDrawable.draw(canvas);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AlertDialog.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AlertDialog.java
index 41f79690a..4afb008ad 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AlertDialog.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AlertDialog.java
@@ -44,8 +44,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.telegram.messenger.AndroidUtilities;
+import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
+import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.LineProgressView;
@@ -57,7 +59,7 @@ import org.telegram.ui.Components.spoilers.SpoilersTextView;
import java.util.ArrayList;
import java.util.Map;
-public class AlertDialog extends Dialog implements Drawable.Callback {
+public class AlertDialog extends Dialog implements Drawable.Callback, NotificationCenter.NotificationCenterDelegate {
private View customView;
private int customViewHeight = LayoutHelper.WRAP_CONTENT;
@@ -594,7 +596,14 @@ public class AlertDialog extends Dialog implements Drawable.Callback {
contentScrollView.addView(scrollContainer, new ScrollView.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
- messageTextView = new SpoilersTextView(getContext(), false);
+ messageTextView = new SpoilersTextView(getContext(), false) {
+ @Override
+ public void setText(CharSequence text, BufferType type) {
+ text = Emoji.replaceEmoji(text, getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
+ super.setText(text, type);
+ }
+ };
+ NotificationCenter.listenEmojiLoading(messageTextView);
messageTextView.setTextColor(getThemedColor(topAnimationIsNew ? Theme.key_windowBackgroundWhiteGrayText : Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
@@ -955,6 +964,8 @@ public class AlertDialog extends Dialog implements Drawable.Callback {
}
window.setAttributes(params);
+
+ NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiLoaded);
}
@Override
@@ -1095,8 +1106,18 @@ public class AlertDialog extends Dialog implements Drawable.Callback {
return false;
}
+ @Override
+ public void didReceivedNotification(int id, int account, Object... args) {
+ if (id == NotificationCenter.emojiLoaded) {
+ if (messageTextView != null) {
+ messageTextView.invalidate();
+ }
+ }
+ }
+
@Override
public void dismiss() {
+ NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiLoaded);
if (onDismissListener != null) {
onDismissListener.onDismiss(this);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BaseFragment.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BaseFragment.java
index a46d198bd..ddbb39f47 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BaseFragment.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BaseFragment.java
@@ -76,6 +76,7 @@ public abstract class BaseFragment {
protected boolean inTransitionAnimation = false;
protected boolean fragmentBeginToShow;
private boolean removingFromStack;
+ private PreviewDelegate previewDelegate;
public BaseFragment() {
classGuid = ConnectionsManager.generateClassGuid();
@@ -262,7 +263,7 @@ public abstract class BaseFragment {
}
}
- protected ActionBar createActionBar(Context context) {
+ public ActionBar createActionBar(Context context) {
ActionBar actionBar = new ActionBar(context, getResourceProvider());
actionBar.setBackgroundColor(getThemedColor(Theme.key_actionBarDefault));
actionBar.setItemsBackgroundColor(getThemedColor(Theme.key_actionBarDefaultSelector), false);
@@ -290,7 +291,11 @@ public abstract class BaseFragment {
parentDialog.dismiss();
return;
}
- finishFragment(true);
+ if (inPreviewMode && previewDelegate != null) {
+ previewDelegate.finishFragment();
+ } else {
+ finishFragment(true);
+ }
}
public void finishFragment(boolean animated) {
@@ -514,6 +519,10 @@ public abstract class BaseFragment {
}
+ public void onSlideProgressFront(boolean isOpen, float progress) {
+
+ }
+
public void onTransitionAnimationProgress(boolean isOpen, float progress) {
}
@@ -838,4 +847,25 @@ public abstract class BaseFragment {
public void drawOverlay(Canvas canvas, View parent) {
}
+
+ public void setPreviewOpenedProgress(float progress) {
+
+ }
+
+ public void setPreviewReplaceProgress(float progress) {
+
+ }
+
+ public boolean closeLastFragment() {
+ return false;
+ }
+
+ public void setPreviewDelegate(PreviewDelegate previewDelegate) {
+ this.previewDelegate = previewDelegate;
+ }
+
+ public interface PreviewDelegate {
+ void finishFragment();
+ }
+
}
\ No newline at end of file
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java
index bca7d0f60..33c586fa1 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java
@@ -816,7 +816,7 @@ public class BottomSheet extends Dialog {
textView.setTextColor(getThemedColor(Theme.key_featuredStickers_buttonText));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
- textView.setBackground(Theme.AdaptiveRipple.filledRect(getThemedColor(Theme.key_featuredStickers_addButton), 4));
+ textView.setBackground(Theme.AdaptiveRipple.filledRect(getThemedColor(Theme.key_featuredStickers_addButton), 6));
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, 16, 16, 16));
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/EmojiThemes.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/EmojiThemes.java
index 86c81decd..9707e24d6 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/EmojiThemes.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/EmojiThemes.java
@@ -245,7 +245,12 @@ public class EmojiThemes {
if (themeInfo == null) {
int settingsIndex = getSettingsIndex(index);
TLRPC.TL_theme tlTheme = getTlTheme(index);
- Theme.ThemeInfo baseTheme = Theme.getTheme(Theme.getBaseThemeKey(tlTheme.settings.get(settingsIndex)));
+ Theme.ThemeInfo baseTheme;
+ if (tlTheme != null) {
+ baseTheme = Theme.getTheme(Theme.getBaseThemeKey(tlTheme.settings.get(settingsIndex)));
+ } else {
+ baseTheme = Theme.getTheme("Blue");
+ }
themeInfo = new Theme.ThemeInfo(baseTheme);
accent = themeInfo.createNewAccent(tlTheme, currentAccount, true, settingsIndex);
themeInfo.setCurrentAccentId(accent.id);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/INavigationLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/INavigationLayout.java
index ad9fc190e..d1cc4d6d8 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/INavigationLayout.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/INavigationLayout.java
@@ -385,4 +385,8 @@ public interface INavigationLayout {
BACK,
MENU
}
+
+ interface IBackButtonDrawable {
+ BackButtonState getBackButtonState();
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/MenuDrawable.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/MenuDrawable.java
index d9af7a13b..18fa3a60d 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/MenuDrawable.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/MenuDrawable.java
@@ -144,7 +144,7 @@ public class MenuDrawable extends Drawable {
canvas.save();
- canvas.translate(getIntrinsicWidth() / 2 - AndroidUtilities.dp(9), getIntrinsicHeight() / 2);
+ canvas.translate(getIntrinsicWidth() / 2 - AndroidUtilities.dp(9) - AndroidUtilities.dp(1) * currentRotation, getIntrinsicHeight() / 2);
float endYDiff;
float endXDiff;
float startYDiff;
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/SimpleTextView.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/SimpleTextView.java
index f8cb565d5..52b57bb6e 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/SimpleTextView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/SimpleTextView.java
@@ -34,6 +34,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.Emoji;
+import org.telegram.messenger.LocaleController;
import org.telegram.ui.Cells.DialogCell;
import org.telegram.ui.Components.AnimatedEmojiDrawable;
import org.telegram.ui.Components.AnimatedEmojiSpan;
@@ -93,7 +94,7 @@ public class SimpleTextView extends View implements Drawable.Callback {
private boolean wasLayout;
private boolean rightDrawableOutside;
- private boolean ellipsizeByGradient;
+ private boolean ellipsizeByGradient, ellipsizeByGradientLeft;
private int ellipsizeByGradientWidthDp = 16;
private int paddingRight;
@@ -218,9 +219,17 @@ public class SimpleTextView extends View implements Drawable.Callback {
fadePaintBack.setShader(new LinearGradient(0, 0, AndroidUtilities.dp(6), 0, new int[]{0, 0xffffffff}, new float[]{0f, 1f}, Shader.TileMode.CLAMP));
fadePaintBack.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
}
- if ((fadeEllpsizePaint == null || fadeEllpsizePaintWidth != AndroidUtilities.dp(ellipsizeByGradientWidthDp)) && ellipsizeByGradient) {
- fadeEllpsizePaint = new Paint();
- fadeEllpsizePaint.setShader(new LinearGradient(0, 0, fadeEllpsizePaintWidth = AndroidUtilities.dp(ellipsizeByGradientWidthDp), 0, new int[]{0, 0xffffffff}, new float[]{0f, 1f}, Shader.TileMode.CLAMP));
+ boolean ellipsizeLeft = getAlignment() == Layout.Alignment.ALIGN_NORMAL && LocaleController.isRTL || getAlignment() == Layout.Alignment.ALIGN_OPPOSITE && !LocaleController.isRTL;
+ if ((fadeEllpsizePaint == null || fadeEllpsizePaintWidth != AndroidUtilities.dp(ellipsizeByGradientWidthDp) || ellipsizeByGradientLeft != ellipsizeLeft) && ellipsizeByGradient) {
+ if (fadeEllpsizePaint == null) {
+ fadeEllpsizePaint = new Paint();
+ }
+ ellipsizeByGradientLeft = ellipsizeLeft;
+ if (ellipsizeByGradientLeft) {
+ fadeEllpsizePaint.setShader(new LinearGradient(0, 0, fadeEllpsizePaintWidth = AndroidUtilities.dp(ellipsizeByGradientWidthDp), 0, new int[]{0xffffffff, 0}, new float[]{0f, 1f}, Shader.TileMode.CLAMP));
+ } else {
+ fadeEllpsizePaint.setShader(new LinearGradient(0, 0, fadeEllpsizePaintWidth = AndroidUtilities.dp(ellipsizeByGradientWidthDp), 0, new int[]{0, 0xffffffff}, new float[]{0f, 1f}, Shader.TileMode.CLAMP));
+ }
fadeEllpsizePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
}
}
@@ -254,6 +263,9 @@ public class SimpleTextView extends View implements Drawable.Callback {
}
private void calcOffset(int width) {
+ if (layout == null) {
+ return;
+ }
if (layout.getLineCount() > 0) {
textWidth = (int) Math.ceil(layout.getLineWidth(0));
if (fullLayout != null) {
@@ -282,7 +294,7 @@ public class SimpleTextView extends View implements Drawable.Callback {
offsetX = -AndroidUtilities.dp(8);
}
offsetX += getPaddingLeft();
- textDoesNotFit = textWidth > width;
+ textDoesNotFit = textWidth > (width - paddingRight);
if (fullLayout != null && fullLayoutAdditionalWidth > 0) {
fullLayoutLeftCharactersOffset = fullLayout.getPrimaryHorizontal(0) - firstLineLayout.getPrimaryHorizontal(0);
@@ -659,6 +671,34 @@ public class SimpleTextView extends View implements Drawable.Callback {
public void setRightPadding(int padding) {
if (paddingRight != padding) {
paddingRight = padding;
+
+ int width = getMaxTextWidth() - getPaddingLeft() - getPaddingRight() - minusWidth;
+ if (leftDrawable != null) {
+ width -= leftDrawable.getIntrinsicWidth();
+ width -= drawablePadding;
+ }
+ int rightDrawableWidth = 0;
+ if (rightDrawable != null && !rightDrawableOutside) {
+ rightDrawableWidth = (int) (rightDrawable.getIntrinsicWidth() * rightDrawableScale);
+ width -= rightDrawableWidth;
+ width -= drawablePadding;
+ }
+ if (replacedText != null && replacedDrawable != null) {
+ if ((replacingDrawableTextIndex = text.toString().indexOf(replacedText)) < 0) {
+ width -= replacedDrawable.getIntrinsicWidth();
+ width -= drawablePadding;
+ }
+ }
+ if (canHideRightDrawable && rightDrawableWidth != 0 && !rightDrawableOutside) {
+ CharSequence string = TextUtils.ellipsize(text, textPaint, width, TextUtils.TruncateAt.END);
+ if (!text.equals(string)) {
+ rightDrawableHidden = true;
+ width += rightDrawableWidth;
+ width += drawablePadding;
+ }
+ }
+ calcOffset(width);
+
invalidate();
}
}
@@ -831,9 +871,12 @@ public class SimpleTextView extends View implements Drawable.Callback {
canvas.translate(getMaxTextWidth() - paddingRight - AndroidUtilities.dp(6), 0);
canvas.drawRect(0, 0, AndroidUtilities.dp(6), getMeasuredHeight(), fadePaintBack);
canvas.restore();
- } else if (ellipsizeByGradient && (!widthWrapContent || textDoesNotFit) && fadeEllpsizePaint != null) {
+ } else if (ellipsizeByGradient && textDoesNotFit && fadeEllpsizePaint != null) {
canvas.save();
- canvas.translate(getMaxTextWidth() - paddingRight - fadeEllpsizePaintWidth - AndroidUtilities.dp(rightDrawable != null && !(rightDrawable instanceof AnimatedEmojiDrawable.SwapAnimatedEmojiDrawable) && rightDrawableOutside ? +2 : 0), 0);
+ updateFadePaints();
+ if (!ellipsizeByGradientLeft) {
+ canvas.translate(getMaxTextWidth() - paddingRight - fadeEllpsizePaintWidth - AndroidUtilities.dp(rightDrawable != null && !(rightDrawable instanceof AnimatedEmojiDrawable.SwapAnimatedEmojiDrawable) && rightDrawableOutside ? +2 : 0), 0);
+ }
canvas.drawRect(0, 0, fadeEllpsizePaintWidth, getMeasuredHeight(), fadeEllpsizePaint);
canvas.restore();
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java
index 346abb90d..30d74f3ab 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java
@@ -2913,7 +2913,7 @@ public class Theme {
public static Paint avatar_backgroundPaint;
public static Drawable listSelector;
- public static Drawable[] avatarDrawables = new Drawable[12];
+ public static Drawable[] avatarDrawables = new Drawable[13];
public static Drawable moveUpDrawable;
@@ -3011,6 +3011,7 @@ public class Theme {
public static TextPaint chat_msgTextPaint;
public static TextPaint chat_actionTextPaint;
+ public static TextPaint chat_actionTextPaint2;
public static TextPaint chat_unlockExtendedMediaTextPaint;
public static TextPaint chat_msgBotButtonPaint;
public static TextPaint chat_msgGameTextPaint;
@@ -4048,6 +4049,7 @@ public class Theme {
public static final String key_paint_chatActionBackgroundSelected = "paintChatActionBackgroundSelected";
public static final String key_paint_chatMessageBackgroundSelected = "paintChatMessageBackgroundSelected";
public static final String key_paint_chatActionText = "paintChatActionText";
+ public static final String key_paint_chatActionText2 = "paintChatActionText2";
public static final String key_paint_chatBotButton = "paintChatBotButton";
public static final String key_paint_chatComposeBackground = "paintChatComposeBackground";
public static final String key_paint_chatTimeBackground = "paintChatTimeBackground";
@@ -8799,6 +8801,7 @@ public class Theme {
avatarDrawables[9] = resources.getDrawable(R.drawable.msg_folders_archive);
avatarDrawables[10] = resources.getDrawable(R.drawable.msg_folders_private);
avatarDrawables[11] = resources.getDrawable(R.drawable.chats_replies);
+ avatarDrawables[12] = resources.getDrawable(R.drawable.other_chats);
if (dialogs_archiveAvatarDrawable != null) {
@@ -9091,7 +9094,7 @@ public class Theme {
chat_timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
}
- final float[] emojiSizePercents = new float[] {.7f, .52f, .37f, .28f, .25f, .19f};
+ final float[] emojiSizePercents = new float[] {.68f, .46f, .34f, .28f, .22f, .19f};
for (int i = 0; i < chat_msgTextPaintEmoji.length; ++i) {
chat_msgTextPaintEmoji[i] = new TextPaint(Paint.ANTI_ALIAS_FLAG);
chat_msgTextPaintEmoji[i].setTextSize(AndroidUtilities.dp(emojiSizePercents[i] * 120f));
@@ -9185,6 +9188,7 @@ public class Theme {
chat_statusRecordPaint.setStyle(Paint.Style.STROKE);
chat_statusRecordPaint.setStrokeCap(Paint.Cap.ROUND);
chat_actionTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
+ chat_actionTextPaint2 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
chat_actionTextPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
chat_unlockExtendedMediaTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
chat_unlockExtendedMediaTextPaint.setTypeface(AndroidUtilities.getTypeface(AndroidUtilities.TYPEFACE_ROBOTO_MEDIUM));
@@ -9208,6 +9212,7 @@ public class Theme {
addChatPaint(key_paint_chatActionBackground, chat_actionBackgroundPaint, key_chat_serviceBackground);
addChatPaint(key_paint_chatActionBackgroundSelected, chat_actionBackgroundSelectedPaint, key_chat_serviceBackgroundSelected);
addChatPaint(key_paint_chatActionText, chat_actionTextPaint, key_chat_serviceText);
+ addChatPaint(key_paint_chatActionText2, chat_actionTextPaint2, key_chat_serviceText);
addChatPaint(key_paint_chatBotButton, chat_botButtonPaint, key_chat_botButtonText);
addChatPaint(key_paint_chatComposeBackground, chat_composeBackgroundPaint, key_chat_messagePanelBackground);
addChatPaint(key_paint_chatTimeBackground, chat_timeBackgroundPaint, key_chat_mediaTimeBackground);
@@ -9522,6 +9527,7 @@ public class Theme {
chat_instantViewRectPaint.setStrokeWidth(AndroidUtilities.dp(1));
chat_pollTimerPaint.setStrokeWidth(AndroidUtilities.dp(1.1f));
chat_actionTextPaint.setTextSize(AndroidUtilities.dp(Math.max(16, SharedConfig.fontSize) - 2));
+ chat_actionTextPaint2.setTextSize(AndroidUtilities.dp(Math.max(16, SharedConfig.fontSize) - 2));
chat_unlockExtendedMediaTextPaint.setTextSize(AndroidUtilities.dp(Math.max(16, SharedConfig.fontSize)));
chat_contextResult_titleTextPaint.setTextSize(AndroidUtilities.dp(15));
chat_contextResult_descriptionTextPaint.setTextSize(AndroidUtilities.dp(13));
@@ -9583,6 +9589,7 @@ public class Theme {
chat_statusPaint.setColor(getColor(key_chat_status));
chat_statusRecordPaint.setColor(getColor(key_chat_status));
chat_actionTextPaint.setColor(getColor(key_chat_serviceText));
+ chat_actionTextPaint2.setColor(getColor(key_chat_serviceText));
chat_actionTextPaint.linkColor = getColor(key_chat_serviceLink);
chat_unlockExtendedMediaTextPaint.setColor(getColor(key_chat_serviceText));
chat_contextResult_titleTextPaint.setColor(getColor(key_windowBackgroundWhiteBlackText));
@@ -9827,6 +9834,7 @@ public class Theme {
setDrawableColor(chat_msgStickerViewsDrawable, 0xffffffff);
setDrawableColor(chat_msgStickerRepliesDrawable, 0xffffffff);
chat_actionTextPaint.setColor(0xffffffff);
+ chat_actionTextPaint2.setColor(0xffffffff);
chat_actionTextPaint.linkColor = 0xffffffff;
chat_unlockExtendedMediaTextPaint.setColor(0xffffffff);
chat_botButtonPaint.setColor(0xffffffff);
@@ -9848,6 +9856,7 @@ public class Theme {
setDrawableColorByKey(chat_msgStickerViewsDrawable, key_chat_serviceText);
setDrawableColorByKey(chat_msgStickerRepliesDrawable, key_chat_serviceText);
chat_actionTextPaint.setColor(getColor(key_chat_serviceText));
+ chat_actionTextPaint2.setColor(getColor(key_chat_serviceText));
chat_actionTextPaint.linkColor = getColor(key_chat_serviceLink);
chat_unlockExtendedMediaTextPaint.setColor(getColor(key_chat_serviceText));
setDrawableColorByKey(chat_commentStickerDrawable, key_chat_serviceIcon);
@@ -9974,6 +9983,10 @@ public class Theme {
setDrawableColorByKey(profile_verifiedCheckDrawable, key_profile_verifiedCheck);
}
+ public static Drawable getThemedDrawable(Context context, int resId, String key, Theme.ResourcesProvider resourcesProvider) {
+ return getThemedDrawable(context, resId, getColor(key, resourcesProvider));
+ }
+
public static Drawable getThemedDrawable(Context context, int resId, String key) {
return getThemedDrawable(context, resId, getColor(key));
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java
index a073c9819..c070fdf84 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java
@@ -24,11 +24,12 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
+import androidx.recyclerview.widget.DiffUtil;
+import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import org.telegram.messenger.AndroidUtilities;
-import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.DialogObject;
@@ -57,6 +58,7 @@ import org.telegram.ui.Components.BlurredRecyclerView;
import org.telegram.ui.Components.CombinedDrawable;
import org.telegram.ui.Components.FlickerLoadingView;
import org.telegram.ui.Components.LayoutHelper;
+import org.telegram.ui.Components.ListView.AdapterWithDiffUtils;
import org.telegram.ui.Components.PullForegroundDrawable;
import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.DialogsActivity;
@@ -64,23 +66,24 @@ import org.telegram.ui.DialogsActivity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Objects;
public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements DialogCell.DialogCellDelegate {
public final static int VIEW_TYPE_DIALOG = 0,
- VIEW_TYPE_FLICKER = 1,
- VIEW_TYPE_RECENTLY_VIEWED = 2,
- VIEW_TYPE_DIVIDER = 3,
- VIEW_TYPE_ME_URL = 4,
- VIEW_TYPE_EMPTY = 5,
- VIEW_TYPE_USER = 6,
- VIEW_TYPE_HEADER = 7,
- VIEW_TYPE_SHADOW = 8,
- VIEW_TYPE_ARCHIVE = 9,
- VIEW_TYPE_LAST_EMPTY = 10,
- VIEW_TYPE_NEW_CHAT_HINT = 11,
- VIEW_TYPE_TEXT = 12,
- VIEW_TYPE_CONTACTS_FLICKER = 13,
- VIEW_TYPE_HEADER_2 = 14;
+ VIEW_TYPE_FLICKER = 1,
+ VIEW_TYPE_RECENTLY_VIEWED = 2,
+ VIEW_TYPE_DIVIDER = 3,
+ VIEW_TYPE_ME_URL = 4,
+ VIEW_TYPE_EMPTY = 5,
+ VIEW_TYPE_USER = 6,
+ VIEW_TYPE_HEADER = 7,
+ VIEW_TYPE_SHADOW = 8,
+ VIEW_TYPE_ARCHIVE = 9,
+ VIEW_TYPE_LAST_EMPTY = 10,
+ VIEW_TYPE_NEW_CHAT_HINT = 11,
+ VIEW_TYPE_TEXT = 12,
+ VIEW_TYPE_CONTACTS_FLICKER = 13,
+ VIEW_TYPE_HEADER_2 = 14;
private Context mContext;
private ArchiveHintCell archiveHintCell;
@@ -101,7 +104,11 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
private boolean showArchiveHint;
private boolean isReordering;
private long lastSortTime;
+ private boolean collapsedView;
+ RecyclerListView recyclerListView;
private PullForegroundDrawable pullForegroundDrawable;
+ ArrayList itemInternals = new ArrayList<>();
+ ArrayList oldItems = new ArrayList<>();
private Drawable arrowDrawable;
@@ -109,6 +116,8 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
private boolean forceShowEmptyCell;
private DialogsActivity parentFragment;
+ private boolean isTransitionSupport;
+ private boolean fromDiffUtils;
public DialogsAdapter(DialogsActivity fragment, Context context, int type, int folder, boolean onlySelect, ArrayList selected, int account) {
mContext = context;
@@ -129,6 +138,10 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
}
+ public void setRecyclerListView(RecyclerListView recyclerListView) {
+ this.recyclerListView = recyclerListView;
+ }
+
public void setOpenedDialogId(long id) {
openedDialogId = id;
}
@@ -152,8 +165,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
public boolean isDataSetChanged() {
- int current = currentCount;
- return current != getItemCount() || current == 1;
+ return true;
}
public void setDialogsType(int type) {
@@ -171,140 +183,115 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
@Override
public int getItemCount() {
- MessagesController messagesController = MessagesController.getInstance(currentAccount);
- ArrayList array = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
- dialogsCount = array.size();
- if (!forceUpdatingContacts && !forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && dialogsType != 11 && dialogsCount == 0 && (folderId != 0 || messagesController.isLoadingDialogs(folderId) || !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId))) {
- onlineContacts = null;
- if (BuildVars.LOGS_ENABLED) {
- FileLog.d("DialogsAdapter dialogsCount=" + dialogsCount + " dialogsType=" + dialogsType + " isLoadingDialogs=" + messagesController.isLoadingDialogs(folderId) + " isDialogsEndReached=" + MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId));
+ currentCount = itemInternals.size();
+ return currentCount;
+ }
+
+ public int findDialogPosition(long dialogId) {
+ for (int i = 0; i < itemInternals.size(); i++) {
+ if (itemInternals.get(i).dialog != null && itemInternals.get(i).dialog.id == dialogId) {
+ return i;
}
- if (folderId == 1 && showArchiveHint) {
- return (currentCount = 2);
- }
- return (currentCount = 0);
}
- if (dialogsCount == 0 && messagesController.isLoadingDialogs(folderId)) {
- return (currentCount = 0);
- }
- int count = dialogsCount;
- if (dialogsType == 7 || dialogsType == 8) {
- if (dialogsCount == 0) {
- count++;
- }
+ return -1;
+ }
+
+ public int fixScrollGap(RecyclerListView animationSupportListView, int p, int offset, boolean hasHidenArchive, boolean oppened) {
+ int itemsToEnd = getItemCount() - p ;
+ int cellHeight = AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 78 : 72);
+ int bottom = offset + animationSupportListView.getPaddingTop() + itemsToEnd * cellHeight + itemsToEnd - 1;
+ //fix height changed
+ int top = offset + animationSupportListView.getPaddingTop() - p * cellHeight - p;
+ if (oppened) {
+ bottom -= AndroidUtilities.dp(44);
} else {
- if (!messagesController.isDialogsEndReached(folderId) || dialogsCount == 0) {
- count++;
- }
+ bottom += AndroidUtilities.dp(44);
}
- boolean hasContacts = false;
- if (hasHints) {
- count += 2 + messagesController.hintDialogs.size();
- } else if (dialogsType == 0 && folderId == 0 && messagesController.isDialogsEndReached(folderId)) {
- if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts && !forceUpdatingContacts) {
- onlineContacts = null;
- if (BuildVars.LOGS_ENABLED) {
- FileLog.d("DialogsAdapter loadingContacts=" + (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts) + "dialogsCount=" + dialogsCount + " dialogsType=" + dialogsType);
- }
- return (currentCount = 0);
- }
+ if (hasHidenArchive) {
+ top += cellHeight;
+ }
+ if (top > animationSupportListView.getPaddingTop()) {
+ return offset + animationSupportListView.getPaddingTop() - top;
+ }
+ if (bottom < animationSupportListView.getMeasuredHeight()) {
+ return offset + (animationSupportListView.getMeasuredHeight() - bottom);
+ }
+ return offset;
+ }
- if (messagesController.getAllFoldersDialogsCount() <= 10 && ContactsController.getInstance(currentAccount).doneLoadingContacts && !ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
- if (onlineContacts == null || prevDialogsCount != dialogsCount || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
- onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
- prevContactsCount = onlineContacts.size();
- prevDialogsCount = messagesController.dialogs_dict.size();
- long selfId = UserConfig.getInstance(currentAccount).clientUserId;
- for (int a = 0, N = onlineContacts.size(); a < N; a++) {
- long userId = onlineContacts.get(a).user_id;
- if (userId == selfId || messagesController.dialogs_dict.get(userId) != null) {
- onlineContacts.remove(a);
- a--;
- N--;
- }
- }
- if (onlineContacts.isEmpty()) {
- onlineContacts = null;
- }
- sortOnlineContacts(false);
+ private class ItemInternal extends AdapterWithDiffUtils.Item {
- if (parentFragment.getContactsAlpha() == 0f) {
- registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
- @Override
- public void onChanged() {
- parentFragment.setContactsAlpha(0f);
- parentFragment.animateContactsAlpha(1f);
+ TLRPC.Dialog dialog;
+ TLRPC.RecentMeUrl recentMeUrl;
+ TLRPC.TL_contact contact;
+ boolean isForumCell;
+ private boolean pinned;
+ private boolean isFolder;
- unregisterAdapterDataObserver(this);
- }
- });
- }
- }
- if (onlineContacts != null) {
- count += onlineContacts.size() + 2;
- hasContacts = true;
- }
+ public ItemInternal(int viewType, TLRPC.Dialog dialog) {
+ super(viewType, true);
+ this.dialog = dialog;
+ if (dialog != null) {
+ pinned = dialog.pinned;
+ isFolder = dialog.isFolder;
+ isForumCell = MessagesController.getInstance(currentAccount).isForum(dialog.id);
}
}
- if (folderId == 0 && !hasContacts && dialogsCount == 0 && forceUpdatingContacts) {
- count += 3;
- }
- if (folderId == 0 && onlineContacts != null) {
- if (!hasContacts) {
- onlineContacts = null;
- }
- }
- if (folderId == 1 && showArchiveHint) {
- count += 2;
- }
- if (folderId == 0 && dialogsCount != 0) {
- count++;
- if (dialogsCount > 10 && dialogsType == 0) {
- count++;
- }
- }
- if (dialogsType == 11 || dialogsType == 13) {
- count += 2;
- } else if (dialogsType == 12) {
- count += 1;
- }
- currentCount = count;
- return count;
+ public ItemInternal(int viewTypeMeUrl, TLRPC.RecentMeUrl recentMeUrl) {
+ super(viewTypeMeUrl, true);
+ this.recentMeUrl = recentMeUrl;
+ }
+
+ public ItemInternal(int viewTypeEmpty) {
+ super(viewTypeEmpty, true);
+ }
+
+ public ItemInternal(int viewTypeUser, TLRPC.TL_contact tl_contact) {
+ super(viewTypeUser, true);
+ contact = tl_contact;
+ }
+
+ boolean compare(ItemInternal itemInternal) {
+ if (viewType != itemInternal.viewType) {
+ return false;
+ }
+ if (viewType == VIEW_TYPE_DIALOG) {
+ return dialog != null && itemInternal.dialog != null && dialog.id == itemInternal.dialog.id
+ && isFolder == itemInternal.isFolder &&
+ isForumCell == itemInternal.isForumCell &&
+ pinned == itemInternal.pinned;
+ }
+ if (viewType == VIEW_TYPE_HEADER_2) {
+ return dialog != null && itemInternal.dialog != null && dialog.id == itemInternal.dialog.id && dialog.isFolder == itemInternal.dialog.isFolder;
+ }
+ if (viewType == VIEW_TYPE_ME_URL) {
+ return recentMeUrl != null && itemInternal.recentMeUrl != null && recentMeUrl.url != null && recentMeUrl.url.equals(recentMeUrl.url);
+ }
+ if (viewType == VIEW_TYPE_USER) {
+ return contact != null && itemInternal.contact != null && contact.user_id == itemInternal.contact.user_id;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(dialog, recentMeUrl, contact);
+ }
}
public TLObject getItem(int i) {
- if (onlineContacts != null && (dialogsCount == 0 || i >= dialogsCount)) {
- if (dialogsCount == 0) {
- i -= 3;
- } else {
- i -= dialogsCount + 2;
- }
- if (i < 0 || i >= onlineContacts.size()) {
- return null;
- }
- return MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(i).user_id);
- }
- if (showArchiveHint) {
- i -= 2;
- } else if (dialogsType == 11 || dialogsType == 13) {
- i -= 2;
- } else if (dialogsType == 12) {
- i -= 1;
- }
- ArrayList arrayList = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
- if (hasHints) {
- int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
- if (i < 2 + count) {
- return MessagesController.getInstance(currentAccount).hintDialogs.get(i - 1);
- } else {
- i -= count + 2;
- }
- }
- if (i < 0 || i >= arrayList.size()) {
+ if (i < 0 || i >= itemInternals.size()) {
return null;
}
- return arrayList.get(i);
+ if (itemInternals.get(i).dialog != null) {
+ return itemInternals.get(i).dialog;
+ } else if (itemInternals.get(i).contact != null) {
+ return itemInternals.get(i).contact;
+ } else if (itemInternals.get(i).recentMeUrl != null) {
+ return itemInternals.get(i).recentMeUrl;
+ }
+ return null;
}
public void sortOnlineContacts(boolean notify) {
@@ -367,6 +354,10 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
dialogsListFrozen = frozen;
}
+ public boolean getDialogsListIsFrozen() {
+ return dialogsListFrozen;
+ }
+
public ViewPager getArchiveHintCellPager() {
return archiveHintCell != null ? archiveHintCell.getViewPager() : null;
}
@@ -375,19 +366,71 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
hasHints = folderId == 0 && dialogsType == 0 && !isOnlySelect && !MessagesController.getInstance(currentAccount).hintDialogs.isEmpty();
}
+ public void updateList(RecyclerListView recyclerListView) {
+ oldItems.clear();
+ oldItems.addAll(itemInternals);
+ updateItemList();
+
+ if (recyclerListView != null && recyclerListView.getChildCount() > 0) {
+ LinearLayoutManager layoutManager = ((LinearLayoutManager) recyclerListView.getLayoutManager());
+ View view = null;
+ int position = -1;
+ int top = Integer.MAX_VALUE;
+ for (int i = 0; i < recyclerListView.getChildCount(); i++) {
+ int childPosition = recyclerListView.getChildAdapterPosition(recyclerListView.getChildAt(i));
+ View child = recyclerListView.getChildAt(i);
+ if (childPosition != RecyclerListView.NO_POSITION && child.getTop() < top) {
+ view = child;
+ position = childPosition;
+ top = child.getTop();
+ }
+ }
+ if (view != null) {
+ layoutManager.scrollToPositionWithOffset(position, view.getTop() - recyclerListView.getPaddingTop());
+ }
+ }
+
+
+ fromDiffUtils = true;
+ DiffUtil.calculateDiff(new DiffUtil.Callback() {
+ @Override
+ public int getOldListSize() {
+ return oldItems.size();
+ }
+
+ @Override
+ public int getNewListSize() {
+ return itemInternals.size();
+ }
+
+ @Override
+ public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
+ return oldItems.get(oldItemPosition).compare(itemInternals.get(newItemPosition));
+ }
+
+ @Override
+ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
+ return oldItems.get(oldItemPosition).viewType == itemInternals.get(newItemPosition).viewType;
+ }
+ }).dispatchUpdatesTo(this);
+ fromDiffUtils = false;
+ }
+
@Override
public void notifyDataSetChanged() {
- updateHasHints();
+ updateItemList();
super.notifyDataSetChanged();
}
+
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
if (holder.itemView instanceof DialogCell) {
DialogCell dialogCell = (DialogCell) holder.itemView;
dialogCell.onReorderStateChanged(isReordering, false);
int position = fixPosition(holder.getAdapterPosition());
- dialogCell.setDialogIndex(position);
+ // dialogCell.setDialogIndex(position);
+ // dialogCell.collapsed = collapsedView;
dialogCell.checkCurrentDialogIndex(dialogsListFrozen);
dialogCell.setChecked(selectedDialogs.contains(dialogCell.getDialogId()), false);
}
@@ -413,6 +456,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
dialogCell.setArchivedPullAnimation(pullForegroundDrawable);
dialogCell.setPreloader(preloader);
dialogCell.setDialogCellDelegate(this);
+ dialogCell.setIsTransitionSupport(isTransitionSupport);
view = dialogCell;
}
break;
@@ -564,6 +608,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
public int lastDialogsEmptyType = -1;
+
public int dialogsEmptyType() {
if (dialogsType == 7 || dialogsType == 8) {
if (MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId)) {
@@ -643,6 +688,11 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
cell.setChecked(selectedDialogs.contains(dialog.id), false);
cell.setDialog(dialog, dialogsType, folderId);
+ cell.checkHeight();
+ if (cell.collapsed != collapsedView) {
+ cell.collapsed = collapsedView;
+ cell.requestLayout();
+ }
if (preloader != null && i < 10) {
preloader.add(dialog.id);
}
@@ -681,13 +731,8 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
case VIEW_TYPE_USER: {
UserCell cell = (UserCell) holder.itemView;
- int position;
- if (dialogsCount == 0) {
- position = i - 3;
- } else {
- position = i - dialogsCount - 2;
- }
- TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(position).user_id);
+ TLRPC.TL_contact contact = (TLRPC.TL_contact) getItem(i);
+ TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(contact.user_id);
cell.setData(user, null, null, 0);
break;
}
@@ -755,113 +800,30 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
@Override
public int getItemViewType(int i) {
- if (dialogsCount == 0 && forceUpdatingContacts) {
- switch (i) {
- case 0:
- return VIEW_TYPE_EMPTY;
- case 1:
- return VIEW_TYPE_SHADOW;
- case 2:
- return VIEW_TYPE_HEADER;
- case 3:
- return VIEW_TYPE_CONTACTS_FLICKER;
- }
- } else if (onlineContacts != null) {
- if (dialogsCount == 0) {
- if (i == 0) {
- return VIEW_TYPE_EMPTY;
- } else if (i == 1) {
- return VIEW_TYPE_SHADOW;
- } else if (i == 2) {
- return VIEW_TYPE_HEADER;
- }
- } else {
- if (i < dialogsCount) {
- return VIEW_TYPE_DIALOG;
- } else if (i == dialogsCount) {
- return VIEW_TYPE_SHADOW;
- } else if (i == dialogsCount + 1) {
- return VIEW_TYPE_HEADER;
- } else if (i == currentCount - 1) {
- return VIEW_TYPE_LAST_EMPTY;
- }
- }
- return VIEW_TYPE_USER;
- } else if (hasHints) {
- int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
- if (i < 2 + count) {
- if (i == 0) {
- return VIEW_TYPE_RECENTLY_VIEWED;
- } else if (i == 1 + count) {
- return VIEW_TYPE_DIVIDER;
- }
- return VIEW_TYPE_ME_URL;
- } else {
- i -= 2 + count;
- }
- } else if (showArchiveHint) {
- if (i == 0) {
- return VIEW_TYPE_ARCHIVE;
- } else if (i == 1) {
- return VIEW_TYPE_SHADOW;
- } else {
- i -= 2;
- }
- } else if (dialogsType == 11 || dialogsType == 13) {
- if (i == 0) {
- return VIEW_TYPE_HEADER;
- } else if (i == 1) {
- return VIEW_TYPE_TEXT;
- } else {
- i -= 2;
- }
- } else if (dialogsType == 12) {
- if (i == 0) {
- return VIEW_TYPE_HEADER;
- } else {
- i -= 1;
- }
- }
- if (folderId == 0 && dialogsCount > 10 && i == currentCount - 2 && dialogsType == 0) {
- return VIEW_TYPE_NEW_CHAT_HINT;
- }
- int size = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
- if (i == size) {
- if (!forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId)) {
- return VIEW_TYPE_FLICKER;
- } else if (size == 0) {
- return VIEW_TYPE_EMPTY;
- } else {
- return VIEW_TYPE_LAST_EMPTY;
- }
- } else if (i > size) {
- return VIEW_TYPE_LAST_EMPTY;
- }
- if (dialogsType == 2 && getItem(i) instanceof DialogsActivity.DialogsHeader) {
- return VIEW_TYPE_HEADER_2;
- }
- return VIEW_TYPE_DIALOG;
+ return itemInternals.get(i).viewType;
}
@Override
public void notifyItemMoved(int fromPosition, int toPosition) {
- ArrayList dialogs = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, false);
- int fromIndex = fixPosition(fromPosition);
- int toIndex = fixPosition(toPosition);
- TLRPC.Dialog fromDialog = dialogs.get(fromIndex);
- TLRPC.Dialog toDialog = dialogs.get(toIndex);
- if (dialogsType == 7 || dialogsType == 8) {
- MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
- int idx1 = filter.pinnedDialogs.get(fromDialog.id);
- int idx2 = filter.pinnedDialogs.get(toDialog.id);
- filter.pinnedDialogs.put(fromDialog.id, idx2);
- filter.pinnedDialogs.put(toDialog.id, idx1);
- } else {
- int oldNum = fromDialog.pinnedNum;
- fromDialog.pinnedNum = toDialog.pinnedNum;
- toDialog.pinnedNum = oldNum;
+ if (!fromDiffUtils) {
+ ArrayList dialogs = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, false);
+ int fromIndex = fixPosition(fromPosition);
+ int toIndex = fixPosition(toPosition);
+ TLRPC.Dialog fromDialog = dialogs.get(fromIndex);
+ TLRPC.Dialog toDialog = dialogs.get(toIndex);
+ if (dialogsType == 7 || dialogsType == 8) {
+ MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
+ int idx1 = filter.pinnedDialogs.get(fromDialog.id);
+ int idx2 = filter.pinnedDialogs.get(toDialog.id);
+ filter.pinnedDialogs.put(fromDialog.id, idx2);
+ filter.pinnedDialogs.put(toDialog.id, idx1);
+ } else {
+ int oldNum = fromDialog.pinnedNum;
+ fromDialog.pinnedNum = toDialog.pinnedNum;
+ toDialog.pinnedNum = oldNum;
+ }
+ Collections.swap(dialogs, fromIndex, toIndex);
}
- Collections.swap(dialogs, fromIndex, toIndex);
super.notifyItemMoved(fromPosition, toPosition);
}
@@ -902,6 +864,34 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
return selectedDialogs.isEmpty();
}
+ public void setIsTransitionSupport() {
+ this.isTransitionSupport = true;
+ }
+
+ public void setCollapsedView(boolean collapsedView, RecyclerListView listView) {
+ this.collapsedView = collapsedView;
+ for (int i = 0; i < listView.getChildCount(); i++) {
+ if (listView.getChildAt(i) instanceof DialogCell) {
+ ((DialogCell) listView.getChildAt(i)).collapsed = collapsedView;
+ }
+ }
+ for (int i = 0; i < listView.getCachedChildCount(); i++) {
+ if (listView.getCachedChildAt(i) instanceof DialogCell) {
+ ((DialogCell) listView.getCachedChildAt(i)).collapsed = collapsedView;
+ }
+ }
+ for (int i = 0; i < listView.getHiddenChildCount(); i++) {
+ if (listView.getHiddenChildAt(i) instanceof DialogCell) {
+ ((DialogCell) listView.getHiddenChildAt(i)).collapsed = collapsedView;
+ }
+ }
+ for (int i = 0; i < listView.getAttachedScrapChildCount(); i++) {
+ if (listView.getAttachedScrapChildAt(i) instanceof DialogCell) {
+ ((DialogCell) listView.getAttachedScrapChildAt(i)).collapsed = collapsedView;
+ }
+ }
+ }
+
public static class DialogsPreloader {
private final int MAX_REQUEST_COUNT = 4;
@@ -973,7 +963,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
private boolean preloadIsAvilable() {
return false;
- // return DownloadController.getInstance(UserConfig.selectedAccount).getCurrentDownloadMask() != 0;
+ // return DownloadController.getInstance(UserConfig.selectedAccount).getCurrentDownloadMask() != 0;
}
public void updateList() {
@@ -1029,7 +1019,7 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int size = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen).size();
+ int size = itemInternals.size();
boolean hasArchive = dialogsType == 0 && MessagesController.getInstance(currentAccount).dialogs_dict.get(DialogObject.makeFolderDialogId(1)) != null;
View parent = (View) getParent();
int height;
@@ -1051,7 +1041,17 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
}
height -= blurOffset;
int cellHeight = AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 78 : 72);
- int dialogsHeight = size * cellHeight + (size - 1);
+ int dialogsHeight = 0;
+ for (int i = 0; i < size; i++) {
+ if (itemInternals.get(i).viewType == VIEW_TYPE_DIALOG) {
+ if (itemInternals.get(i).isForumCell && !collapsedView) {
+ dialogsHeight += AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 86 : 91);
+ } else {
+ dialogsHeight += cellHeight;
+ }
+ }
+ }
+ dialogsHeight += size - 1;
if (onlineContacts != null) {
dialogsHeight += onlineContacts.size() * AndroidUtilities.dp(58) + (onlineContacts.size() - 1) + AndroidUtilities.dp(52);
}
@@ -1079,4 +1079,108 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter implements
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), height);
}
}
+
+
+ private void updateItemList() {
+ itemInternals.clear();
+ updateHasHints();
+
+ MessagesController messagesController = MessagesController.getInstance(currentAccount);
+ ArrayList array = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
+ dialogsCount = array.size();
+
+ if (!hasHints && dialogsType == 0 && folderId == 0 && messagesController.isDialogsEndReached(folderId) && !forceUpdatingContacts) {
+ if (messagesController.getAllFoldersDialogsCount() <= 10 && ContactsController.getInstance(currentAccount).doneLoadingContacts && !ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
+ onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
+ long selfId = UserConfig.getInstance(currentAccount).clientUserId;
+ for (int a = 0, N = onlineContacts.size(); a < N; a++) {
+ long userId = onlineContacts.get(a).user_id;
+ if (userId == selfId || messagesController.dialogs_dict.get(userId) != null) {
+ onlineContacts.remove(a);
+ a--;
+ N--;
+ }
+ }
+ if (onlineContacts.isEmpty()) {
+ onlineContacts = null;
+ } else {
+ sortOnlineContacts(false);
+ }
+ } else {
+ onlineContacts = null;
+ }
+ }
+
+ boolean stopUpdate = false;
+ if (collapsedView || isTransitionSupport) {
+ for (int k = 0; k < array.size(); k++) {
+ if (dialogsType == 2 && array.get(k) instanceof DialogsActivity.DialogsHeader) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER_2, array.get(k)));
+ } else {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_DIALOG, array.get(k)));
+ }
+ }
+ return;
+ }
+
+ if (dialogsCount == 0 && forceUpdatingContacts) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_EMPTY));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_SHADOW));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_CONTACTS_FLICKER));
+ } else if (onlineContacts != null) {
+ if (dialogsCount == 0) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_EMPTY));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_SHADOW));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER));
+ } else {
+ for (int k = 0; k < array.size(); k++) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_DIALOG, array.get(k)));
+ }
+ itemInternals.add(new ItemInternal(VIEW_TYPE_SHADOW));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER));
+ for (int k = 0; k < onlineContacts.size(); k++) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_USER, onlineContacts.get(k)));
+ }
+ itemInternals.add(new ItemInternal(VIEW_TYPE_LAST_EMPTY));
+ }
+ stopUpdate = true;
+ } else if (hasHints) {
+ int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
+ itemInternals.add(new ItemInternal(VIEW_TYPE_RECENTLY_VIEWED));
+ for (int k = 0; k < count; k++) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_ME_URL, MessagesController.getInstance(currentAccount).hintDialogs.get(k)));
+ }
+ itemInternals.add(new ItemInternal(VIEW_TYPE_DIVIDER));
+ } else if (showArchiveHint) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_ARCHIVE));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_SHADOW));
+ } else if (dialogsType == 11 || dialogsType == 13) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER));
+ itemInternals.add(new ItemInternal(VIEW_TYPE_TEXT));
+ } else if (dialogsType == 12) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER));
+ }
+
+ if (!stopUpdate) {
+ for (int k = 0; k < array.size(); k++) {
+ if (dialogsType == 2 && array.get(k) instanceof DialogsActivity.DialogsHeader) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_HEADER_2, array.get(k)));
+ } else {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_DIALOG, array.get(k)));
+ }
+ }
+ }
+
+ if (!forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId)) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_FLICKER));
+ } else if (dialogsCount == 0) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_EMPTY));
+ } else {
+ if (folderId == 0 && dialogsCount > 10 && dialogsType == 0) {
+ itemInternals.add(new ItemInternal(VIEW_TYPE_NEW_CHAT_HINT));
+ }
+ itemInternals.add(new ItemInternal(VIEW_TYPE_LAST_EMPTY));
+ }
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java
index 4e42ab0be..49462a918 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java
@@ -49,6 +49,7 @@ import org.telegram.ui.Cells.HashtagSearchCell;
import org.telegram.ui.Cells.HintDialogCell;
import org.telegram.ui.Cells.ProfileSearchCell;
import org.telegram.ui.Cells.TextCell;
+import org.telegram.ui.Cells.TopicSearchCell;
import org.telegram.ui.Components.FlickerLoadingView;
import org.telegram.ui.Components.ForegroundColorSpanThemable;
import org.telegram.ui.Components.RecyclerListView;
@@ -64,25 +65,32 @@ public class DialogsSearchAdapter extends RecyclerListView.SelectionAdapter {
private final int VIEW_TYPE_PROFILE_CELL = 0;
private final int VIEW_TYPE_GRAY_SECTION = 1;
private final int VIEW_TYPE_DIALOG_CELL = 2;
- private final int VIEW_TYPE_LOADING = 3;
- private final int VIEW_TYPE_HASHTAG_CELL = 4;
- private final int VIEW_TYPE_CATEGORY_LIST = 5;
- private final int VIEW_TYPE_ADD_BY_PHONE = 6;
+ private final int VIEW_TYPE_TOPIC_CELL = 3;
+ private final int VIEW_TYPE_LOADING = 4;
+ private final int VIEW_TYPE_HASHTAG_CELL = 5;
+ private final int VIEW_TYPE_CATEGORY_LIST = 6;
+ private final int VIEW_TYPE_ADD_BY_PHONE = 7;
private Context mContext;
private Runnable searchRunnable;
private Runnable searchRunnable2;
private ArrayList