use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class ConversationActivity method attachFileToConversation.
private void attachFileToConversation(Conversation conversation, Uri uri) {
if (conversation == null) {
return;
}
final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
prepareFileToast.show();
xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() {
@Override
public void inform(final String text) {
hidePrepareFileToast(prepareFileToast);
runOnUiThread(new Runnable() {
@Override
public void run() {
replaceToast(text);
}
});
}
@Override
public void success(Message message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
hideToast();
}
});
hidePrepareFileToast(prepareFileToast);
xmppConnectionService.sendMessage(message);
}
@Override
public void error(final int errorCode, Message message) {
hidePrepareFileToast(prepareFileToast);
runOnUiThread(new Runnable() {
@Override
public void run() {
replaceToast(getString(errorCode));
}
});
}
@Override
public void userInputRequried(PendingIntent pi, Message message) {
hidePrepareFileToast(prepareFileToast);
}
});
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
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 eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class XmppConnectionService method resendFailedMessages.
public void resendFailedMessages(final Message message) {
final Collection<Message> messages = new ArrayList<>();
Message current = message;
while (current.getStatus() == Message.STATUS_SEND_FAILED) {
messages.add(current);
if (current.mergeable(current.next())) {
current = current.next();
} else {
break;
}
}
for (final Message msg : messages) {
msg.setTime(System.currentTimeMillis());
markMessage(msg, Message.STATUS_WAITING);
this.resendMessage(msg, false);
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
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 {
callback.success(message);
}
}
use of eu.siacs.conversations.entities.Message in project Conversations by siacs.
the class XmppConnectionService method onOtrSessionEstablished.
public void onOtrSessionEstablished(Conversation conversation) {
final Account account = conversation.getAccount();
final Session otrSession = conversation.getOtrSession();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {
@Override
public void onMessageFound(Message message) {
SessionID id = otrSession.getSessionID();
try {
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (InvalidJidException e) {
return;
}
if (message.needsUploading()) {
mJingleConnectionManager.createNewConnection(message);
} else {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
if (outPacket != null) {
mMessageGenerator.addDelay(outPacket, message.getTimeSent());
message.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(message);
sendMessagePacket(account, outPacket);
}
}
updateConversationUi();
}
});
}
Aggregations