Search in sources :

Example 21 with Void

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

the class JsFacade method favoriteChat.

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

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

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

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

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

the class JsFacade method clearChat.

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

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

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

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

use of im.actor.runtime.actors.messages.Void 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)

Example 24 with Void

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

the class RouterActor method onMessageReadByMe.

private Promise<Void> onMessageReadByMe(Peer peer, long date, int counter) {
    ConversationState state = conversationStates.getValue(peer.getUnuqueId());
    if (state.getInReadDate() >= date) {
        return Promise.success(null);
    }
    state = state.changeCounter(counter).changeInReadDate(date);
    conversationStates.addOrUpdateItem(state);
    Promise<Void> res = getDialogsRouter().onCounterChanged(peer, counter);
    notifyActiveDialogsVM();
    context().getNotificationsModule().onOwnRead(peer, date);
    return res;
}
Also used : ConversationState(im.actor.core.entity.ConversationState) Void(im.actor.runtime.actors.messages.Void)

Example 25 with Void

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

the class SequenceHandlerActor method onDifferenceUpdate.

private Promise<Void> onDifferenceUpdate(@NotNull List<ApiUser> users, @NotNull List<ApiGroup> groups, @NotNull List<ApiUserOutPeer> userOutPeers, @NotNull List<ApiGroupOutPeer> groupOutPeers, @NotNull List<Update> updates) {
    if (updates.size() > 0) {
        String command = "Difference updates:";
        for (Update u : updates) {
            command += "\n| " + u;
        }
        Log.d(TAG, command);
    }
    beginUpdates();
    // Related Users
    Promise<Void> currentPromise = updates().applyRelatedData(users, groups);
    // Loading missing peers
    currentPromise = currentPromise.chain(v -> updates().loadRequiredPeers(userOutPeers, groupOutPeers));
    // Apply Diff
    long applyStart = im.actor.runtime.Runtime.getCurrentTime();
    currentPromise = currentPromise.chain(v -> processor.applyDifferenceUpdate(updates)).then(v -> {
        Log.d(TAG, "Difference applied in " + (im.actor.runtime.Runtime.getCurrentTime() - applyStart) + " ms");
        endUpdates();
    });
    return currentPromise;
}
Also used : HandlerDifferenceUpdates(im.actor.core.modules.sequence.internal.HandlerDifferenceUpdates) ModuleContext(im.actor.core.modules.ModuleContext) ActorCreator(im.actor.runtime.actors.ActorCreator) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ArrayList(java.util.ArrayList) UpdateProcessor(im.actor.core.modules.sequence.processor.UpdateProcessor) HandlerRelatedResponse(im.actor.core.modules.sequence.internal.HandlerRelatedResponse) PromisesArray(im.actor.runtime.promise.PromisesArray) HandlerWeakUpdate(im.actor.core.modules.sequence.internal.HandlerWeakUpdate) RequestGetReferencedEntitites(im.actor.core.api.rpc.RequestGetReferencedEntitites) ApiGroup(im.actor.core.api.ApiGroup) Void(im.actor.runtime.actors.messages.Void) Runtime(im.actor.runtime.Runtime) Constructor(im.actor.runtime.function.Constructor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) HandlerSeqUpdate(im.actor.core.modules.sequence.internal.HandlerSeqUpdate) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) Function(im.actor.runtime.function.Function) Update(im.actor.core.network.parser.Update) Promises(im.actor.runtime.promise.Promises) HandlerWeakUpdate(im.actor.core.modules.sequence.internal.HandlerWeakUpdate) HandlerSeqUpdate(im.actor.core.modules.sequence.internal.HandlerSeqUpdate) Update(im.actor.core.network.parser.Update) Void(im.actor.runtime.actors.messages.Void)

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