use of im.actor.runtime.json.JSONObject 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");
}
}
use of im.actor.runtime.json.JSONObject 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);
}
}
use of im.actor.runtime.json.JSONObject in project actor-platform by actorapp.
the class InviteHandler method handleIntent.
public static void handleIntent(BaseActivity activity, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW) && intent.getData() != null) {
String joinGroupUrl = intent.getData().toString();
if (joinGroupUrl != null && (joinGroupUrl.contains("join") || joinGroupUrl.contains("token"))) {
String[] urlSplit = null;
if (joinGroupUrl.contains("join")) {
urlSplit = joinGroupUrl.split("/join/");
} else if (joinGroupUrl.contains("token")) {
urlSplit = joinGroupUrl.split("token=");
}
if (urlSplit != null) {
joinGroupUrl = urlSplit[urlSplit.length - 1];
final String token = joinGroupUrl;
HTTP.getMethod(ActorSDK.sharedActor().getInviteDataUrl() + joinGroupUrl, 0, 0, 0).then(new Consumer<HTTPResponse>() {
@Override
public void apply(HTTPResponse httpResponse) {
try {
JSONObject data = new JSONObject(new String(httpResponse.getContent(), "UTF-8"));
JSONObject group = data.getJSONObject("group");
String title = group.getString("title");
if (group.has("id") && group.has("isPublic")) {
int gid = group.getInt("id");
boolean isPublic = group.getBoolean("isPublic");
// Check if we have this group
try {
GroupVM groupVM = groups().get(gid);
if (groupVM.isMember().get() || isPublic) {
// Have this group, is member or group is public, just open it
activity.startActivity(Intents.openDialog(Peer.group(gid), false, activity));
} else {
// Have this group, but not member, join it
joinViaToken(token, title, activity);
}
} catch (Exception e) {
// Do not have this group, join it
if (isPublic) {
messenger().findPublicGroupById(gid).then(peer -> activity.startActivity(Intents.openDialog(peer, false, activity)));
} else {
joinViaToken(token, title, activity);
}
}
} else {
joinViaToken(token, title, activity);
}
} catch (JSONException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
});
}
}
}
}
use of im.actor.runtime.json.JSONObject in project actor-platform by actorapp.
the class SDKPushReceiver method onPushReceived.
@Override
public void onPushReceived(String payload) {
try {
JSONObject object = new JSONObject(payload);
if (object.has("data")) {
JSONObject data = object.getJSONObject("data");
ActorSDK.sharedActor().waitForReady();
if (data.has("seq")) {
int seq = data.getInt("seq");
int authId = data.optInt("authId");
Log.d("SDKPushReceiver", "Seq Received: " + seq);
ActorSDK.sharedActor().getMessenger().onPushReceived(seq, authId);
} else if (data.has("callId")) {
Long callId = Long.parseLong(data.getString("callId"));
int attempt = 0;
if (data.has("attemptIndex")) {
attempt = data.getInt("attemptIndex");
}
Log.d("SDKPushReceiver", "Received Call #" + callId + " (" + attempt + ")");
ActorSDK.sharedActor().getMessenger().checkCall(callId, attempt);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of im.actor.runtime.json.JSONObject in project actor-platform by actorapp.
the class JsonContent method getContentDescription.
public String getContentDescription() {
String res;
try {
JSONObject data = new JSONObject(getRawJson());
res = data.getJSONObject("data").getString("text");
} catch (JSONException e) {
res = "";
}
return res;
}
Aggregations