Search in sources :

Example 1 with JoinCallByUrlAlert

use of org.telegram.ui.Components.JoinCallByUrlAlert in project Telegram-FOSS by Telegram-FOSS-Team.

the class VoIPHelper method doInitiateCall.

private static void doInitiateCall(TLRPC.User user, TLRPC.Chat chat, String hash, TLRPC.InputPeer peer, boolean hasFewPeers, boolean videoCall, boolean canVideoCall, boolean createCall, Activity activity, BaseFragment fragment, AccountInstance accountInstance, boolean checkJoiner, boolean checkAnonymous) {
    if (activity == null || user == null && chat == null) {
        return;
    }
    if (SystemClock.elapsedRealtime() - lastCallTime < (chat != null ? 200 : 2000)) {
        return;
    }
    if (checkJoiner && chat != null && !createCall) {
        TLRPC.ChatFull chatFull = accountInstance.getMessagesController().getChatFull(chat.id);
        if (chatFull != null && chatFull.groupcall_default_join_as != null) {
            long did = MessageObject.getPeerId(chatFull.groupcall_default_join_as);
            TLRPC.InputPeer inputPeer = accountInstance.getMessagesController().getInputPeer(did);
            JoinCallAlert.checkFewUsers(activity, -chat.id, accountInstance, param -> {
                if (!param && hash != null) {
                    JoinCallByUrlAlert alert = new JoinCallByUrlAlert(activity, chat) {

                        @Override
                        protected void onJoin() {
                            doInitiateCall(user, chat, hash, inputPeer, true, videoCall, canVideoCall, false, activity, fragment, accountInstance, false, false);
                        }
                    };
                    if (fragment != null) {
                        fragment.showDialog(alert);
                    }
                } else {
                    doInitiateCall(user, chat, hash, inputPeer, !param, videoCall, canVideoCall, false, activity, fragment, accountInstance, false, false);
                }
            });
            return;
        }
    }
    if (checkJoiner && chat != null) {
        JoinCallAlert.open(activity, -chat.id, accountInstance, fragment, createCall ? JoinCallAlert.TYPE_CREATE : JoinCallAlert.TYPE_JOIN, null, (selectedPeer, hasFew, schedule) -> {
            if (createCall && schedule) {
                GroupCallActivity.create((LaunchActivity) activity, accountInstance, chat, selectedPeer, hasFew, hash);
            } else if (!hasFew && hash != null) {
                JoinCallByUrlAlert alert = new JoinCallByUrlAlert(activity, chat) {

                    @Override
                    protected void onJoin() {
                        doInitiateCall(user, chat, hash, selectedPeer, false, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, false, true);
                    }
                };
                if (fragment != null) {
                    fragment.showDialog(alert);
                }
            } else {
                doInitiateCall(user, chat, hash, selectedPeer, hasFew, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, false, true);
            }
        });
        return;
    }
    if (checkAnonymous && !hasFewPeers && peer instanceof TLRPC.TL_inputPeerUser && ChatObject.shouldSendAnonymously(chat) && (!ChatObject.isChannel(chat) || chat.megagroup)) {
        new AlertDialog.Builder(activity).setTitle(ChatObject.isChannelOrGiga(chat) ? LocaleController.getString("VoipChannelVoiceChat", R.string.VoipChannelVoiceChat) : LocaleController.getString("VoipGroupVoiceChat", R.string.VoipGroupVoiceChat)).setMessage(ChatObject.isChannelOrGiga(chat) ? LocaleController.getString("VoipChannelJoinAnonymouseAlert", R.string.VoipChannelJoinAnonymouseAlert) : LocaleController.getString("VoipGroupJoinAnonymouseAlert", R.string.VoipGroupJoinAnonymouseAlert)).setPositiveButton(LocaleController.getString("VoipChatJoin", R.string.VoipChatJoin), (dialog, which) -> doInitiateCall(user, chat, hash, peer, false, videoCall, canVideoCall, createCall, activity, fragment, accountInstance, false, false)).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).show();
        return;
    }
    if (chat != null && peer != null) {
        TLRPC.ChatFull chatFull = accountInstance.getMessagesController().getChatFull(chat.id);
        if (chatFull != null) {
            if (peer instanceof TLRPC.TL_inputPeerUser) {
                chatFull.groupcall_default_join_as = new TLRPC.TL_peerUser();
                chatFull.groupcall_default_join_as.user_id = peer.user_id;
            } else if (peer instanceof TLRPC.TL_inputPeerChat) {
                chatFull.groupcall_default_join_as = new TLRPC.TL_peerChat();
                chatFull.groupcall_default_join_as.chat_id = peer.chat_id;
            } else if (peer instanceof TLRPC.TL_inputPeerChannel) {
                chatFull.groupcall_default_join_as = new TLRPC.TL_peerChannel();
                chatFull.groupcall_default_join_as.channel_id = peer.channel_id;
            }
            if (chatFull instanceof TLRPC.TL_chatFull) {
                chatFull.flags |= 32768;
            } else {
                chatFull.flags |= 67108864;
            }
        }
    }
    if (chat != null && !createCall) {
        ChatObject.Call call = accountInstance.getMessagesController().getGroupCall(chat.id, false);
        if (call != null && call.isScheduled()) {
            GroupCallActivity.create((LaunchActivity) activity, accountInstance, chat, peer, hasFewPeers, hash);
            return;
        }
    }
    lastCallTime = SystemClock.elapsedRealtime();
    Intent intent = new Intent(activity, VoIPService.class);
    if (user != null) {
        intent.putExtra("user_id", user.id);
    } else {
        intent.putExtra("chat_id", chat.id);
        intent.putExtra("createGroupCall", createCall);
        intent.putExtra("hasFewPeers", hasFewPeers);
        intent.putExtra("hash", hash);
        if (peer != null) {
            intent.putExtra("peerChannelId", peer.channel_id);
            intent.putExtra("peerChatId", peer.chat_id);
            intent.putExtra("peerUserId", peer.user_id);
            intent.putExtra("peerAccessHash", peer.access_hash);
        }
    }
    intent.putExtra("is_outgoing", true);
    intent.putExtra("start_incall_activity", true);
    intent.putExtra("video_call", Build.VERSION.SDK_INT >= 18 && videoCall);
    intent.putExtra("can_video_call", Build.VERSION.SDK_INT >= 18 && canVideoCall);
    intent.putExtra("account", UserConfig.selectedAccount);
    try {
        activity.startService(intent);
    } catch (Throwable e) {
        FileLog.e(e);
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatObject(org.telegram.messenger.ChatObject) Intent(android.content.Intent) TLRPC(org.telegram.tgnet.TLRPC) JoinCallByUrlAlert(org.telegram.ui.Components.JoinCallByUrlAlert)

Aggregations

Intent (android.content.Intent)1 ChatObject (org.telegram.messenger.ChatObject)1 TLRPC (org.telegram.tgnet.TLRPC)1 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)1 JoinCallByUrlAlert (org.telegram.ui.Components.JoinCallByUrlAlert)1