use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ShareWithActivity method share.
private void share(final Conversation conversation) {
final Account account = conversation.getAccount();
final XmppConnection connection = account.getXmppConnection();
final long max = connection == null ? -1 : connection.getFeatures().getMaxHttpUploadSize();
mListView.setEnabled(false);
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
if (share.uuid == null) {
showInstallPgpDialog();
} else {
Toast.makeText(this, R.string.openkeychain_not_installed, Toast.LENGTH_SHORT).show();
finish();
}
return;
}
if (share.uris.size() != 0) {
OnPresenceSelected callback = new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
attachmentCounter.set(share.uris.size());
if (share.image) {
share.multiple = share.uris.size() > 1;
replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image));
for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) {
ShareWithActivity.this.xmppConnectionService.attachImageToConversation(conversation, i.next(), attachFileCallback);
}
} else {
replaceToast(getString(R.string.preparing_file));
ShareWithActivity.this.xmppConnectionService.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback);
}
}
};
if (account.httpUploadAvailable() && ((share.image && !neverCompressPictures()) || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(this, share.uris, max)) && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) {
callback.onPresenceSelected();
} else {
selectPresence(conversation, callback);
}
} else {
if (mReturnToPrevious && this.share.text != null && !this.share.text.isEmpty()) {
final OnPresenceSelected callback = new OnPresenceSelected() {
private void finishAndSend(Message message) {
xmppConnectionService.sendMessage(message);
replaceToast(getString(R.string.shared_text_with_x, conversation.getName()));
finish();
}
private UiCallback<Message> messageEncryptionCallback = new UiCallback<Message>() {
@Override
public void success(final Message message) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
runOnUiThread(new Runnable() {
@Override
public void run() {
finishAndSend(message);
}
});
}
@Override
public void error(final int errorCode, Message object) {
runOnUiThread(new Runnable() {
@Override
public void run() {
replaceToast(getString(errorCode));
finish();
}
});
}
@Override
public void userInputRequried(PendingIntent pi, Message object) {
finish();
}
};
@Override
public void onPresenceSelected() {
final int encryption = conversation.getNextEncryption();
Message message = new Message(conversation, share.text, encryption);
Log.d(Config.LOGTAG, "on presence selected encrpytion=" + encryption);
if (encryption == Message.ENCRYPTION_PGP) {
replaceToast(getString(R.string.encrypting_message));
xmppConnectionService.getPgpEngine().encrypt(message, messageEncryptionCallback);
return;
}
if (encryption == Message.ENCRYPTION_OTR) {
message.setCounterpart(conversation.getNextCounterpart());
}
finishAndSend(message);
}
};
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
selectPresence(conversation, callback);
} else {
callback.onPresenceSelected();
}
} else {
switchToConversation(conversation, this.share.text, true);
}
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ConversationFragment method updateStatusMessages.
protected void updateStatusMessages() {
synchronized (this.messageList) {
if (showLoadMoreMessages(conversation)) {
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
}
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;
}
}
}
}
} else {
ChatState state = ChatState.COMPOSING;
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
if (users.size() == 0) {
state = ChatState.PAUSED;
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
}
if (users.size() > 0) {
Message statusMessage;
if (users.size() == 1) {
MucOptions.User user = users.get(0);
int id = state == ChatState.COMPOSING ? R.string.contact_is_typing : R.string.contact_has_stopped_typing;
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.getDisplayName(user)));
statusMessage.setTrueCounterpart(user.getRealJid());
statusMessage.setCounterpart(user.getFullJid());
} else {
StringBuilder builder = new StringBuilder();
for (MucOptions.User user : users) {
if (builder.length() != 0) {
builder.append(", ");
}
builder.append(UIHelper.getDisplayName(user));
}
int id = state == ChatState.COMPOSING ? R.string.contacts_are_typing : R.string.contacts_have_stopped_typing;
statusMessage = Message.createStatusMessage(conversation, getString(id, builder.toString()));
}
this.messageList.add(statusMessage);
}
}
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ConversationFragment method sendMessage.
private void sendMessage() {
final String body = mEditMessage.getText().toString();
if (body.length() == 0 || this.conversation == null) {
return;
}
final Message message;
if (conversation.getCorrectingMessage() == null) {
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);
}
}
} else {
message = conversation.getCorrectingMessage();
message.setBody(body);
message.setEdited(message.getUuid());
message.setUuid(UUID.randomUUID().toString());
}
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);
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ConversationFragment method populateContextMenu.
private void populateContextMenu(ContextMenu menu) {
final Message m = this.selectedMessage;
final Transferable t = m.getTransferable();
Message relevantForCorrection = m;
while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
relevantForCorrection = relevantForCorrection.next();
}
if (m.getType() != Message.TYPE_STATUS) {
final boolean treatAsFile = m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE && t == null;
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
MenuItem copyText = menu.findItem(R.id.copy_text);
MenuItem selectText = menu.findItem(R.id.select_text);
MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
MenuItem correctMessage = menu.findItem(R.id.correct_message);
MenuItem shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
MenuItem deleteFile = menu.findItem(R.id.delete_file);
MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
if (!treatAsFile && !GeoHelper.isGeoUri(m.getBody()) && m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true);
selectText.setVisible(ListSelectionManager.isSupported());
}
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
retryDecryption.setVisible(true);
}
if (relevantForCorrection.getType() == Message.TYPE_TEXT && relevantForCorrection.isLastCorrectableMessage() && (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
correctMessage.setVisible(true);
}
if (treatAsFile || (GeoHelper.isGeoUri(m.getBody()))) {
shareWith.setVisible(true);
}
if (m.getStatus() == Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(true);
}
if (m.hasFileOnRemoteHost() || GeoHelper.isGeoUri(m.getBody()) || m.treatAsDownloadable() == Message.Decision.MUST || (t != null && t instanceof HttpDownloadConnection)) {
copyUrl.setVisible(true);
}
if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER) || (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
}
boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED;
if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
cancelTransmission.setVisible(true);
}
if (treatAsFile) {
String path = m.getRelativeFilePath();
if (path == null || !path.startsWith("/")) {
deleteFile.setVisible(true);
deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
}
}
if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
showErrorMessage.setVisible(true);
}
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ConversationFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
activity.getSelectedConversation().getAccount().getPgpDecryptionService().continueDecryption(true);
} else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) {
final String body = mEditMessage.getText().toString();
Message message = new Message(conversation, body, conversation.getNextEncryption());
sendAxolotlMessage(message);
} else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_MENU) {
int choice = data.getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID);
activity.selectPresenceToAttachFile(choice, conversation.getNextEncryption());
}
}
}
Aggregations