Search in sources :

Example 21 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesController method checkCanOpenChat.

public boolean checkCanOpenChat(Bundle bundle, BaseFragment fragment, MessageObject originalMessage) {
    if (bundle == null || fragment == null) {
        return true;
    }
    TLRPC.User user = null;
    TLRPC.Chat chat = null;
    long userId = bundle.getLong("user_id", 0);
    long chatId = bundle.getLong("chat_id", 0);
    int messageId = bundle.getInt("message_id", 0);
    if (userId != 0) {
        user = getUser(userId);
    } else if (chatId != 0) {
        chat = getChat(chatId);
    }
    if (user == null && chat == null) {
        return true;
    }
    String reason;
    if (chat != null) {
        reason = getRestrictionReason(chat.restriction_reason);
    } else {
        reason = getRestrictionReason(user.restriction_reason);
    }
    if (reason != null) {
        showCantOpenAlert(fragment, reason);
        return false;
    }
    if (messageId != 0 && originalMessage != null && chat != null && chat.access_hash == 0) {
        long did = originalMessage.getDialogId();
        if (!DialogObject.isEncryptedDialog(did)) {
            AlertDialog progressDialog = new AlertDialog(fragment.getParentActivity(), 3);
            TLObject req;
            if (did < 0) {
                chat = getChat(-did);
            }
            if (did > 0 || !ChatObject.isChannel(chat)) {
                TLRPC.TL_messages_getMessages request = new TLRPC.TL_messages_getMessages();
                request.id.add(originalMessage.getId());
                req = request;
            } else {
                chat = getChat(-did);
                TLRPC.TL_channels_getMessages request = new TLRPC.TL_channels_getMessages();
                request.channel = getInputChannel(chat);
                request.id.add(originalMessage.getId());
                req = request;
            }
            int reqId = getConnectionsManager().sendRequest(req, (response, error) -> {
                if (response != null) {
                    AndroidUtilities.runOnUIThread(() -> {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                        putUsers(res.users, false);
                        putChats(res.chats, false);
                        getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
                        fragment.presentFragment(new ChatActivity(bundle), true);
                    });
                }
            });
            progressDialog.setOnCancelListener(dialog -> {
                getConnectionsManager().cancelRequest(reqId, true);
                fragment.setVisibleDialog(null);
            });
            fragment.setVisibleDialog(progressDialog);
            progressDialog.show();
            return false;
        }
    }
    return true;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) TLObject(org.telegram.tgnet.TLObject)

Example 22 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesController method deleteMessages.

public void deleteMessages(ArrayList<Integer> messages, ArrayList<Long> randoms, TLRPC.EncryptedChat encryptedChat, long dialogId, boolean forAll, boolean scheduled, boolean cacheOnly, long taskId, TLObject taskRequest) {
    if ((messages == null || messages.isEmpty()) && taskId == 0) {
        return;
    }
    ArrayList<Integer> toSend = null;
    long channelId;
    if (taskId == 0) {
        if (dialogId != 0 && DialogObject.isChatDialog(dialogId)) {
            TLRPC.Chat chat = getChat(-dialogId);
            channelId = ChatObject.isChannel(chat) ? chat.id : 0;
        } else {
            channelId = 0;
        }
        if (!cacheOnly) {
            toSend = new ArrayList<>();
            for (int a = 0, N = messages.size(); a < N; a++) {
                Integer mid = messages.get(a);
                if (mid > 0) {
                    toSend.add(mid);
                }
            }
        }
        if (scheduled) {
            getMessagesStorage().markMessagesAsDeleted(dialogId, messages, true, false, true);
        } else {
            if (channelId == 0) {
                for (int a = 0; a < messages.size(); a++) {
                    Integer id = messages.get(a);
                    MessageObject obj = dialogMessagesByIds.get(id);
                    if (obj != null) {
                        obj.deleted = true;
                    }
                }
            } else {
                markDialogMessageAsDeleted(dialogId, messages);
            }
            getMessagesStorage().markMessagesAsDeleted(dialogId, messages, true, forAll, false);
            getMessagesStorage().updateDialogsWithDeletedMessages(dialogId, channelId, messages, null, true);
        }
        getNotificationCenter().postNotificationName(NotificationCenter.messagesDeleted, messages, channelId, scheduled);
    } else {
        if (taskRequest instanceof TLRPC.TL_channels_deleteMessages) {
            channelId = ((TLRPC.TL_channels_deleteMessages) taskRequest).channel.channel_id;
        } else {
            channelId = 0;
        }
    }
    if (cacheOnly) {
        return;
    }
    long newTaskId;
    if (scheduled) {
        TLRPC.TL_messages_deleteScheduledMessages req;
        if (taskRequest instanceof TLRPC.TL_messages_deleteScheduledMessages) {
            req = (TLRPC.TL_messages_deleteScheduledMessages) taskRequest;
            newTaskId = taskId;
        } else {
            req = new TLRPC.TL_messages_deleteScheduledMessages();
            req.id = toSend;
            req.peer = getInputPeer(dialogId);
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(12 + req.getObjectSize());
                data.writeInt32(24);
                data.writeInt64(dialogId);
                req.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        }
        getConnectionsManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                TLRPC.Updates updates = (TLRPC.Updates) response;
                processUpdates(updates, false);
            }
            if (newTaskId != 0) {
                getMessagesStorage().removePendingTask(newTaskId);
            }
        });
    } else if (channelId != 0) {
        TLRPC.TL_channels_deleteMessages req;
        if (taskRequest != null) {
            req = (TLRPC.TL_channels_deleteMessages) taskRequest;
            newTaskId = taskId;
        } else {
            req = new TLRPC.TL_channels_deleteMessages();
            req.id = toSend;
            req.channel = getInputChannel(channelId);
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(12 + req.getObjectSize());
                data.writeInt32(24);
                data.writeInt64(dialogId);
                req.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        }
        getConnectionsManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
                processNewChannelDifferenceParams(res.pts, res.pts_count, channelId);
            }
            if (newTaskId != 0) {
                getMessagesStorage().removePendingTask(newTaskId);
            }
        });
    } else {
        if (randoms != null && encryptedChat != null && !randoms.isEmpty()) {
            getSecretChatHelper().sendMessagesDeleteMessage(encryptedChat, randoms, null);
        }
        TLRPC.TL_messages_deleteMessages req;
        if (taskRequest instanceof TLRPC.TL_messages_deleteMessages) {
            req = (TLRPC.TL_messages_deleteMessages) taskRequest;
            newTaskId = taskId;
        } else {
            req = new TLRPC.TL_messages_deleteMessages();
            req.id = toSend;
            req.revoke = forAll;
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(12 + req.getObjectSize());
                data.writeInt32(24);
                data.writeInt64(dialogId);
                req.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        }
        getConnectionsManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
                processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
            }
            if (newTaskId != 0) {
                getMessagesStorage().removePendingTask(newTaskId);
            }
        });
    }
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) ProfileActivity(org.telegram.ui.ProfileActivity) Locale(java.util.Locale) Looper(android.os.Looper) Map(java.util.Map) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) LongSparseLongArray(org.telegram.messenger.support.LongSparseLongArray) DialogsActivity(org.telegram.ui.DialogsActivity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) Consumer(androidx.core.util.Consumer) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) LaunchActivity(org.telegram.ui.LaunchActivity) Location(android.location.Location) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) VoIPService(org.telegram.messenger.voip.VoIPService) SparseIntArray(android.util.SparseIntArray) Theme(org.telegram.ui.ActionBar.Theme) RequestDelegate(org.telegram.tgnet.RequestDelegate) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) SystemClock(android.os.SystemClock) HashMap(java.util.HashMap) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TLRPC(org.telegram.tgnet.TLRPC) TelephonyManager(android.telephony.TelephonyManager) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) EditWidgetActivity(org.telegram.ui.EditWidgetActivity) Build(android.os.Build) SQLiteException(org.telegram.SQLite.SQLiteException) SerializedData(org.telegram.tgnet.SerializedData) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) LongSparseArray(androidx.collection.LongSparseArray) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) File(java.io.File) AppWidgetManager(android.appwidget.AppWidgetManager) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) Base64(android.util.Base64) Comparator(java.util.Comparator) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 23 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaDataController method loadRecents.

public void loadRecents(int type, boolean gif, boolean cache, boolean force) {
    if (gif) {
        if (loadingRecentGifs) {
            return;
        }
        loadingRecentGifs = true;
        if (recentGifsLoaded) {
            cache = false;
        }
    } else {
        if (loadingRecentStickers[type]) {
            return;
        }
        loadingRecentStickers[type] = true;
        if (recentStickersLoaded[type]) {
            cache = false;
        }
    }
    if (cache) {
        getMessagesStorage().getStorageQueue().postRunnable(() -> {
            try {
                int cacheType;
                if (gif) {
                    cacheType = 2;
                } else if (type == TYPE_IMAGE) {
                    cacheType = 3;
                } else if (type == TYPE_MASK) {
                    cacheType = 4;
                } else if (type == TYPE_GREETINGS) {
                    cacheType = 6;
                } else {
                    cacheType = 5;
                }
                SQLiteCursor cursor = getMessagesStorage().getDatabase().queryFinalized("SELECT document FROM web_recent_v3 WHERE type = " + cacheType + " ORDER BY date DESC");
                ArrayList<TLRPC.Document> arrayList = new ArrayList<>();
                while (cursor.next()) {
                    if (!cursor.isNull(0)) {
                        NativeByteBuffer data = cursor.byteBufferValue(0);
                        if (data != null) {
                            TLRPC.Document document = TLRPC.Document.TLdeserialize(data, data.readInt32(false), false);
                            if (document != null) {
                                arrayList.add(document);
                            }
                            data.reuse();
                        }
                    }
                }
                cursor.dispose();
                AndroidUtilities.runOnUIThread(() -> {
                    if (gif) {
                        recentGifs = arrayList;
                        loadingRecentGifs = false;
                        recentGifsLoaded = true;
                    } else {
                        recentStickers[type] = arrayList;
                        loadingRecentStickers[type] = false;
                        recentStickersLoaded[type] = true;
                    }
                    if (type == TYPE_GREETINGS) {
                        preloadNextGreetingsSticker();
                    }
                    getNotificationCenter().postNotificationName(NotificationCenter.recentDocumentsDidLoad, gif, type);
                    loadRecents(type, gif, false, false);
                });
            } catch (Throwable e) {
                FileLog.e(e);
            }
        });
    } else {
        SharedPreferences preferences = MessagesController.getEmojiSettings(currentAccount);
        if (!force) {
            long lastLoadTime;
            if (gif) {
                lastLoadTime = preferences.getLong("lastGifLoadTime", 0);
            } else if (type == TYPE_IMAGE) {
                lastLoadTime = preferences.getLong("lastStickersLoadTime", 0);
            } else if (type == TYPE_MASK) {
                lastLoadTime = preferences.getLong("lastStickersLoadTimeMask", 0);
            } else if (type == TYPE_GREETINGS) {
                lastLoadTime = preferences.getLong("lastStickersLoadTimeGreet", 0);
            } else {
                lastLoadTime = preferences.getLong("lastStickersLoadTimeFavs", 0);
            }
            if (Math.abs(System.currentTimeMillis() - lastLoadTime) < 60 * 60 * 1000) {
                if (gif) {
                    loadingRecentGifs = false;
                } else {
                    loadingRecentStickers[type] = false;
                }
                return;
            }
        }
        if (gif) {
            TLRPC.TL_messages_getSavedGifs req = new TLRPC.TL_messages_getSavedGifs();
            req.hash = calcDocumentsHash(recentGifs);
            getConnectionsManager().sendRequest(req, (response, error) -> {
                ArrayList<TLRPC.Document> arrayList = null;
                if (response instanceof TLRPC.TL_messages_savedGifs) {
                    TLRPC.TL_messages_savedGifs res = (TLRPC.TL_messages_savedGifs) response;
                    arrayList = res.gifs;
                }
                processLoadedRecentDocuments(type, arrayList, true, 0, true);
            });
        } else {
            TLObject request;
            if (type == TYPE_FAVE) {
                TLRPC.TL_messages_getFavedStickers req = new TLRPC.TL_messages_getFavedStickers();
                req.hash = calcDocumentsHash(recentStickers[type]);
                request = req;
            } else if (type == TYPE_GREETINGS) {
                TLRPC.TL_messages_getStickers req = new TLRPC.TL_messages_getStickers();
                req.emoticon = "\uD83D\uDC4B" + Emoji.fixEmoji("⭐");
                req.hash = calcDocumentsHash(recentStickers[type]);
                request = req;
            } else {
                TLRPC.TL_messages_getRecentStickers req = new TLRPC.TL_messages_getRecentStickers();
                req.hash = calcDocumentsHash(recentStickers[type]);
                req.attached = type == TYPE_MASK;
                request = req;
            }
            getConnectionsManager().sendRequest(request, (response, error) -> {
                ArrayList<TLRPC.Document> arrayList = null;
                if (type == TYPE_GREETINGS) {
                    if (response instanceof TLRPC.TL_messages_stickers) {
                        TLRPC.TL_messages_stickers res = (TLRPC.TL_messages_stickers) response;
                        arrayList = res.stickers;
                    }
                } else if (type == TYPE_FAVE) {
                    if (response instanceof TLRPC.TL_messages_favedStickers) {
                        TLRPC.TL_messages_favedStickers res = (TLRPC.TL_messages_favedStickers) response;
                        arrayList = res.stickers;
                    }
                } else {
                    if (response instanceof TLRPC.TL_messages_recentStickers) {
                        TLRPC.TL_messages_recentStickers res = (TLRPC.TL_messages_recentStickers) response;
                        arrayList = res.stickers;
                    }
                }
                processLoadedRecentDocuments(type, arrayList, false, 0, true);
            });
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SharedPreferences(android.content.SharedPreferences) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Paint(android.graphics.Paint) TLObject(org.telegram.tgnet.TLObject)

Example 24 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessageObject method replaceWithLink.

public static CharSequence replaceWithLink(CharSequence source, String param, TLObject object) {
    int start = TextUtils.indexOf(source, param);
    if (start >= 0) {
        String name;
        String id;
        TLObject spanObject = null;
        if (object instanceof TLRPC.User) {
            name = UserObject.getUserName((TLRPC.User) object);
            id = "" + ((TLRPC.User) object).id;
        } else if (object instanceof TLRPC.Chat) {
            name = ((TLRPC.Chat) object).title;
            id = "" + -((TLRPC.Chat) object).id;
        } else if (object instanceof TLRPC.TL_game) {
            TLRPC.TL_game game = (TLRPC.TL_game) object;
            name = game.title;
            id = "game";
        } else if (object instanceof TLRPC.TL_chatInviteExported) {
            TLRPC.TL_chatInviteExported invite = (TLRPC.TL_chatInviteExported) object;
            name = invite.link;
            id = "invite";
            spanObject = invite;
        } else {
            name = "";
            id = "0";
        }
        name = name.replace('\n', ' ');
        SpannableStringBuilder builder = new SpannableStringBuilder(TextUtils.replace(source, new String[] { param }, new String[] { name }));
        URLSpanNoUnderlineBold span = new URLSpanNoUnderlineBold("" + id);
        span.setObject(spanObject);
        builder.setSpan(span, start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }
    return source;
}
Also used : SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) URLSpanNoUnderlineBold(org.telegram.ui.Components.URLSpanNoUnderlineBold) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 25 with TLObject

use of org.telegram.tgnet.TLObject 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

TLObject (org.telegram.tgnet.TLObject)85 TLRPC (org.telegram.tgnet.TLRPC)79 Paint (android.graphics.Paint)36 ArrayList (java.util.ArrayList)36 TextPaint (android.text.TextPaint)25 SuppressLint (android.annotation.SuppressLint)22 ConnectionsManager (org.telegram.tgnet.ConnectionsManager)22 File (java.io.File)21 HashMap (java.util.HashMap)20 Context (android.content.Context)19 Build (android.os.Build)19 TextUtils (android.text.TextUtils)19 MessageObject (org.telegram.messenger.MessageObject)19 Theme (org.telegram.ui.ActionBar.Theme)19 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)18 LongSparseArray (androidx.collection.LongSparseArray)17 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)17 Bundle (android.os.Bundle)16 SpannableStringBuilder (android.text.SpannableStringBuilder)16 ChatObject (org.telegram.messenger.ChatObject)16