Search in sources :

Example 1 with Void

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

the class JsFacade method deleteChat.

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

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

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

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "deleteChat: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)

Example 2 with Void

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

the class JsFacade method archiveChat.

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

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

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

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "archiveChat: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)

Example 3 with Void

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

the class JsFacade method terminateSession.

@UsedByApp
public JsPromise terminateSession(final int id) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.terminateSession(id).start(new CommandCallback<Void>() {

                @Override
                public void onResult(Void res) {
                    resolve();
                }

                @Override
                public void onError(Exception e) {
                    Log.e(TAG, e);
                    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)

Example 4 with Void

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

the class JsFacade method terminateAllSessions.

@UsedByApp
public JsPromise terminateAllSessions() {
    return JsPromise.create(new JsPromiseExecutor() {

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

                @Override
                public void onResult(Void res) {
                    resolve();
                }

                @Override
                public void onError(Exception e) {
                    Log.e(TAG, e);
                    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)

Example 5 with Void

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

the class ContactsSyncActor method performSync.

public void performSync() {
    if (ENABLE_LOG) {
        Log.d(TAG, "Checking sync");
    }
    if (isInProgress) {
        if (ENABLE_LOG) {
            Log.d(TAG, "Sync in progress, invalidating current sync");
        }
        isInvalidated = true;
        return;
    }
    isInProgress = true;
    isInvalidated = false;
    if (ENABLE_LOG) {
        Log.d(TAG, "Starting sync");
    }
    Integer[] uids = contacts.toArray(new Integer[contacts.size()]);
    Arrays.sort(uids);
    String hash = "";
    for (long u : uids) {
        if (hash.length() != 0) {
            hash += ",";
        }
        hash += u;
    }
    byte[] hashData;
    try {
        hashData = hash.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return;
    }
    String hashValue = Crypto.hex(Crypto.SHA256(hashData));
    if (ENABLE_LOG) {
        Log.d(TAG, "Performing sync with hash: " + hashValue);
        Log.d(TAG, "Performing sync with uids: " + hash);
    }
    request(new RequestGetContacts(hashValue, ApiSupportConfiguration.OPTIMIZATIONS), new RpcCallback<ResponseGetContacts>() {

        @Override
        public void onResult(ResponseGetContacts response) {
            if (ENABLE_LOG) {
                Log.d(TAG, "Sync received " + (response.getUsers().size() + response.getUserPeers().size()) + " contacts");
            }
            if (response.getUserPeers().size() > 0) {
                updates().loadRequiredPeers(response.getUserPeers(), new ArrayList<>()).then(v -> onContactsLoaded(response));
            } else {
                updates().applyRelatedData(response.getUsers()).then(v -> onContactsLoaded(response));
            }
        }

        @Override
        public void onError(RpcException e) {
            isInProgress = false;
            e.printStackTrace();
        }
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ModuleContext(im.actor.core.modules.ModuleContext) Arrays(java.util.Arrays) Void(im.actor.runtime.actors.messages.Void) ResponseGetContacts(im.actor.core.api.rpc.ResponseGetContacts) IOException(java.io.IOException) ApiUser(im.actor.core.api.ApiUser) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataInput(im.actor.runtime.bser.DataInput) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) User(im.actor.core.entity.User) RequestGetContacts(im.actor.core.api.rpc.RequestGetContacts) DataOutput(im.actor.runtime.bser.DataOutput) RpcCallback(im.actor.core.network.RpcCallback) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Log(im.actor.runtime.Log) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) Contact(im.actor.core.entity.Contact) Crypto(im.actor.runtime.Crypto) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestGetContacts(im.actor.core.api.rpc.RequestGetContacts) RpcException(im.actor.core.network.RpcException) ResponseGetContacts(im.actor.core.api.rpc.ResponseGetContacts)

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