Search in sources :

Example 46 with SQLiteCursor

use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method hasInviteMeMessage.

public boolean hasInviteMeMessage(long chatId) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    boolean[] result = new boolean[1];
    storageQueue.postRunnable(() -> {
        try {
            long selfId = getUserConfig().getClientUserId();
            SQLiteCursor cursor = database.queryFinalized("SELECT data FROM messages_v2 WHERE uid = " + -chatId + " AND out = 0 ORDER BY mid DESC LIMIT 100");
            while (cursor.next()) {
                NativeByteBuffer data = cursor.byteBufferValue(0);
                if (data != null) {
                    TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
                    data.reuse();
                    if (message.action instanceof TLRPC.TL_messageActionChatAddUser && message.action.users.contains(selfId)) {
                        result[0] = true;
                        break;
                    }
                }
            }
            cursor.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (Exception e) {
        FileLog.e(e);
    }
    return result[0];
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) CountDownLatch(java.util.concurrent.CountDownLatch) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 47 with SQLiteCursor

use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method broadcastScheduledMessagesChange.

private void broadcastScheduledMessagesChange(Long did) {
    try {
        SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT COUNT(mid) FROM scheduled_messages_v2 WHERE uid = %d", did));
        int count;
        if (cursor.next()) {
            count = cursor.intValue(0);
        } else {
            count = 0;
        }
        cursor.dispose();
        AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.scheduledMessagesUpdated, did, count));
    } catch (Exception e) {
        FileLog.e(e);
    }
}
Also used : SQLiteCursor(org.telegram.SQLite.SQLiteCursor) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 48 with SQLiteCursor

use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method updateWidgets.

private void updateWidgets(ArrayList<Long> dids) {
    if (dids.isEmpty()) {
        return;
    }
    try {
        AppWidgetManager appWidgetManager = null;
        String ids = TextUtils.join(",", dids);
        SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT DISTINCT id FROM shortcut_widget WHERE did IN(%s,-1)", TextUtils.join(",", dids)));
        while (cursor.next()) {
            if (appWidgetManager == null) {
                appWidgetManager = AppWidgetManager.getInstance(ApplicationLoader.applicationContext);
            }
            appWidgetManager.notifyAppWidgetViewDataChanged(cursor.intValue(0), R.id.list_view);
        }
        cursor.dispose();
    } catch (Exception e) {
        FileLog.e(e);
    }
}
Also used : AppWidgetManager(android.appwidget.AppWidgetManager) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 49 with SQLiteCursor

use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method calcUnreadCounters.

private void calcUnreadCounters(boolean apply) {
    try {
        for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
                contacts[a][b] = nonContacts[a][b] = bots[a][b] = channels[a][b] = groups[a][b] = 0;
            }
        }
        dialogsWithMentions.clear();
        dialogsWithUnread.clear();
        ArrayList<TLRPC.User> users = new ArrayList<>();
        ArrayList<TLRPC.User> encUsers = new ArrayList<>();
        ArrayList<TLRPC.Chat> chats = new ArrayList<>();
        ArrayList<Long> usersToLoad = new ArrayList<>();
        ArrayList<Long> chatsToLoad = new ArrayList<>();
        ArrayList<Integer> encryptedToLoad = new ArrayList<>();
        LongSparseIntArray dialogsByFolders = new LongSparseIntArray();
        SQLiteCursor cursor = database.queryFinalized("SELECT did, folder_id, unread_count, unread_count_i FROM dialogs WHERE unread_count > 0 OR flags > 0 UNION ALL " + "SELECT did, folder_id, unread_count, unread_count_i FROM dialogs WHERE unread_count_i > 0");
        while (cursor.next()) {
            int folderId = cursor.intValue(1);
            long did = cursor.longValue(0);
            int unread = cursor.intValue(2);
            int mentions = cursor.intValue(3);
            if (unread > 0) {
                dialogsWithUnread.put(did, unread);
            }
            if (mentions > 0) {
                dialogsWithMentions.put(did, mentions);
            }
            /*if (BuildVars.DEBUG_VERSION) {
                    FileLog.d("unread chat " + did + " counters = " + unread + " and " + mentions);
                }*/
            dialogsByFolders.put(did, folderId);
            if (DialogObject.isEncryptedDialog(did)) {
                int encryptedChatId = DialogObject.getEncryptedChatId(did);
                if (!encryptedToLoad.contains(encryptedChatId)) {
                    encryptedToLoad.add(encryptedChatId);
                }
            } else if (DialogObject.isUserDialog(did)) {
                if (!usersToLoad.contains(did)) {
                    usersToLoad.add(did);
                }
            } else {
                if (!chatsToLoad.contains(-did)) {
                    chatsToLoad.add(-did);
                }
            }
        }
        cursor.dispose();
        LongSparseArray<TLRPC.User> usersDict = new LongSparseArray<>();
        LongSparseArray<TLRPC.Chat> chatsDict = new LongSparseArray<>();
        LongSparseArray<TLRPC.User> encUsersDict = new LongSparseArray<>();
        LongSparseIntArray encryptedChatsByUsersCount = new LongSparseIntArray();
        LongSparseArray<Boolean> mutedDialogs = new LongSparseArray<>();
        LongSparseArray<Boolean> archivedDialogs = new LongSparseArray<>();
        if (!usersToLoad.isEmpty()) {
            getUsersInternal(TextUtils.join(",", usersToLoad), users);
            for (int a = 0, N = users.size(); a < N; a++) {
                TLRPC.User user = users.get(a);
                boolean muted = getMessagesController().isDialogMuted(user.id);
                int idx1 = dialogsByFolders.get(user.id);
                int idx2 = muted ? 1 : 0;
                if (muted) {
                    mutedDialogs.put(user.id, true);
                }
                if (idx1 == 1) {
                    archivedDialogs.put(user.id, true);
                }
                if (user.bot) {
                    bots[idx1][idx2]++;
                } else if (user.self || user.contact) {
                    contacts[idx1][idx2]++;
                } else {
                    nonContacts[idx1][idx2]++;
                }
                usersDict.put(user.id, user);
            }
        }
        if (!encryptedToLoad.isEmpty()) {
            ArrayList<Long> encUsersToLoad = new ArrayList<>();
            ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<>();
            getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, encUsersToLoad);
            if (!encUsersToLoad.isEmpty()) {
                getUsersInternal(TextUtils.join(",", encUsersToLoad), encUsers);
                for (int a = 0, N = encUsers.size(); a < N; a++) {
                    TLRPC.User user = encUsers.get(a);
                    encUsersDict.put(user.id, user);
                }
                for (int a = 0, N = encryptedChats.size(); a < N; a++) {
                    TLRPC.EncryptedChat encryptedChat = encryptedChats.get(a);
                    TLRPC.User user = encUsersDict.get(encryptedChat.user_id);
                    if (user == null) {
                        continue;
                    }
                    long did = DialogObject.makeEncryptedDialogId(encryptedChat.id);
                    boolean muted = getMessagesController().isDialogMuted(did);
                    int idx1 = dialogsByFolders.get(did);
                    int idx2 = muted ? 1 : 0;
                    if (muted) {
                        mutedDialogs.put(user.id, true);
                    }
                    if (idx1 == 1) {
                        archivedDialogs.put(user.id, true);
                    }
                    if (user.self || user.contact) {
                        contacts[idx1][idx2]++;
                    } else {
                        nonContacts[idx1][idx2]++;
                    }
                    int count = encryptedChatsByUsersCount.get(user.id, 0);
                    encryptedChatsByUsersCount.put(user.id, count + 1);
                }
            }
        }
        if (!chatsToLoad.isEmpty()) {
            getChatsInternal(TextUtils.join(",", chatsToLoad), chats);
            for (int a = 0, N = chats.size(); a < N; a++) {
                TLRPC.Chat chat = chats.get(a);
                if (chat.migrated_to instanceof TLRPC.TL_inputChannel || ChatObject.isNotInChat(chat)) {
                    dialogsWithUnread.remove(-chat.id);
                    dialogsWithMentions.remove(-chat.id);
                    continue;
                }
                boolean muted = getMessagesController().isDialogMuted(-chat.id, chat);
                int idx1 = dialogsByFolders.get(-chat.id);
                int idx2 = muted && dialogsWithMentions.indexOfKey(-chat.id) < 0 ? 1 : 0;
                if (muted) {
                    mutedDialogs.put(-chat.id, true);
                }
                if (idx1 == 1) {
                    archivedDialogs.put(-chat.id, true);
                }
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    channels[idx1][idx2]++;
                } else {
                    groups[idx1][idx2]++;
                }
                chatsDict.put(chat.id, chat);
            }
        }
        /*if (BuildVars.DEBUG_VERSION) {
                for (int b = 0; b < 2; b++) {
                    FileLog.d("contacts = " + contacts[b][0] + ", " + contacts[b][1]);
                    FileLog.d("nonContacts = " + nonContacts[b][0] + ", " + nonContacts[b][1]);
                    FileLog.d("groups = " + groups[b][0] + ", " + groups[b][1]);
                    FileLog.d("channels = " + channels[b][0] + ", " + channels[b][1]);
                    FileLog.d("bots = " + bots[b][0] + ", " + bots[b][1]);
                }
            }*/
        for (int a = 0, N = dialogFilters.size(); a < N + 2; a++) {
            MessagesController.DialogFilter filter;
            int flags;
            if (a < N) {
                filter = dialogFilters.get(a);
                if (filter.pendingUnreadCount >= 0) {
                    continue;
                }
                flags = filter.flags;
            } else {
                filter = null;
                flags = MessagesController.DIALOG_FILTER_FLAG_ALL_CHATS;
                if (a == N) {
                    if (!getNotificationsController().showBadgeMuted) {
                        flags |= MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED;
                    }
                    flags |= MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED;
                } else {
                    flags |= MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED;
                }
            }
            int unreadCount = 0;
            if ((flags & MessagesController.DIALOG_FILTER_FLAG_CONTACTS) != 0) {
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED) == 0) {
                    unreadCount += contacts[0][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += contacts[0][1];
                    }
                }
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0) {
                    unreadCount += contacts[1][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += contacts[1][1];
                    }
                }
            }
            if ((flags & MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS) != 0) {
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED) == 0) {
                    unreadCount += nonContacts[0][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += nonContacts[0][1];
                    }
                }
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0) {
                    unreadCount += nonContacts[1][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += nonContacts[1][1];
                    }
                }
            }
            if ((flags & MessagesController.DIALOG_FILTER_FLAG_GROUPS) != 0) {
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED) == 0) {
                    unreadCount += groups[0][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += groups[0][1];
                    }
                }
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0) {
                    unreadCount += groups[1][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += groups[1][1];
                    }
                }
            }
            if ((flags & MessagesController.DIALOG_FILTER_FLAG_CHANNELS) != 0) {
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED) == 0) {
                    unreadCount += channels[0][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += channels[0][1];
                    }
                }
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0) {
                    unreadCount += channels[1][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += channels[1][1];
                    }
                }
            }
            if ((flags & MessagesController.DIALOG_FILTER_FLAG_BOTS) != 0) {
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_ONLY_ARCHIVED) == 0) {
                    unreadCount += bots[0][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += bots[0][1];
                    }
                }
                if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0) {
                    unreadCount += bots[1][0];
                    if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0) {
                        unreadCount += bots[1][1];
                    }
                }
            }
            if (filter != null) {
                for (int b = 0, N2 = filter.alwaysShow.size(); b < N2; b++) {
                    long did = filter.alwaysShow.get(b);
                    if (DialogObject.isUserDialog(did)) {
                        for (int i = 0; i < 2; i++) {
                            LongSparseArray<TLRPC.User> dict = i == 0 ? usersDict : encUsersDict;
                            TLRPC.User user = dict.get(did);
                            if (user != null) {
                                int count;
                                if (i == 0) {
                                    count = 1;
                                } else {
                                    count = encryptedChatsByUsersCount.get(did, 0);
                                    if (count == 0) {
                                        continue;
                                    }
                                }
                                int flag;
                                if (user.bot) {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_BOTS;
                                } else if (user.self || user.contact) {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
                                } else {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
                                }
                                if ((flags & flag) == 0) {
                                    unreadCount += count;
                                } else if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) != 0 && mutedDialogs.indexOfKey(user.id) >= 0) {
                                    unreadCount += count;
                                } else if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) != 0 && archivedDialogs.indexOfKey(user.id) >= 0) {
                                    unreadCount += count;
                                }
                            }
                        }
                    } else {
                        TLRPC.Chat chat = chatsDict.get(-did);
                        if (chat != null) {
                            int flag;
                            if (ChatObject.isChannel(chat) && !chat.megagroup) {
                                flag = MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
                            } else {
                                flag = MessagesController.DIALOG_FILTER_FLAG_GROUPS;
                            }
                            if ((flags & flag) == 0) {
                                unreadCount++;
                            } else if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) != 0 && mutedDialogs.indexOfKey(-chat.id) >= 0 && dialogsWithMentions.indexOfKey(-chat.id) < 0) {
                                unreadCount++;
                            } else if ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) != 0 && archivedDialogs.indexOfKey(-chat.id) >= 0) {
                                unreadCount++;
                            }
                        }
                    }
                }
                for (int b = 0, N2 = filter.neverShow.size(); b < N2; b++) {
                    long did = filter.neverShow.get(b);
                    if (DialogObject.isUserDialog(did)) {
                        for (int i = 0; i < 2; i++) {
                            LongSparseArray<TLRPC.User> dict = i == 0 ? usersDict : encUsersDict;
                            TLRPC.User user = dict.get(did);
                            if (user != null) {
                                int count;
                                if (i == 0) {
                                    count = 1;
                                } else {
                                    count = encryptedChatsByUsersCount.get(did, 0);
                                    if (count == 0) {
                                        continue;
                                    }
                                }
                                int flag;
                                if (user.bot) {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_BOTS;
                                } else if (user.self || user.contact) {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_CONTACTS;
                                } else {
                                    flag = MessagesController.DIALOG_FILTER_FLAG_NON_CONTACTS;
                                }
                                if ((flags & flag) != 0) {
                                    if (((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0 || archivedDialogs.indexOfKey(user.id) < 0) && ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0 || mutedDialogs.indexOfKey(user.id) < 0)) {
                                        unreadCount -= count;
                                    }
                                }
                            }
                        }
                    } else {
                        TLRPC.Chat chat = chatsDict.get(-did);
                        if (chat != null) {
                            int flag;
                            if (ChatObject.isChannel(chat) && !chat.megagroup) {
                                flag = MessagesController.DIALOG_FILTER_FLAG_CHANNELS;
                            } else {
                                flag = MessagesController.DIALOG_FILTER_FLAG_GROUPS;
                            }
                            if ((flags & flag) != 0) {
                                if (((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_ARCHIVED) == 0 || archivedDialogs.indexOfKey(-chat.id) < 0) && ((flags & MessagesController.DIALOG_FILTER_FLAG_EXCLUDE_MUTED) == 0 || mutedDialogs.indexOfKey(-chat.id) < 0 || dialogsWithMentions.indexOfKey(-chat.id) >= 0)) {
                                    unreadCount--;
                                }
                            }
                        }
                    }
                }
                filter.pendingUnreadCount = unreadCount;
                /*if (BuildVars.DEBUG_VERSION) {
                        FileLog.d("filter " + filter.name + " flags = " + filter.flags + " unread count = " + filter.pendingUnreadCount);
                    }*/
                if (apply) {
                    filter.unreadCount = unreadCount;
                }
            } else if (a == N) {
                pendingMainUnreadCount = unreadCount;
                if (apply) {
                    mainUnreadCount = unreadCount;
                }
            } else if (a == N + 1) {
                pendingArchiveUnreadCount = unreadCount;
                if (apply) {
                    archiveUnreadCount = unreadCount;
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) ArrayList(java.util.ArrayList) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 50 with SQLiteCursor

use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method loadPendingTasks.

private void loadPendingTasks() {
    storageQueue.postRunnable(() -> {
        try {
            SQLiteCursor cursor = database.queryFinalized("SELECT id, data FROM pending_tasks WHERE 1");
            while (cursor.next()) {
                long taskId = cursor.longValue(0);
                NativeByteBuffer data = cursor.byteBufferValue(1);
                if (data != null) {
                    int type = data.readInt32(false);
                    switch(type) {
                        case 0:
                            {
                                TLRPC.Chat chat = TLRPC.Chat.TLdeserialize(data, data.readInt32(false), false);
                                if (chat != null) {
                                    Utilities.stageQueue.postRunnable(() -> getMessagesController().loadUnknownChannel(chat, taskId));
                                }
                                break;
                            }
                        case 1:
                            {
                                long channelId = data.readInt32(false);
                                int newDialogType = data.readInt32(false);
                                Utilities.stageQueue.postRunnable(() -> getMessagesController().getChannelDifference(channelId, newDialogType, taskId, null));
                                break;
                            }
                        case 2:
                        case 5:
                        case 8:
                        case 10:
                        case 14:
                            {
                                TLRPC.Dialog dialog = new TLRPC.TL_dialog();
                                dialog.id = data.readInt64(false);
                                dialog.top_message = data.readInt32(false);
                                dialog.read_inbox_max_id = data.readInt32(false);
                                dialog.read_outbox_max_id = data.readInt32(false);
                                dialog.unread_count = data.readInt32(false);
                                dialog.last_message_date = data.readInt32(false);
                                dialog.pts = data.readInt32(false);
                                dialog.flags = data.readInt32(false);
                                if (type >= 5) {
                                    dialog.pinned = data.readBool(false);
                                    dialog.pinnedNum = data.readInt32(false);
                                }
                                if (type >= 8) {
                                    dialog.unread_mentions_count = data.readInt32(false);
                                }
                                if (type >= 10) {
                                    dialog.unread_mark = data.readBool(false);
                                }
                                if (type >= 14) {
                                    dialog.folder_id = data.readInt32(false);
                                }
                                TLRPC.InputPeer peer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().checkLastDialogMessage(dialog, peer, taskId));
                                break;
                            }
                        case 3:
                            {
                                long random_id = data.readInt64(false);
                                TLRPC.InputPeer peer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                TLRPC.TL_inputMediaGame game = (TLRPC.TL_inputMediaGame) TLRPC.InputMedia.TLdeserialize(data, data.readInt32(false), false);
                                getSendMessagesHelper().sendGame(peer, game, random_id, taskId);
                                break;
                            }
                        case 4:
                            {
                                long did = data.readInt64(false);
                                boolean pin = data.readBool(false);
                                TLRPC.InputPeer peer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().pinDialog(did, pin, peer, taskId));
                                break;
                            }
                        case 6:
                            {
                                long channelId = data.readInt32(false);
                                int newDialogType = data.readInt32(false);
                                TLRPC.InputChannel inputChannel = TLRPC.InputChannel.TLdeserialize(data, data.readInt32(false), false);
                                Utilities.stageQueue.postRunnable(() -> getMessagesController().getChannelDifference(channelId, newDialogType, taskId, inputChannel));
                                break;
                            }
                        case 25:
                            {
                                long channelId = data.readInt64(false);
                                int newDialogType = data.readInt32(false);
                                TLRPC.InputChannel inputChannel = TLRPC.InputChannel.TLdeserialize(data, data.readInt32(false), false);
                                Utilities.stageQueue.postRunnable(() -> getMessagesController().getChannelDifference(channelId, newDialogType, taskId, inputChannel));
                                break;
                            }
                        case 7:
                            {
                                long channelId = data.readInt32(false);
                                int constructor = data.readInt32(false);
                                TLObject request = TLRPC.TL_messages_deleteMessages.TLdeserialize(data, constructor, false);
                                if (request == null) {
                                    request = TLRPC.TL_channels_deleteMessages.TLdeserialize(data, constructor, false);
                                }
                                if (request == null) {
                                    removePendingTask(taskId);
                                } else {
                                    TLObject finalRequest = request;
                                    AndroidUtilities.runOnUIThread(() -> getMessagesController().deleteMessages(null, null, null, -channelId, true, false, false, taskId, finalRequest));
                                }
                                break;
                            }
                        case 24:
                            {
                                long dialogId = data.readInt64(false);
                                int constructor = data.readInt32(false);
                                TLObject request = TLRPC.TL_messages_deleteMessages.TLdeserialize(data, constructor, false);
                                if (request == null) {
                                    request = TLRPC.TL_channels_deleteMessages.TLdeserialize(data, constructor, false);
                                }
                                if (request == null) {
                                    removePendingTask(taskId);
                                } else {
                                    TLObject finalRequest = request;
                                    AndroidUtilities.runOnUIThread(() -> getMessagesController().deleteMessages(null, null, null, dialogId, true, false, false, taskId, finalRequest));
                                }
                                break;
                            }
                        case 9:
                            {
                                long did = data.readInt64(false);
                                TLRPC.InputPeer peer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().markDialogAsUnread(did, peer, taskId));
                                break;
                            }
                        case 11:
                            {
                                TLRPC.InputChannel inputChannel;
                                int mid = data.readInt32(false);
                                long channelId = data.readInt32(false);
                                int ttl = data.readInt32(false);
                                if (channelId != 0) {
                                    inputChannel = TLRPC.InputChannel.TLdeserialize(data, data.readInt32(false), false);
                                } else {
                                    inputChannel = null;
                                }
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().markMessageAsRead2(-channelId, mid, inputChannel, ttl, taskId));
                                break;
                            }
                        case 23:
                            {
                                TLRPC.InputChannel inputChannel;
                                long dialogId = data.readInt64(false);
                                int mid = data.readInt32(false);
                                int ttl = data.readInt32(false);
                                if (!DialogObject.isEncryptedDialog(dialogId) && DialogObject.isChatDialog(dialogId) && data.hasRemaining()) {
                                    inputChannel = TLRPC.InputChannel.TLdeserialize(data, data.readInt32(false), false);
                                } else {
                                    inputChannel = null;
                                }
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().markMessageAsRead2(dialogId, mid, inputChannel, ttl, taskId));
                                break;
                            }
                        case 12:
                        case 19:
                        case 20:
                            removePendingTask(taskId);
                            break;
                        case 21:
                            {
                                Theme.OverrideWallpaperInfo info = new Theme.OverrideWallpaperInfo();
                                long id = data.readInt64(false);
                                info.isBlurred = data.readBool(false);
                                info.isMotion = data.readBool(false);
                                info.color = data.readInt32(false);
                                info.gradientColor1 = data.readInt32(false);
                                info.rotation = data.readInt32(false);
                                info.intensity = (float) data.readDouble(false);
                                boolean install = data.readBool(false);
                                info.slug = data.readString(false);
                                info.originalFileName = data.readString(false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().saveWallpaperToServer(null, info, install, taskId));
                                break;
                            }
                        case 13:
                            {
                                long did = data.readInt64(false);
                                boolean first = data.readBool(false);
                                int onlyHistory = data.readInt32(false);
                                int maxIdDelete = data.readInt32(false);
                                boolean revoke = data.readBool(false);
                                TLRPC.InputPeer inputPeer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().deleteDialog(did, first ? 1 : 0, onlyHistory, maxIdDelete, revoke, inputPeer, taskId));
                                break;
                            }
                        case 15:
                            {
                                TLRPC.InputPeer inputPeer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                Utilities.stageQueue.postRunnable(() -> getMessagesController().loadUnknownDialog(inputPeer, taskId));
                                break;
                            }
                        case 16:
                            {
                                int folderId = data.readInt32(false);
                                int count = data.readInt32(false);
                                ArrayList<TLRPC.InputDialogPeer> peers = new ArrayList<>();
                                for (int a = 0; a < count; a++) {
                                    TLRPC.InputDialogPeer inputPeer = TLRPC.InputDialogPeer.TLdeserialize(data, data.readInt32(false), false);
                                    peers.add(inputPeer);
                                }
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().reorderPinnedDialogs(folderId, peers, taskId));
                                break;
                            }
                        case 17:
                            {
                                int folderId = data.readInt32(false);
                                int count = data.readInt32(false);
                                ArrayList<TLRPC.TL_inputFolderPeer> peers = new ArrayList<>();
                                for (int a = 0; a < count; a++) {
                                    TLRPC.TL_inputFolderPeer inputPeer = TLRPC.TL_inputFolderPeer.TLdeserialize(data, data.readInt32(false), false);
                                    peers.add(inputPeer);
                                }
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().addDialogToFolder(null, folderId, -1, peers, taskId));
                                break;
                            }
                        case 18:
                            {
                                long dialogId = data.readInt64(false);
                                data.readInt32(false);
                                int constructor = data.readInt32(false);
                                TLObject request = TLRPC.TL_messages_deleteScheduledMessages.TLdeserialize(data, constructor, false);
                                if (request == null) {
                                    removePendingTask(taskId);
                                } else {
                                    AndroidUtilities.runOnUIThread(() -> getMessagesController().deleteMessages(null, null, null, dialogId, true, true, false, taskId, request));
                                }
                                break;
                            }
                        case 22:
                            {
                                TLRPC.InputPeer inputPeer = TLRPC.InputPeer.TLdeserialize(data, data.readInt32(false), false);
                                AndroidUtilities.runOnUIThread(() -> getMessagesController().reloadMentionsCountForChannel(inputPeer, taskId));
                                break;
                            }
                        case 100:
                            {
                                final int chatId = data.readInt32(false);
                                final boolean revoke = data.readBool(false);
                                AndroidUtilities.runOnUIThread(() -> getSecretChatHelper().declineSecretChat(chatId, revoke, taskId));
                                break;
                            }
                    }
                    data.reuse();
                }
            }
            cursor.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) TLObject(org.telegram.tgnet.TLObject) Theme(org.telegram.ui.ActionBar.Theme)

Aggregations

SQLiteCursor (org.telegram.SQLite.SQLiteCursor)118 SQLiteException (org.telegram.SQLite.SQLiteException)105 TLRPC (org.telegram.tgnet.TLRPC)77 NativeByteBuffer (org.telegram.tgnet.NativeByteBuffer)66 ArrayList (java.util.ArrayList)58 SQLitePreparedStatement (org.telegram.SQLite.SQLitePreparedStatement)42 LongSparseArray (androidx.collection.LongSparseArray)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)19 Paint (android.graphics.Paint)18 SparseArray (android.util.SparseArray)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 SpannableStringBuilder (android.text.SpannableStringBuilder)10 LongSparseIntArray (org.telegram.messenger.support.LongSparseIntArray)10 File (java.io.File)8 HashMap (java.util.HashMap)7 Pair (android.util.Pair)6 TLObject (org.telegram.tgnet.TLObject)6 LinkedHashMap (java.util.LinkedHashMap)4 SharedPreferences (android.content.SharedPreferences)3 SpannedString (android.text.SpannedString)3