finished offline otr

This commit is contained in:
iNPUTmice 2014-06-12 23:04:28 +02:00
parent b1482212b8
commit 592aded106
5 changed files with 47 additions and 23 deletions

View file

@ -97,9 +97,6 @@
<string name="error_loading_image">Error loading image (File not found)</string> <string name="error_loading_image">Error loading image (File not found)</string>
<string name="image_offered_for_download"><i>Image file offered for download</i></string> <string name="image_offered_for_download"><i>Image file offered for download</i></string>
<string name="not_connected">Not Connected</string> <string name="not_connected">Not Connected</string>
<string name="you_are_offline">You have to be online to send %s but your account assoziated with this Conversation is currently offline.</string>
<string name="you_are_offline_blank">You can not perform this action while being offline</string>
<string name="files">files</string>
<string name="otr_messages">OTR encrypted messages</string> <string name="otr_messages">OTR encrypted messages</string>
<string name="manage_account">Manage account</string> <string name="manage_account">Manage account</string>
<string name="contact_offline">Your Contact is Offline</string> <string name="contact_offline">Your Contact is Offline</string>
@ -112,6 +109,7 @@
<string name="restart">Restart</string> <string name="restart">Restart</string>
<string name="install">Install</string> <string name="install">Install</string>
<string name="offering">offering&#8230;</string> <string name="offering">offering&#8230;</string>
<string name="waiting">waiting&#8230;</string>
<string name="no_pgp_key">No OpenPGP Key found</string> <string name="no_pgp_key">No OpenPGP Key found</string>
<string name="contact_has_no_pgp_key">Conversations is unable to encrypt your messages because your contact is not announcing his or hers public key.\n\n<small>Please ask your contact to setup OpenPGP.</small></string> <string name="contact_has_no_pgp_key">Conversations is unable to encrypt your messages because your contact is not announcing his or hers public key.\n\n<small>Please ask your contact to setup OpenPGP.</small></string>
<string name="no_pgp_keys">No OpenPGP Keys found</string> <string name="no_pgp_keys">No OpenPGP Keys found</string>

View file

@ -19,6 +19,7 @@ public class Message extends AbstractEntity {
public static final int STATUS_SEND = 2; public static final int STATUS_SEND = 2;
public static final int STATUS_SEND_FAILED = 3; public static final int STATUS_SEND_FAILED = 3;
public static final int STATUS_SEND_REJECTED = 4; public static final int STATUS_SEND_REJECTED = 4;
public static final int STATUS_WAITING = 5;
public static final int STATUS_OFFERED = 6; public static final int STATUS_OFFERED = 6;
public static final int STATUS_SEND_RECEIVED = 7; public static final int STATUS_SEND_RECEIVED = 7;
public static final int STATUS_SEND_DISPLAYED = 8; public static final int STATUS_SEND_DISPLAYED = 8;
@ -200,8 +201,12 @@ public class Message extends AbstractEntity {
} }
public void setPresence(String presence) { public void setPresence(String presence) {
if (presence == null) {
this.counterpart = this.counterpart.split("/")[0];
} else {
this.counterpart = this.counterpart.split("/")[0] + "/" + presence; this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
} }
}
public String getPresence() { public String getPresence() {
String[] counterparts = this.counterpart.split("/"); String[] counterparts = this.counterpart.split("/");

View file

@ -102,7 +102,7 @@ public class XmppConnectionService extends Service {
Conversation conversation = findActiveConversation(contact); Conversation conversation = findActiveConversation(contact);
if (conversation != null) { if (conversation != null) {
conversation.endOtrIfNeeded(); conversation.endOtrIfNeeded();
if (online&&(contact.getPresences().size() == 1)) { if (online && (contact.getPresences().size() == 1)) {
sendUnsendMessages(conversation); sendUnsendMessages(conversation);
} }
} }
@ -653,17 +653,19 @@ public class XmppConnectionService extends Service {
mJingleConnectionManager.createNewConnection(message); mJingleConnectionManager.createNewConnection(message);
} else { } else {
if (message.getEncryption() == Message.ENCRYPTION_OTR) { if (message.getEncryption() == Message.ENCRYPTION_OTR) {
if (!conv.hasValidOtrSession()) { if (!conv.hasValidOtrSession()&&(message.getPresence() != null)) {
// starting otr session. messages will be send later // starting otr session. messages will be send later
conv.startOtrSession(getApplicationContext(), message.getPresence(), conv.startOtrSession(getApplicationContext(),
true); message.getPresence(), true);
} else if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) { } else if (conv.hasValidOtrSession() && conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
// otr session aleary exists, creating message packet // otr session aleary exists, creating message packet
// accordingly // accordingly
packet = prepareMessagePacket(account, message, packet = prepareMessagePacket(account, message,
conv.getOtrSession()); conv.getOtrSession());
send = true; send = true;
message.setStatus(Message.STATUS_SEND); message.setStatus(Message.STATUS_SEND);
} else if (message.getPresence() == null) {
message.setStatus(Message.STATUS_WAITING);
} }
saveInDb = true; saveInDb = true;
addToConversation = true; addToConversation = true;
@ -700,10 +702,15 @@ public class XmppConnectionService extends Service {
message.setBody(decryptedBody); message.setBody(decryptedBody);
addToConversation = true; addToConversation = true;
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) { } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
if (!conv.hasValidOtrSession()) { if (conv.hasValidOtrSession()) {
conv.startOtrSession(getApplicationContext(), message.getPresence(),false); message.setPresence(conv.getOtrSession().getSessionID()
.getUserID());
} else if (!conv.hasValidOtrSession() && message.getPresence() != null) {
conv.startOtrSession(getApplicationContext(),
message.getPresence(), false);
} else if (message.getPresence() == null) {
message.setStatus(Message.STATUS_WAITING);
} }
message.setPresence(conv.getOtrSession().getSessionID().getUserID());
saveInDb = true; saveInDb = true;
addToConversation = true; addToConversation = true;
} else { } else {
@ -729,7 +736,9 @@ public class XmppConnectionService extends Service {
private void sendUnsendMessages(Conversation conversation) { private void sendUnsendMessages(Conversation conversation) {
for (int i = 0; i < conversation.getMessages().size(); ++i) { for (int i = 0; i < conversation.getMessages().size(); ++i) {
if (conversation.getMessages().get(i).getStatus() == Message.STATUS_UNSEND) { int status = conversation.getMessages().get(i).getStatus();
if ((status == Message.STATUS_UNSEND)
|| (status == Message.STATUS_WAITING)) {
resendMessage(conversation.getMessages().get(i)); resendMessage(conversation.getMessages().get(i));
} }
} }
@ -756,14 +765,19 @@ public class XmppConnectionService extends Service {
packet.addChild("x", "jabber:x:encrypted").setContent( packet.addChild("x", "jabber:x:encrypted").setContent(
message.getBody()); message.getBody());
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) { } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
Presences presences = message.getConversation().getContact().getPresences(); Presences presences = message.getConversation().getContact()
.getPresences();
if (!message.getConversation().hasValidOtrSession()) { if (!message.getConversation().hasValidOtrSession()) {
if ((message.getPresence() != null)&&(presences.has(message.getPresence()))) { if ((message.getPresence() != null)
message.getConversation().startOtrSession(getApplicationContext(), message.getPresence(), true); && (presences.has(message.getPresence()))) {
message.getConversation().startOtrSession(
getApplicationContext(), message.getPresence(),
true);
} else { } else {
if (presences.size() == 1) { if (presences.size() == 1) {
String presence = presences.asStringArray()[0]; String presence = presences.asStringArray()[0];
message.getConversation().startOtrSession(getApplicationContext(), presence, true); message.getConversation().startOtrSession(
getApplicationContext(), presence, true);
} }
} }
} }
@ -774,6 +788,7 @@ public class XmppConnectionService extends Service {
} }
} else if (message.getType() == Message.TYPE_IMAGE) { } else if (message.getType() == Message.TYPE_IMAGE) {
// TODO: send images // TODO: send images
} }
} }
@ -1194,10 +1209,12 @@ public class XmppConnectionService extends Service {
Account account = conversation.getAccount(); Account account = conversation.getAccount();
List<Message> messages = conversation.getMessages(); List<Message> messages = conversation.getMessages();
Session otrSession = conversation.getOtrSession(); Session otrSession = conversation.getOtrSession();
Log.d(LOGTAG,account.getJid()+" otr session established with "+conversation.getContactJid()+"/"+otrSession.getSessionID().getUserID()); Log.d(LOGTAG, account.getJid() + " otr session established with "
+ conversation.getContactJid() + "/"
+ otrSession.getSessionID().getUserID());
for (int i = 0; i < messages.size(); ++i) { for (int i = 0; i < messages.size(); ++i) {
Message msg = messages.get(i); Message msg = messages.get(i);
if ((msg.getStatus() == Message.STATUS_UNSEND) if ((msg.getStatus() == Message.STATUS_UNSEND || msg.getStatus() == Message.STATUS_WAITING)
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) { && (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
MessagePacket outPacket = prepareMessagePacket(account, msg, MessagePacket outPacket = prepareMessagePacket(account, msg,
otrSession); otrSession);

View file

@ -389,7 +389,7 @@ public class ConversationActivity extends XmppActivity {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}, "file"); });
} }
private void attachFile(final int attachmentChoice) { private void attachFile(final int attachmentChoice) {
@ -868,7 +868,7 @@ public class ConversationActivity extends XmppActivity {
} }
public void selectPresence(final Conversation conversation, public void selectPresence(final Conversation conversation,
final OnPresenceSelected listener, String reason) { final OnPresenceSelected listener) {
Contact contact = conversation.getContact(); Contact contact = conversation.getContact();
if (contact == null) { if (contact == null) {
showAddToRosterDialog(conversation); showAddToRosterDialog(conversation);

View file

@ -207,6 +207,9 @@ public class ConversationFragment extends Fragment {
} }
} }
switch (message.getStatus()) { switch (message.getStatus()) {
case Message.STATUS_WAITING:
info = getString(R.string.waiting);
break;
case Message.STATUS_UNSEND: case Message.STATUS_UNSEND:
info = getString(R.string.sending); info = getString(R.string.sending);
break; break;
@ -883,7 +886,7 @@ public class ConversationFragment extends Fragment {
} }
protected void sendOtrMessage(final Message message) { protected void sendOtrMessage(final Message message) {
ConversationActivity activity = (ConversationActivity) getActivity(); final ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService; final XmppConnectionService xmppService = activity.xmppConnectionService;
if (conversation.hasValidOtrSession()) { if (conversation.hasValidOtrSession()) {
activity.xmppConnectionService.sendMessage(message); activity.xmppConnectionService.sendMessage(message);
@ -896,6 +899,7 @@ public class ConversationFragment extends Fragment {
public void onPresenceSelected(boolean success, public void onPresenceSelected(boolean success,
String presence) { String presence) {
if (success) { if (success) {
Log.d("xmppService","selected presence "+presence);
message.setPresence(presence); message.setPresence(presence);
xmppService.sendMessage(message); xmppService.sendMessage(message);
messageSent(); messageSent();
@ -908,7 +912,7 @@ public class ConversationFragment extends Fragment {
xmppService.sendMessage(message); xmppService.sendMessage(message);
messageSent(); messageSent();
} }
}, "otr"); });
} }
} }