Search in sources :

Example 21 with NativeByteBuffer

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

the class MessagesStorage method loadChannelAdmins.

public void loadChannelAdmins(long chatId) {
    storageQueue.postRunnable(() -> {
        try {
            SQLiteCursor cursor = database.queryFinalized("SELECT uid, data FROM channel_admins_v3 WHERE did = " + chatId);
            LongSparseArray<TLRPC.ChannelParticipant> ids = new LongSparseArray<>();
            while (cursor.next()) {
                NativeByteBuffer data = cursor.byteBufferValue(1);
                if (data != null) {
                    TLRPC.ChannelParticipant participant = TLRPC.ChannelParticipant.TLdeserialize(data, data.readInt32(false), false);
                    data.reuse();
                    if (participant != null) {
                        ids.put(cursor.longValue(0), participant);
                    }
                }
            }
            cursor.dispose();
            getMessagesController().processLoadedChannelAdmins(ids, chatId, true);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 22 with NativeByteBuffer

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

the class MessagesStorage method putDialogPhotos.

public void putDialogPhotos(long did, TLRPC.photos_Photos photos, ArrayList<TLRPC.Message> messages) {
    if (photos == null) {
        return;
    }
    storageQueue.postRunnable(() -> {
        try {
            database.executeFast("DELETE FROM user_photos WHERE uid = " + did).stepThis().dispose();
            SQLitePreparedStatement state = database.executeFast("REPLACE INTO user_photos VALUES(?, ?, ?)");
            for (int a = 0, N = photos.photos.size(); a < N; a++) {
                TLRPC.Photo photo = photos.photos.get(a);
                if (photo instanceof TLRPC.TL_photoEmpty) {
                    continue;
                }
                state.requery();
                int size = photo.getObjectSize();
                if (messages != null) {
                    size += messages.get(a).getObjectSize();
                }
                NativeByteBuffer data = new NativeByteBuffer(size);
                photo.serializeToStream(data);
                if (messages != null) {
                    messages.get(a).serializeToStream(data);
                }
                state.bindLong(1, did);
                state.bindLong(2, photo.id);
                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 23 with NativeByteBuffer

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

the class MediaDataController method processLoadedRecentDocuments.

protected void processLoadedRecentDocuments(int type, ArrayList<TLRPC.Document> documents, boolean gif, int date, boolean replace) {
    if (documents != null) {
        getMessagesStorage().getStorageQueue().postRunnable(() -> {
            try {
                SQLiteDatabase database = getMessagesStorage().getDatabase();
                int maxCount;
                if (gif) {
                    maxCount = getMessagesController().maxRecentGifsCount;
                } else {
                    if (type == TYPE_GREETINGS) {
                        maxCount = 200;
                    } else if (type == TYPE_FAVE) {
                        maxCount = getMessagesController().maxFaveStickersCount;
                    } else {
                        maxCount = getMessagesController().maxRecentStickersCount;
                    }
                }
                database.beginTransaction();
                SQLitePreparedStatement state = database.executeFast("REPLACE INTO web_recent_v3 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                int count = documents.size();
                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;
                }
                if (replace) {
                    database.executeFast("DELETE FROM web_recent_v3 WHERE type = " + cacheType).stepThis().dispose();
                }
                for (int a = 0; a < count; a++) {
                    if (a == maxCount) {
                        break;
                    }
                    TLRPC.Document document = documents.get(a);
                    state.requery();
                    state.bindString(1, "" + document.id);
                    state.bindInteger(2, cacheType);
                    state.bindString(3, "");
                    state.bindString(4, "");
                    state.bindString(5, "");
                    state.bindInteger(6, 0);
                    state.bindInteger(7, 0);
                    state.bindInteger(8, 0);
                    state.bindInteger(9, date != 0 ? date : count - a);
                    NativeByteBuffer data = new NativeByteBuffer(document.getObjectSize());
                    document.serializeToStream(data);
                    state.bindByteBuffer(10, data);
                    state.step();
                    data.reuse();
                }
                state.dispose();
                database.commitTransaction();
                if (documents.size() >= maxCount) {
                    database.beginTransaction();
                    for (int a = maxCount; a < documents.size(); a++) {
                        database.executeFast("DELETE FROM web_recent_v3 WHERE id = '" + documents.get(a).id + "' AND type = " + cacheType).stepThis().dispose();
                    }
                    database.commitTransaction();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        });
    }
    if (date == 0) {
        AndroidUtilities.runOnUIThread(() -> {
            SharedPreferences.Editor editor = MessagesController.getEmojiSettings(currentAccount).edit();
            if (gif) {
                loadingRecentGifs = false;
                recentGifsLoaded = true;
                editor.putLong("lastGifLoadTime", System.currentTimeMillis()).commit();
            } else {
                loadingRecentStickers[type] = false;
                recentStickersLoaded[type] = true;
                if (type == TYPE_IMAGE) {
                    editor.putLong("lastStickersLoadTime", System.currentTimeMillis()).commit();
                } else if (type == TYPE_MASK) {
                    editor.putLong("lastStickersLoadTimeMask", System.currentTimeMillis()).commit();
                } else if (type == TYPE_GREETINGS) {
                    editor.putLong("lastStickersLoadTimeGreet", System.currentTimeMillis()).commit();
                } else {
                    editor.putLong("lastStickersLoadTimeFavs", System.currentTimeMillis()).commit();
                }
            }
            if (documents != null) {
                if (gif) {
                    recentGifs = documents;
                } else {
                    recentStickers[type] = documents;
                }
                if (type == TYPE_GREETINGS) {
                    preloadNextGreetingsSticker();
                }
                getNotificationCenter().postNotificationName(NotificationCenter.recentDocumentsDidLoad, gif, type);
            } else {
            }
        });
    }
}
Also used : SQLiteDatabase(org.telegram.SQLite.SQLiteDatabase) SharedPreferences(android.content.SharedPreferences) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement)

Example 24 with NativeByteBuffer

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

the class MediaDataController method putReactionsToCache.

private void putReactionsToCache(List<TLRPC.TL_availableReaction> reactions, int hash, int date) {
    ArrayList<TLRPC.TL_availableReaction> reactionsFinal = reactions != null ? new ArrayList<>(reactions) : null;
    getMessagesStorage().getStorageQueue().postRunnable(() -> {
        try {
            if (reactionsFinal != null) {
                getMessagesStorage().getDatabase().executeFast("DELETE FROM reactions").stepThis().dispose();
                SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO reactions VALUES(?, ?, ?)");
                state.requery();
                // Integer.BYTES
                int size = 4;
                for (int a = 0; a < reactionsFinal.size(); a++) {
                    size += reactionsFinal.get(a).getObjectSize();
                }
                NativeByteBuffer data = new NativeByteBuffer(size);
                data.writeInt32(reactionsFinal.size());
                for (int a = 0; a < reactionsFinal.size(); a++) {
                    reactionsFinal.get(a).serializeToStream(data);
                }
                state.bindByteBuffer(1, data);
                state.bindInteger(2, hash);
                state.bindInteger(3, date);
                state.step();
                data.reuse();
                state.dispose();
            } else {
                SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("UPDATE reactions SET date = ?");
                state.requery();
                state.bindLong(1, date);
                state.step();
                state.dispose();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Paint(android.graphics.Paint) SQLiteException(org.telegram.SQLite.SQLiteException) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement)

Example 25 with NativeByteBuffer

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

the class MessagesStorage method addRecentLocalFile.

public void addRecentLocalFile(String imageUrl, String localUrl, TLRPC.Document document) {
    if (imageUrl == null || imageUrl.length() == 0 || ((localUrl == null || localUrl.length() == 0) && document == null)) {
        return;
    }
    storageQueue.postRunnable(() -> {
        try {
            if (document != null) {
                SQLitePreparedStatement state = database.executeFast("UPDATE web_recent_v3 SET document = ? WHERE image_url = ?");
                state.requery();
                NativeByteBuffer data = new NativeByteBuffer(document.getObjectSize());
                document.serializeToStream(data);
                state.bindByteBuffer(1, data);
                state.bindString(2, imageUrl);
                state.step();
                state.dispose();
                data.reuse();
            } else {
                SQLitePreparedStatement state = database.executeFast("UPDATE web_recent_v3 SET local_url = ? WHERE image_url = ?");
                state.requery();
                state.bindString(1, localUrl);
                state.bindString(2, imageUrl);
                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)

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