Search in sources :

Example 6 with NativeByteBuffer

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

the class MessagesController method loadUnknownDialog.

protected void loadUnknownDialog(final TLRPC.InputPeer peer, long taskId) {
    if (peer == null) {
        return;
    }
    long dialogId = DialogObject.getPeerDialogId(peer);
    if (gettingUnknownDialogs.indexOfKey(dialogId) >= 0) {
        return;
    }
    gettingUnknownDialogs.put(dialogId, true);
    if (BuildVars.LOGS_ENABLED) {
        FileLog.d("load unknown dialog " + dialogId);
    }
    TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
    TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
    inputDialogPeer.peer = peer;
    req.peers.add(inputDialogPeer);
    long newTaskId;
    if (taskId == 0) {
        NativeByteBuffer data = null;
        try {
            data = new NativeByteBuffer(4 + peer.getObjectSize());
            data.writeInt32(15);
            peer.serializeToStream(data);
        } catch (Exception e) {
            FileLog.e(e);
        }
        newTaskId = getMessagesStorage().createPendingTask(data);
    } else {
        newTaskId = taskId;
    }
    getConnectionsManager().sendRequest(req, (response, error) -> {
        if (response != null) {
            TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
            if (!res.dialogs.isEmpty()) {
                TLRPC.TL_dialog dialog = (TLRPC.TL_dialog) res.dialogs.get(0);
                TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
                dialogs.dialogs.addAll(res.dialogs);
                dialogs.messages.addAll(res.messages);
                dialogs.users.addAll(res.users);
                dialogs.chats.addAll(res.chats);
                processLoadedDialogs(dialogs, null, dialog.folder_id, 0, 1, DIALOGS_LOAD_TYPE_UNKNOWN, false, false, false);
            }
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        gettingUnknownDialogs.delete(dialogId);
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 7 with NativeByteBuffer

use of org.telegram.tgnet.NativeByteBuffer 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 8 with NativeByteBuffer

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

the class MediaDataController method updateBotInfo.

public void updateBotInfo(long dialogId, TLRPC.TL_updateBotCommands update) {
    TLRPC.BotInfo botInfo = botInfos.get(update.bot_id + "_" + dialogId);
    if (botInfo != null) {
        botInfo.commands = update.commands;
        getNotificationCenter().postNotificationName(NotificationCenter.botInfoDidLoad, botInfo, 0);
    }
    getMessagesStorage().getStorageQueue().postRunnable(() -> {
        try {
            TLRPC.BotInfo info = loadBotInfoInternal(update.bot_id, dialogId);
            if (info != null) {
                info.commands = update.commands;
            }
            SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO bot_info_v2 VALUES(?, ?, ?)");
            state.requery();
            NativeByteBuffer data = new NativeByteBuffer(info.getObjectSize());
            info.serializeToStream(data);
            state.bindLong(1, info.user_id);
            state.bindLong(2, dialogId);
            state.bindByteBuffer(3, data);
            state.step();
            data.reuse();
            state.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement)

Example 9 with NativeByteBuffer

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

the class MediaDataController method putDiceStickersToCache.

private void putDiceStickersToCache(String emoji, TLRPC.TL_messages_stickerSet stickers, int date) {
    if (TextUtils.isEmpty(emoji)) {
        return;
    }
    getMessagesStorage().getStorageQueue().postRunnable(() -> {
        try {
            if (stickers != null) {
                SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO stickers_dice VALUES(?, ?, ?)");
                state.requery();
                NativeByteBuffer data = new NativeByteBuffer(stickers.getObjectSize());
                stickers.serializeToStream(data);
                state.bindString(1, emoji);
                state.bindByteBuffer(2, data);
                state.bindInteger(3, date);
                state.step();
                data.reuse();
                state.dispose();
            } else {
                SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("UPDATE stickers_dice SET date = ?");
                state.requery();
                state.bindInteger(1, date);
                state.step();
                state.dispose();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteException(org.telegram.SQLite.SQLiteException) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement)

Example 10 with NativeByteBuffer

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

the class MediaDataController method putBotInfo.

public void putBotInfo(long dialogId, TLRPC.BotInfo botInfo) {
    if (botInfo == null) {
        return;
    }
    botInfos.put(botInfo.user_id + "_" + dialogId, botInfo);
    getMessagesStorage().getStorageQueue().postRunnable(() -> {
        try {
            SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO bot_info_v2 VALUES(?, ?, ?)");
            state.requery();
            NativeByteBuffer data = new NativeByteBuffer(botInfo.getObjectSize());
            botInfo.serializeToStream(data);
            state.bindLong(1, botInfo.user_id);
            state.bindLong(2, dialogId);
            state.bindByteBuffer(3, data);
            state.step();
            data.reuse();
            state.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteException(org.telegram.SQLite.SQLiteException) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement)

Aggregations

NativeByteBuffer (org.telegram.tgnet.NativeByteBuffer)108 TLRPC (org.telegram.tgnet.TLRPC)92 SQLiteException (org.telegram.SQLite.SQLiteException)91 SQLiteCursor (org.telegram.SQLite.SQLiteCursor)68 SQLitePreparedStatement (org.telegram.SQLite.SQLitePreparedStatement)54 ArrayList (java.util.ArrayList)47 Paint (android.graphics.Paint)19 LongSparseArray (androidx.collection.LongSparseArray)18 SparseArray (android.util.SparseArray)12 File (java.io.File)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 TLObject (org.telegram.tgnet.TLObject)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 SpannableStringBuilder (android.text.SpannableStringBuilder)7 SharedPreferences (android.content.SharedPreferences)6 Pair (android.util.Pair)6 HashMap (java.util.HashMap)6 SparseIntArray (android.util.SparseIntArray)5 SQLiteDatabase (org.telegram.SQLite.SQLiteDatabase)5 LongSparseIntArray (org.telegram.messenger.support.LongSparseIntArray)5