use of org.telegram.tgnet.TLObject 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.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method getEncryptedChatDB.
public TLRPC.EncryptedChat getEncryptedChatDB(int chatId, boolean created) {
TLRPC.EncryptedChat chat = encryptedChats.get(chatId);
if (chat == null || created && (chat instanceof TLRPC.TL_encryptedChatWaiting || chat instanceof TLRPC.TL_encryptedChatRequested)) {
CountDownLatch countDownLatch = new CountDownLatch(1);
ArrayList<TLObject> result = new ArrayList<>();
getMessagesStorage().getEncryptedChat(chatId, countDownLatch, result);
try {
countDownLatch.await();
} catch (Exception e) {
FileLog.e(e);
}
if (result.size() == 2) {
chat = (TLRPC.EncryptedChat) result.get(0);
TLRPC.User user = (TLRPC.User) result.get(1);
putEncryptedChat(chat, false);
putUser(user, true);
}
}
return chat;
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method openByUserName.
public void openByUserName(String username, BaseFragment fragment, int type) {
if (username == null || fragment == null) {
return;
}
TLObject object = getUserOrChat(username);
TLRPC.User user = null;
TLRPC.Chat chat = null;
if (object instanceof TLRPC.User) {
user = (TLRPC.User) object;
if (user.min) {
user = null;
}
} else if (object instanceof TLRPC.Chat) {
chat = (TLRPC.Chat) object;
if (chat.min) {
chat = null;
}
}
if (user != null) {
openChatOrProfileWith(user, null, fragment, type, false);
} else if (chat != null) {
openChatOrProfileWith(null, chat, fragment, 1, false);
} else {
if (fragment.getParentActivity() == null) {
return;
}
AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(fragment.getParentActivity(), 3) };
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
req.username = username;
int reqId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Exception ignored) {
}
progressDialog[0] = null;
fragment.setVisibleDialog(null);
if (error == null) {
TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
putUsers(res.users, false);
putChats(res.chats, false);
getMessagesStorage().putUsersAndChats(res.users, res.chats, false, true);
if (!res.chats.isEmpty()) {
openChatOrProfileWith(null, res.chats.get(0), fragment, 1, false);
} else if (!res.users.isEmpty()) {
openChatOrProfileWith(res.users.get(0), null, fragment, type, false);
}
} else {
if (fragment.getParentActivity() != null) {
try {
BulletinFactory.of(fragment).createErrorBulletin(LocaleController.getString("NoUsernameFound", R.string.NoUsernameFound)).show();
} catch (Exception e) {
FileLog.e(e);
}
}
}
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(reqId, true));
fragment.showDialog(progressDialog[0]);
}, 500);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method addUserToChat.
public void addUserToChat(long chatId, TLRPC.User user, int forwardCount, String botHash, BaseFragment fragment, Runnable onFinishRunnable) {
if (user == null) {
return;
}
TLObject request;
boolean isChannel = ChatObject.isChannel(chatId, currentAccount);
boolean isMegagroup = isChannel && getChat(chatId).megagroup;
TLRPC.InputUser inputUser = getInputUser(user);
if (botHash == null || isChannel && !isMegagroup) {
if (isChannel) {
if (inputUser instanceof TLRPC.TL_inputUserSelf) {
if (joiningToChannels.contains(chatId)) {
return;
}
TLRPC.TL_channels_joinChannel req = new TLRPC.TL_channels_joinChannel();
req.channel = getInputChannel(chatId);
request = req;
joiningToChannels.add(chatId);
} else {
TLRPC.TL_channels_inviteToChannel req = new TLRPC.TL_channels_inviteToChannel();
req.channel = getInputChannel(chatId);
req.users.add(inputUser);
request = req;
}
} else {
TLRPC.TL_messages_addChatUser req = new TLRPC.TL_messages_addChatUser();
req.chat_id = chatId;
req.fwd_limit = forwardCount;
req.user_id = inputUser;
request = req;
}
} else {
TLRPC.TL_messages_startBot req = new TLRPC.TL_messages_startBot();
req.bot = inputUser;
if (isChannel) {
req.peer = getInputPeer(-chatId);
} else {
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = chatId;
}
req.start_param = botHash;
req.random_id = Utilities.random.nextLong();
request = req;
}
getConnectionsManager().sendRequest(request, (response, error) -> {
if (isChannel && inputUser instanceof TLRPC.TL_inputUserSelf) {
AndroidUtilities.runOnUIThread(() -> joiningToChannels.remove(chatId));
}
if (error != null) {
AndroidUtilities.runOnUIThread(() -> {
AlertsCreator.processError(currentAccount, error, fragment, request, isChannel && !isMegagroup);
if (isChannel && inputUser instanceof TLRPC.TL_inputUserSelf) {
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT);
}
});
return;
}
boolean hasJoinMessage = false;
TLRPC.Updates updates = (TLRPC.Updates) response;
for (int a = 0; a < updates.updates.size(); a++) {
TLRPC.Update update = updates.updates.get(a);
if (update instanceof TLRPC.TL_updateNewChannelMessage) {
if (((TLRPC.TL_updateNewChannelMessage) update).message.action instanceof TLRPC.TL_messageActionChatAddUser) {
hasJoinMessage = true;
break;
}
}
}
processUpdates(updates, false);
if (isChannel) {
if (!hasJoinMessage && inputUser instanceof TLRPC.TL_inputUserSelf) {
generateJoinMessage(chatId, true);
}
AndroidUtilities.runOnUIThread(() -> loadFullChat(chatId, 0, true), 1000);
}
if (isChannel && inputUser instanceof TLRPC.TL_inputUserSelf) {
getMessagesStorage().updateDialogsWithDeletedMessages(-chatId, chatId, new ArrayList<>(), null, true);
}
if (onFinishRunnable != null) {
AndroidUtilities.runOnUIThread(onFinishRunnable);
}
});
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method changeChatTitle.
public void changeChatTitle(long chatId, String title) {
TLObject request;
if (ChatObject.isChannel(chatId, currentAccount)) {
TLRPC.TL_channels_editTitle req = new TLRPC.TL_channels_editTitle();
req.channel = getInputChannel(chatId);
req.title = title;
request = req;
} else {
TLRPC.TL_messages_editChatTitle req = new TLRPC.TL_messages_editChatTitle();
req.chat_id = chatId;
req.title = title;
request = req;
}
getConnectionsManager().sendRequest(request, (response, error) -> {
if (error != null) {
return;
}
processUpdates((TLRPC.Updates) response, false);
}, ConnectionsManager.RequestFlagInvokeAfter);
}
Aggregations