@Override protected boolean execute(Conversation conversation) { CompoundMessage message = new CompoundMessage(); message.setBody(text); message.setRead(true); message.setHidden(true); message.setSenderId(conversation.getPerson().getId()); message.setAssociatedFiles(null); conversation.getMessageManager().sendMessage(message); return true; } }, "send attachment text");
public void bindView(final RecyclerView parent, final CompoundMessage message) { body.setText(message.getBody()); } }
public boolean getTextOnly() { return getBoolean(KEY_TEXT_ONLY); }
@Override public void onFinishComposing() { messagingActionHandler.sendEmptyMessage(MSG_REMOVE_COMPOSER); Util.hideSoftKeyboard(hostingActivityRef.get(), getView()); messagingActionHandler.sendEmptyMessage(MSG_SEND_PENDING_CONTEXT_MESSAGE); if (!TextUtils.isEmpty(composerEditText.getText().toString().trim()) || pendingAttachments.size() > 0) { CompoundMessage compoundMessage = new CompoundMessage(); compoundMessage.setBody(composerEditText.getText().toString().trim()); compoundMessage.setRead(true); compoundMessage.setCustomData(ApptentiveInternal.getInstance().getAndClearCustomData()); compoundMessage.setAssociatedImages(new ArrayList<ImageItem>(pendingAttachments)); ConversationProxy conversation = getConversation(); if (conversation != null && conversation.hasActiveState()) { compoundMessage.setSenderId(conversation.getPerson().getId()); } messagingActionHandler.sendMessage(messagingActionHandler.obtainMessage(MSG_START_SENDING, compoundMessage)); composingViewSavedState = null; composerEditText.getText().clear(); pendingAttachments.clear(); clearPendingComposingMessage(); } showFab(); showProfileButton(); }
CompoundMessage message = new CompoundMessage(); message.setBody(contextMessage.getBody()); message.setAutomated(true); message.setRead(true);
boolean shouldEncrypt = isAuthenticated(); ByteArrayOutputStream data = new ByteArrayOutputStream(); .append("Content-Type: application/json;charset=UTF-8").append(lineEnd) .append(lineEnd) .append(marshallForSending().toString()).append(lineEnd); byte[] partBytes = part.toString().getBytes(); final EncryptionKey encryptionKey = getEncryptionKey(); if (shouldEncrypt) { header logException(e); continue; } finally {
imageBandView.setupUi(); messageBodyView.setText(message.getBody()); Double createdAt = message.getCreatedAt(); String statusText; if (createdAt == null || createdAt > Double.MIN_VALUE) { showProgress = createdAt == null && !fragment.isPaused() && (message.getAssociatedFiles() != null || !TextUtils.isEmpty(message.getBody())); statusText = createStatus(createdAt, message.isLastSent(), fragment.isPaused()); } else { showProgress = false; List<StoredFile> files = message.getAssociatedFiles(); int imagebandWidth = 0; if (files != null && files.size() > 0) {
public void bindView(MessageCenterFragment fragment, final RecyclerView parent, final MessageCenterRecyclerViewAdapter adapter, final CompoundMessage message) { super.bindView(fragment, parent, message); imageBandView.setupUi(); ImageUtil.startDownloadAvatarTask(avatar, message.getSenderProfilePhoto()); int viewWidth = container.getMeasuredWidth(); messageBodyView.setText(message.getBody()); messageBodyView.setTextIsSelectable(talkbackNotEnabled); String name = message.getSenderUsername(); if (name != null && !name.isEmpty()) { nameView.setVisibility(View.VISIBLE); final List<StoredFile> files = message.getRemoteAttachments(); if (imageBandView != null) { if (files == null || files.size() == 0) {
hasNoAttachments = false; setTextOnly(hasNoAttachments); ArrayList<StoredFile> attachmentStoredFiles = new ArrayList<StoredFile>(); for (ImageItem image : attachedImages) { StoredFile storedFile = new StoredFile(); storedFile.setId(getNonce()); storedFile.setApptentiveUri(""); storedFile.setSourceUriOrPath(image.originalPath); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to set associated images in worker thread"); logException(e); } finally { return bRet;
@Test public void textMessageRoundTrip() throws JSONException { String exampleMessage = loadTextAssetAsString(TEST_DATA_DIR + "testTextMessageRoundTrip.json"); CompoundMessage message = new CompoundMessage(exampleMessage); assertNotNull(message); String recoveredMessage = message.toString(); assertEquals(true, recoveredMessage.contains("\"id\":\"520a84fe4712c71b65000005\"")); assertEquals(true, recoveredMessage.contains("\"nonce\":\"33b042735704283c0407f22e6d6f8c6fcb0d2f073bf964f76d36ef176ec26472\"")); assertEquals(true, recoveredMessage.contains("\"created_at\":1.376421118499E9")); assertEquals(true, recoveredMessage.contains("\"client_created_at\":1376421112")); assertEquals(true, recoveredMessage.contains("\"client_created_at_utc_offset\":-25200")); assertEquals(true, recoveredMessage.contains("\"type\":\"CompoundMessage\"")); assertEquals(true, recoveredMessage.contains("\"name\":\"Sky Kelsey\"")); assertEquals(true, recoveredMessage.contains("\"id\":\"4de48b826688000001000007\"")); assertEquals(true, recoveredMessage.contains("\"body\":\"Test reply via email.\"")); } }
public List<StoredFile> getAssociatedFiles() { if (hasNoAttachments) { return null; } List<StoredFile> associatedFiles = null; try { Future<List<StoredFile>> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().getAssociatedFiles(getNonce()); associatedFiles = future.get(); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to get associated files in worker thread"); logException(e); } finally { return associatedFiles; } }
private boolean parseAttachmentsArray(String messageString) throws JSONException { JSONObject root = new JSONObject(messageString); if (!root.isNull(KEY_ATTACHMENTS)) { JSONArray items = root.getJSONArray(KEY_ATTACHMENTS); remoteAttachmentStoredFiles = new ArrayList<StoredFile>(); for (int i = 0; i < items.length(); i++) { String json = items.getJSONObject(i).toString(); JSONObject attachment = new JSONObject(json); String mimeType = attachment.optString("content_type"); StoredFile storedFile = new StoredFile(); storedFile.setId(getNonce()); storedFile.setApptentiveUri(attachment.optString("url")); storedFile.setSourceUriOrPath(attachment.optString("thumbnail_url")); storedFile.setLocalFilePath(attachment.optString("")); storedFile.setMimeType(mimeType); storedFile.setCreationTime(0); remoteAttachmentStoredFiles.add(storedFile); } if (remoteAttachmentStoredFiles.size() > 0) { setTextOnly(false); return true; } } return false; }
public static ApptentiveMessage fromJson(String json) { try { // If KEY_TYPE is set to CompoundMessage or not set, treat them as CompoundMessage ApptentiveMessage.Type type = ApptentiveMessage.Type.CompoundMessage; JSONObject root = new JSONObject(json); if (!root.isNull(ApptentiveMessage.KEY_TYPE)) { String typeStr = root.getString(ApptentiveMessage.KEY_TYPE); if (!StringUtils.isNullOrEmpty(typeStr)) { type = ApptentiveMessage.Type.valueOf(typeStr); } } switch (type) { case CompoundMessage: return new CompoundMessage(json); case unknown: break; default: break; } } catch (JSONException e) { ApptentiveLog.v(MESSAGES, e, "Error parsing json as Message: %s", json); logException(e); } catch (IllegalArgumentException e) { // Exception treated as unknown type logException(e); } return null; } }
public void bindView(MessageCenterFragment fragment, RecyclerView recyclerView, CompoundMessage message) { String datestampString = message.getDatestamp(); datestamp.setText(datestampString); datestamp.setVisibility(!TextUtils.isEmpty(datestampString) ? View.VISIBLE : View.GONE); } }
((CompoundMessage) apptentiveMessage).deleteAssociatedFiles(); messageStore.deleteMessage(apptentiveMessage.getNonce()); return;
public void deleteAssociatedFiles() { try { Future<List<StoredFile>> future = ApptentiveInternal.getInstance().getApptentiveTaskManager().getAssociatedFiles(getNonce()); List<StoredFile> associatedFiles = future.get(); // Delete local cached files if (associatedFiles == null || associatedFiles.size() == 0) { return; } for (StoredFile file : associatedFiles) { File localFile = new File(file.getLocalFilePath()); localFile.delete(); } // Delete records from db ApptentiveInternal.getInstance().getApptentiveTaskManager().deleteAssociatedFiles(getNonce()); } catch (Exception e) { ApptentiveLog.e(MESSAGES, "Unable to delete associated files in worker thread"); logException(e); } }
@Override protected boolean execute(Conversation conversation) { if (is == null) { return false; // TODO: add error message } CompoundMessage message = new CompoundMessage(); // No body, just attachment message.setBody(null); message.setRead(true); message.setHidden(true); message.setSenderId(conversation.getPerson().getId()); ArrayList<StoredFile> attachmentStoredFiles = new ArrayList<StoredFile>(); String localFilePath = Util.generateCacheFilePathFromNonceOrPrefix(ApptentiveInternal.getInstance().getApplicationContext(), message.getNonce(), null); String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType); if (!TextUtils.isEmpty(extension)) { localFilePath += "." + extension; } // When created from InputStream, there is no source file uri or path, thus just use the cache file path StoredFile storedFile = Util.createLocalStoredFile(is, localFilePath, localFilePath, mimeType); if (storedFile == null) { return false; // TODO: add error message } storedFile.setId(message.getNonce()); attachmentStoredFiles.add(storedFile); message.setAssociatedFiles(attachmentStoredFiles); conversation.getMessageManager().sendMessage(message); return true; } }, "add unread message listener");
return false; // TODO: add error message CompoundMessage message = new CompoundMessage(); message.setBody(null); message.setRead(true); message.setHidden(true); message.setSenderId(conversation.getPerson().getId()); String localFilePath = Util.generateCacheFilePathFromNonceOrPrefix(context, message.getNonce(), Uri.parse(uri).getLastPathSegment()); storedFile.setId(message.getNonce()); attachmentStoredFiles.add(storedFile); message.setAssociatedFiles(attachmentStoredFiles); conversation.getMessageManager().sendMessage(message); return true;