use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method updateMessageReactions.
public void updateMessageReactions(long dialogId, int msgId, TLRPC.TL_messageReactions reactions) {
storageQueue.postRunnable(() -> {
try {
database.beginTransaction();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM messages_v2 WHERE mid = %d AND uid = %d", msgId, dialogId));
if (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
if (message != null) {
message.readAttachPath(data, getUserConfig().clientUserId);
data.reuse();
MessageObject.updateReactions(message, reactions);
SQLitePreparedStatement state = database.executeFast("UPDATE messages_v2 SET data = ? WHERE mid = ? AND uid = ?");
NativeByteBuffer data2 = new NativeByteBuffer(message.getObjectSize());
message.serializeToStream(data2);
state.requery();
state.bindByteBuffer(1, data2);
state.bindInteger(2, msgId);
state.bindLong(3, dialogId);
state.step();
data2.reuse();
state.dispose();
} else {
data.reuse();
}
}
}
cursor.dispose();
database.commitTransaction();
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method saveSecretParams.
public void saveSecretParams(int lsv, int sg, byte[] pbytes) {
storageQueue.postRunnable(() -> {
try {
SQLitePreparedStatement state = database.executeFast("UPDATE params SET lsv = ?, sg = ?, pbytes = ? WHERE id = 1");
state.bindInteger(1, lsv);
state.bindInteger(2, sg);
NativeByteBuffer data = new NativeByteBuffer(pbytes != null ? pbytes.length : 1);
if (pbytes != null) {
data.writeBytes(pbytes);
}
state.bindByteBuffer(3, data);
state.step();
state.dispose();
data.reuse();
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method getChatsInternal.
public void getChatsInternal(String chatsToLoad, ArrayList<TLRPC.Chat> result) throws Exception {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM chats WHERE uid IN(%s)", chatsToLoad));
while (cursor.next()) {
try {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.Chat chat = TLRPC.Chat.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (chat != null) {
result.add(chat);
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
cursor.dispose();
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method putUsersInternal.
private void putUsersInternal(ArrayList<TLRPC.User> users) throws Exception {
if (users == null || users.isEmpty()) {
return;
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO users VALUES(?, ?, ?, ?)");
for (int a = 0; a < users.size(); a++) {
TLRPC.User user = users.get(a);
if (user.min) {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM users WHERE uid = %d", user.id));
if (cursor.next()) {
try {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.User oldUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (oldUser != null) {
if (user.username != null) {
oldUser.username = user.username;
oldUser.flags |= 8;
} else {
oldUser.username = null;
oldUser.flags = oldUser.flags & ~8;
}
if (user.apply_min_photo) {
if (user.photo != null) {
oldUser.photo = user.photo;
oldUser.flags |= 32;
} else {
oldUser.photo = null;
oldUser.flags = oldUser.flags & ~32;
}
}
user = oldUser;
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
cursor.dispose();
}
state.requery();
NativeByteBuffer data = new NativeByteBuffer(user.getObjectSize());
user.serializeToStream(data);
state.bindLong(1, user.id);
state.bindString(2, formatUserSearchName(user));
if (user.status != null) {
if (user.status instanceof TLRPC.TL_userStatusRecently) {
user.status.expires = -100;
} else if (user.status instanceof TLRPC.TL_userStatusLastWeek) {
user.status.expires = -101;
} else if (user.status instanceof TLRPC.TL_userStatusLastMonth) {
user.status.expires = -102;
}
state.bindInteger(3, user.status.expires);
} else {
state.bindInteger(3, 0);
}
state.bindByteBuffer(4, data);
state.step();
data.reuse();
}
state.dispose();
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method saveBotCache.
public void saveBotCache(String key, TLObject result) {
if (result == null || TextUtils.isEmpty(key)) {
return;
}
storageQueue.postRunnable(() -> {
try {
int currentDate = getConnectionsManager().getCurrentTime();
if (result instanceof TLRPC.TL_messages_botCallbackAnswer) {
currentDate += ((TLRPC.TL_messages_botCallbackAnswer) result).cache_time;
} else if (result instanceof TLRPC.TL_messages_botResults) {
currentDate += ((TLRPC.TL_messages_botResults) result).cache_time;
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO botcache VALUES(?, ?, ?)");
NativeByteBuffer data = new NativeByteBuffer(result.getObjectSize());
result.serializeToStream(data);
state.bindString(1, key);
state.bindInteger(2, currentDate);
state.bindByteBuffer(3, data);
state.step();
state.dispose();
data.reuse();
} catch (Exception e) {
FileLog.e(e);
}
});
}
Aggregations