Search in sources :

Example 1 with Command

use of im.actor.core.viewmodel.Command in project actor-platform by actorapp.

the class Authentication method requestStartEmailAuth.

@Deprecated
public Command<AuthState> requestStartEmailAuth(final String email) {
    return callback -> {
        ArrayList<String> langs1 = new ArrayList<>();
        for (String s : modules.getConfiguration().getPreferredLanguages()) {
            langs1.add(s);
        }
        request(new RequestStartEmailAuth(email, apiConfiguration.getAppId(), apiConfiguration.getAppKey(), deviceHash, apiConfiguration.getDeviceTitle(), modules.getConfiguration().getTimeZone(), langs1), new RpcCallback<ResponseStartEmailAuth>() {

            @Override
            public void onResult(ResponseStartEmailAuth response) {
                modules.getPreferences().putString(KEY_EMAIL, email);
                modules.getPreferences().putString(KEY_TRANSACTION_HASH, response.getTransactionHash());
                ApiEmailActivationType emailActivationType = response.getActivationType();
                if (emailActivationType.equals(ApiEmailActivationType.OAUTH2)) {
                    state = AuthState.GET_OAUTH_PARAMS;
                } else if (emailActivationType.equals(ApiEmailActivationType.CODE)) {
                    state = AuthState.CODE_VALIDATION_EMAIL;
                } else if (emailActivationType.equals(ApiEmailActivationType.PASSWORD)) {
                    state = AuthState.PASSWORD_VALIDATION;
                } else {
                    state = AuthState.CODE_VALIDATION_EMAIL;
                }
                Runtime.postToMainThread(() -> callback.onResult(state));
            }

            @Override
            public void onError(final RpcException e) {
                Runtime.postToMainThread(() -> {
                    Log.e(TAG, e);
                    callback.onError(e);
                });
            }
        });
    };
}
Also used : ApiPhoneActivationType(im.actor.core.api.ApiPhoneActivationType) ResponseStartEmailAuth(im.actor.core.api.rpc.ResponseStartEmailAuth) RequestSendCodeByPhoneCall(im.actor.core.api.rpc.RequestSendCodeByPhoneCall) RequestSignUp(im.actor.core.api.rpc.RequestSignUp) Promise(im.actor.runtime.promise.Promise) Request(im.actor.core.network.parser.Request) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ResponseStartPhoneAuth(im.actor.core.api.rpc.ResponseStartPhoneAuth) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) AuthCodeRes(im.actor.core.entity.AuthCodeRes) User(im.actor.core.entity.User) RequestGetOAuth2Params(im.actor.core.api.rpc.RequestGetOAuth2Params) Response(im.actor.core.network.parser.Response) Modules(im.actor.core.modules.Modules) im.actor.runtime(im.actor.runtime) RequestValidateCode(im.actor.core.api.rpc.RequestValidateCode) RpcCallback(im.actor.core.network.RpcCallback) ApiEmailActivationType(im.actor.core.api.ApiEmailActivationType) CommandCallback(im.actor.core.viewmodel.CommandCallback) Sex(im.actor.core.entity.Sex) RequestStartEmailAuth(im.actor.core.api.rpc.RequestStartEmailAuth) Command(im.actor.core.viewmodel.Command) AuthRes(im.actor.core.entity.AuthRes) ResponseStartUsernameAuth(im.actor.core.api.rpc.ResponseStartUsernameAuth) ApiConfiguration(im.actor.core.ApiConfiguration) ResponseGetOAuth2Params(im.actor.core.api.rpc.ResponseGetOAuth2Params) AuthStartRes(im.actor.core.entity.AuthStartRes) ResponseAuth(im.actor.core.api.rpc.ResponseAuth) IOException(java.io.IOException) AuthState(im.actor.core.AuthState) Runtime(im.actor.runtime.Runtime) RequestStartUsernameAuth(im.actor.core.api.rpc.RequestStartUsernameAuth) RpcException(im.actor.core.network.RpcException) ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint) TrustedKey(im.actor.core.network.TrustedKey) RequestStartPhoneAuth(im.actor.core.api.rpc.RequestStartPhoneAuth) ApiSex(im.actor.core.api.ApiSex) Endpoints(im.actor.core.network.Endpoints) ConnectionEndpointArray(im.actor.runtime.mtproto.ConnectionEndpointArray) ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RequestCompleteOAuth2(im.actor.core.api.rpc.RequestCompleteOAuth2) RequestValidatePassword(im.actor.core.api.rpc.RequestValidatePassword) RequestStartAnonymousAuth(im.actor.core.api.rpc.RequestStartAnonymousAuth) AuthMode(im.actor.core.entity.AuthMode) ApiEmailActivationType(im.actor.core.api.ApiEmailActivationType) RequestStartEmailAuth(im.actor.core.api.rpc.RequestStartEmailAuth) ResponseStartEmailAuth(im.actor.core.api.rpc.ResponseStartEmailAuth) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) RpcCallback(im.actor.core.network.RpcCallback)

Example 2 with Command

use of im.actor.core.viewmodel.Command in project actor-platform by actorapp.

the class AndroidMessenger method sendUri.

public Command<Boolean> sendUri(final Peer peer, final Uri uri, String appName) {
    return callback -> fileDownloader.execute(() -> {
        String[] filePathColumn = { MediaStore.Images.Media.DATA, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.TITLE };
        String picturePath;
        String mimeType;
        String fileName;
        String ext = "";
        Cursor cursor = context.getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            picturePath = cursor.getString(cursor.getColumnIndex(filePathColumn[0]));
            mimeType = cursor.getString(cursor.getColumnIndex(filePathColumn[1]));
            fileName = cursor.getString(cursor.getColumnIndex(filePathColumn[2]));
            cursor.close();
        } else {
            picturePath = uri.getPath();
            fileName = new File(uri.getPath()).getName();
            int index = fileName.lastIndexOf(".");
            if (index > 0) {
                ext = fileName.substring(index + 1);
                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
            } else {
                mimeType = "?/?";
            }
        }
        if (mimeType == null) {
            mimeType = "?/?";
        }
        if (picturePath == null || !uri.getScheme().equals("file")) {
            File externalFile = context.getExternalFilesDir(null);
            if (externalFile == null) {
                callback.onError(new NullPointerException());
                return;
            }
            String externalPath = externalFile.getAbsolutePath();
            File dest = new File(externalPath + "/" + appName + "/");
            dest.mkdirs();
            if (ext.isEmpty() && picturePath != null) {
                int index = picturePath.lastIndexOf(".");
                ext = picturePath.substring(index + 1);
            }
            File outputFile = new File(dest, "upload_" + random.nextLong() + "." + ext);
            picturePath = outputFile.getAbsolutePath();
            try {
                IOUtils.copy(context.getContentResolver().openInputStream(uri), new File(picturePath));
            } catch (IOException e) {
                e.printStackTrace();
                callback.onError(e);
                return;
            }
        }
        if (fileName == null) {
            fileName = picturePath;
        }
        if (!ext.isEmpty() && !fileName.endsWith(ext))
            fileName += "." + ext;
        if (mimeType.startsWith("video/")) {
            sendVideo(peer, picturePath, fileName);
        } else if (mimeType.startsWith("image/")) {
            sendPhoto(peer, picturePath, new File(fileName).getName());
        } else {
            sendDocument(peer, picturePath, new File(fileName).getName());
        }
        callback.onResult(true);
    });
}
Also used : FastThumb(im.actor.core.entity.content.FastThumb) GalleryScannerActor(im.actor.core.utils.GalleryScannerActor) Uri(android.net.Uri) Random(java.util.Random) PowerManager(android.os.PowerManager) AppStateActor(im.actor.core.utils.AppStateActor) ContactsContract(android.provider.ContactsContract) MediaStore(android.provider.MediaStore) Display(android.view.Display) Actor(im.actor.runtime.actors.Actor) ConnectivityManager(android.net.ConnectivityManager) EventBus(im.actor.runtime.eventbus.EventBus) ImageHelper(im.actor.core.utils.ImageHelper) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) BroadcastReceiver(android.content.BroadcastReceiver) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) Executors(java.util.concurrent.Executors) ContentObserver(android.database.ContentObserver) AppStateVM(im.actor.core.viewmodel.AppStateVM) DisplayManager(android.hardware.display.DisplayManager) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) Message(im.actor.core.entity.Message) Dialog(im.actor.core.entity.Dialog) Context(android.content.Context) MediaMetadataRetriever(android.media.MediaMetadataRetriever) ActorCreator(im.actor.runtime.actors.ActorCreator) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) AndroidContext(im.actor.runtime.android.AndroidContext) ActorSystem(im.actor.runtime.actors.ActorSystem) ActorRef(im.actor.runtime.actors.ActorRef) Build(android.os.Build) BindedDisplayList(im.actor.runtime.generic.mvvm.BindedDisplayList) Cursor(android.database.Cursor) Contact(im.actor.core.entity.Contact) SearchEntity(im.actor.core.entity.SearchEntity) Command(im.actor.core.viewmodel.Command) Executor(java.util.concurrent.Executor) IOException(java.io.IOException) Runtime(im.actor.runtime.Runtime) File(java.io.File) ShortcutBadger(me.leolin.shortcutbadger.ShortcutBadger) Bitmap(android.graphics.Bitmap) NetworkState(im.actor.core.network.NetworkState) IOUtils(im.actor.core.utils.IOUtils) GalleryVM(im.actor.core.viewmodel.GalleryVM) MimeTypeMap(android.webkit.MimeTypeMap) IOException(java.io.IOException) Cursor(android.database.Cursor) File(java.io.File)

Example 3 with Command

use of im.actor.core.viewmodel.Command in project actor-platform by actorapp.

the class Authentication method requestCompleteOauth.

@Deprecated
public Command<AuthState> requestCompleteOauth(final String code) {
    return callback -> request(new RequestCompleteOAuth2(modules.getPreferences().getString(KEY_TRANSACTION_HASH), code), new RpcCallback<ResponseAuth>() {

        @Override
        public void onResult(ResponseAuth response) {
            onLoggedIn(callback, response);
        }

        @Override
        public void onError(final RpcException e) {
            if ("EMAIL_EXPIRED".equals(e.getTag())) {
                resetAuth();
            } else if ("EMAIL_UNOCCUPIED".equals(e.getTag())) {
                state = AuthState.SIGN_UP;
                callback.onResult(AuthState.SIGN_UP);
                return;
            }
            Runtime.postToMainThread(() -> {
                Log.e(TAG, e);
                callback.onError(e);
            });
        }
    });
}
Also used : ApiPhoneActivationType(im.actor.core.api.ApiPhoneActivationType) ResponseStartEmailAuth(im.actor.core.api.rpc.ResponseStartEmailAuth) RequestSendCodeByPhoneCall(im.actor.core.api.rpc.RequestSendCodeByPhoneCall) RequestSignUp(im.actor.core.api.rpc.RequestSignUp) Promise(im.actor.runtime.promise.Promise) Request(im.actor.core.network.parser.Request) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ResponseStartPhoneAuth(im.actor.core.api.rpc.ResponseStartPhoneAuth) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) AuthCodeRes(im.actor.core.entity.AuthCodeRes) User(im.actor.core.entity.User) RequestGetOAuth2Params(im.actor.core.api.rpc.RequestGetOAuth2Params) Response(im.actor.core.network.parser.Response) Modules(im.actor.core.modules.Modules) im.actor.runtime(im.actor.runtime) RequestValidateCode(im.actor.core.api.rpc.RequestValidateCode) RpcCallback(im.actor.core.network.RpcCallback) ApiEmailActivationType(im.actor.core.api.ApiEmailActivationType) CommandCallback(im.actor.core.viewmodel.CommandCallback) Sex(im.actor.core.entity.Sex) RequestStartEmailAuth(im.actor.core.api.rpc.RequestStartEmailAuth) Command(im.actor.core.viewmodel.Command) AuthRes(im.actor.core.entity.AuthRes) ResponseStartUsernameAuth(im.actor.core.api.rpc.ResponseStartUsernameAuth) ApiConfiguration(im.actor.core.ApiConfiguration) ResponseGetOAuth2Params(im.actor.core.api.rpc.ResponseGetOAuth2Params) AuthStartRes(im.actor.core.entity.AuthStartRes) ResponseAuth(im.actor.core.api.rpc.ResponseAuth) IOException(java.io.IOException) AuthState(im.actor.core.AuthState) Runtime(im.actor.runtime.Runtime) RequestStartUsernameAuth(im.actor.core.api.rpc.RequestStartUsernameAuth) RpcException(im.actor.core.network.RpcException) ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint) TrustedKey(im.actor.core.network.TrustedKey) RequestStartPhoneAuth(im.actor.core.api.rpc.RequestStartPhoneAuth) ApiSex(im.actor.core.api.ApiSex) Endpoints(im.actor.core.network.Endpoints) ConnectionEndpointArray(im.actor.runtime.mtproto.ConnectionEndpointArray) ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RequestCompleteOAuth2(im.actor.core.api.rpc.RequestCompleteOAuth2) RequestValidatePassword(im.actor.core.api.rpc.RequestValidatePassword) RequestStartAnonymousAuth(im.actor.core.api.rpc.RequestStartAnonymousAuth) AuthMode(im.actor.core.entity.AuthMode) RequestCompleteOAuth2(im.actor.core.api.rpc.RequestCompleteOAuth2) ResponseAuth(im.actor.core.api.rpc.ResponseAuth) RpcException(im.actor.core.network.RpcException)

Example 4 with Command

use of im.actor.core.viewmodel.Command in project actor-platform by actorapp.

the class ContactsModule method removeContact.

public Command<Boolean> removeContact(final int uid) {
    return callback -> {
        User user = users().getValue(uid);
        if (user == null) {
            runOnUiThread(() -> callback.onError(new RpcInternalException()));
            return;
        }
        request(new RequestRemoveContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {

            @Override
            public void onResult(ResponseSeq response) {
                ArrayList<Integer> uids = new ArrayList<>();
                uids.add(uid);
                SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsRemoved.HEADER, new UpdateContactsRemoved(uids).toByteArray());
                updates().onUpdateReceived(update);
                runOnUiThread(() -> callback.onResult(true));
            }

            @Override
            public void onError(RpcException e) {
                runOnUiThread(() -> callback.onError(new RpcInternalException()));
            }
        });
    };
}
Also used : ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) Modules(im.actor.core.modules.Modules) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) Contact(im.actor.core.entity.Contact) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) Command(im.actor.core.viewmodel.Command) RpcInternalException(im.actor.core.network.RpcInternalException) RequestSearchContacts(im.actor.core.api.rpc.RequestSearchContacts) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved) ApiOutPeer(im.actor.core.api.ApiOutPeer) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) RpcException(im.actor.core.network.RpcException) Storage(im.actor.runtime.Storage) UserVM(im.actor.core.viewmodel.UserVM) Props(im.actor.runtime.actors.Props) RequestAddContact(im.actor.core.api.rpc.RequestAddContact) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) SeqUpdate(im.actor.core.api.base.SeqUpdate) ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) SeqUpdate(im.actor.core.api.base.SeqUpdate) RpcInternalException(im.actor.core.network.RpcInternalException) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) RpcCallback(im.actor.core.network.RpcCallback) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved)

Example 5 with Command

use of im.actor.core.viewmodel.Command in project actor-platform by actorapp.

the class ContactsModule method addContact.

public Command<Boolean> addContact(final int uid) {
    return callback -> {
        User user = users().getValue(uid);
        if (user == null) {
            runOnUiThread(() -> callback.onError(new RpcInternalException()));
            return;
        }
        request(new RequestAddContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {

            @Override
            public void onResult(ResponseSeq response) {
                ArrayList<Integer> uids = new ArrayList<>();
                uids.add(uid);
                SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray());
                updates().onUpdateReceived(update);
                runOnUiThread(() -> callback.onResult(true));
            }

            @Override
            public void onError(RpcException e) {
                runOnUiThread(() -> callback.onError(new RpcInternalException()));
            }
        });
    };
}
Also used : ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) Modules(im.actor.core.modules.Modules) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) Contact(im.actor.core.entity.Contact) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) Command(im.actor.core.viewmodel.Command) RpcInternalException(im.actor.core.network.RpcInternalException) RequestSearchContacts(im.actor.core.api.rpc.RequestSearchContacts) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved) ApiOutPeer(im.actor.core.api.ApiOutPeer) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) RpcException(im.actor.core.network.RpcException) Storage(im.actor.runtime.Storage) UserVM(im.actor.core.viewmodel.UserVM) Props(im.actor.runtime.actors.Props) RequestAddContact(im.actor.core.api.rpc.RequestAddContact) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) SeqUpdate(im.actor.core.api.base.SeqUpdate) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) SeqUpdate(im.actor.core.api.base.SeqUpdate) RpcInternalException(im.actor.core.network.RpcInternalException) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) RpcCallback(im.actor.core.network.RpcCallback) RequestAddContact(im.actor.core.api.rpc.RequestAddContact)

Aggregations

Command (im.actor.core.viewmodel.Command)5 User (im.actor.core.entity.User)4 AbsModule (im.actor.core.modules.AbsModule)4 Modules (im.actor.core.modules.Modules)4 RpcCallback (im.actor.core.network.RpcCallback)4 RpcException (im.actor.core.network.RpcException)4 Contact (im.actor.core.entity.Contact)3 Runtime (im.actor.runtime.Runtime)3 ActorRef (im.actor.runtime.actors.ActorRef)3 ActorSystem.system (im.actor.runtime.actors.ActorSystem.system)3 Props (im.actor.runtime.actors.Props)3 Promise (im.actor.runtime.promise.Promise)3 ArrayList (java.util.ArrayList)3 ApiOutPeer (im.actor.core.api.ApiOutPeer)2 ApiUser (im.actor.core.api.ApiUser)2 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)2 SeqUpdate (im.actor.core.api.base.SeqUpdate)2 RequestAddContact (im.actor.core.api.rpc.RequestAddContact)2 RequestRemoveContact (im.actor.core.api.rpc.RequestRemoveContact)2 RequestSearchContacts (im.actor.core.api.rpc.RequestSearchContacts)2