private void shareWith(Message message) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); if (GeoHelper.isGeoUri(message.getBody())) { shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody()); shareIntent.setType("text/plain"); } else { shareIntent.putExtra( Intent.EXTRA_STREAM, activity.xmppConnectionService.getFileBackend().getJingleFileUri(message)); shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String mime = message.getMimeType(); if (mime == null) { mime = "image/webp"; } shareIntent.setType(mime); } try { activity.startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with))); } catch (ActivityNotFoundException e) { // This should happen only on faulty androids because normally chooser is always available Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT) .show(); } }
public void updateMessages() { synchronized (this.messageList) { if (getView() == null) { return; } final ConversationActivity activity = (ConversationActivity) getActivity(); if (this.conversation != null) { updateSnackBar(this.conversation); conversation.populateWithMessages(ConversationFragment.this.messageList); for (final Message message : this.messageList) { if (message.getEncryption() == Message.ENCRYPTION_PGP && (message.getStatus() == Message.STATUS_RECEIVED || message.getStatus() >= Message.STATUS_SEND) && message.getTransferable() == null) { if (!mEncryptedMessages.contains(message)) { mEncryptedMessages.add(message); } } } decryptNext(); updateStatusMessages(); this.messageListAdapter.notifyDataSetChanged(); updateChatMsgHint(); if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) { activity.sendReadMarkerIfNecessary(conversation); } this.updateSendButton(); } } }
private void sendMessage() { final String body = mEditMessage.getText().toString(); if (body.length() == 0 || this.conversation == null) { return; } Message message = new Message(conversation, body, conversation.getNextEncryption()); if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getNextCounterpart() != null) { message.setCounterpart(conversation.getNextCounterpart()); message.setType(Message.TYPE_PRIVATE); } } switch (conversation.getNextEncryption()) { case Message.ENCRYPTION_OTR: sendOtrMessage(message); break; case Message.ENCRYPTION_PGP: sendPgpMessage(message); break; case Message.ENCRYPTION_AXOLOTL: if (!activity.trustKeysIfNeeded(ConversationActivity.REQUEST_TRUST_KEYS_TEXT)) { sendAxolotlMessage(message); } break; default: sendPlainTextMessage(message); } }
private boolean handleErrorMessage(Account account, MessagePacket packet) { if (packet.getType() == MessagePacket.TYPE_ERROR) { Jid from = packet.getFrom(); if (from != null) { Element error = packet.findChild("error"); String text = error == null ? null : error.findChildContent("text"); if (text != null) { Log.d( Config.LOGTAG, account.getJid().toBareJid() + ": sending message to " + from + " failed - " + text); } else if (error != null) { Log.d( Config.LOGTAG, account.getJid().toBareJid() + ": sending message to " + from + " failed - " + error); } Message message = mXmppConnectionService.markMessage( account, from.toBareJid(), packet.getId(), Message.STATUS_SEND_FAILED); if (message != null && message.getEncryption() == Message.ENCRYPTION_OTR) { message.getConversation().endOtrIfNeeded(); } } return true; } return false; }
protected void updateStatusMessages() { synchronized (this.messageList) { if (conversation.getMode() == Conversation.MODE_SINGLE) { ChatState state = conversation.getIncomingChatState(); if (state == ChatState.COMPOSING) { this.messageList.add( Message.createStatusMessage( conversation, getString(R.string.contact_is_typing, conversation.getName()))); } else if (state == ChatState.PAUSED) { this.messageList.add( Message.createStatusMessage( conversation, getString(R.string.contact_has_stopped_typing, conversation.getName()))); } else { for (int i = this.messageList.size() - 1; i >= 0; --i) { if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) { return; } else { if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) { this.messageList.add( i + 1, Message.createStatusMessage( conversation, getString( R.string.contact_has_read_up_to_this_point, conversation.getName()))); return; } } } } } } }
public void findUnreadMessages(OnMessageFound onMessageFound) { synchronized (this.messages) { for (Message message : this.messages) { if (!message.isRead()) { onMessageFound.onMessageFound(message); } } } }
public void findWaitingMessages(OnMessageFound onMessageFound) { synchronized (this.messages) { for (Message message : this.messages) { if (message.getStatus() == Message.STATUS_WAITING) { onMessageFound.onMessageFound(message); } } } }
public void findMessagesWithFiles(final OnMessageFound onMessageFound) { synchronized (this.messages) { for (final Message message : this.messages) { if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP) { onMessageFound.onMessageFound(message); } } } }
public Message findSentMessageWithUuid(String id) { synchronized (this.messages) { for (Message message : this.messages) { if (id.equals(message.getUuid())) { return message; } } } return null; }
public void findUnsentTextMessages(OnMessageFound onMessageFound) { synchronized (this.messages) { for (Message message : this.messages) { if (message.getType() != Message.TYPE_IMAGE && message.getStatus() == Message.STATUS_UNSEND) { onMessageFound.onMessageFound(message); } } } }
public void findUnsentMessagesWithEncryption(int encryptionType, OnMessageFound onMessageFound) { synchronized (this.messages) { for (Message message : this.messages) { if ((message.getStatus() == Message.STATUS_UNSEND || message.getStatus() == Message.STATUS_WAITING) && (message.getEncryption() == encryptionType)) { onMessageFound.onMessageFound(message); } } } }
public Message getLatestMessage() { if (this.messages.size() == 0) { Message message = new Message(this, "", Message.ENCRYPTION_NONE); message.setTime(getCreated()); return message; } else { Message message = this.messages.get(this.messages.size() - 1); message.setConversation(this); return message; } }
private void resendMessage(Message message) { if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) { DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (!file.exists()) { Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); return; } } activity.xmppConnectionService.resendFailedMessages(message); }
public Message findMessageWithFileAndUuid(final String uuid) { synchronized (this.messages) { for (final Message message : this.messages) { if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP && message.getUuid().equals(uuid)) { return message; } } } return null; }
public XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message) { XmppAxolotlMessage axolotlMessage = messageCache.get(message.getUuid()); if (axolotlMessage != null) { Log.d( Config.LOGTAG, AxolotlService.getLogprefix(account) + "Cache hit: " + message.getUuid()); messageCache.remove(message.getUuid()); } else { Log.d( Config.LOGTAG, AxolotlService.getLogprefix(account) + "Cache miss: " + message.getUuid()); } return axolotlMessage; }
public List<Message> markRead() { final List<Message> unread = new ArrayList<>(); synchronized (this.messages) { for (Message message : this.messages) { if (!message.isRead()) { message.markRead(); unread.add(message); } } } return unread; }
public Message findSentMessageWithUuidOrRemoteId(String id) { synchronized (this.messages) { for (Message message : this.messages) { if (id.equals(message.getUuid()) || (message.getStatus() >= Message.STATUS_SEND && id.equals(message.getRemoteMsgId()))) { return message; } } } return null; }
public Message findUnsentMessageWithUuid(String uuid) { synchronized (this.messages) { for (final Message message : this.messages) { final int s = message.getStatus(); if ((s == Message.STATUS_UNSEND || s == Message.STATUS_WAITING) && message.getUuid().equals(uuid)) { return message; } } } return null; }
public static boolean receivedLocationQuestion(Message message) { if (message == null || message.getStatus() != Message.STATUS_RECEIVED || message.getType() != Message.TYPE_TEXT) { return false; } String body = message.getBody() == null ? null : message.getBody().trim().toLowerCase(Locale.getDefault()); body = body.replace("?", "").replace("¿", ""); return LOCATION_QUESTIONS.contains(body); }
public long getLastMessageTransmitted() { long last_clear = getLastClearHistory(); if (last_clear != 0) { return last_clear; } synchronized (this.messages) { for (int i = this.messages.size() - 1; i >= 0; --i) { Message message = this.messages.get(i); if (message.getStatus() == Message.STATUS_RECEIVED || message.isCarbon()) { return message.getTimeSent(); } } } return 0; }
private int getMostRecentlyUsedIncomingEncryption() { synchronized (this.messages) { for (int i = this.messages.size() - 1; i >= 0; --i) { final Message m = this.messages.get(i); if (m.getStatus() == Message.STATUS_RECEIVED) { final int e = m.getEncryption(); if (e == Message.ENCRYPTION_DECRYPTED || e == Message.ENCRYPTION_DECRYPTION_FAILED) { return Message.ENCRYPTION_PGP; } else { return e; } } } } return Message.ENCRYPTION_NONE; }
private void copyUrl(Message message) { final String url; final int resId; if (GeoHelper.isGeoUri(message.getBody())) { resId = R.string.location; url = message.getBody(); } else if (message.hasFileOnRemoteHost()) { resId = R.string.file_url; url = message.getFileParams().url.toString(); } else { url = message.getBody().trim(); resId = R.string.file_url; } if (activity.copyTextToClipboard(url, resId)) { Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show(); } }
private void cancelTransmission(Message message) { Transferable transferable = message.getTransferable(); if (transferable != null) { transferable.cancel(); } else { activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); } }
private int getIndexOf(String uuid, List<Message> messages) { if (uuid == null) { return 0; } for (int i = 0; i < messages.size(); ++i) { if (uuid.equals(messages.get(i).getUuid())) { return i; } else { Message next = messages.get(i); while (next != null && next.wasMergedIntoPrevious()) { if (uuid.equals(next.getUuid())) { return i; } next = next.next(); } } } return 0; }
public Message findSentMessageWithBody(String body) { synchronized (this.messages) { for (int i = this.messages.size() - 1; i >= 0; --i) { Message message = this.messages.get(i); if (message.getStatus() == Message.STATUS_UNSEND || message.getStatus() == Message.STATUS_SEND) { String otherBody; if (message.hasFileOnRemoteHost()) { otherBody = message.getFileParams().url.toString(); } else { otherBody = message.body; } if (otherBody != null && otherBody.equals(body)) { return message; } } } return null; } }
public void sort() { synchronized (this.messages) { Collections.sort( this.messages, new Comparator<Message>() { @Override public int compare(Message left, Message right) { if (left.getTimeSent() < right.getTimeSent()) { return -1; } else if (left.getTimeSent() > right.getTimeSent()) { return 1; } else { return 0; } } }); for (Message message : this.messages) { message.untie(); } } }
@Nullable public XmppAxolotlMessage encrypt(Message message) { XmppAxolotlMessage axolotlMessage = buildHeader(message.getContact()); if (axolotlMessage != null) { final String content; if (message.hasFileOnRemoteHost()) { content = message.getFileParams().url.toString(); } else { content = message.getBody(); } try { axolotlMessage.encrypt(content); } catch (CryptoFailedException e) { Log.w( Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage()); return null; } } return axolotlMessage; }
private Message parseAxolotlChat( Element axolotlMessage, Jid from, String id, Conversation conversation, int status) { Message finishedMessage = null; AxolotlService service = conversation.getAccount().getAxolotlService(); XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid()); XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage); if (plaintextMessage != null) { finishedMessage = new Message( conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status); finishedMessage.setAxolotlFingerprint(plaintextMessage.getFingerprint()); Log.d( Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount()) + " Received Message with session fingerprint: " + plaintextMessage.getFingerprint()); } return finishedMessage; }
public static String getFileDescriptionString(final Context context, final Message message) { if (message.getType() == Message.TYPE_IMAGE) { return context.getString(R.string.image); } final String mime = message.getMimeType(); if (mime == null) { return context.getString(R.string.file); } else if (mime.startsWith("audio/")) { return context.getString(R.string.audio); } else if (mime.startsWith("video/")) { return context.getString(R.string.video); } else if (mime.startsWith("image/")) { return context.getString(R.string.image); } else if (mime.contains("pdf")) { return context.getString(R.string.pdf_document); } else if (mime.contains("application/vnd.android.package-archive")) { return context.getString(R.string.apk); } else if (mime.contains("vcard")) { return context.getString(R.string.vcard); } else { return mime; } }
protected void sendOtrMessage(final Message message) { final ConversationActivity activity = (ConversationActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; activity.selectPresence( message.getConversation(), new OnPresenceSelected() { @Override public void onPresenceSelected() { message.setCounterpart(conversation.getNextCounterpart()); xmppService.sendMessage(message); messageSent(); } }); }