introduced downloadable interface. reverted some of the changes made to OTR

This commit is contained in:
iNPUTmice 2014-09-08 20:09:44 +02:00
parent a6f0f0cb6e
commit b23f8bd472
7 changed files with 20 additions and 40 deletions

View file

@ -240,7 +240,6 @@
<string name="missing_presence_updates">Missing presence updates from contact</string> <string name="missing_presence_updates">Missing presence updates from contact</string>
<string name="request_presence_updates">Please request presence updates from your contact first.\n\n<small>This will be used to determine what client(s) your contact is using.</small></string> <string name="request_presence_updates">Please request presence updates from your contact first.\n\n<small>This will be used to determine what client(s) your contact is using.</small></string>
<string name="request_now">Request now</string> <string name="request_now">Request now</string>
<string name="unable_to_decrypt_otr_message"><i>Unable to decrypt OTR message</i></string>
<string name="delete_fingerprint">Delete Fingerprint</string> <string name="delete_fingerprint">Delete Fingerprint</string>
<string name="sure_delete_fingerprint">Are you sure you would like to delete this fingerprint?</string> <string name="sure_delete_fingerprint">Are you sure you would like to delete this fingerprint?</string>
<string name="ignore">Ignore</string> <string name="ignore">Ignore</string>

View file

@ -174,21 +174,7 @@ public class OtrEngine implements OtrEngineHost {
@Override @Override
public void messageFromAnotherInstanceReceived(SessionID id) { public void messageFromAnotherInstanceReceived(SessionID id) {
String jid = id.getAccountID(); Log.d(Config.LOGTAG,"unreadable message received from "+id.getAccountID());
Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, jid, false);
Message error = new Message(conversation, null, Message.ENCRYPTION_OTR);
conversation.getMessages().add(error);
error.setStatus(Message.STATUS_RECEPTION_FAILED);
mXmppConnectionService.databaseBackend.createMessage(error);
SessionImpl session = conversation.getOtrSession();
if (session != null
&& session.getSessionStatus() != SessionStatus.ENCRYPTED) {
try {
session.startSession();
} catch (OtrException e) {
}
}
} }
@Override @Override

View file

@ -0,0 +1,5 @@
package eu.siacs.conversations.entities;
public interface Downloadable {
public void start();
}

View file

@ -2,7 +2,6 @@ package eu.siacs.conversations.entities;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.xmpp.jingle.JingleConnection;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
@ -60,7 +59,7 @@ public class Message extends AbstractEntity {
protected transient Conversation conversation = null; protected transient Conversation conversation = null;
protected transient JingleConnection jingleConnection = null; protected transient Downloadable downloadable = null;
private Message() { private Message() {
@ -151,8 +150,6 @@ public class Message extends AbstractEntity {
public String getReadableBody(Context context) { public String getReadableBody(Context context) {
if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) { if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) {
return context.getText(R.string.encrypted_message_received).toString(); return context.getText(R.string.encrypted_message_received).toString();
} else if (encryption == ENCRYPTION_OTR && type == TYPE_TEXT && status == STATUS_RECEPTION_FAILED) {
return context.getText(R.string.unable_to_decrypt_otr_message).toString();
} else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) { } else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) {
return context.getText(R.string.encrypted_image_received).toString(); return context.getText(R.string.encrypted_image_received).toString();
} else if (encryption == ENCRYPTION_DECRYPTION_FAILED) { } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) {
@ -270,12 +267,12 @@ public class Message extends AbstractEntity {
} }
} }
public void setJingleConnection(JingleConnection connection) { public void setDownloadable(Downloadable downloadable) {
this.jingleConnection = connection; this.downloadable = downloadable;
} }
public JingleConnection getJingleConnection() { public Downloadable getDownloadable() {
return this.jingleConnection; return this.downloadable;
} }
public static Message createStatusMessage(Conversation conversation) { public static Message createStatusMessage(Conversation conversation) {

View file

@ -62,10 +62,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
if (latestMessage.getType() == Message.TYPE_TEXT if (latestMessage.getType() == Message.TYPE_TEXT
|| latestMessage.getType() == Message.TYPE_PRIVATE) { || latestMessage.getType() == Message.TYPE_PRIVATE) {
if (latestMessage.getEncryption() == Message.ENCRYPTION_OTR if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& latestMessage.getStatus() == Message.STATUS_RECEPTION_FAILED) {
convLastMsg.setText(R.string.unable_to_decrypt_otr_message);
} else if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) { && (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
String body = Config.PARSE_EMOTICONS ? UIHelper String body = Config.PARSE_EMOTICONS ? UIHelper
.transformAsciiEmoticons(latestMessage.getBody()) .transformAsciiEmoticons(latestMessage.getBody())

View file

@ -7,6 +7,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
@ -461,10 +462,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
JingleConnection connection = item Downloadable downloadable = item.getDownloadable();
.getJingleConnection(); if (downloadable != null) {
if (connection != null) { downloadable.start();
connection.accept();
} }
} }
}); });
@ -495,11 +495,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
displayDecryptionFailed(viewHolder); displayDecryptionFailed(viewHolder);
} else if (item.getEncryption() == Message.ENCRYPTION_OTR
&& item.getStatus() == Message.STATUS_RECEPTION_FAILED
&& item.getType() == Message.TYPE_TEXT) {
displayInfoMessage(viewHolder,
R.string.unable_to_decrypt_otr_message);
} else { } else {
displayTextMessage(viewHolder, item); displayTextMessage(viewHolder, item);
} }

View file

@ -15,6 +15,7 @@ import android.util.Log;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
@ -24,7 +25,7 @@ import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
import eu.siacs.conversations.xmpp.jingle.stanzas.Reason; import eu.siacs.conversations.xmpp.jingle.stanzas.Reason;
import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleConnection { public class JingleConnection implements Downloadable {
private final String[] extensions = { "webp", "jpeg", "jpg", "png" }; private final String[] extensions = { "webp", "jpeg", "jpg", "png" };
private final String[] cryptoExtensions = { "pgp", "gpg", "otr" }; private final String[] cryptoExtensions = { "pgp", "gpg", "otr" };
@ -259,7 +260,7 @@ public class JingleConnection {
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
this.message.setType(Message.TYPE_IMAGE); this.message.setType(Message.TYPE_IMAGE);
this.message.setStatus(Message.STATUS_RECEIVED_OFFER); this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
this.message.setJingleConnection(this); this.message.setDownloadable(this);
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
this.message.setPresence(fromParts[1]); this.message.setPresence(fromParts[1]);
this.account = account; this.account = account;
@ -866,7 +867,7 @@ public class JingleConnection {
return this.transport; return this.transport;
} }
public void accept() { public void start() {
if (status == STATUS_INITIATED) { if (status == STATUS_INITIATED) {
new Thread(new Runnable() { new Thread(new Runnable() {