Search in sources :

Example 1 with NativeByteBuffer

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

the class MessagesController method loadUnknownChannel.

protected void loadUnknownChannel(final TLRPC.Chat channel, long taskId) {
    if (!(channel instanceof TLRPC.TL_channel) || gettingUnknownChannels.indexOfKey(channel.id) >= 0) {
        return;
    }
    if (channel.access_hash == 0) {
        if (taskId != 0) {
            getMessagesStorage().removePendingTask(taskId);
        }
        return;
    }
    TLRPC.TL_inputPeerChannel inputPeer = new TLRPC.TL_inputPeerChannel();
    inputPeer.channel_id = channel.id;
    inputPeer.access_hash = channel.access_hash;
    gettingUnknownChannels.put(channel.id, true);
    TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
    TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
    inputDialogPeer.peer = inputPeer;
    req.peers.add(inputDialogPeer);
    long newTaskId;
    if (taskId == 0) {
        NativeByteBuffer data = null;
        try {
            data = new NativeByteBuffer(4 + channel.getObjectSize());
            data.writeInt32(0);
            channel.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() && !res.chats.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_CHANNEL, false, false, false);
            }
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
        gettingUnknownChannels.delete(channel.id);
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 2 with NativeByteBuffer

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

the class MessagesController method markMessageAsRead2.

public void markMessageAsRead2(long dialogId, int mid, TLRPC.InputChannel inputChannel, int ttl, long taskId) {
    if (mid == 0 || ttl <= 0) {
        return;
    }
    if (DialogObject.isChatDialog(dialogId) && inputChannel == null) {
        inputChannel = getInputChannel(dialogId);
        if (inputChannel == null) {
            return;
        }
    }
    long newTaskId;
    if (taskId == 0) {
        NativeByteBuffer data = null;
        try {
            data = new NativeByteBuffer(20 + (inputChannel != null ? inputChannel.getObjectSize() : 0));
            data.writeInt32(23);
            data.writeInt64(dialogId);
            data.writeInt32(mid);
            data.writeInt32(ttl);
            if (inputChannel != null) {
                inputChannel.serializeToStream(data);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        newTaskId = getMessagesStorage().createPendingTask(data);
    } else {
        newTaskId = taskId;
    }
    int time = getConnectionsManager().getCurrentTime();
    getMessagesStorage().createTaskForMid(dialogId, mid, time, time, ttl, false);
    if (inputChannel != null) {
        TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
        req.channel = inputChannel;
        req.id.add(mid);
        getConnectionsManager().sendRequest(req, (response, error) -> {
            if (newTaskId != 0) {
                getMessagesStorage().removePendingTask(newTaskId);
            }
        });
    } else {
        TLRPC.TL_messages_readMessageContents req = new TLRPC.TL_messages_readMessageContents();
        req.id.add(mid);
        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 : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteException(org.telegram.SQLite.SQLiteException) TLRPC(org.telegram.tgnet.TLRPC)

Example 3 with NativeByteBuffer

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

the class MessagesController method addDialogToFolder.

public int addDialogToFolder(ArrayList<Long> dialogIds, int folderId, int pinnedNum, ArrayList<TLRPC.TL_inputFolderPeer> peers, long taskId) {
    TLRPC.TL_folders_editPeerFolders req = new TLRPC.TL_folders_editPeerFolders();
    boolean[] folderCreated = null;
    long newTaskId;
    if (taskId == 0) {
        boolean added = false;
        long selfUserId = getUserConfig().getClientUserId();
        int size = 0;
        for (int a = 0, N = dialogIds.size(); a < N; a++) {
            long dialogId = dialogIds.get(a);
            if (!DialogObject.isChatDialog(dialogId) && !DialogObject.isUserDialog(dialogId) && !DialogObject.isEncryptedDialog(dialogId)) {
                continue;
            }
            if (folderId == 1 && (dialogId == selfUserId || dialogId == 777000 || isPromoDialog(dialogId, false))) {
                continue;
            }
            TLRPC.Dialog dialog = dialogs_dict.get(dialogId);
            if (dialog == null) {
                continue;
            }
            added = true;
            dialog.folder_id = folderId;
            if (pinnedNum > 0) {
                dialog.pinned = true;
                dialog.pinnedNum = pinnedNum;
            } else {
                dialog.pinned = false;
                dialog.pinnedNum = 0;
            }
            if (folderCreated == null) {
                folderCreated = new boolean[1];
                ensureFolderDialogExists(folderId, folderCreated);
            }
            if (DialogObject.isEncryptedDialog(dialogId)) {
                getMessagesStorage().setDialogsFolderId(null, null, dialogId, folderId);
            } else {
                TLRPC.TL_inputFolderPeer folderPeer = new TLRPC.TL_inputFolderPeer();
                folderPeer.folder_id = folderId;
                folderPeer.peer = getInputPeer(dialogId);
                req.folder_peers.add(folderPeer);
                size += folderPeer.getObjectSize();
            }
        }
        if (!added) {
            return 0;
        }
        sortDialogs(null);
        getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
        if (size != 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(4 + 4 + 4 + size);
                data.writeInt32(17);
                data.writeInt32(folderId);
                data.writeInt32(req.folder_peers.size());
                for (int a = 0, N = req.folder_peers.size(); a < N; a++) {
                    req.folder_peers.get(a).serializeToStream(data);
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        } else {
            newTaskId = 0;
        }
    } else {
        req.folder_peers = peers;
        newTaskId = taskId;
    }
    if (!req.folder_peers.isEmpty()) {
        getConnectionsManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                processUpdates((TLRPC.Updates) response, false);
            }
            if (newTaskId != 0) {
                getMessagesStorage().removePendingTask(newTaskId);
            }
        });
        getMessagesStorage().setDialogsFolderId(null, req.folder_peers, 0, folderId);
    }
    return folderCreated == null ? 0 : (folderCreated[0] ? 2 : 1);
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 4 with NativeByteBuffer

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

the class MessagesController method saveWallpaperToServer.

public void saveWallpaperToServer(File path, Theme.OverrideWallpaperInfo info, boolean install, long taskId) {
    if (uploadingWallpaper != null) {
        File finalPath = new File(ApplicationLoader.getFilesDirFixed(), info.originalFileName);
        if (path != null && (path.getAbsolutePath().equals(uploadingWallpaper) || path.equals(finalPath))) {
            uploadingWallpaperInfo = info;
            return;
        }
        getFileLoader().cancelFileUpload(uploadingWallpaper, false);
        uploadingWallpaper = null;
        uploadingWallpaperInfo = null;
    }
    if (path != null) {
        uploadingWallpaper = path.getAbsolutePath();
        uploadingWallpaperInfo = info;
        getFileLoader().uploadFile(uploadingWallpaper, false, true, ConnectionsManager.FileTypePhoto);
    } else if (!info.isDefault() && !info.isColor() && info.wallpaperId > 0 && !info.isTheme()) {
        TLRPC.InputWallPaper inputWallPaper;
        if (info.wallpaperId > 0) {
            TLRPC.TL_inputWallPaper inputWallPaperId = new TLRPC.TL_inputWallPaper();
            inputWallPaperId.id = info.wallpaperId;
            inputWallPaperId.access_hash = info.accessHash;
            inputWallPaper = inputWallPaperId;
        } else {
            TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
            inputWallPaperSlug.slug = info.slug;
            inputWallPaper = inputWallPaperSlug;
        }
        TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings();
        settings.blur = info.isBlurred;
        settings.motion = info.isMotion;
        if (info.color != 0) {
            settings.background_color = info.color & 0x00ffffff;
            settings.flags |= 1;
            settings.intensity = (int) (info.intensity * 100);
            settings.flags |= 8;
        }
        if (info.gradientColor1 != 0) {
            settings.second_background_color = info.gradientColor1 & 0x00ffffff;
            settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
            settings.flags |= 16;
        }
        if (info.gradientColor2 != 0) {
            settings.third_background_color = info.gradientColor2 & 0x00ffffff;
            settings.flags |= 32;
        }
        if (info.gradientColor3 != 0) {
            settings.fourth_background_color = info.gradientColor3 & 0x00ffffff;
            settings.flags |= 64;
        }
        TLObject req;
        if (install) {
            TLRPC.TL_account_installWallPaper request = new TLRPC.TL_account_installWallPaper();
            request.wallpaper = inputWallPaper;
            request.settings = settings;
            req = request;
        } else {
            TLRPC.TL_account_saveWallPaper request = new TLRPC.TL_account_saveWallPaper();
            request.wallpaper = inputWallPaper;
            request.settings = settings;
            req = request;
        }
        long newTaskId;
        if (taskId != 0) {
            newTaskId = taskId;
        } else {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(1024);
                data.writeInt32(21);
                data.writeBool(info.isBlurred);
                data.writeBool(info.isMotion);
                data.writeInt32(info.color);
                data.writeInt32(info.gradientColor1);
                data.writeInt32(info.rotation);
                data.writeDouble(info.intensity);
                data.writeBool(install);
                data.writeString(info.slug);
                data.writeString(info.originalFileName);
                data.limit(data.position());
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        }
        getConnectionsManager().sendRequest(req, (response, error) -> getMessagesStorage().removePendingTask(newTaskId));
    }
    if ((info.isColor() || info.gradientColor2 != 0) && info.wallpaperId <= 0) {
        TLRPC.WallPaper wallPaper;
        if (info.isColor()) {
            wallPaper = new TLRPC.TL_wallPaperNoFile();
        } else {
            wallPaper = new TLRPC.TL_wallPaper();
            wallPaper.slug = info.slug;
            wallPaper.document = new TLRPC.TL_documentEmpty();
        }
        if (info.wallpaperId == 0) {
            wallPaper.id = Utilities.random.nextLong();
            if (wallPaper.id > 0) {
                wallPaper.id = -wallPaper.id;
            }
        } else {
            wallPaper.id = info.wallpaperId;
        }
        wallPaper.dark = MotionBackgroundDrawable.isDark(info.color, info.gradientColor1, info.gradientColor2, info.gradientColor3);
        wallPaper.flags |= 4;
        wallPaper.settings = new TLRPC.TL_wallPaperSettings();
        wallPaper.settings.blur = info.isBlurred;
        wallPaper.settings.motion = info.isMotion;
        if (info.color != 0) {
            wallPaper.settings.background_color = info.color;
            wallPaper.settings.flags |= 1;
            wallPaper.settings.intensity = (int) (info.intensity * 100);
            wallPaper.settings.flags |= 8;
        }
        if (info.gradientColor1 != 0) {
            wallPaper.settings.second_background_color = info.gradientColor1;
            wallPaper.settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
            wallPaper.settings.flags |= 16;
        }
        if (info.gradientColor2 != 0) {
            wallPaper.settings.third_background_color = info.gradientColor2;
            wallPaper.settings.flags |= 32;
        }
        if (info.gradientColor3 != 0) {
            wallPaper.settings.fourth_background_color = info.gradientColor3;
            wallPaper.settings.flags |= 64;
        }
        ArrayList<TLRPC.WallPaper> arrayList = new ArrayList<>();
        arrayList.add(wallPaper);
        getMessagesStorage().putWallpapers(arrayList, -3);
        getMessagesStorage().getWallpapers();
    }
}
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) ArrayList(java.util.ArrayList) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) TLObject(org.telegram.tgnet.TLObject) File(java.io.File)

Example 5 with NativeByteBuffer

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

the class MessagesController method pinDialog.

public boolean pinDialog(long dialogId, boolean pin, TLRPC.InputPeer peer, long taskId) {
    TLRPC.Dialog dialog = dialogs_dict.get(dialogId);
    if (dialog == null || dialog.pinned == pin) {
        return dialog != null;
    }
    int folderId = dialog.folder_id;
    ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
    dialog.pinned = pin;
    if (pin) {
        int maxPinnedNum = 0;
        for (int a = 0; a < dialogs.size(); a++) {
            TLRPC.Dialog d = dialogs.get(a);
            if (d instanceof TLRPC.TL_dialogFolder) {
                continue;
            }
            if (!d.pinned) {
                if (d.id != promoDialogId) {
                    break;
                }
                continue;
            }
            maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum);
        }
        dialog.pinnedNum = maxPinnedNum + 1;
    } else {
        dialog.pinnedNum = 0;
    }
    sortDialogs(null);
    if (!pin && !dialogs.isEmpty() && dialogs.get(dialogs.size() - 1) == dialog && !dialogsEndReached.get(folderId)) {
        dialogs.remove(dialogs.size() - 1);
    }
    getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
    if (!DialogObject.isEncryptedDialog(dialogId)) {
        if (taskId != -1) {
            TLRPC.TL_messages_toggleDialogPin req = new TLRPC.TL_messages_toggleDialogPin();
            req.pinned = pin;
            if (peer == null) {
                peer = getInputPeer(dialogId);
            }
            if (peer instanceof TLRPC.TL_inputPeerEmpty) {
                return false;
            }
            TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
            inputDialogPeer.peer = peer;
            req.peer = inputDialogPeer;
            long newTaskId;
            if (taskId == 0) {
                NativeByteBuffer data = null;
                try {
                    data = new NativeByteBuffer(16 + peer.getObjectSize());
                    data.writeInt32(4);
                    data.writeInt64(dialogId);
                    data.writeBool(pin);
                    peer.serializeToStream(data);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                newTaskId = getMessagesStorage().createPendingTask(data);
            } else {
                newTaskId = taskId;
            }
            getConnectionsManager().sendRequest(req, (response, error) -> {
                if (newTaskId != 0) {
                    getMessagesStorage().removePendingTask(newTaskId);
                }
            });
        }
    }
    getMessagesStorage().setDialogPinned(dialogId, dialog.pinnedNum);
    return true;
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) AlertDialog(org.telegram.ui.ActionBar.AlertDialog)

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