Search in sources :

Example 56 with TLObject

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;
}
Also used : TLObject(org.telegram.tgnet.TLObject) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) CountDownLatch(java.util.concurrent.CountDownLatch) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 57 with TLObject

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;
}
Also used : TLObject(org.telegram.tgnet.TLObject) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 58 with TLObject

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);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) ProfileActivity(org.telegram.ui.ProfileActivity) Locale(java.util.Locale) Looper(android.os.Looper) Map(java.util.Map) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) LongSparseLongArray(org.telegram.messenger.support.LongSparseLongArray) DialogsActivity(org.telegram.ui.DialogsActivity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) Consumer(androidx.core.util.Consumer) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) LaunchActivity(org.telegram.ui.LaunchActivity) Location(android.location.Location) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) VoIPService(org.telegram.messenger.voip.VoIPService) SparseIntArray(android.util.SparseIntArray) Theme(org.telegram.ui.ActionBar.Theme) RequestDelegate(org.telegram.tgnet.RequestDelegate) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) SystemClock(android.os.SystemClock) HashMap(java.util.HashMap) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TLRPC(org.telegram.tgnet.TLRPC) TelephonyManager(android.telephony.TelephonyManager) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) EditWidgetActivity(org.telegram.ui.EditWidgetActivity) Build(android.os.Build) SQLiteException(org.telegram.SQLite.SQLiteException) SerializedData(org.telegram.tgnet.SerializedData) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) LongSparseArray(androidx.collection.LongSparseArray) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) File(java.io.File) AppWidgetManager(android.appwidget.AppWidgetManager) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) Base64(android.util.Base64) Comparator(java.util.Comparator) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) TLRPC(org.telegram.tgnet.TLRPC) SQLiteException(org.telegram.SQLite.SQLiteException) TLObject(org.telegram.tgnet.TLObject)

Example 59 with TLObject

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);
        }
    });
}
Also used : TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject)

Example 60 with TLObject

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);
}
Also used : TLObject(org.telegram.tgnet.TLObject) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

TLObject (org.telegram.tgnet.TLObject)85 TLRPC (org.telegram.tgnet.TLRPC)79 Paint (android.graphics.Paint)36 ArrayList (java.util.ArrayList)36 TextPaint (android.text.TextPaint)25 SuppressLint (android.annotation.SuppressLint)22 ConnectionsManager (org.telegram.tgnet.ConnectionsManager)22 File (java.io.File)21 HashMap (java.util.HashMap)20 Context (android.content.Context)19 Build (android.os.Build)19 TextUtils (android.text.TextUtils)19 MessageObject (org.telegram.messenger.MessageObject)19 Theme (org.telegram.ui.ActionBar.Theme)19 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)18 LongSparseArray (androidx.collection.LongSparseArray)17 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)17 Bundle (android.os.Bundle)16 SpannableStringBuilder (android.text.SpannableStringBuilder)16 ChatObject (org.telegram.messenger.ChatObject)16