private void onFileUploaded(long rid, FileReference fileReference) { PendingMessage msg = findPending(rid); if (msg == null) { return; } pendingMessages.getPendingMessages().remove(msg); AbsContent nContent; if (msg.getContent() instanceof PhotoContent) { PhotoContent basePhotoContent = (PhotoContent) msg.getContent(); nContent = PhotoContent.createRemotePhoto( fileReference, basePhotoContent.getW(), basePhotoContent.getH(), basePhotoContent.getFastThumb()); } else if (msg.getContent() instanceof VideoContent) { VideoContent baseVideoContent = (VideoContent) msg.getContent(); nContent = VideoContent.createRemoteVideo( fileReference, baseVideoContent.getW(), baseVideoContent.getH(), baseVideoContent.getDuration(), baseVideoContent.getFastThumb()); } else if (msg.getContent() instanceof VoiceContent) { VoiceContent baseVoiceContent = (VoiceContent) msg.getContent(); nContent = VoiceContent.createRemoteAudio(fileReference, baseVoiceContent.getDuration()); } else if (msg.getContent() instanceof AnimationContent) { AnimationContent baseAnimcationContent = (AnimationContent) msg.getContent(); nContent = AnimationContent.createRemoteAnimation( fileReference, baseAnimcationContent.getW(), baseAnimcationContent.getH(), baseAnimcationContent.getFastThumb()); } else if (msg.getContent() instanceof DocumentContent) { DocumentContent baseDocContent = (DocumentContent) msg.getContent(); nContent = DocumentContent.createRemoteDocument(fileReference, baseDocContent.getFastThumb()); } else { return; } pendingMessages .getPendingMessages() .add(new PendingMessage(msg.getPeer(), msg.getRid(), nContent)); context() .getMessagesModule() .getRouter() .onContentChanged(msg.getPeer(), msg.getRid(), nContent); performSendContent(msg.getPeer(), rid, nContent); fileUplaodingWakeLocks.remove(rid).releaseLock(); }
public void doSendPhoto( Peer peer, FastThumb fastThumb, String descriptor, String fileName, int fileSize, int w, int h) { long rid = RandomUtils.nextRid(); long date = createPendingDate(); long sortDate = date + 365 * 24 * 60 * 60 * 1000L; PhotoContent photoContent = PhotoContent.createLocalPhoto(descriptor, fileName, fileSize, w, h, fastThumb); Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, photoContent); context().getMessagesModule().getRouter().onOutgoingMessage(peer, message); pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, photoContent)); savePending(); performUploadFile(rid, descriptor, fileName); }
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); }