Search in sources :

Example 1 with ApiMessage

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

the class AbsContent method convertData.

protected static AbsContent convertData(AbsContentContainer container) {
    if (container instanceof ContentLocalContainer) {
        ContentLocalContainer localContainer = (ContentLocalContainer) container;
        AbsLocalContent content = ((ContentLocalContainer) container).getContent();
        if (content instanceof LocalPhoto) {
            return new PhotoContent(localContainer);
        } else if (content instanceof LocalVideo) {
            return new VideoContent(localContainer);
        } else if (content instanceof LocalVoice) {
            return new VoiceContent(localContainer);
        } else if (content instanceof LocalAnimation) {
            return new AnimationContent(localContainer);
        } else if (content instanceof LocalDocument) {
            return new DocumentContent(localContainer);
        } else {
            throw new RuntimeException("Unknown type");
        }
    } else if (container instanceof ContentRemoteContainer) {
        ContentRemoteContainer remoteContainer = (ContentRemoteContainer) container;
        ApiMessage content = ((ContentRemoteContainer) container).getMessage();
        try {
            if (content instanceof ApiDocumentMessage) {
                ApiDocumentMessage d = (ApiDocumentMessage) content;
                if (d.getExt() instanceof ApiDocumentExPhoto) {
                    return new PhotoContent(remoteContainer);
                } else if (d.getExt() instanceof ApiDocumentExVideo) {
                    return new VideoContent(remoteContainer);
                } else if (d.getExt() instanceof ApiDocumentExVoice) {
                    return new VoiceContent(remoteContainer);
                } else if (d.getExt() instanceof ApiDocumentExAnimation) {
                    return new AnimationContent(remoteContainer);
                } else {
                    return new DocumentContent(remoteContainer);
                }
            } else if (content instanceof ApiTextMessage) {
                return new TextContent(remoteContainer);
            } else if (content instanceof ApiServiceMessage) {
                ApiServiceEx ext = ((ApiServiceMessage) content).getExt();
                if (ext instanceof ApiServiceExContactRegistered) {
                    return new ServiceUserRegistered(remoteContainer);
                } else if (ext instanceof ApiServiceExChangedTitle) {
                    return new ServiceGroupTitleChanged(remoteContainer);
                } else if (ext instanceof ApiServiceExChangedTopic) {
                    return new ServiceGroupTopicChanged(remoteContainer);
                } else if (ext instanceof ApiServiceExChangedAbout) {
                    return new ServiceGroupAboutChanged(remoteContainer);
                } else if (ext instanceof ApiServiceExChangedAvatar) {
                    return new ServiceGroupAvatarChanged(remoteContainer);
                } else if (ext instanceof ApiServiceExGroupCreated) {
                    return new ServiceGroupCreated(remoteContainer);
                } else if (ext instanceof ApiServiceExUserInvited) {
                    return new ServiceGroupUserInvited(remoteContainer);
                } else if (ext instanceof ApiServiceExUserKicked) {
                    return new ServiceGroupUserKicked(remoteContainer);
                } else if (ext instanceof ApiServiceExUserLeft) {
                    return new ServiceGroupUserLeave(remoteContainer);
                } else if (ext instanceof ApiServiceExUserJoined) {
                    return new ServiceGroupUserJoined(remoteContainer);
                } else if (ext instanceof ApiServiceExPhoneCall) {
                    return new ServiceCallEnded(remoteContainer);
                } else if (ext instanceof ApiServiceExPhoneMissed) {
                    return new ServiceCallMissed(remoteContainer);
                } else {
                    return new ServiceContent(remoteContainer);
                }
            } else if (content instanceof ApiJsonMessage) {
                ApiJsonMessage json = (ApiJsonMessage) content;
                JSONObject object = new JSONObject(json.getRawJson());
                if (object.getString("dataType").equals("contact")) {
                    return new ContactContent(remoteContainer);
                } else if (object.getString("dataType").equals("location")) {
                    return new LocationContent(remoteContainer);
                } else {
                    return new JsonContent(remoteContainer);
                }
            } else if (content instanceof ApiStickerMessage) {
                return new StickerContent(remoteContainer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Fallback
        return new UnsupportedContent(remoteContainer);
    } else {
        throw new RuntimeException("Unknown type");
    }
}
Also used : ApiTextMessage(im.actor.core.api.ApiTextMessage) ApiStickerMessage(im.actor.core.api.ApiStickerMessage) ApiServiceExUserLeft(im.actor.core.api.ApiServiceExUserLeft) ApiServiceExChangedAvatar(im.actor.core.api.ApiServiceExChangedAvatar) LocalPhoto(im.actor.core.entity.content.internal.LocalPhoto) ApiServiceExChangedTopic(im.actor.core.api.ApiServiceExChangedTopic) ApiServiceExUserJoined(im.actor.core.api.ApiServiceExUserJoined) ApiServiceMessage(im.actor.core.api.ApiServiceMessage) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) ApiServiceExChangedAbout(im.actor.core.api.ApiServiceExChangedAbout) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) ApiDocumentExAnimation(im.actor.core.api.ApiDocumentExAnimation) ContentLocalContainer(im.actor.core.entity.content.internal.ContentLocalContainer) ApiDocumentExVideo(im.actor.core.api.ApiDocumentExVideo) LocalVoice(im.actor.core.entity.content.internal.LocalVoice) AbsLocalContent(im.actor.core.entity.content.internal.AbsLocalContent) ApiServiceExUserInvited(im.actor.core.api.ApiServiceExUserInvited) JSONObject(im.actor.runtime.json.JSONObject) ApiMessage(im.actor.core.api.ApiMessage) LocalDocument(im.actor.core.entity.content.internal.LocalDocument) ApiDocumentExVoice(im.actor.core.api.ApiDocumentExVoice) ApiServiceEx(im.actor.core.api.ApiServiceEx) ApiServiceExChangedTitle(im.actor.core.api.ApiServiceExChangedTitle) ApiServiceExPhoneCall(im.actor.core.api.ApiServiceExPhoneCall) ApiServiceExPhoneMissed(im.actor.core.api.ApiServiceExPhoneMissed) LocalAnimation(im.actor.core.entity.content.internal.LocalAnimation) ApiServiceExGroupCreated(im.actor.core.api.ApiServiceExGroupCreated) IOException(java.io.IOException) LocalVideo(im.actor.core.entity.content.internal.LocalVideo) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) ApiDocumentExPhoto(im.actor.core.api.ApiDocumentExPhoto) ApiServiceExUserKicked(im.actor.core.api.ApiServiceExUserKicked) ApiServiceExContactRegistered(im.actor.core.api.ApiServiceExContactRegistered)

Example 2 with ApiMessage

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

the class SenderActor method performSendContent.

// Sending content
private void performSendContent(final Peer peer, final long rid, AbsContent content) {
    WakeLock wakeLock = im.actor.runtime.Runtime.makeWakeLock();
    ApiMessage message;
    if (content instanceof TextContent) {
        message = new ApiTextMessage(((TextContent) content).getText(), ((TextContent) content).getMentions(), ((TextContent) content).getTextMessageEx());
    } else if (content instanceof DocumentContent) {
        DocumentContent documentContent = (DocumentContent) content;
        FileRemoteSource source = (FileRemoteSource) documentContent.getSource();
        ApiDocumentEx documentEx = null;
        if (content instanceof PhotoContent) {
            PhotoContent photoContent = (PhotoContent) content;
            documentEx = new ApiDocumentExPhoto(photoContent.getW(), photoContent.getH());
        } else if (content instanceof VideoContent) {
            VideoContent videoContent = (VideoContent) content;
            documentEx = new ApiDocumentExVideo(videoContent.getW(), videoContent.getH(), videoContent.getDuration());
        } else if (content instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) content;
            documentEx = new ApiDocumentExAnimation(animationContent.getW(), animationContent.getH());
        } else if (content instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) content;
            documentEx = new ApiDocumentExVoice(voiceContent.getDuration());
        }
        ApiFastThumb fastThumb = null;
        if (documentContent.getFastThumb() != null) {
            fastThumb = new ApiFastThumb(documentContent.getFastThumb().getW(), documentContent.getFastThumb().getH(), documentContent.getFastThumb().getImage());
        }
        message = new ApiDocumentMessage(source.getFileReference().getFileId(), source.getFileReference().getAccessHash(), source.getFileReference().getFileSize(), source.getFileReference().getFileName(), documentContent.getMimeType(), fastThumb, documentEx);
    } else if (content instanceof LocationContent) {
        message = new ApiJsonMessage(((LocationContent) content).getRawJson());
    } else if (content instanceof ContactContent) {
        message = new ApiJsonMessage(((ContactContent) content).getRawJson());
    } else if (content instanceof JsonContent) {
        message = new ApiJsonMessage(((JsonContent) content).getRawJson());
    } else if (content instanceof StickerContent) {
        message = ((ContentRemoteContainer) content.getContentContainer()).getMessage();
    } else {
        return;
    }
    performSendApiContent(peer, rid, message, wakeLock);
}
Also used : ApiFastThumb(im.actor.core.api.ApiFastThumb) ApiDocumentEx(im.actor.core.api.ApiDocumentEx) ApiDocumentExVoice(im.actor.core.api.ApiDocumentExVoice) StickerContent(im.actor.core.entity.content.StickerContent) LocationContent(im.actor.core.entity.content.LocationContent) WakeLock(im.actor.runtime.power.WakeLock) VideoContent(im.actor.core.entity.content.VideoContent) ApiTextMessage(im.actor.core.api.ApiTextMessage) JsonContent(im.actor.core.entity.content.JsonContent) AnimationContent(im.actor.core.entity.content.AnimationContent) ContactContent(im.actor.core.entity.content.ContactContent) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) ApiMessage(im.actor.core.api.ApiMessage) ApiDocumentExPhoto(im.actor.core.api.ApiDocumentExPhoto) ApiDocumentExAnimation(im.actor.core.api.ApiDocumentExAnimation) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) ApiDocumentExVideo(im.actor.core.api.ApiDocumentExVideo) TextContent(im.actor.core.entity.content.TextContent) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 3 with ApiMessage

use of im.actor.core.api.ApiMessage 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

ApiMessage (im.actor.core.api.ApiMessage)3 ApiTextMessage (im.actor.core.api.ApiTextMessage)3 ApiDocumentExAnimation (im.actor.core.api.ApiDocumentExAnimation)2 ApiDocumentExPhoto (im.actor.core.api.ApiDocumentExPhoto)2 ApiDocumentExVideo (im.actor.core.api.ApiDocumentExVideo)2 ApiDocumentExVoice (im.actor.core.api.ApiDocumentExVoice)2 ApiDocumentMessage (im.actor.core.api.ApiDocumentMessage)2 ApiJsonMessage (im.actor.core.api.ApiJsonMessage)2 JsonContent (im.actor.core.entity.content.JsonContent)2 TextContent (im.actor.core.entity.content.TextContent)2 ContentRemoteContainer (im.actor.core.entity.content.internal.ContentRemoteContainer)2 ApiDocumentEx (im.actor.core.api.ApiDocumentEx)1 ApiFastThumb (im.actor.core.api.ApiFastThumb)1 ApiOutPeer (im.actor.core.api.ApiOutPeer)1 ApiPeer (im.actor.core.api.ApiPeer)1 ApiPeerType (im.actor.core.api.ApiPeerType)1 ApiServiceEx (im.actor.core.api.ApiServiceEx)1 ApiServiceExChangedAbout (im.actor.core.api.ApiServiceExChangedAbout)1 ApiServiceExChangedAvatar (im.actor.core.api.ApiServiceExChangedAvatar)1 ApiServiceExChangedTitle (im.actor.core.api.ApiServiceExChangedTitle)1