use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method directReply.
private void directReply(Conversation conversation, String body, final boolean dismissAfterReply) {
Message message = new Message(conversation, body, conversation.getNextEncryption());
message.markUnread();
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
getPgpEngine().encrypt(message, new UiCallback<Message>() {
@Override
public void success(Message message) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
sendMessage(message);
if (dismissAfterReply) {
markRead(message.getConversation(), true);
} else {
mNotificationService.pushFromDirectReply(message);
}
}
@Override
public void error(int errorCode, Message object) {
}
@Override
public void userInputRequried(PendingIntent pi, Message object) {
}
});
} else {
sendMessage(message);
if (dismissAfterReply) {
markRead(conversation, true);
} else {
mNotificationService.pushFromDirectReply(message);
}
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method attachLocationToConversation.
public void attachLocationToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) {
int encryption = conversation.getNextEncryption();
if (encryption == Message.ENCRYPTION_PGP) {
encryption = Message.ENCRYPTION_DECRYPTED;
}
Message message = new Message(conversation, uri.toString(), encryption);
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
}
if (encryption == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback);
} else {
sendMessage(message);
callback.success(message);
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method attachPhotoToConversation.
private void attachPhotoToConversation(Conversation conversation, Uri uri) {
if (conversation == null) {
return;
}
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
prepareFileToast.show();
activity.delegateUriPermissionsToService(uri);
activity.xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback<Message>() {
@Override
public void userInputRequried(PendingIntent pi, Message object) {
hidePrepareFileToast(prepareFileToast);
}
@Override
public void success(Message message) {
hidePrepareFileToast(prepareFileToast);
}
@Override
public void error(final int error, Message message) {
hidePrepareFileToast(prepareFileToast);
activity.runOnUiThread(() -> activity.replaceToast(getString(error)));
}
});
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method processExtras.
private void processExtras(Bundle extras) {
final String downloadUuid = extras.getString(ConversationActivity.EXTRA_DOWNLOAD_UUID);
final String text = extras.getString(ConversationActivity.EXTRA_TEXT);
final String nick = extras.getString(ConversationActivity.EXTRA_NICK);
final boolean pm = extras.getBoolean(ConversationActivity.EXTRA_IS_PRIVATE_MESSAGE, false);
if (nick != null) {
if (pm) {
Jid jid = conversation.getJid();
try {
Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
privateMessageWith(next);
} catch (final InvalidJidException ignored) {
// do nothing
}
} else {
highlightInConference(nick);
}
} else {
appendText(text);
}
final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid);
if (message != null) {
startDownloadable(message);
}
}
use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method handlePositiveActivityResult.
private void handlePositiveActivityResult(int requestCode, final Intent data) {
switch(requestCode) {
case REQUEST_TRUST_KEYS_TEXT:
final String body = binding.textinput.getText().toString();
Message message = new Message(conversation, body, conversation.getNextEncryption());
sendAxolotlMessage(message);
break;
case REQUEST_TRUST_KEYS_MENU:
int choice = data.getIntExtra("choice", ATTACHMENT_CHOICE_INVALID);
selectPresenceToAttachFile(choice);
break;
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
List<Uri> imageUris = AttachmentTool.extractUriFromIntent(data);
int ImageUrisCount = imageUris.size();
if (activity.xmppConnectionServiceBound) {
if (ImageUrisCount == 1) {
Uri uri = imageUris.get(0);
Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE");
attachImageToConversation(conversation, uri, false);
} else {
for (Iterator<Uri> i = imageUris.iterator(); i.hasNext(); i.remove()) {
Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching images to conversations. CHOOSE_IMAGES");
attachImagesToConversation(conversation, i.next());
}
}
}
break;
case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA:
Uri takePhotoUri = pendingTakePhotoUri.pop();
if (takePhotoUri != null) {
attachPhotoToConversation(conversation, takePhotoUri);
} else {
Log.d(Config.LOGTAG, "lost take photo uri. unable to to attach");
}
break;
case ATTACHMENT_CHOICE_CHOOSE_FILE:
case ATTACHMENT_CHOICE_RECORD_VOICE:
final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data);
String type = data.getType();
final PresenceSelector.OnPresenceSelected callback = () -> {
for (Iterator<Uri> i = fileUris.iterator(); i.hasNext(); i.remove()) {
Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE");
attachFileToConversation(conversation, i.next(), type);
}
};
if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), fileUris, getMaxHttpUploadSize(conversation))) {
callback.onPresenceSelected();
} else {
activity.selectPresence(conversation, callback);
}
break;
case ATTACHMENT_CHOICE_LOCATION:
double latitude = data.getDoubleExtra("latitude", 0);
double longitude = data.getDoubleExtra("longitude", 0);
Uri geo = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude));
attachLocationToConversation(conversation, geo);
break;
case REQUEST_INVITE_TO_CONVERSATION:
XmppActivity.ConferenceInvite invite = XmppActivity.ConferenceInvite.parse(data);
if (invite != null) {
if (invite.execute(activity)) {
activity.mToast = Toast.makeText(activity, R.string.creating_conference, Toast.LENGTH_LONG);
activity.mToast.show();
}
}
break;
}
}
Aggregations