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);
}
});
}
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);
}
});
}
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 {
}
});
}
}
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);
}
});
}
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);
}
});
}
Aggregations