Search in sources :

Example 6 with Promise

use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.

the class JsFileInput method read.

@Override
public Promise<FilePart> read(int fileOffset, int len) {
    return new Promise<>(resolver -> {
        JsFileReader fileReader = JsFileReader.create();
        fileReader.setOnLoaded(message -> {
            Uint8Array array = TypedArrays.createUint8Array(message);
            byte[] data = new byte[len];
            for (int i = 0; i < len; i++) {
                data[i] = (byte) (array.get(i));
            }
            resolver.result(new FilePart(fileOffset, len, data));
        });
        fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
    });
}
Also used : Promise(im.actor.runtime.promise.Promise) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) FilePart(im.actor.runtime.files.FilePart)

Example 7 with Promise

use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.

the class AskcableActor method onReceive.

@Override
public void onReceive(Object message) {
    if (message instanceof AskIntRequest) {
        AskIntRequest askRequest = (AskIntRequest) message;
        try {
            Promise p = onAsk(askRequest.getMessage());
            if (p == null) {
                // Just ignore. We assume that message is stashed
                return;
            }
            p.pipeTo(askRequest.getFuture());
        } catch (Exception e) {
            e.printStackTrace();
            askRequest.getFuture().tryError(e);
        }
    } else {
        super.onReceive(message);
    }
}
Also used : Promise(im.actor.runtime.promise.Promise) AskIntRequest(im.actor.runtime.actors.ask.AskIntRequest)

Example 8 with Promise

use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.

the class BaseActivity method execute.

public <T> void execute(Promise<T> promise, int title) {
    final ProgressDialog dialog = ProgressDialog.show(this, "", getString(title), true, false);
    promise.then(t -> dismissDialog(dialog)).failure(e -> dismissDialog(dialog));
}
Also used : Bundle(android.os.Bundle) ValueDoubleChangedListener(im.actor.runtime.mvvm.ValueDoubleChangedListener) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Promise(im.actor.runtime.promise.Promise) ColorDrawable(android.graphics.drawable.ColorDrawable) GroupVM(im.actor.core.viewmodel.GroupVM) Avatar(im.actor.core.entity.Avatar) AvatarView(im.actor.sdk.view.avatar.AvatarView) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) ActionBar(android.support.v7.app.ActionBar) Command(im.actor.core.viewmodel.Command) ActorSDK(im.actor.sdk.ActorSDK) ProgressDialog(android.app.ProgressDialog) AppCompatActivity(android.support.v7.app.AppCompatActivity) ActorBinder(im.actor.sdk.controllers.ActorBinder) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) BiFunction(im.actor.runtime.function.BiFunction) ActorStyle(im.actor.sdk.ActorStyle) Function(im.actor.runtime.function.Function) ValueChangedListener(im.actor.runtime.mvvm.ValueChangedListener) Value(im.actor.runtime.mvvm.Value) ProgressDialog(android.app.ProgressDialog)

Example 9 with Promise

use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.

the class GroupUsersFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.done) {
        if (isChannel) {
            if (getSelectedCount() > 0) {
                Promise invites = null;
                for (int uid : getSelected()) {
                    if (invites == null) {
                        invites = messenger().inviteMemberPromise(gid, uid);
                    } else {
                        invites.chain(o -> messenger().inviteMemberPromise(gid, uid));
                    }
                }
                execute(invites.then(o -> openChannel()), R.string.progress_common);
            } else {
                openChannel();
            }
        } else {
            if (getSelectedCount() > 0) {
                execute(messenger().createGroup(title, avatarPath, BoxUtil.unbox(getSelected())).then(gid -> {
                    getActivity().startActivity(Intents.openGroupDialog(gid, true, getActivity()));
                    getActivity().finish();
                }).failure(e -> {
                    Toast.makeText(getActivity(), getString(R.string.toast_unable_create_group), Toast.LENGTH_LONG).show();
                }));
            }
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Bundle(android.os.Bundle) Spanned(android.text.Spanned) UserSpan(im.actor.sdk.controllers.compose.view.UserSpan) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Spannable(android.text.Spannable) Promise(im.actor.runtime.promise.Promise) BoxUtil(im.actor.sdk.util.BoxUtil) Editable(android.text.Editable) MenuItem(android.view.MenuItem) Screen(im.actor.sdk.util.Screen) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Contact(im.actor.core.entity.Contact) Intents(im.actor.sdk.controllers.Intents) ActorSDK(im.actor.sdk.ActorSDK) SpannableString(android.text.SpannableString) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) ViewGroup(android.view.ViewGroup) Consumer(im.actor.runtime.function.Consumer) R(im.actor.sdk.R) BaseContactFragment(im.actor.sdk.controllers.contacts.BaseContactFragment) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Promise(im.actor.runtime.promise.Promise)

Example 10 with Promise

use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.

the class MessagesModule method updateMessage.

public Promise<Void> updateMessage(final Peer peer, final String message, final long rid) {
    context().getTypingModule().onMessageSent(peer);
    ArrayList<Integer> mentions = new ArrayList<>();
    TextContent content = TextContent.create(message, null, mentions);
    if (peer.getPeerType() == PeerType.GROUP) {
        Group group = groups().getValue(peer.getPeerId());
        String lowText = message.toLowerCase();
        for (GroupMember member : group.getMembers()) {
            User user = users().getValue(member.getUid());
            if (user.getNick() != null) {
                String nick = "@" + user.getNick().toLowerCase();
                // TODO: Better filtering
                if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
                    mentions.add(user.getUid());
                }
            }
        }
    }
    ApiMessage editMessage = new ApiTextMessage(message, content.getMentions(), content.getTextMessageEx());
    return buildOutPeer(peer).flatMap(apiOutPeer -> api(new RequestUpdateMessage(apiOutPeer, rid, editMessage))).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateMessageContentChanged(new ApiPeer(peer.getPeerType().toApi(), peer.getPeerId()), rid, editMessage)));
}
Also used : RequestMessageSetReaction(im.actor.core.api.rpc.RequestMessageSetReaction) DialogsInt(im.actor.core.modules.messaging.dialogs.DialogsInt) ModuleContext(im.actor.core.modules.ModuleContext) ConversationVM(im.actor.core.viewmodel.ConversationVM) FastThumb(im.actor.core.entity.content.FastThumb) RequestDeleteChat(im.actor.core.api.rpc.RequestDeleteChat) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) DialogGroupsVM(im.actor.core.viewmodel.DialogGroupsVM) ResponseReactionsResponse(im.actor.core.api.rpc.ResponseReactionsResponse) JsonContent(im.actor.core.entity.content.JsonContent) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) RouterInt(im.actor.core.modules.messaging.router.RouterInt) RequestFavouriteDialog(im.actor.core.api.rpc.RequestFavouriteDialog) RequestUnfavouriteDialog(im.actor.core.api.rpc.RequestUnfavouriteDialog) Actor(im.actor.runtime.actors.Actor) ApiPeer(im.actor.core.api.ApiPeer) CommandCallback(im.actor.core.viewmodel.CommandCallback) MessageDeleteActor(im.actor.core.modules.messaging.actions.MessageDeleteActor) TextContent(im.actor.core.entity.content.TextContent) Sticker(im.actor.core.entity.Sticker) RpcInternalException(im.actor.core.network.RpcInternalException) ApiTextMessage(im.actor.core.api.ApiTextMessage) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) Void(im.actor.runtime.actors.messages.Void) ResponseDialogsOrder(im.actor.core.api.rpc.ResponseDialogsOrder) GroupMember(im.actor.core.entity.GroupMember) ArchivedDialogsActor(im.actor.core.modules.messaging.history.ArchivedDialogsActor) ApiOutPeer(im.actor.core.api.ApiOutPeer) MVVMCollection(im.actor.runtime.mvvm.MVVMCollection) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) DialogsHistoryActor(im.actor.core.modules.messaging.history.DialogsHistoryActor) Nullable(org.jetbrains.annotations.Nullable) CursorReceiverActor(im.actor.core.modules.messaging.actions.CursorReceiverActor) PromiseResolver(im.actor.runtime.promise.PromiseResolver) RequestClearChat(im.actor.core.api.rpc.RequestClearChat) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) Message(im.actor.core.entity.Message) Dialog(im.actor.core.entity.Dialog) NotNull(org.jetbrains.annotations.NotNull) Function(im.actor.runtime.function.Function) ApiPeerType(im.actor.core.api.ApiPeerType) RequestArchiveChat(im.actor.core.api.rpc.RequestArchiveChat) RequestUpdateMessage(im.actor.core.api.rpc.RequestUpdateMessage) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestMessageRemoveReaction(im.actor.core.api.rpc.RequestMessageRemoveReaction) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ActorCreator(im.actor.runtime.actors.ActorCreator) Promise(im.actor.runtime.promise.Promise) HashMap(java.util.HashMap) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ArrayList(java.util.ArrayList) ConversationState(im.actor.core.entity.ConversationState) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) BusSubscriber(im.actor.runtime.eventbus.BusSubscriber) ConversationHistoryActor(im.actor.core.modules.messaging.history.ConversationHistoryActor) PeerChatOpened(im.actor.core.events.PeerChatOpened) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) PeerType(im.actor.core.entity.PeerType) Command(im.actor.core.viewmodel.Command) ConversationHistory(im.actor.core.modules.messaging.history.ConversationHistory) AbsContent(im.actor.core.entity.content.AbsContent) PeerChatPreload(im.actor.core.events.PeerChatPreload) ApiMessage(im.actor.core.api.ApiMessage) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) CursorReaderActor(im.actor.core.modules.messaging.actions.CursorReaderActor) Storage(im.actor.runtime.Storage) DialogsActor(im.actor.core.modules.messaging.dialogs.DialogsActor) SenderActor(im.actor.core.modules.messaging.actions.SenderActor) FileSystemReference(im.actor.runtime.files.FileSystemReference) ResponseLoadArchived(im.actor.core.api.rpc.ResponseLoadArchived) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) Event(im.actor.runtime.eventbus.Event) SeqUpdate(im.actor.core.api.base.SeqUpdate) Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) User(im.actor.core.entity.User) ApiTextMessage(im.actor.core.api.ApiTextMessage) ArrayList(java.util.ArrayList) ApiMessage(im.actor.core.api.ApiMessage) TextContent(im.actor.core.entity.content.TextContent) RequestUpdateMessage(im.actor.core.api.rpc.RequestUpdateMessage) ApiPeer(im.actor.core.api.ApiPeer)

Aggregations

Promise (im.actor.runtime.promise.Promise)19 Function (im.actor.runtime.function.Function)10 ArrayList (java.util.ArrayList)9 ModuleContext (im.actor.core.modules.ModuleContext)8 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)7 User (im.actor.core.entity.User)7 Void (im.actor.runtime.actors.messages.Void)7 List (java.util.List)7 Peer (im.actor.core.entity.Peer)6 ModuleActor (im.actor.core.modules.ModuleActor)6 Tuple2 (im.actor.runtime.function.Tuple2)6 Update (im.actor.core.network.parser.Update)5 Log (im.actor.runtime.Log)5 HashSet (java.util.HashSet)5 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)4 Group (im.actor.core.entity.Group)4 PromisesArray (im.actor.runtime.promise.PromisesArray)4 ApiAvatar (im.actor.core.api.ApiAvatar)3 ApiMapValue (im.actor.core.api.ApiMapValue)3 ApiUser (im.actor.core.api.ApiUser)3