Search in sources :

Example 1 with UpdateMessageDelete

use of im.actor.core.api.updates.UpdateMessageDelete in project actor-platform by actorapp.

the class RouterActor method onUpdate.

//
// Messages
//
public Promise<Void> onUpdate(Update update) {
    if (update instanceof UpdateMessage) {
        UpdateMessage msg = (UpdateMessage) update;
        Peer peer = convert(msg.getPeer());
        AbsContent msgContent = AbsContent.fromMessage(msg.getMessage());
        Message message = new Message(msg.getRid(), msg.getDate(), msg.getDate(), msg.getSenderUid(), myUid() == msg.getSenderUid() ? MessageState.SENT : MessageState.UNKNOWN, msgContent);
        ArrayList<Message> messages = new ArrayList<>();
        messages.add(message);
        return onNewMessages(peer, messages);
    } else if (update instanceof UpdateMessageSent) {
        UpdateMessageSent messageSent = (UpdateMessageSent) update;
        Peer peer = convert(messageSent.getPeer());
        if (isValidPeer(peer)) {
            // Notify Sender
            context().getMessagesModule().getSendMessageActor().send(new SenderActor.MessageSent(peer, messageSent.getRid()));
            return onOutgoingSent(peer, messageSent.getRid(), messageSent.getDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageRead) {
        UpdateMessageRead read = (UpdateMessageRead) update;
        Peer peer = convert(read.getPeer());
        if (isValidPeer(peer)) {
            return onMessageRead(peer, read.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReadByMe) {
        UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) update;
        Peer peer = convert(readByMe.getPeer());
        if (isValidPeer(peer)) {
            int counter = 0;
            if (readByMe.getUnreadCounter() != null) {
                counter = readByMe.getUnreadCounter();
            }
            return onMessageReadByMe(peer, readByMe.getStartDate(), counter);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReceived) {
        UpdateMessageReceived received = (UpdateMessageReceived) update;
        Peer peer = convert(received.getPeer());
        if (isValidPeer(peer)) {
            return onMessageReceived(peer, received.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDelete) {
        UpdateChatDelete delete = (UpdateChatDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onChatDelete(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatClear) {
        UpdateChatClear clear = (UpdateChatClear) update;
        Peer peer = convert(clear.getPeer());
        if (isValidPeer(peer)) {
            return onChatClear(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDropCache) {
        UpdateChatDropCache dropCache = (UpdateChatDropCache) update;
        Peer peer = convert(dropCache.getPeer());
        if (isValidPeer(peer)) {
            return onChatDropCache(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatGroupsChanged) {
        UpdateChatGroupsChanged chatGroupsChanged = (UpdateChatGroupsChanged) update;
        onActiveDialogsChanged(chatGroupsChanged.getDialogs(), true, true);
        return Promise.success(null);
    } else if (update instanceof UpdateMessageDelete) {
        UpdateMessageDelete delete = (UpdateMessageDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onMessageDeleted(peer, delete.getRids());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageContentChanged) {
        UpdateMessageContentChanged contentChanged = (UpdateMessageContentChanged) update;
        Peer peer = convert(contentChanged.getPeer());
        if (isValidPeer(peer)) {
            AbsContent content = AbsContent.fromMessage(contentChanged.getMessage());
            return onContentUpdate(peer, contentChanged.getRid(), content);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateReactionsUpdate) {
        UpdateReactionsUpdate reactionsUpdate = (UpdateReactionsUpdate) update;
        Peer peer = convert(reactionsUpdate.getPeer());
        if (isValidPeer(peer)) {
            ArrayList<Reaction> reactions = new ArrayList<>();
            for (ApiMessageReaction r : reactionsUpdate.getReactions()) {
                reactions.add(new Reaction(r.getCode(), r.getUsers()));
            }
            return onReactionsUpdate(peer, reactionsUpdate.getRid(), reactions);
        }
        return Promise.success(null);
    }
    return Promise.success(null);
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) Peer(im.actor.core.entity.Peer) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) AbsContent(im.actor.core.entity.content.AbsContent) ArrayList(java.util.ArrayList) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) UpdateChatDropCache(im.actor.core.api.updates.UpdateChatDropCache) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) Reaction(im.actor.core.entity.Reaction) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead)

Example 2 with UpdateMessageDelete

use of im.actor.core.api.updates.UpdateMessageDelete in project actor-platform by actorapp.

the class MessageDeleteActor method performDelete.

public void performDelete(final Peer peer, final List<Long> rids) {
    final ApiOutPeer outPeer = buidOutPeer(peer);
    final ApiPeer apiPeer = buildApiPeer(peer);
    request(new RequestDeleteMessage(outPeer, rids), new RpcCallback<ResponseSeq>() {

        @Override
        public void onResult(ResponseSeq response) {
            if (deleteStorage.getPendingDeletions().containsKey(peer)) {
                deleteStorage.getPendingDeletions().get(peer).getRids().removeAll(rids);
                saveStorage();
            }
            updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateMessageDelete.HEADER, new UpdateMessageDelete(apiPeer, rids).toByteArray()));
        }

        @Override
        public void onError(RpcException e) {
        }
    });
}
Also used : SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestDeleteMessage(im.actor.core.api.rpc.RequestDeleteMessage) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) ApiOutPeer(im.actor.core.api.ApiOutPeer) ApiPeer(im.actor.core.api.ApiPeer)

Aggregations

UpdateMessageDelete (im.actor.core.api.updates.UpdateMessageDelete)2 ApiMessageReaction (im.actor.core.api.ApiMessageReaction)1 ApiOutPeer (im.actor.core.api.ApiOutPeer)1 ApiPeer (im.actor.core.api.ApiPeer)1 SeqUpdate (im.actor.core.api.base.SeqUpdate)1 RequestDeleteMessage (im.actor.core.api.rpc.RequestDeleteMessage)1 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)1 UpdateChatClear (im.actor.core.api.updates.UpdateChatClear)1 UpdateChatDelete (im.actor.core.api.updates.UpdateChatDelete)1 UpdateChatDropCache (im.actor.core.api.updates.UpdateChatDropCache)1 UpdateChatGroupsChanged (im.actor.core.api.updates.UpdateChatGroupsChanged)1 UpdateMessage (im.actor.core.api.updates.UpdateMessage)1 UpdateMessageContentChanged (im.actor.core.api.updates.UpdateMessageContentChanged)1 UpdateMessageRead (im.actor.core.api.updates.UpdateMessageRead)1 UpdateMessageReadByMe (im.actor.core.api.updates.UpdateMessageReadByMe)1 UpdateMessageReceived (im.actor.core.api.updates.UpdateMessageReceived)1 UpdateMessageSent (im.actor.core.api.updates.UpdateMessageSent)1 UpdateReactionsUpdate (im.actor.core.api.updates.UpdateReactionsUpdate)1 Message (im.actor.core.entity.Message)1 Peer (im.actor.core.entity.Peer)1