use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method loadUnknownDialog.
protected void loadUnknownDialog(final TLRPC.InputPeer peer, long taskId) {
if (peer == null) {
return;
}
long dialogId = DialogObject.getPeerDialogId(peer);
if (gettingUnknownDialogs.indexOfKey(dialogId) >= 0) {
return;
}
gettingUnknownDialogs.put(dialogId, true);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("load unknown dialog " + dialogId);
}
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = peer;
req.peers.add(inputDialogPeer);
long newTaskId;
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(4 + peer.getObjectSize());
data.writeInt32(15);
peer.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()) {
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_UNKNOWN, false, false, false);
}
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
gettingUnknownDialogs.delete(dialogId);
});
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method deleteMessages.
public void deleteMessages(ArrayList<Integer> messages, ArrayList<Long> randoms, TLRPC.EncryptedChat encryptedChat, long dialogId, boolean forAll, boolean scheduled, boolean cacheOnly, long taskId, TLObject taskRequest) {
if ((messages == null || messages.isEmpty()) && taskId == 0) {
return;
}
ArrayList<Integer> toSend = null;
long channelId;
if (taskId == 0) {
if (dialogId != 0 && DialogObject.isChatDialog(dialogId)) {
TLRPC.Chat chat = getChat(-dialogId);
channelId = ChatObject.isChannel(chat) ? chat.id : 0;
} else {
channelId = 0;
}
if (!cacheOnly) {
toSend = new ArrayList<>();
for (int a = 0, N = messages.size(); a < N; a++) {
Integer mid = messages.get(a);
if (mid > 0) {
toSend.add(mid);
}
}
}
if (scheduled) {
getMessagesStorage().markMessagesAsDeleted(dialogId, messages, true, false, true);
} else {
if (channelId == 0) {
for (int a = 0; a < messages.size(); a++) {
Integer id = messages.get(a);
MessageObject obj = dialogMessagesByIds.get(id);
if (obj != null) {
obj.deleted = true;
}
}
} else {
markDialogMessageAsDeleted(dialogId, messages);
}
getMessagesStorage().markMessagesAsDeleted(dialogId, messages, true, forAll, false);
getMessagesStorage().updateDialogsWithDeletedMessages(dialogId, channelId, messages, null, true);
}
getNotificationCenter().postNotificationName(NotificationCenter.messagesDeleted, messages, channelId, scheduled);
} else {
if (taskRequest instanceof TLRPC.TL_channels_deleteMessages) {
channelId = ((TLRPC.TL_channels_deleteMessages) taskRequest).channel.channel_id;
} else {
channelId = 0;
}
}
if (cacheOnly) {
return;
}
long newTaskId;
if (scheduled) {
TLRPC.TL_messages_deleteScheduledMessages req;
if (taskRequest instanceof TLRPC.TL_messages_deleteScheduledMessages) {
req = (TLRPC.TL_messages_deleteScheduledMessages) taskRequest;
newTaskId = taskId;
} else {
req = new TLRPC.TL_messages_deleteScheduledMessages();
req.id = toSend;
req.peer = getInputPeer(dialogId);
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(12 + req.getObjectSize());
data.writeInt32(24);
data.writeInt64(dialogId);
req.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.Updates updates = (TLRPC.Updates) response;
processUpdates(updates, false);
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
} else if (channelId != 0) {
TLRPC.TL_channels_deleteMessages req;
if (taskRequest != null) {
req = (TLRPC.TL_channels_deleteMessages) taskRequest;
newTaskId = taskId;
} else {
req = new TLRPC.TL_channels_deleteMessages();
req.id = toSend;
req.channel = getInputChannel(channelId);
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(12 + req.getObjectSize());
data.writeInt32(24);
data.writeInt64(dialogId);
req.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
processNewChannelDifferenceParams(res.pts, res.pts_count, channelId);
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
} else {
if (randoms != null && encryptedChat != null && !randoms.isEmpty()) {
getSecretChatHelper().sendMessagesDeleteMessage(encryptedChat, randoms, null);
}
TLRPC.TL_messages_deleteMessages req;
if (taskRequest instanceof TLRPC.TL_messages_deleteMessages) {
req = (TLRPC.TL_messages_deleteMessages) taskRequest;
newTaskId = taskId;
} else {
req = new TLRPC.TL_messages_deleteMessages();
req.id = toSend;
req.revoke = forAll;
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(12 + req.getObjectSize());
data.writeInt32(24);
data.writeInt64(dialogId);
req.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
}
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);
}
});
}
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaDataController method updateBotInfo.
public void updateBotInfo(long dialogId, TLRPC.TL_updateBotCommands update) {
TLRPC.BotInfo botInfo = botInfos.get(update.bot_id + "_" + dialogId);
if (botInfo != null) {
botInfo.commands = update.commands;
getNotificationCenter().postNotificationName(NotificationCenter.botInfoDidLoad, botInfo, 0);
}
getMessagesStorage().getStorageQueue().postRunnable(() -> {
try {
TLRPC.BotInfo info = loadBotInfoInternal(update.bot_id, dialogId);
if (info != null) {
info.commands = update.commands;
}
SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO bot_info_v2 VALUES(?, ?, ?)");
state.requery();
NativeByteBuffer data = new NativeByteBuffer(info.getObjectSize());
info.serializeToStream(data);
state.bindLong(1, info.user_id);
state.bindLong(2, dialogId);
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 putDiceStickersToCache.
private void putDiceStickersToCache(String emoji, TLRPC.TL_messages_stickerSet stickers, int date) {
if (TextUtils.isEmpty(emoji)) {
return;
}
getMessagesStorage().getStorageQueue().postRunnable(() -> {
try {
if (stickers != null) {
SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO stickers_dice VALUES(?, ?, ?)");
state.requery();
NativeByteBuffer data = new NativeByteBuffer(stickers.getObjectSize());
stickers.serializeToStream(data);
state.bindString(1, emoji);
state.bindByteBuffer(2, data);
state.bindInteger(3, date);
state.step();
data.reuse();
state.dispose();
} else {
SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("UPDATE stickers_dice SET date = ?");
state.requery();
state.bindInteger(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 MediaDataController method putBotInfo.
public void putBotInfo(long dialogId, TLRPC.BotInfo botInfo) {
if (botInfo == null) {
return;
}
botInfos.put(botInfo.user_id + "_" + dialogId, botInfo);
getMessagesStorage().getStorageQueue().postRunnable(() -> {
try {
SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("REPLACE INTO bot_info_v2 VALUES(?, ?, ?)");
state.requery();
NativeByteBuffer data = new NativeByteBuffer(botInfo.getObjectSize());
botInfo.serializeToStream(data);
state.bindLong(1, botInfo.user_id);
state.bindLong(2, dialogId);
state.bindByteBuffer(3, data);
state.step();
data.reuse();
state.dispose();
} catch (Exception e) {
FileLog.e(e);
}
});
}
Aggregations