use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method getSentFile.
public Object[] getSentFile(String path, int type) {
if (path == null || path.toLowerCase().endsWith("attheme")) {
return null;
}
CountDownLatch countDownLatch = new CountDownLatch(1);
Object[] result = new Object[2];
storageQueue.postRunnable(() -> {
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, parent FROM sent_files_v2 WHERE uid = '%s' AND type = %d", id, type));
if (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLObject file = TLRPC.MessageMedia.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (file instanceof TLRPC.TL_messageMediaDocument) {
result[0] = ((TLRPC.TL_messageMediaDocument) file).document;
} else if (file instanceof TLRPC.TL_messageMediaPhoto) {
result[0] = ((TLRPC.TL_messageMediaPhoto) file).photo;
}
if (result[0] != null) {
result[1] = cursor.stringValue(1);
}
}
}
cursor.dispose();
}
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (Exception e) {
FileLog.e(e);
}
return result[0] != null ? result : null;
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesStorage method markMessageReactionsAsReadInternal.
public void markMessageReactionsAsReadInternal(long dialogId, int messageId) {
try {
SQLitePreparedStatement state = getMessagesStorage().getDatabase().executeFast("UPDATE reaction_mentions SET state = 0 WHERE message_id = ? AND dialog_id = ?");
state.bindInteger(1, messageId);
state.bindLong(2, dialogId);
state.step();
state.dispose();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT data FROM messages_v2 WHERE uid = %d AND mid = %d", dialogId, messageId));
TLRPC.Message message = null;
if (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
message.readAttachPath(data, getUserConfig().clientUserId);
data.reuse();
if (message.reactions != null && message.reactions.recent_reactions != null) {
for (int i = 0; i < message.reactions.recent_reactions.size(); i++) {
message.reactions.recent_reactions.get(i).unread = false;
}
}
}
}
cursor.dispose();
if (message != null) {
state = getMessagesStorage().getDatabase().executeFast(String.format(Locale.US, "UPDATE messages_v2 SET data = ? WHERE uid = %d AND mid = %d", dialogId, messageId));
try {
NativeByteBuffer data = new NativeByteBuffer(message.getObjectSize());
message.serializeToStream(data);
state.bindByteBuffer(1, data);
state.step();
state.dispose();
data.reuse();
} catch (Exception e) {
FileLog.e(e);
}
}
} catch (SQLiteException e) {
FileLog.e(e);
}
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method reorderPinnedDialogs.
public void reorderPinnedDialogs(int folderId, ArrayList<TLRPC.InputDialogPeer> order, long taskId) {
TLRPC.TL_messages_reorderPinnedDialogs req = new TLRPC.TL_messages_reorderPinnedDialogs();
req.folder_id = folderId;
req.force = true;
long newTaskId;
if (taskId == 0) {
ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
if (dialogs.isEmpty()) {
return;
}
int size = 0;
ArrayList<Long> dids = new ArrayList<>();
ArrayList<Integer> pinned = new ArrayList<>();
for (int a = 0, N = dialogs.size(); a < N; a++) {
TLRPC.Dialog dialog = dialogs.get(a);
if (dialog instanceof TLRPC.TL_dialogFolder) {
continue;
}
if (!dialog.pinned) {
if (dialog.id != promoDialogId) {
break;
}
continue;
}
dids.add(dialog.id);
pinned.add(dialog.pinnedNum);
if (!DialogObject.isEncryptedDialog(dialog.id)) {
TLRPC.InputPeer inputPeer = getInputPeer(dialog.id);
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = inputPeer;
req.order.add(inputDialogPeer);
size += inputDialogPeer.getObjectSize();
}
}
getMessagesStorage().setDialogsPinned(dids, pinned);
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(4 + 4 + 4 + size);
data.writeInt32(16);
data.writeInt32(folderId);
data.writeInt32(req.order.size());
for (int a = 0, N = req.order.size(); a < N; a++) {
req.order.get(a).serializeToStream(data);
}
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
req.order = order;
newTaskId = taskId;
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method markDialogAsUnread.
public void markDialogAsUnread(long dialogId, TLRPC.InputPeer peer, long taskId) {
TLRPC.Dialog dialog = dialogs_dict.get(dialogId);
if (dialog != null) {
dialog.unread_mark = true;
if (dialog.unread_count == 0 && !isDialogMuted(dialogId)) {
unreadUnmutedDialogs++;
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_READ_DIALOG_MESSAGE);
getMessagesStorage().setDialogUnread(dialogId, true);
for (int b = 0; b < selectedDialogFilter.length; b++) {
if (selectedDialogFilter[b] != null && (selectedDialogFilter[b].flags & DIALOG_FILTER_FLAG_EXCLUDE_READ) != 0) {
sortDialogs(null);
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
break;
}
}
}
if (!DialogObject.isEncryptedDialog(dialogId)) {
TLRPC.TL_messages_markDialogUnread req = new TLRPC.TL_messages_markDialogUnread();
req.unread = true;
if (peer == null) {
peer = getInputPeer(dialogId);
}
if (peer instanceof TLRPC.TL_inputPeerEmpty) {
return;
}
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = peer;
req.peer = inputDialogPeer;
long newTaskId;
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(12 + peer.getObjectSize());
data.writeInt32(9);
data.writeInt64(dialogId);
peer.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = taskId;
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
}
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method deleteDialog.
protected void deleteDialog(long did, int first, int onlyHistory, int max_id, boolean revoke, TLRPC.InputPeer peer, long taskId) {
if (onlyHistory == 2) {
getMessagesStorage().deleteDialog(did, onlyHistory);
return;
}
for (int i = 0; i < sendAsPeers.size(); i++) {
SendAsPeersInfo sendAsInfo = sendAsPeers.valueAt(i);
if (sendAsInfo.sendAsPeers != null) {
for (int j = 0; j < sendAsInfo.sendAsPeers.chats.size(); j++) {
if (sendAsInfo.sendAsPeers.chats.get(j).id == -did) {
sendAsInfo.sendAsPeers.chats.remove(j);
break;
}
}
for (int j = 0; j < sendAsInfo.sendAsPeers.peers.size(); j++) {
if (sendAsInfo.sendAsPeers.peers.get(j).channel_id == -did || sendAsInfo.sendAsPeers.peers.get(j).chat_id == -did) {
sendAsInfo.sendAsPeers.peers.remove(j);
break;
}
}
}
}
sendAsPeers.remove(did);
if (first == 1 && max_id == 0) {
TLRPC.InputPeer peerFinal = peer;
getMessagesStorage().getDialogMaxMessageId(did, (param) -> {
deleteDialog(did, 2, onlyHistory, Math.max(0, param), revoke, peerFinal, taskId);
checkIfFolderEmpty(1);
});
return;
}
if (onlyHistory == 0 || onlyHistory == 3) {
getMediaDataController().uninstallShortcut(did);
}
int max_id_delete = max_id;
if (first != 0) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("delete dialog with id " + did);
}
boolean isPromoDialog = false;
getMessagesStorage().deleteDialog(did, onlyHistory);
TLRPC.Dialog dialog = dialogs_dict.get(did);
if (onlyHistory == 0 || onlyHistory == 3) {
getNotificationCenter().postNotificationName(NotificationCenter.dialogDeleted, did);
getNotificationsController().deleteNotificationChannel(did);
JoinCallAlert.processDeletedChat(currentAccount, did);
}
if (onlyHistory == 0) {
getMediaDataController().cleanDraft(did, 0, false);
}
if (dialog != null) {
if (first == 2) {
max_id_delete = Math.max(0, dialog.top_message);
max_id_delete = Math.max(max_id_delete, dialog.read_inbox_max_id);
max_id_delete = Math.max(max_id_delete, dialog.read_outbox_max_id);
}
if (onlyHistory == 0 || onlyHistory == 3) {
if (isPromoDialog = (promoDialog != null && promoDialog.id == did)) {
isLeftPromoChannel = true;
if (promoDialog.id < 0) {
TLRPC.Chat chat = getChat(-promoDialog.id);
if (chat != null) {
chat.left = true;
}
}
sortDialogs(null);
} else {
removeDialog(dialog);
int offset = nextDialogsCacheOffset.get(dialog.folder_id, 0);
if (offset > 0) {
nextDialogsCacheOffset.put(dialog.folder_id, offset - 1);
}
}
} else {
dialog.unread_count = 0;
}
if (!isPromoDialog) {
int lastMessageId;
MessageObject object = dialogMessage.get(dialog.id);
dialogMessage.remove(dialog.id);
if (object != null) {
lastMessageId = object.getId();
if (object.messageOwner.peer_id.channel_id == 0) {
dialogMessagesByIds.remove(object.getId());
}
} else {
lastMessageId = dialog.top_message;
object = dialogMessagesByIds.get(dialog.top_message);
if (object != null && object.messageOwner.peer_id.channel_id == 0) {
dialogMessagesByIds.remove(dialog.top_message);
}
}
if (object != null && object.messageOwner.random_id != 0) {
dialogMessagesByRandomIds.remove(object.messageOwner.random_id);
}
if (onlyHistory == 1 && !DialogObject.isEncryptedDialog(did) && lastMessageId > 0) {
TLRPC.TL_messageService message = new TLRPC.TL_messageService();
message.id = dialog.top_message;
message.out = getUserConfig().getClientUserId() == did;
message.from_id = new TLRPC.TL_peerUser();
message.from_id.user_id = getUserConfig().getClientUserId();
message.flags |= 256;
message.action = new TLRPC.TL_messageActionHistoryClear();
message.date = dialog.last_message_date;
message.dialog_id = did;
message.peer_id = getPeer(did);
boolean isDialogCreated = createdDialogIds.contains(message.dialog_id);
MessageObject obj = new MessageObject(currentAccount, message, isDialogCreated, isDialogCreated);
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<>();
arr.add(message);
updateInterfaceWithMessages(did, objArr, false);
getMessagesStorage().putMessages(arr, false, true, false, 0, false);
} else {
dialog.top_message = 0;
}
}
}
if (first == 2) {
Integer max = dialogs_read_inbox_max.get(did);
if (max != null) {
max_id_delete = Math.max(max, max_id_delete);
}
max = dialogs_read_outbox_max.get(did);
if (max != null) {
max_id_delete = Math.max(max, max_id_delete);
}
}
if (!dialogsInTransaction) {
if (isPromoDialog) {
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, true);
} else {
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
getNotificationCenter().postNotificationName(NotificationCenter.removeAllMessagesFromDialog, did, false, null);
}
}
getMessagesStorage().getStorageQueue().postRunnable(() -> AndroidUtilities.runOnUIThread(() -> getNotificationsController().removeNotificationsForDialog(did)));
}
if (onlyHistory == 3) {
return;
}
if (!DialogObject.isEncryptedDialog(did)) {
if (peer == null) {
peer = getInputPeer(did);
}
if (peer == null) {
return;
}
long newTaskId;
if (!(peer instanceof TLRPC.TL_inputPeerChannel) || onlyHistory != 0) {
if (max_id_delete > 0 && max_id_delete != Integer.MAX_VALUE) {
int current = deletedHistory.get(did, 0);
deletedHistory.put(did, Math.max(current, max_id_delete));
}
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(4 + 8 + 4 + 4 + 4 + 4 + peer.getObjectSize());
data.writeInt32(13);
data.writeInt64(did);
data.writeBool(first != 0);
data.writeInt32(onlyHistory);
data.writeInt32(max_id_delete);
data.writeBool(revoke);
peer.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = taskId;
}
} else {
newTaskId = taskId;
}
if (peer instanceof TLRPC.TL_inputPeerChannel) {
if (onlyHistory == 0) {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
return;
}
TLRPC.TL_channels_deleteHistory req = new TLRPC.TL_channels_deleteHistory();
req.channel = new TLRPC.TL_inputChannel();
req.channel.channel_id = peer.channel_id;
req.channel.access_hash = peer.access_hash;
req.max_id = max_id_delete > 0 ? max_id_delete : Integer.MAX_VALUE;
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
}, ConnectionsManager.RequestFlagInvokeAfter);
} else {
TLRPC.TL_messages_deleteHistory req = new TLRPC.TL_messages_deleteHistory();
req.peer = peer;
req.max_id = max_id_delete > 0 ? max_id_delete : Integer.MAX_VALUE;
req.just_clear = onlyHistory != 0;
req.revoke = revoke;
int max_id_delete_final = max_id_delete;
TLRPC.InputPeer peerFinal = peer;
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
if (error == null) {
TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response;
if (res.offset > 0) {
deleteDialog(did, 0, onlyHistory, max_id_delete_final, revoke, peerFinal, 0);
}
processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
getMessagesStorage().onDeleteQueryComplete(did);
}
}, ConnectionsManager.RequestFlagInvokeAfter);
}
} else {
int encryptedId = DialogObject.getEncryptedChatId(did);
if (onlyHistory == 1) {
getSecretChatHelper().sendClearHistoryMessage(getEncryptedChat(encryptedId), null);
} else {
getSecretChatHelper().declineSecretChat(encryptedId, revoke);
}
}
}
Aggregations