Search in sources :

Example 1 with ApiJsonMessage

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

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

the class ContactContent method create.

@NotNull
public static ContactContent create(@NotNull String name, @NotNull ArrayList<String> phones, @NotNull ArrayList<String> emails, @Nullable String base64photo) {
    try {
        JSONObject obj = new JSONObject();
        obj.put("dataType", "contact");
        JSONObject contact = new JSONObject();
        contact.put("name", name);
        if (base64photo != null) {
            contact.put("photo", base64photo);
        }
        JSONArray phoneArray = new JSONArray();
        for (String phone : phones) {
            phoneArray.put(phone);
        }
        JSONArray emailArray = new JSONArray();
        for (String phone : emails) {
            emailArray.put(phone);
        }
        contact.put("emails", emailArray);
        contact.put("phones", phoneArray);
        JSONObject data = new JSONObject();
        data.put("contact", contact);
        obj.put("data", data);
        return new ContactContent(new ContentRemoteContainer(new ApiJsonMessage(obj.toString())));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONObject(im.actor.runtime.json.JSONObject) JSONArray(im.actor.runtime.json.JSONArray) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) JSONException(im.actor.runtime.json.JSONException) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ApiJsonMessage

use of im.actor.core.api.ApiJsonMessage 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 4 with ApiJsonMessage

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

the class LocationContent method create.

@NotNull
public static LocationContent create(double longitude, double latitude, @Nullable String street, @Nullable String place) {
    try {
        JSONObject obj = new JSONObject();
        obj.put("dataType", "location");
        JSONObject location = new JSONObject();
        location.put("latitude", latitude);
        location.put("longitude", longitude);
        if (street != null) {
            location.put("street", street);
        }
        if (place != null) {
            location.put("place", place);
        }
        JSONObject data = new JSONObject();
        data.put("location", location);
        obj.put("data", data);
        return new LocationContent(new ContentRemoteContainer(new ApiJsonMessage(obj.toString())));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONObject(im.actor.runtime.json.JSONObject) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) JSONException(im.actor.runtime.json.JSONException) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ApiJsonMessage (im.actor.core.api.ApiJsonMessage)4 ContentRemoteContainer (im.actor.core.entity.content.internal.ContentRemoteContainer)4 JSONObject (im.actor.runtime.json.JSONObject)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 ApiMessage (im.actor.core.api.ApiMessage)2 ApiTextMessage (im.actor.core.api.ApiTextMessage)2 ApiDocumentEx (im.actor.core.api.ApiDocumentEx)1 ApiFastThumb (im.actor.core.api.ApiFastThumb)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 ApiServiceExChangedTopic (im.actor.core.api.ApiServiceExChangedTopic)1 ApiServiceExContactRegistered (im.actor.core.api.ApiServiceExContactRegistered)1 ApiServiceExGroupCreated (im.actor.core.api.ApiServiceExGroupCreated)1 ApiServiceExPhoneCall (im.actor.core.api.ApiServiceExPhoneCall)1