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");
}
}
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);
}
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)));
}
Aggregations