From 58aded63e9713ef796d76f3e29a60a5254f803b4 Mon Sep 17 00:00:00 2001 From: xaxtix Date: Tue, 21 Sep 2021 12:51:08 +0300 Subject: [PATCH] Update to 8.1.1 (2431) --- .../telegram/messenger/AndroidUtilities.java | 25 +- .../org/telegram/messenger/BuildVars.java | 4 +- .../telegram/messenger/MessagesStorage.java | 1917 +++++++++-------- .../telegram/messenger/OpenChatReceiver.java | 5 +- .../org/telegram/ui/ActionBar/ChatTheme.java | 6 +- .../java/org/telegram/ui/ActionBar/Theme.java | 8 +- .../telegram/ui/Adapters/DialogsAdapter.java | 11 + .../java/org/telegram/ui/ChatActivity.java | 20 +- .../ui/Components/ChatThemeBottomSheet.java | 5 +- .../ui/Components/SharedMediaLayout.java | 2 +- .../telegram/ui/DatabaseMigrationHint.java | 9 +- .../java/org/telegram/ui/DialogsActivity.java | 37 +- .../telegram/ui/EmojiAnimationsOverlay.java | 42 +- .../java/org/telegram/ui/LaunchActivity.java | 5 +- .../java/org/telegram/ui/LoginActivity.java | 2 +- .../java/org/telegram/ui/MessageSeenView.java | 66 +- .../java/org/telegram/ui/ProfileActivity.java | 15 +- 17 files changed, 1125 insertions(+), 1054 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java index 3439034a3..6dc291fd9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java @@ -2242,33 +2242,12 @@ public class AndroidUtilities { }*/ public static void startAppCenter(Activity context) { -// if (BuildConfig.DEBUG) { -// return; -// } -// try { -// if (BuildVars.DEBUG_VERSION) { -// Distribute.setEnabledForDebuggableBuild(true); -// AppCenter.start(context.getApplication(), BuildVars.DEBUG_VERSION ? BuildVars.APPCENTER_HASH_DEBUG : BuildVars.APPCENTER_HASH, Distribute.class, Crashes.class); -// AppCenter.setUserId("uid=" + UserConfig.getInstance(UserConfig.selectedAccount).clientUserId); -// } -// } catch (Throwable e) { -// FileLog.e(e); -// } + } private static long lastUpdateCheckTime; public static void checkForUpdates() { -// try { -// if (BuildVars.DEBUG_VERSION) { -// if (SystemClock.elapsedRealtime() - lastUpdateCheckTime < 60 * 60 * 1000) { -// return; -// } -// lastUpdateCheckTime = SystemClock.elapsedRealtime(); -// Distribute.checkForUpdate(); -// } -// } catch (Throwable e) { -// FileLog.e(e); -// } + } public static void 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 9d1aa32d7..cd643bb6a 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -19,8 +19,8 @@ public class BuildVars { public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; public static boolean NO_SCOPED_STORAGE = true/* || Build.VERSION.SDK_INT <= 28*/; - public static int BUILD_VERSION = 2428; - public static String BUILD_VERSION_STRING = "8.0.1"; + public static int BUILD_VERSION = 2431; + public static String BUILD_VERSION_STRING = "8.1.1"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; public static String SMS_HASH = isStandaloneApp() ? "w0lkcmTZkKh" : (DEBUG_VERSION ? "O2P2z+/jBpJ" : "oLeq9AcOZkT"); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index 88bc00fa3..23e1ebbc2 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -99,6 +99,7 @@ public class MessagesStorage extends BaseController { private static volatile MessagesStorage[] Instance = new MessagesStorage[UserConfig.MAX_ACCOUNT_COUNT]; private final static int LAST_DB_VERSION = 84; + private boolean databaseMigrationInProgress; public static MessagesStorage getInstance(int num) { MessagesStorage localInstance = Instance[num]; @@ -469,990 +470,991 @@ public class MessagesStorage extends BaseController { } } - private void updateDbToLastVersion(int currentVersion) { + public boolean isDatabaseMigrationInProgress() { + return databaseMigrationInProgress; + } + + private void updateDbToLastVersion(int currentVersion) throws Exception { AndroidUtilities.runOnUIThread(() -> { + databaseMigrationInProgress = true; NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.onDatabaseMigration, true); }); - storageQueue.postRunnable(() -> { - try { - int version = currentVersion; - 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(); + 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(); - 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("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 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_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 INDEX IF NOT EXISTS mid_idx_randoms ON randoms(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 TABLE IF NOT EXISTS sent_files_v2(uid TEXT, type INTEGER, data BLOB, PRIMARY KEY (uid, type))").stepThis().dispose(); + database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").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 sent_files_v2(uid TEXT, type INTEGER, data BLOB, PRIMARY KEY (uid, type))").stepThis().dispose(); - database.executeFast("CREATE TABLE IF NOT EXISTS dialog_settings(did INTEGER PRIMARY KEY, flags INTEGER);").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 INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose(); + database.executeFast("CREATE TABLE IF NOT EXISTS dialog_settings(did INTEGER PRIMARY KEY, flags INTEGER);").stepThis().dispose(); - database.executeFast("UPDATE messages SET send_state = 2 WHERE mid < 0 AND send_state = 1").stepThis().dispose(); + database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").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); + 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.bindLong(1, mid); + state.bindInteger(1, data.readInt32(false)); 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; + data.reuse(); } - 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(); + } + state.dispose(); + cursor.dispose(); + database.commitTransaction(); - 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.executeFast("DROP INDEX IF EXISTS date_idx_enc_tasks;").stepThis().dispose(); + database.executeFast("DROP TABLE IF EXISTS enc_tasks;").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); + 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(); } - 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(); + } + state.dispose(); + cursor.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); + 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(); - 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.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); - 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(); + state.requery(); + state.bindLong(1, mid); + state.bindInteger(2, date); + state.bindInteger(3, media); + state.step(); + } + state.dispose(); + cursor.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("DROP INDEX IF EXISTS date_idx_enc_tasks_v2;").stepThis().dispose(); + database.executeFast("DROP TABLE IF EXISTS enc_tasks_v2;").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("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 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 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.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.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); - AndroidUtilities.runOnUIThread(() -> { - NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.onDatabaseMigration, false); - }); + 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; + + 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"); + + 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) { + + } + + + FileLog.d("MessagesStorage db migration finished"); + AndroidUtilities.runOnUIThread(() -> { + databaseMigrationInProgress = false; + NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.onDatabaseMigration, false); }); } @@ -2285,6 +2287,7 @@ public class MessagesStorage extends BaseController { private int[] mentionGroups = new int[2]; private LongSparseArray dialogsWithMentions = new LongSparseArray<>(); private LongSparseArray dialogsWithUnread = new LongSparseArray<>(); + private void calcUnreadCounters(boolean apply) { try { for (int a = 0; a < 2; a++) { @@ -3109,7 +3112,7 @@ public class MessagesStorage extends BaseController { public void saveDialogFiltersOrderInternal() { try { SQLitePreparedStatement state = database.executeFast("UPDATE dialog_filter SET ord = ?, flags = ? WHERE id = ?"); - for (int a = 0, N = dialogFilters.size(); a < N ;a++) { + for (int a = 0, N = dialogFilters.size(); a < N; a++) { MessagesController.DialogFilter filter = dialogFilters.get(a); state.requery(); state.bindInteger(1, filter.order); @@ -3987,7 +3990,7 @@ public class MessagesStorage extends BaseController { message.media.photo = new TLRPC.TL_photoEmpty(); } } - message.media.flags = message.media.flags &~ 1; + message.media.flags = message.media.flags & ~1; message.id = cursor.intValue(1); message.date = cursor.intValue(2); message.dialog_id = cursor.longValue(3); @@ -5351,7 +5354,7 @@ public class MessagesStorage extends BaseController { TLObject result = null; try { database.executeFast("DELETE FROM botcache WHERE date < " + currentDate).stepThis().dispose(); - SQLiteCursor cursor = database.queryFinalized( "SELECT data FROM botcache WHERE id = ?", key); + SQLiteCursor cursor = database.queryFinalized("SELECT data FROM botcache WHERE id = ?", key); if (cursor.next()) { try { NativeByteBuffer data = cursor.byteBufferValue(0); @@ -8332,9 +8335,9 @@ public class MessagesStorage extends BaseController { private int getMessageMediaType(TLRPC.Message message) { if (message instanceof TLRPC.TL_message_secret) { if (message.media instanceof TLRPC.TL_messageMediaPhoto || MessageObject.isGifMessage(message) || - MessageObject.isVoiceMessage(message) || - MessageObject.isVideoMessage(message) || - MessageObject.isRoundVideoMessage(message)) { + MessageObject.isVoiceMessage(message) || + MessageObject.isVideoMessage(message) || + MessageObject.isRoundVideoMessage(message)) { if (message.ttl > 0 && message.ttl <= 60) { return 1; } else { @@ -9809,7 +9812,7 @@ public class MessagesStorage extends BaseController { ArrayList mids = dialogs.valueAt(a); AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.messagesDeleted, mids, 0L, false)); updateDialogsWithReadMessagesInternal(mids, null, null, null); - markMessagesAsDeletedInternal(dialogId, mids, true, false); + markMessagesAsDeletedInternal(dialogId, mids, true, false); updateDialogsWithDeletedMessagesInternal(dialogId, 0, mids, null); } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/OpenChatReceiver.java b/TMessagesProj/src/main/java/org/telegram/messenger/OpenChatReceiver.java index a85575515..0c2501d00 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/OpenChatReceiver.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/OpenChatReceiver.java @@ -29,13 +29,14 @@ public class OpenChatReceiver extends Activity { return; } try { - long chatId = intent.getLongExtra("chatId", 0); - long userId = intent.getLongExtra("userId", 0); + long chatId = intent.getLongExtra("chatId", intent.getIntExtra("chatId", 0)); + long userId = intent.getLongExtra("userId", intent.getIntExtra("userId", 0)); int encId = intent.getIntExtra("encId", 0); if (chatId == 0 && userId == 0 && encId == 0) { return; } } catch (Throwable e) { + FileLog.e(e); return; } Intent intent2 = new Intent(this, LaunchActivity.class); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ChatTheme.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ChatTheme.java index 994dabb08..e64a91052 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ChatTheme.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ChatTheme.java @@ -155,8 +155,10 @@ public class ChatTheme { public void loadWallpaperThumb(boolean isDark, ResultCallback> callback) { final TLRPC.WallPaper wallpaper = getWallpaper(isDark); - if (wallpaper == null && callback != null) { - callback.onComplete(null); + if (wallpaper == null) { + if (callback != null) { + callback.onComplete(null); + } return; } 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 64ac990e9..e0a3a0f61 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java @@ -316,7 +316,7 @@ public class Theme { } else { num = currentType == TYPE_PREVIEW ? 1 : 0; } - if (gradientColor2 != 0 && animatedGradient && motionBackground[num] != null) { + if (!isCrossfadeBackground && gradientColor2 != 0 && animatedGradient && motionBackground[num] != null) { int[] colors = motionBackground[num].getColors(); currentColor = colors[0]; currentGradientColor1 = colors[1]; @@ -325,8 +325,10 @@ public class Theme { } if (isCrossfadeBackground && gradientColor2 != 0 && animatedGradient) { if (backgroundHeight != currentBackgroundHeight || crosfadeFromBitmapShader == null || currentColor != color || currentGradientColor1 != gradientColor1 || currentGradientColor2 != gradientColor2 || currentGradientColor3 != gradientColor3 || currentAnimateGradient != animatedGradient) { - crosfadeFromBitmap = Bitmap.createBitmap(60, 80, Bitmap.Config.ARGB_8888); - crosfadeFromBitmapShader = new BitmapShader(crosfadeFromBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); + if (crosfadeFromBitmap == null) { + crosfadeFromBitmap = Bitmap.createBitmap(60, 80, Bitmap.Config.ARGB_8888); + crosfadeFromBitmapShader = new BitmapShader(crosfadeFromBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); + } if (motionBackground[num] == null) { motionBackground[num] = new MotionBackgroundDrawable(); if (currentType != TYPE_PREVIEW) { 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 e3d54ae59..051fd0ce7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsAdapter.java @@ -28,6 +28,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager.widget.ViewPager; import org.telegram.messenger.AndroidUtilities; +import org.telegram.messenger.BuildVars; import org.telegram.messenger.ContactsController; import org.telegram.messenger.DialogObject; import org.telegram.messenger.FileLog; @@ -155,6 +156,9 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter { dialogsCount = array.size(); if (!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)); + } if (folderId == 1 && showArchiveHint) { return (currentCount = 2); } @@ -176,6 +180,9 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter { } else if (dialogsType == 0 && messagesController.dialogs_dict.size() <= 10 && folderId == 0 && messagesController.isDialogsEndReached(folderId)) { if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts) { 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); } @@ -224,6 +231,10 @@ public class DialogsAdapter extends RecyclerListView.SelectionAdapter { count += 1; } currentCount = count; + + if (BuildVars.LOGS_ENABLED) { + FileLog.d("DialogsAdapter dialogsCount=" + dialogsCount + " dialogsType=" + dialogsType); + } return count; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 8c3ae610e..f53da384e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -8039,7 +8039,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } private void openAnotherForward() { - if (forwardingMessages == null) { + if (forwardingMessages == null || forwardingMessages.messages == null) { return; } boolean fewSenders = false; @@ -8063,7 +8063,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not message = LocaleController.formatString("CancelForwardPrivate", R.string.CancelForwardPrivate, LocaleController.formatPluralString("MessagesBold", forwardingMessages.messages.size()), ContactsController.formatName(user.first_name, user.last_name)); } else { TLRPC.Chat chat = getMessagesController().getChat(-dialogId); - message = LocaleController.formatString("CancelForwardChat", R.string.CancelForwardChat, LocaleController.formatPluralString("MessagesBold", forwardingMessages.messages.size()), chat.title); + message = LocaleController.formatString("CancelForwardChat", R.string.CancelForwardChat, LocaleController.formatPluralString("MessagesBold", forwardingMessages.messages.size()), chat == null ? "" : chat.title); } builder.setMessage(AndroidUtilities.replaceTags(message)); builder.setTitle(LocaleController.formatPluralString("messages", forwardingMessages.messages.size())); @@ -19956,7 +19956,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not boolean showMessageSeen = currentChat != null && message.isOutOwner() && message.isSent() && !message.isEditing() && !message.isSending() && !message.isSendError() && !message.isContentUnread() && !message.isUnread() && (ConnectionsManager.getInstance(currentAccount).getCurrentTime() - message.messageOwner.date < 7 * 86400) && (ChatObject.isMegagroup(currentChat) || !ChatObject.isChannel(currentChat)) && chatInfo != null && chatInfo.participants_count < 50; MessageSeenView messageSeenView = null; if (showMessageSeen) { - messageSeenView = new MessageSeenView(contentView.getContext(), currentAccount, message); + messageSeenView = new MessageSeenView(contentView.getContext(), currentAccount, message, currentChat); Drawable shadowDrawable2 = ContextCompat.getDrawable(contentView.getContext(), R.drawable.popup_fixed_alert).mutate(); shadowDrawable2.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_actionBarDefaultSubmenuBackground), PorterDuff.Mode.MULTIPLY)); FrameLayout messageSeenLayout = new FrameLayout(contentView.getContext()); @@ -20116,7 +20116,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not args.putLong("user_id", user.id); ProfileActivity fragment = new ProfileActivity(args); presentFragment(fragment); - mesageSeenUsersPopupWindow.dismiss(); + if (mesageSeenUsersPopupWindow != null) { + mesageSeenUsersPopupWindow.dismiss(); + } }); } }); @@ -24648,7 +24650,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not themeDescriptions.add(new ThemeDescription(alertNameTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_chat_topPanelTitle)); themeDescriptions.add(new ThemeDescription(alertTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_chat_topPanelMessage)); themeDescriptions.add(new ThemeDescription(closePinned, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chat_topPanelClose)); - themeDescriptions.add(new ThemeDescription(pinnedListButton, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chat_topPanelTitle)); + themeDescriptions.add(new ThemeDescription(pinnedListButton, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chat_topPanelClose)); themeDescriptions.add(new ThemeDescription(closeReportSpam, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chat_topPanelClose)); themeDescriptions.add(new ThemeDescription(topChatPanelView, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_chat_topPanelBackground)); themeDescriptions.add(new ThemeDescription(alertView, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_chat_topPanelBackground)); @@ -25041,7 +25043,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } if (!setup) { - Theme.refreshThemeColors(); + Theme.refreshThemeColors(true, false); } } @@ -25223,6 +25225,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not animatingMessageDrawable.crossfadeFromDrawable = parentLayout.messageDrawableOutStart; animatingMessageMediaDrawable = (Theme.MessageDrawable) getThemedDrawable(Theme.key_drawable_msgOutMedia); animatingMessageMediaDrawable.crossfadeFromDrawable = parentLayout.messageDrawableOutMediaStart; + animatingMessageDrawable.crossfadeProgress = 0f; + animatingMessageMediaDrawable.crossfadeProgress = 0f; + updateMessagesVisiblePart(false); updateServiceMessageColor(0); }; animationSettings.afterAnimationRunnable = () -> { @@ -25263,7 +25268,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not Theme.ThemeInfo activeTheme; if (Theme.getActiveTheme().isDark() == isDark) { - activeTheme = Theme.getCurrentTheme(); + activeTheme = Theme.getActiveTheme(); } else { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("themeconfig", Activity.MODE_PRIVATE); String dayThemeName = preferences.getString("lastDayTheme", "Blue"); @@ -25277,7 +25282,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not activeTheme = isDark ? Theme.getTheme(nightThemeName) : Theme.getTheme(dayThemeName); } - Theme.applyTheme(activeTheme, false, isDark); } else { currentColors = chatTheme.getCurrentColors(currentAccount, isDark); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatThemeBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatThemeBottomSheet.java index 9776caeb2..10230fdf2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatThemeBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatThemeBottomSheet.java @@ -153,7 +153,7 @@ public class ChatThemeBottomSheet extends BottomSheet implements NotificationCen recyclerView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); recyclerView.setPadding(AndroidUtilities.dp(12), 0, AndroidUtilities.dp(12), 0); recyclerView.setOnItemClickListener((view, position) -> { - if (adapter.items.get(position) == selectedItem) { + if (adapter.items.get(position) == selectedItem || changeDayNightView != null) { return; } selectedItem = adapter.items.get(position); @@ -855,6 +855,7 @@ public class ChatThemeBottomSheet extends BottomSheet implements NotificationCen drawable.setPatternBitmap(intensity >= 0 ? 100 : -100, result.second); drawable.setPatternColorFilter(drawable.getPatternColor()); } + invalidate(); } }); } @@ -965,7 +966,7 @@ public class ChatThemeBottomSheet extends BottomSheet implements NotificationCen noThemeTextPaint.setTextSize(AndroidUtilities.dp(14)); noThemeTextPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textLayout = StaticLayoutEx.createStaticLayout2( - LocaleController.getString("NoTheme", R.string.ChatNoTheme), + LocaleController.getString("ChatNoTheme", R.string.ChatNoTheme), noThemeTextPaint, AndroidUtilities.dp(52), Layout.Alignment.ALIGN_CENTER, diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java index 5321c16b2..818e4435b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java @@ -2829,7 +2829,7 @@ public class SharedMediaLayout extends FrameLayout implements NotificationCenter } private boolean onItemLongClick(MessageObject item, View view, int a) { - if (isActionModeShowed || profileActivity.getParentActivity() == null) { + if (isActionModeShowed || profileActivity.getParentActivity() == null || item == null) { return false; } AndroidUtilities.hideKeyboard(profileActivity.getParentActivity().getCurrentFocus()); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DatabaseMigrationHint.java b/TMessagesProj/src/main/java/org/telegram/ui/DatabaseMigrationHint.java index 438bdf84c..74419a0f0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DatabaseMigrationHint.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DatabaseMigrationHint.java @@ -3,6 +3,8 @@ package org.telegram.ui; import android.content.Context; import android.util.TypedValue; import android.view.Gravity; +import android.view.MotionEvent; +import android.view.View; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; @@ -60,6 +62,11 @@ public class DatabaseMigrationHint extends FrameLayout { addView(container, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); - + setOnTouchListener(new OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return true; + } + }); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index 68bee2345..f99edc203 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -736,7 +736,12 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. if (child == null || child.getVisibility() == GONE || child == commentView || child == actionBar) { continue; } - if (child instanceof ViewPage) { + if (child instanceof DatabaseMigrationHint) { + int contentWidthSpec = View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY); + int h = View.MeasureSpec.getSize(heightMeasureSpec) + keyboardSize; + int contentHeightSpec = View.MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), h - inputFieldHeight + AndroidUtilities.dp(2) - actionBar.getMeasuredHeight()), View.MeasureSpec.EXACTLY); + child.measure(contentWidthSpec, contentHeightSpec); + } else if (child instanceof ViewPage) { int contentWidthSpec = View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY); int h; if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) { @@ -850,6 +855,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. childTop = actionBar.getMeasuredHeight(); } else if (child == searchViewPager) { childTop = (onlySelect ? 0 : actionBar.getMeasuredHeight()) + topPadding + (searchTabsView == null ? 0 : AndroidUtilities.dp(44)); + } else if (child instanceof DatabaseMigrationHint) { + childTop = actionBar.getMeasuredHeight(); } else if (child instanceof ViewPage) { if (!onlySelect) { if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) { @@ -1815,18 +1822,24 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. getNotificationCenter().addObserver(this, NotificationCenter.fileLoaded); getNotificationCenter().addObserver(this, NotificationCenter.fileLoadFailed); getNotificationCenter().addObserver(this, NotificationCenter.fileLoadProgressChanged); - getNotificationCenter().addObserver(this, NotificationCenter.onDatabaseMigration); NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetPasscode); NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.appUpdateAvailable); } getNotificationCenter().addObserver(this, NotificationCenter.messagesDeleted); - + getNotificationCenter().addObserver(this, NotificationCenter.onDatabaseMigration); getNotificationCenter().addObserver(this, NotificationCenter.didClearDatabase); loadDialogs(getAccountInstance()); getMessagesController().loadPinnedDialogs(folderId, 0, null); + if (databaseMigrationHint != null && !getMessagesStorage().isDatabaseMigrationInProgress()) { + View localView = databaseMigrationHint; + if (localView.getParent() != null) { + ((ViewGroup) localView.getParent()).removeView(localView); + } + databaseMigrationHint = null; + } return true; } @@ -1887,6 +1900,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.appUpdateAvailable); } + getNotificationCenter().removeObserver(this, NotificationCenter.onDatabaseMigration); getNotificationCenter().removeObserver(this, NotificationCenter.didClearDatabase); if (commentView != null) { commentView.onDestroy(); @@ -2056,7 +2070,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. @Override public boolean canToggleSearch() { - return !actionBar.isActionModeShowed(); + return !actionBar.isActionModeShowed() && databaseMigrationHint == null; } }); searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search)); @@ -4530,7 +4544,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. } private void updateFilterTabsVisibility(boolean animated) { - if (isPaused) { + if (isPaused || databaseMigrationHint != null) { animated = false; } if (searchIsShowed) { @@ -6539,22 +6553,21 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. ((ContentView) fragmentView).addView(databaseMigrationHint); databaseMigrationHint.animate().alpha(1).setDuration(300).setStartDelay(1000).start(); } + databaseMigrationHint.setTag(1); } else { - if (databaseMigrationHint != null) { + if (databaseMigrationHint != null && databaseMigrationHint.getTag() != null) { View localView = databaseMigrationHint; localView.animate().setListener(null).cancel(); localView.animate().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (localView.getParent() != null) { - ((ContentView) fragmentView).removeView(localView); + ((ViewGroup) localView.getParent()).removeView(localView); } - + databaseMigrationHint = null; } - }).alpha(0f).setDuration(150).start(); - - databaseMigrationHint = null; - + }).alpha(0f).setStartDelay(0).setDuration(150).start(); + databaseMigrationHint.setTag(null); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/EmojiAnimationsOverlay.java b/TMessagesProj/src/main/java/org/telegram/ui/EmojiAnimationsOverlay.java index d7ea010f5..5790887f9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/EmojiAnimationsOverlay.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/EmojiAnimationsOverlay.java @@ -55,9 +55,11 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe ArrayList animationIndexes = new ArrayList<>(); Runnable sentInteractionsRunnable; + Runnable hintRunnable; private final static HashSet supportedEmoji = new HashSet<>(); private final static HashSet excludeEmojiFromPack = new HashSet<>(); - static { + + static { // 1️⃣, 2️⃣, 3️⃣... etc excludeEmojiFromPack.add("\u0030\u20E3"); excludeEmojiFromPack.add("\u0031\u20E3"); @@ -93,12 +95,14 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe checkStickerPack(); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.diceStickersDidLoad); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.onEmojiInteractionsReceived); + NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.updateInterfaces); } protected void onDetachedFromWindow() { attached = false; NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.diceStickersDidLoad); NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.onEmojiInteractionsReceived); + NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.updateInterfaces); } public void checkStickerPack() { @@ -131,7 +135,7 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe String[] heartEmojies = new String[]{"🧡", "💛", "💚", "💙", "💜", "🖤", "🤍", "🤎"}; for (String heart : heartEmojies) { supportedEmoji.add(heart); - emojiInteractionsStickersMap.put(heart, stickers); + emojiInteractionsStickersMap.put(heart, stickers); } } } @@ -174,6 +178,11 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe } } + } else if (id == NotificationCenter.updateInterfaces) { + Integer printingType = MessagesController.getInstance(currentAccount).getPrintingStringType(dialogId, threadMsgId); + if (printingType != null && printingType == 5) { + cancelHintRunnable(); + } } } @@ -231,7 +240,7 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe } } - drawingObject.imageReceiver.setImageCoords(drawingObject.lastX + drawingObject.randomOffsetX, drawingObject.lastY + drawingObject.randomOffsetY, drawingObject.lastW * 3, drawingObject.lastW * 3); + drawingObject.imageReceiver.setImageCoords(drawingObject.lastX + drawingObject.randomOffsetX, drawingObject.lastY + drawingObject.randomOffsetY, drawingObject.lastW * 3, drawingObject.lastW * 3); if (!drawingObject.isOut) { canvas.save(); canvas.scale(-1f, 1, drawingObject.imageReceiver.getCenterX(), drawingObject.imageReceiver.getCenterY()); @@ -262,7 +271,13 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe if (show && !EmojiData.hasEmojiSupportVibration(view.getMessageObject().getStickerEmoji())) { view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } - if ((Bulletin.getVisibleBulletin() == null || !Bulletin.getVisibleBulletin().isShowing()) && SharedConfig.emojiInteractionsHintCount > 0) { + + Integer printingType = MessagesController.getInstance(currentAccount).getPrintingStringType(dialogId, threadMsgId); + boolean canShowHint = true; + if (printingType != null && printingType == 5) { + canShowHint = false; + } + if (canShowHint && hintRunnable == null && show && (Bulletin.getVisibleBulletin() == null || !Bulletin.getVisibleBulletin().isShowing()) && SharedConfig.emojiInteractionsHintCount > 0) { SharedConfig.updateEmojiInteractionsHintCount(SharedConfig.emojiInteractionsHintCount - 1); TLRPC.Document document = MediaDataController.getInstance(currentAccount).getEmojiAnimatedSticker(view.getMessageObject().getStickerEmoji()); StickerSetBulletinLayout layout = new StickerSetBulletinLayout(chatActivity.getParentActivity(), null, StickerSetBulletinLayout.TYPE_EMPTY, document, chatActivity.getResourceProvider()); @@ -271,10 +286,24 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe layout.titleTextView.setTypeface(null); layout.titleTextView.setMaxLines(3); layout.titleTextView.setSingleLine(false); - Bulletin.make(chatActivity, layout, Bulletin.DURATION_LONG).show(); + Bulletin bulletin = Bulletin.make(chatActivity, layout, Bulletin.DURATION_LONG); + AndroidUtilities.runOnUIThread(hintRunnable = new Runnable() { + @Override + public void run() { + bulletin.show(); + hintRunnable = null; + } + }, 1500); } } + public void cancelHintRunnable() { + if (hintRunnable != null) { + AndroidUtilities.cancelRunOnUIThread(hintRunnable); + } + hintRunnable = null; + } + private boolean showAnimationForCell(ChatMessageCell view, int animation, boolean sendTap, boolean sendSeen) { if (drawingObjects.size() > 12) { return false; @@ -351,7 +380,8 @@ public class EmojiAnimationsOverlay implements NotificationCenter.NotificationCe if (lastTappedTime == 0) { lastTappedTime = System.currentTimeMillis(); timeIntervals.clear(); - animationIndexes.clear();; + animationIndexes.clear(); + ; timeIntervals.add(0L); animationIndexes.add(animation); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index d2b4af000..9ce645340 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -2109,8 +2109,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa } else if (intent.getAction().equals("new_dialog")) { open_new_dialog = 1; } else if (intent.getAction().startsWith("com.tmessages.openchat")) { - long chatId = intent.getLongExtra("chatId", 0); - long userId = intent.getLongExtra("userId", 0); + + long chatId = intent.getLongExtra("chatId", intent.getIntExtra("chatId", 0)); + long userId = intent.getLongExtra("userId", intent.getIntExtra("userId", 0)); int encId = intent.getIntExtra("encId", 0); int widgetId = intent.getIntExtra("appWidgetId", 0); if (widgetId != 0) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index fab78132d..a227ce0ac 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -1542,7 +1542,7 @@ public class LoginActivity extends BaseFragment { private void setCountry(HashMap languageMap, String country) { String name = languageMap.get(country); - if (name != null) { + if (name != null && countriesArray != null) { CountrySelectActivity.Country countryWithCode = null; for (int i = 0; i < countriesArray.size(); i++) { if (countriesArray.get(i) != null && countriesArray.get(i).name.equals(country)) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessageSeenView.java b/TMessagesProj/src/main/java/org/telegram/ui/MessageSeenView.java index b24ca7f0d..9b9b41e56 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessageSeenView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessageSeenView.java @@ -21,8 +21,12 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.exoplayer2.util.Log; + import org.telegram.messenger.AndroidUtilities; +import org.telegram.messenger.ChatObject; import org.telegram.messenger.ContactsController; +import org.telegram.messenger.FileLog; import org.telegram.messenger.ImageLocation; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MessageObject; @@ -57,7 +61,7 @@ public class MessageSeenView extends FrameLayout { FlickerLoadingView flickerLoadingView; - public MessageSeenView(@NonNull Context context, int currentAccount, MessageObject messageObject) { + public MessageSeenView(@NonNull Context context, int currentAccount, MessageObject messageObject, TLRPC.Chat chat) { super(context); this.currentAccount = currentAccount; isVoice = (messageObject.isRoundVideo() || messageObject.isVoice()); @@ -98,6 +102,7 @@ public class MessageSeenView extends FrameLayout { } long finalFromId = fromId; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { + FileLog.e("MessageSeenView request completed"); if (error == null) { TLRPC.Vector vector = (TLRPC.Vector) response; ArrayList unknownUsers = new ArrayList<>(); @@ -112,7 +117,7 @@ public class MessageSeenView extends FrameLayout { } TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(peerId); allPeers.add(peerId); - if (user == null) { + if (true || user == null) { unknownUsers.add(peerId); } else { usersLocal.put(peerId, user); @@ -127,25 +132,46 @@ public class MessageSeenView extends FrameLayout { } updateView(); } else { - TLRPC.TL_users_getUsers usersReq = new TLRPC.TL_users_getUsers(); - for (int i = 0; i < unknownUsers.size(); i++) { - usersReq.id.add(MessagesController.getInstance(currentAccount).getInputUser(unknownUsers.get(i))); + if (ChatObject.isChannel(chat)) { + TLRPC.TL_channels_getParticipants usersReq = new TLRPC.TL_channels_getParticipants(); + usersReq.limit = 50; + usersReq.offset = 0; + usersReq.filter = new TLRPC.TL_channelParticipantsRecent(); + usersReq.channel = MessagesController.getInstance(currentAccount).getInputChannel(chat.id); + ConnectionsManager.getInstance(currentAccount).sendRequest(usersReq, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> { + if (response1 != null) { + TLRPC.TL_channels_channelParticipants users = (TLRPC.TL_channels_channelParticipants) response1; + for (int i = 0; i < users.users.size(); i++) { + TLRPC.User user = users.users.get(i); + MessagesController.getInstance(currentAccount).putUser(user, false); + usersLocal.put(user.id, user); + } + for (int i = 0; i < allPeers.size(); i++) { + peerIds.add(allPeers.get(i)); + this.users.add(usersLocal.get(allPeers.get(i))); + } + } + updateView(); + })); + } else { + TLRPC.TL_messages_getFullChat usersReq = new TLRPC.TL_messages_getFullChat(); + usersReq.chat_id = chat.id; + ConnectionsManager.getInstance(currentAccount).sendRequest(usersReq, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> { + if (response1 != null) { + TLRPC.TL_messages_chatFull chatFull = (TLRPC.TL_messages_chatFull) response1; + for (int i = 0; i < chatFull.users.size(); i++) { + TLRPC.User user = chatFull.users.get(i); + MessagesController.getInstance(currentAccount).putUser(user, false); + usersLocal.put(user.id, user); + } + for (int i = 0; i < allPeers.size(); i++) { + peerIds.add(allPeers.get(i)); + this.users.add(usersLocal.get(allPeers.get(i))); + } + } + updateView(); + })); } - ConnectionsManager.getInstance(currentAccount).sendRequest(usersReq, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> { - if (response1 != null) { - TLRPC.Vector users = (TLRPC.Vector) response1; - for (int i = 0; i < users.objects.size(); i++) { - TLRPC.User user = (TLRPC.User) users.objects.get(i); - MessagesController.getInstance(currentAccount).putUser(user, false); - usersLocal.put(user.id, user); - } - for (int i = 0; i < allPeers.size(); i++) { - peerIds.add(allPeers.get(i)); - this.users.add(usersLocal.get(allPeers.get(i))); - } - } - updateView(); - })); } } else { updateView(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index d6c1bb701..f35b1c2b5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -4742,14 +4742,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } } else if (id == NotificationCenter.reloadInterface) { int prevEmptyRow = emptyRow; - updateRowsIds(); - if (listAdapter != null && prevEmptyRow != emptyRow) { - if (emptyRow == -1) { - listAdapter.notifyItemRemoved(emptyRow); - } else { - listAdapter.notifyItemInserted(emptyRow); - } - } + updateListAnimated(false); } else if (id == NotificationCenter.newSuggestionsAvailable) { int prevRow1 = passwordSuggestionRow; int prevRow2 = phoneSuggestionRow; @@ -6847,9 +6840,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. getMessagesController().removeSuggestion(0, type == SettingsSuggestionCell.TYPE_PHONE ? "VALIDATE_PHONE_NUMBER" : "VALIDATE_PASSWORD"); getNotificationCenter().addObserver(ProfileActivity.this, NotificationCenter.newSuggestionsAvailable); int oldRow = type == SettingsSuggestionCell.TYPE_PHONE ? phoneSuggestionRow : passwordSuggestionRow; - updateRowsIds(); - saveScrollPosition(); - listAdapter.notifyItemRangeRemoved(oldRow, 2); + updateListAnimated(false); } @Override @@ -8106,7 +8097,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } int oldIndex = oldPositionToItem.get(oldItemPosition, -1); int newIndex = newPositionToItem.get(newItemPosition, -1); - return oldIndex == newIndex && oldIndex >= 0 && newIndex >= 0; + return oldIndex == newIndex && oldIndex >= 0; } @Override