Search in sources :

Example 16 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class BookImportActor method performImportIfRequired.

private void performImportIfRequired() {
    if (ENABLE_LOG) {
        Log.d(TAG, "performImportIfRequired called");
    }
    if (isUploadingContacts) {
        if (ENABLE_LOG) {
            Log.d(TAG, "performImportIfRequired:exiting:already importing");
        }
        return;
    }
    if (importQueue.size() == 0) {
        if (ENABLE_LOG) {
            Log.d(TAG, "performImportIfRequired:exiting:nothing to import");
        }
        // Marking as everything is imported
        context().getConductor().getConductor().onPhoneBookImported();
        return;
    }
    // 
    // Performing import
    // 
    isUploadingContacts = true;
    final ArrayList<ApiPhoneToImport> phoneToImports = new ArrayList<>();
    final ArrayList<ApiEmailToImport> emailToImports = new ArrayList<>();
    for (int i = 0; i < MAX_IMPORT_SIZE && importQueue.size() > 0; i++) {
        ImportQueueItem importQueueItem = importQueue.remove(0);
        if (importQueueItem instanceof ImportEmailQueueItem) {
            emailToImports.add(new ApiEmailToImport(((ImportEmailQueueItem) importQueueItem).getEmail(), ((ImportEmailQueueItem) importQueueItem).getName()));
        } else if (importQueueItem instanceof ImportPhoneQueueItem) {
            phoneToImports.add(new ApiPhoneToImport(((ImportPhoneQueueItem) importQueueItem).getPhoneNumber(), ((ImportPhoneQueueItem) importQueueItem).getName()));
        } else {
            throw new RuntimeException();
        }
    }
    request(new RequestImportContacts(phoneToImports, emailToImports, ApiSupportConfiguration.OPTIMIZATIONS), new RpcCallback<ResponseImportContacts>() {

        @Override
        public void onResult(ResponseImportContacts response) {
            for (ApiPhoneToImport phoneToImport : phoneToImports) {
                storage.markAsImported(phoneToImport.getPhoneNumber());
                importingPhones.remove(phoneToImport.getPhoneNumber());
            }
            for (ApiEmailToImport emailToImport : emailToImports) {
                storage.markAsImported(emailToImport.getEmail());
                importingEmails.remove(emailToImport.getEmail());
            }
            context().getContactsModule().getBookImportState().put(0, storage.toByteArray());
            // 
            if (response.getUsers().size() != 0 || response.getUserPeers().size() != 0) {
                if (ENABLE_LOG) {
                    Log.d(TAG, "Import success with " + (response.getUsers().size() + response.getUserPeers().size()) + " new contacts");
                }
                if (response.getUserPeers().size() != 0) {
                    // Optimized version
                    ArrayList<Integer> uids = new ArrayList<>();
                    for (ApiUserOutPeer u : response.getUserPeers()) {
                        uids.add(u.getUid());
                    }
                    updates().loadRequiredPeers(response.getUserPeers(), new ArrayList<>()).flatMap(v -> updates().applyUpdate(response.getSeq(), response.getState(), new UpdateContactsAdded(uids)));
                } else {
                    // Old version
                    ArrayList<Integer> uids = new ArrayList<>();
                    for (ApiUser u : response.getUsers()) {
                        uids.add(u.getId());
                    }
                    updates().onUpdateReceived(new FatSeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray(), response.getUsers(), new ArrayList<>()));
                }
            } else {
                if (ENABLE_LOG) {
                    Log.d(TAG, "Import success, but no new contacts found");
                }
            }
            // 
            // Launching next iteration
            // 
            isUploadingContacts = false;
            performImportIfRequired();
        }

        @Override
        public void onError(RpcException e) {
            // TODO: Better error handling
            if (ENABLE_LOG) {
                Log.d(TAG, "Import failure");
            }
            e.printStackTrace();
            // 
            // Launching next iteration
            // 
            isUploadingContacts = false;
            performImportIfRequired();
        }
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ApiEmailToImport(im.actor.core.api.ApiEmailToImport) ModuleContext(im.actor.core.modules.ModuleContext) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) Void(im.actor.runtime.actors.messages.Void) Bser(im.actor.runtime.bser.Bser) ApiPhoneToImport(im.actor.core.api.ApiPhoneToImport) PhoneBookContact(im.actor.core.entity.PhoneBookContact) PhoneBookIds(im.actor.core.entity.PhoneBookIds) ApiUser(im.actor.core.api.ApiUser) FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) ResponseImportContacts(im.actor.core.api.rpc.ResponseImportContacts) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestImportContacts(im.actor.core.api.rpc.RequestImportContacts) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) BookImportStorage(im.actor.core.modules.contacts.entity.BookImportStorage) RpcCallback(im.actor.core.network.RpcCallback) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Log(im.actor.runtime.Log) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) ApiPhoneToImport(im.actor.core.api.ApiPhoneToImport) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) ResponseImportContacts(im.actor.core.api.rpc.ResponseImportContacts) ApiEmailToImport(im.actor.core.api.ApiEmailToImport) RpcException(im.actor.core.network.RpcException) RequestImportContacts(im.actor.core.api.rpc.RequestImportContacts)

Example 17 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class PeerConnectionActor method preStart.

@Override
public void preStart() {
    isReady = false;
    WebRTCIceServer[] rtcIceServers = ManagedList.of(iceServers).map(apiICEServer -> new WebRTCIceServer(apiICEServer.getUrl(), apiICEServer.getUsername(), apiICEServer.getCredential())).toArray(new WebRTCIceServer[0]);
    WebRTCSettings settings = new WebRTCSettings(false, false, config().isVideoCallsEnabled());
    WebRTC.createPeerConnection(rtcIceServers, settings).then(webRTCPeerConnection -> {
        PeerConnectionActor.this.peerConnection = webRTCPeerConnection;
        PeerConnectionActor.this.peerConnection.addOwnStream(userMedia);
        PeerConnectionActor.this.peerConnection.addCallback(new WebRTCPeerConnectionCallback() {

            @Override
            public void onCandidate(int label, String id, String candidate) {
                if (sessionId != -1) {
                    callback.onCandidate(sessionId, label, id, candidate);
                }
            }

            @Override
            public void onRenegotiationNeeded() {
            // if (sessionId != -1) {
            // callback.onNegotiationNeeded(sessionId);
            // }
            }

            @Override
            public void onStreamAdded(WebRTCMediaStream addedStream) {
                // by parent actor
                for (WebRTCMediaTrack track : addedStream.getAudioTracks()) {
                    track.setEnabled(false);
                }
                for (WebRTCMediaTrack track : addedStream.getVideoTracks()) {
                    track.setEnabled(false);
                }
                callback.onStreamAdded(addedStream);
            }

            @Override
            public void onStreamRemoved(WebRTCMediaStream removedStream) {
                callback.onStreamRemoved(removedStream);
            }

            @Override
            public void onDisposed() {
            }
        });
        state = PeerConnectionState.WAITING_HANDSHAKE;
        onReady();
    }).failure(e -> {
        Log.d(TAG, "preStart:error");
        e.printStackTrace();
        onHandshakeFailure();
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTC(im.actor.runtime.WebRTC) CountedReference(im.actor.runtime.function.CountedReference) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) ActorCreator(im.actor.runtime.actors.ActorCreator) Void(im.actor.runtime.actors.messages.Void) ApiICEServer(im.actor.core.api.ApiICEServer) Promise(im.actor.runtime.promise.Promise) AskMessage(im.actor.runtime.actors.ask.AskMessage) ManagedList(im.actor.runtime.collections.ManagedList) WebRTCPeerConnection(im.actor.runtime.webrtc.WebRTCPeerConnection) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription) Property(com.google.j2objc.annotations.Property) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream)

Example 18 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class PeerConnectionActor method onOffer.

public void onOffer(final long sessionId, @NotNull String sdp) {
    // Ignore if we are not waiting for handshake
    if (state != PeerConnectionState.WAITING_HANDSHAKE) {
        return;
    }
    // Ignore if we already have session id
    if (this.sessionId != -1) {
        return;
    }
    // 
    // Stages
    // 1. Set Remote Description
    // 2. Create Answer
    // 3. Set Local Description
    // 4. Send Answer
    // 5. Enter READY mode
    // 
    isReady = false;
    peerConnection.setRemoteDescription(new WebRTCSessionDescription("offer", sdp)).flatMap(description -> {
        return peerConnection.createAnswer();
    }).flatMap(webRTCSessionDescription -> {
        return peerConnection.setLocalDescription(SDPOptimizer.optimize(webRTCSessionDescription));
    }).then(webRTCSessionDescription -> {
        callback.onAnswer(sessionId, webRTCSessionDescription.getSdp());
        PeerConnectionActor.this.sessionId = sessionId;
        onHandShakeCompleted(sessionId);
        onReady();
    }).failure(e -> {
        e.printStackTrace();
        onHandshakeFailure();
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTC(im.actor.runtime.WebRTC) CountedReference(im.actor.runtime.function.CountedReference) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) ActorCreator(im.actor.runtime.actors.ActorCreator) Void(im.actor.runtime.actors.messages.Void) ApiICEServer(im.actor.core.api.ApiICEServer) Promise(im.actor.runtime.promise.Promise) AskMessage(im.actor.runtime.actors.ask.AskMessage) ManagedList(im.actor.runtime.collections.ManagedList) WebRTCPeerConnection(im.actor.runtime.webrtc.WebRTCPeerConnection) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription) Property(com.google.j2objc.annotations.Property) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription)

Example 19 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class SecuritySettingsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fr_settings_encryption, container, false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    res.findViewById(R.id.big_divider).setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
    ((TextView) res.findViewById(R.id.security_settings_title)).setTextColor(ActorSDK.sharedActor().style.getSettingsMainTitleColor());
    loading = (TextView) res.findViewById(R.id.loading);
    loading.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    loading.setVisibility(View.GONE);
    loading.setOnClickListener(v -> performLoad());
    authItems = (LinearLayout) res.findViewById(R.id.authItems);
    ((TextView) res.findViewById(R.id.settings_last_seen_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    ((TextView) res.findViewById(R.id.settings_last_seen_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    res.findViewById(R.id.lastSeen).setOnClickListener(v -> {
        String[] itemsValues = new String[] { "always", "contacts", "none" };
        String[] items = new String[] { getString(R.string.security_last_seen_everybody), getString(R.string.security_last_seen_contacts), getString(R.string.security_last_seen_nobody) };
        int currentLastSeen = Arrays.asList(itemsValues).indexOf(messenger().getPrivacy());
        new AlertDialog.Builder(getActivity()).setTitle(R.string.security_last_seen_title).setSingleChoiceItems(items, currentLastSeen, (dialog, which) -> {
            messenger().setPrivacy(itemsValues[which]);
            dialog.dismiss();
        }).setNegativeButton(R.string.dialog_cancel, null).setPositiveButton(R.string.dialog_ok, null).show();
    });
    res.findViewById(R.id.terminateSessions).setOnClickListener(v -> new AlertDialog.Builder(getActivity()).setMessage(R.string.security_terminate_message).setPositiveButton(R.string.dialog_yes, (dialog, which) -> execute(messenger().terminateAllSessions(), R.string.progress_common, new CommandCallback<Void>() {

        @Override
        public void onResult(Void res1) {
            performLoad();
        }

        @Override
        public void onError(Exception e) {
            performLoad();
            Toast.makeText(getActivity(), R.string.security_toast_unable_remove_auth, Toast.LENGTH_SHORT).show();
        }
    })).setNegativeButton(R.string.dialog_no, null).show().setCanceledOnTouchOutside(true));
    ((TextView) res.findViewById(R.id.settings_terminate_sessions_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    ((TextView) res.findViewById(R.id.settings_terminate_sessions_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    performLoad();
    return res;
}
Also used : AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) ActorSDK(im.actor.sdk.ActorSDK) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) Void(im.actor.runtime.actors.messages.Void) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) AlertDialog(android.app.AlertDialog) List(java.util.List) R(im.actor.sdk.R) TextView(android.widget.TextView) Toast(android.widget.Toast) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Collections(java.util.Collections) ApiAuthSession(im.actor.core.api.ApiAuthSession) ApiAuthHolder(im.actor.core.api.ApiAuthHolder) TextView(android.widget.TextView) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void) TextView(android.widget.TextView) View(android.view.View)

Example 20 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class JsFacade method unfavoriteChat.

@UsedByApp
public JsPromise unfavoriteChat(final JsPeer peer) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.unfavoriteChat(peer.convert()).start(new CommandCallback<Void>() {

                @Override
                public void onResult(Void res) {
                    Log.d(TAG, "unfavouriteChat:result");
                    resolve();
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "unfavouriteChat:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Aggregations

Void (im.actor.runtime.actors.messages.Void)37 ModuleContext (im.actor.core.modules.ModuleContext)16 ModuleActor (im.actor.core.modules.ModuleActor)15 RpcException (im.actor.core.network.RpcException)15 CommandCallback (im.actor.core.viewmodel.CommandCallback)15 ArrayList (java.util.ArrayList)15 List (java.util.List)13 Log (im.actor.runtime.Log)12 Promise (im.actor.runtime.promise.Promise)11 Peer (im.actor.core.entity.Peer)10 UsedByApp (im.actor.core.js.annotations.UsedByApp)9 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)9 Message (im.actor.core.entity.Message)8 UserVM (im.actor.core.viewmodel.UserVM)8 Update (im.actor.core.network.parser.Update)7 HashSet (java.util.HashSet)7 Group (im.actor.core.entity.Group)6 User (im.actor.core.entity.User)6 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)6 AlertDialog (android.app.AlertDialog)5