use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaDataController method loadBotKeyboard.
public void loadBotKeyboard(long dialogId) {
TLRPC.Message keyboard = botKeyboards.get(dialogId);
if (keyboard != null) {
getNotificationCenter().postNotificationName(NotificationCenter.botKeyboardDidLoad, keyboard, dialogId);
return;
}
getMessagesStorage().getStorageQueue().postRunnable(() -> {
try {
TLRPC.Message botKeyboard = null;
SQLiteCursor cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT info FROM bot_keyboard WHERE uid = %d", dialogId));
if (cursor.next()) {
NativeByteBuffer data;
if (!cursor.isNull(0)) {
data = cursor.byteBufferValue(0);
if (data != null) {
botKeyboard = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
}
}
}
cursor.dispose();
if (botKeyboard != null) {
TLRPC.Message botKeyboardFinal = botKeyboard;
AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.botKeyboardDidLoad, botKeyboardFinal, dialogId));
}
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaDataController method loadMusic.
public void loadMusic(long dialogId, long maxId, long minId) {
getMessagesStorage().getStorageQueue().postRunnable(() -> {
ArrayList<MessageObject> arrayListBegin = new ArrayList<>();
ArrayList<MessageObject> arrayListEnd = new ArrayList<>();
try {
for (int a = 0; a < 2; a++) {
ArrayList<MessageObject> arrayList = a == 0 ? arrayListBegin : arrayListEnd;
SQLiteCursor cursor;
if (a == 0) {
if (!DialogObject.isEncryptedDialog(dialogId)) {
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v4 WHERE uid = %d AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", dialogId, maxId, MEDIA_MUSIC));
} else {
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v4 WHERE uid = %d AND mid > %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", dialogId, maxId, MEDIA_MUSIC));
}
} else {
if (!DialogObject.isEncryptedDialog(dialogId)) {
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v4 WHERE uid = %d AND mid > %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", dialogId, minId, MEDIA_MUSIC));
} else {
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v4 WHERE uid = %d AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", dialogId, minId, MEDIA_MUSIC));
}
}
while (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
message.readAttachPath(data, getUserConfig().clientUserId);
data.reuse();
if (MessageObject.isMusicMessage(message)) {
message.id = cursor.intValue(1);
message.dialog_id = dialogId;
arrayList.add(0, new MessageObject(currentAccount, message, false, true));
}
}
}
cursor.dispose();
}
} catch (Exception e) {
FileLog.e(e);
}
AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.musicDidLoad, dialogId, arrayListBegin, arrayListEnd));
});
}
use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method getUnreadMention.
public void getUnreadMention(long dialog_id, IntCallback callback) {
storageQueue.postRunnable(() -> {
try {
int result;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT MIN(mid) FROM messages_v2 WHERE uid = %d AND mention = 1 AND read_state IN(0, 1)", dialog_id));
if (cursor.next()) {
result = cursor.intValue(0);
} else {
result = 0;
}
cursor.dispose();
AndroidUtilities.runOnUIThread(() -> callback.run(result));
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method loadUserInfo.
public void loadUserInfo(TLRPC.User user, boolean force, int classGuid, int fromMessageId) {
if (user == null) {
return;
}
storageQueue.postRunnable(() -> {
HashMap<Integer, MessageObject> pinnedMessagesMap = new HashMap<>();
ArrayList<Integer> pinnedMessages = new ArrayList<>();
int totalPinnedCount = 0;
boolean pinnedEndReached = false;
TLRPC.UserFull info = null;
try {
SQLiteCursor cursor = database.queryFinalized("SELECT info, pinned FROM user_settings WHERE uid = " + user.id);
if (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
info = TLRPC.UserFull.TLdeserialize(data, data.readInt32(false), false);
info.pinned_msg_id = cursor.intValue(1);
data.reuse();
}
}
cursor.dispose();
cursor = getMessagesStorage().getDatabase().queryFinalized(String.format(Locale.US, "SELECT mid FROM chat_pinned_v2 WHERE uid = %d ORDER BY mid DESC", user.id));
while (cursor.next()) {
int id = cursor.intValue(0);
pinnedMessages.add(id);
pinnedMessagesMap.put(id, null);
}
cursor.dispose();
cursor = database.queryFinalized("SELECT count, end FROM chat_pinned_count WHERE uid = " + user.id);
if (cursor.next()) {
totalPinnedCount = cursor.intValue(0);
pinnedEndReached = cursor.intValue(1) != 0;
}
cursor.dispose();
if (info != null && info.pinned_msg_id != 0) {
if (pinnedMessages.isEmpty() || info.pinned_msg_id > pinnedMessages.get(0)) {
pinnedMessages.clear();
pinnedMessages.add(info.pinned_msg_id);
pinnedMessagesMap.put(info.pinned_msg_id, null);
}
}
if (!pinnedMessages.isEmpty()) {
ArrayList<MessageObject> messageObjects = getMediaDataController().loadPinnedMessages(user.id, 0, pinnedMessages, false);
if (messageObjects != null) {
for (int a = 0, N = messageObjects.size(); a < N; a++) {
MessageObject messageObject = messageObjects.get(a);
pinnedMessagesMap.put(messageObject.getId(), messageObject);
}
}
}
} catch (Exception e) {
FileLog.e(e);
} finally {
getMessagesController().processUserInfo(user, info, true, force, classGuid, pinnedMessages, pinnedMessagesMap, totalPinnedCount, pinnedEndReached);
}
});
}
use of org.telegram.SQLite.SQLiteCursor in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method markMessagesContentAsRead.
public void markMessagesContentAsRead(long dialogId, ArrayList<Integer> mids, int date) {
if (isEmpty(mids)) {
return;
}
storageQueue.postRunnable(() -> {
if (dialogId == 0) {
try {
LongSparseArray<ArrayList<Integer>> sparseArray = new LongSparseArray<>();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT uid, mid FROM messages_v2 WHERE mid IN (%s) AND is_channel = 0", TextUtils.join(",", mids)));
while (cursor.next()) {
long did = cursor.longValue(0);
ArrayList<Integer> arrayList = sparseArray.get(did);
if (arrayList == null) {
arrayList = new ArrayList<>();
sparseArray.put(did, arrayList);
}
arrayList.add(cursor.intValue(1));
}
cursor.dispose();
for (int a = 0, N = sparseArray.size(); a < N; a++) {
markMessagesContentAsReadInternal(sparseArray.keyAt(a), sparseArray.valueAt(a), date);
}
} catch (Exception e) {
FileLog.e(e);
}
} else {
markMessagesContentAsReadInternal(dialogId, mids, date);
}
});
}
Aggregations