incomming jingle packets are routed to their connection. added presence chooser in gui

This commit is contained in:
Daniel Gultsch 2014-04-10 14:12:08 +02:00
parent ba0bedc5fa
commit 644473205a
9 changed files with 318 additions and 160 deletions

View File

@ -48,4 +48,6 @@
<string name="problem_connecting_to_accounts">Unable to connect to multiple accounts</string> <string name="problem_connecting_to_accounts">Unable to connect to multiple accounts</string>
<string name="touch_to_fix">Touch here to manage your accounts</string> <string name="touch_to_fix">Touch here to manage your accounts</string>
<string name="action_attach_file">Attach file</string> <string name="action_attach_file">Attach file</string>
<string name="not_in_roster">The contact is not in your roster. Would you like to add it?</string>
<string name="add_contact">Add contact</string>
</resources> </resources>

View File

@ -46,6 +46,8 @@ public class Conversation extends AbstractEntity {
private long created; private long created;
private int mode; private int mode;
private String nextPresence;
private transient List<Message> messages = null; private transient List<Message> messages = null;
private transient Account account = null; private transient Account account = null;
private transient Contact contact; private transient Contact contact;
@ -308,4 +310,12 @@ public class Conversation extends AbstractEntity {
public void setContactJid(String jid) { public void setContactJid(String jid) {
this.contactJid = jid; this.contactJid = jid;
} }
public void setNextPresence(String presence) {
this.nextPresence = presence;
}
public String getNextPresence() {
return this.nextPresence;
}
} }

View File

@ -166,4 +166,8 @@ public class Message extends AbstractEntity {
public int getType() { public int getType() {
return this.type; return this.type;
} }
public void setPresence(String presence) {
this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
}
} }

View File

@ -372,7 +372,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onJinglePacketReceived(Account account, JinglePacket packet) { public void onJinglePacketReceived(Account account, JinglePacket packet) {
Log.d(LOGTAG,account.getJid()+": jingle packet received"+packet.toString()); mJingleConnectionManager.deliverPacket(account, packet);
} }
}; };
@ -401,8 +401,9 @@ public class XmppConnectionService extends Service {
return this.fileBackend; return this.fileBackend;
} }
public Message attachImageToConversation(Conversation conversation, Uri uri) { public Message attachImageToConversation(Conversation conversation, String presence, Uri uri) {
Message message = new Message(conversation, "", Message.ENCRYPTION_NONE); Message message = new Message(conversation, "", Message.ENCRYPTION_NONE);
message.setPresence(presence);
message.setType(Message.TYPE_IMAGE); message.setType(Message.TYPE_IMAGE);
File file = this.fileBackend.copyImageToPrivateStorage(message, uri); File file = this.fileBackend.copyImageToPrivateStorage(message, uri);
Log.d(LOGTAG,"new file"+file.getAbsolutePath()); Log.d(LOGTAG,"new file"+file.getAbsolutePath());

View File

@ -1,9 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
@ -11,11 +9,8 @@ import eu.siacs.conversations.entities.Account;
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.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -24,12 +19,10 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -50,6 +43,7 @@ public class ConversationActivity extends XmppActivity {
public static final String VIEW_CONVERSATION = "viewConversation"; public static final String VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid"; public static final String CONVERSATION = "conversationUuid";
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String PRESENCE = "eu.siacs.conversations.presence";
public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_SEND_MESSAGE = 0x75441;
public static final int REQUEST_DECRYPT_PGP = 0x76783; public static final int REQUEST_DECRYPT_PGP = 0x76783;
@ -74,16 +68,18 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
public void run() { public void run() {
updateConversationList(); updateConversationList();
if(paneShouldBeOpen) { if (paneShouldBeOpen) {
if (conversationList.size() >= 1) { if (conversationList.size() >= 1) {
swapConversationFragment(); swapConversationFragment();
} else { } else {
startActivity(new Intent(getApplicationContext(), ContactsActivity.class)); startActivity(new Intent(getApplicationContext(),
ContactsActivity.class));
finish(); finish();
} }
} }
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
if (selectedFragment!=null) { .findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.updateMessages(); selectedFragment.updateMessages();
} }
} }
@ -91,17 +87,6 @@ public class ConversationActivity extends XmppActivity {
} }
}; };
private DialogInterface.OnClickListener addToRoster = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String jid = getSelectedConversation().getContactJid();
Account account = getSelectedConversation().getAccount();
String name = jid.split("@")[0];
Contact contact = new Contact(account, name, jid, null);
xmppConnectionService.createContact(contact);
}
};
protected ConversationActivity activity = this; protected ConversationActivity activity = this;
public List<Conversation> getConversationList() { public List<Conversation> getConversationList() {
@ -149,7 +134,7 @@ public class ConversationActivity extends XmppActivity {
return view; return view;
} }
if (!spl.isSlideable()) { if (!spl.isSlideable()) {
if (conv==getSelectedConversation()) { if (conv == getSelectedConversation()) {
view.setBackgroundColor(0xffdddddd); view.setBackgroundColor(0xffdddddd);
} else { } else {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
@ -157,24 +142,30 @@ public class ConversationActivity extends XmppActivity {
} else { } else {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
} }
TextView convName = (TextView) view.findViewById(R.id.conversation_name); TextView convName = (TextView) view
.findViewById(R.id.conversation_name);
convName.setText(conv.getName(useSubject)); convName.setText(conv.getName(useSubject));
TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg); TextView convLastMsg = (TextView) view
.findViewById(R.id.conversation_lastmsg);
convLastMsg.setText(conv.getLatestMessage().getBody()); convLastMsg.setText(conv.getLatestMessage().getBody());
if(!conv.isRead()) { if (!conv.isRead()) {
convName.setTypeface(null,Typeface.BOLD); convName.setTypeface(null, Typeface.BOLD);
convLastMsg.setTypeface(null,Typeface.BOLD); convLastMsg.setTypeface(null, Typeface.BOLD);
} else { } else {
convName.setTypeface(null,Typeface.NORMAL); convName.setTypeface(null, Typeface.NORMAL);
convLastMsg.setTypeface(null,Typeface.NORMAL); convLastMsg.setTypeface(null, Typeface.NORMAL);
} }
((TextView) view.findViewById(R.id.conversation_lastupdate)) ((TextView) view.findViewById(R.id.conversation_lastupdate))
.setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent())); .setText(UIHelper.readableTimeDifference(conv
.getLatestMessage().getTimeSent()));
ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image); ImageView imageView = (ImageView) view
imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(useSubject),200, activity.getApplicationContext())); .findViewById(R.id.conversation_image);
imageView.setImageBitmap(UIHelper.getContactPicture(
conv.getContact(), conv.getName(useSubject), 200,
activity.getApplicationContext()));
return view; return view;
} }
@ -190,7 +181,7 @@ public class ConversationActivity extends XmppActivity {
paneShouldBeOpen = false; paneShouldBeOpen = false;
if (selectedConversation != conversationList.get(position)) { if (selectedConversation != conversationList.get(position)) {
selectedConversation = conversationList.get(position); selectedConversation = conversationList.get(position);
swapConversationFragment(); //.onBackendConnected(conversationList.get(position)); swapConversationFragment(); // .onBackendConnected(conversationList.get(position));
} else { } else {
spl.closePane(); spl.closePane();
} }
@ -214,13 +205,16 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
public void onPanelClosed(View arg0) { public void onPanelClosed(View arg0) {
paneShouldBeOpen = false; paneShouldBeOpen = false;
if ((conversationList.size() > 0)&&(getSelectedConversation()!=null)) { if ((conversationList.size() > 0)
&& (getSelectedConversation() != null)) {
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle(getSelectedConversation().getName(useSubject)); getActionBar().setTitle(
getSelectedConversation().getName(useSubject));
invalidateOptionsMenu(); invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
getSelectedConversation().markRead(); getSelectedConversation().markRead();
UIHelper.updateNotification(getApplicationContext(), getConversationList(), null, false); UIHelper.updateNotification(getApplicationContext(),
getConversationList(), null, false);
listView.invalidateViews(); listView.invalidateViews();
} }
} }
@ -239,12 +233,15 @@ public class ConversationActivity extends XmppActivity {
getMenuInflater().inflate(R.menu.conversations, menu); getMenuInflater().inflate(R.menu.conversations, menu);
MenuItem menuSecure = (MenuItem) menu.findItem(R.id.action_security); MenuItem menuSecure = (MenuItem) menu.findItem(R.id.action_security);
MenuItem menuArchive = (MenuItem) menu.findItem(R.id.action_archive); MenuItem menuArchive = (MenuItem) menu.findItem(R.id.action_archive);
MenuItem menuMucDetails = (MenuItem) menu.findItem(R.id.action_muc_details); MenuItem menuMucDetails = (MenuItem) menu
MenuItem menuContactDetails = (MenuItem) menu.findItem(R.id.action_contact_details); .findItem(R.id.action_muc_details);
MenuItem menuInviteContacts = (MenuItem) menu.findItem(R.id.action_invite); MenuItem menuContactDetails = (MenuItem) menu
.findItem(R.id.action_contact_details);
MenuItem menuInviteContacts = (MenuItem) menu
.findItem(R.id.action_invite);
MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file); MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file);
if ((spl.isOpen()&&(spl.isSlideable()))) { if ((spl.isOpen() && (spl.isSlideable()))) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -252,8 +249,9 @@ public class ConversationActivity extends XmppActivity {
menuInviteContacts.setVisible(false); menuInviteContacts.setVisible(false);
menuAttach.setVisible(false); menuAttach.setVisible(false);
} else { } else {
((MenuItem) menu.findItem(R.id.action_add)).setVisible(!spl.isSlideable()); ((MenuItem) menu.findItem(R.id.action_add)).setVisible(!spl
if (this.getSelectedConversation()!=null) { .isSlideable());
if (this.getSelectedConversation() != null) {
if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
menuMucDetails.setVisible(true); menuMucDetails.setVisible(true);
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -265,7 +263,8 @@ public class ConversationActivity extends XmppActivity {
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
menuInviteContacts.setVisible(false); menuInviteContacts.setVisible(false);
menuAttach.setVisible(true); menuAttach.setVisible(true);
if (this.getSelectedConversation().getLatestMessage().getEncryption() != Message.ENCRYPTION_NONE) { if (this.getSelectedConversation().getLatestMessage()
.getEncryption() != Message.ENCRYPTION_NONE) {
menuSecure.setIcon(R.drawable.ic_action_secure); menuSecure.setIcon(R.drawable.ic_action_secure);
} }
} }
@ -281,11 +280,19 @@ public class ConversationActivity extends XmppActivity {
spl.openPane(); spl.openPane();
break; break;
case R.id.action_attach_file: case R.id.action_attach_file:
selectPresence(getSelectedConversation(), new OnPresenceSelected() {
@Override
public void onPresenceSelected(boolean success, String presence) {
if (success) {
Intent attachFileIntent = new Intent(); Intent attachFileIntent = new Intent();
attachFileIntent.setType("image/*"); attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(attachFileIntent, Intent chooser = Intent.createChooser(attachFileIntent, "Attach File");
"Attach File"), ATTACH_FILE); startActivityForResult(chooser, ATTACH_FILE);
}
}
});
break; break;
case R.id.action_add: case R.id.action_add:
startActivity(new Intent(this, ContactsActivity.class)); startActivity(new Intent(this, ContactsActivity.class));
@ -305,22 +312,16 @@ public class ConversationActivity extends XmppActivity {
case R.id.action_contact_details: case R.id.action_contact_details:
Contact contact = this.getSelectedConversation().getContact(); Contact contact = this.getSelectedConversation().getContact();
if (contact != null) { if (contact != null) {
Intent intent = new Intent(this,ContactDetailsActivity.class); Intent intent = new Intent(this, ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra("uuid", contact.getUuid()); intent.putExtra("uuid", contact.getUuid());
startActivity(intent); startActivity(intent);
} else { } else {
String jid = getSelectedConversation().getContactJid(); showAddToRosterDialog(getSelectedConversation());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(jid);
builder.setMessage("The contact is not in your roster. Would you like to add it.");
builder.setNegativeButton("Cancel", null);
builder.setPositiveButton("Add",addToRoster);
builder.create().show();
} }
break; break;
case R.id.action_muc_details: case R.id.action_muc_details:
Intent intent = new Intent(this,MucDetailsActivity.class); Intent intent = new Intent(this, MucDetailsActivity.class);
intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", getSelectedConversation().getUuid()); intent.putExtra("uuid", getSelectedConversation().getUuid());
startActivity(intent); startActivity(intent);
@ -329,15 +330,16 @@ public class ConversationActivity extends XmppActivity {
Intent inviteIntent = new Intent(getApplicationContext(), Intent inviteIntent = new Intent(getApplicationContext(),
ContactsActivity.class); ContactsActivity.class);
inviteIntent.setAction("invite"); inviteIntent.setAction("invite");
inviteIntent.putExtra("uuid",selectedConversation.getUuid()); inviteIntent.putExtra("uuid", selectedConversation.getUuid());
startActivity(inviteIntent); startActivity(inviteIntent);
break; break;
case R.id.action_security: case R.id.action_security:
final Conversation selConv = getSelectedConversation(); final Conversation selConv = getSelectedConversation();
View menuItemView = findViewById(R.id.action_security); View menuItemView = findViewById(R.id.action_security);
PopupMenu popup = new PopupMenu(this, menuItemView); PopupMenu popup = new PopupMenu(this, menuItemView);
final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
if (fragment!=null) { .findFragmentByTag("conversation");
if (fragment != null) {
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override @Override
@ -366,19 +368,24 @@ public class ConversationActivity extends XmppActivity {
popup.inflate(R.menu.encryption_choices); popup.inflate(R.menu.encryption_choices);
switch (selConv.nextMessageEncryption) { switch (selConv.nextMessageEncryption) {
case Message.ENCRYPTION_NONE: case Message.ENCRYPTION_NONE:
popup.getMenu().findItem(R.id.encryption_choice_none).setChecked(true); popup.getMenu().findItem(R.id.encryption_choice_none)
.setChecked(true);
break; break;
case Message.ENCRYPTION_OTR: case Message.ENCRYPTION_OTR:
popup.getMenu().findItem(R.id.encryption_choice_otr).setChecked(true); popup.getMenu().findItem(R.id.encryption_choice_otr)
.setChecked(true);
break; break;
case Message.ENCRYPTION_PGP: case Message.ENCRYPTION_PGP:
popup.getMenu().findItem(R.id.encryption_choice_pgp).setChecked(true); popup.getMenu().findItem(R.id.encryption_choice_pgp)
.setChecked(true);
break; break;
case Message.ENCRYPTION_DECRYPTED: case Message.ENCRYPTION_DECRYPTED:
popup.getMenu().findItem(R.id.encryption_choice_pgp).setChecked(true); popup.getMenu().findItem(R.id.encryption_choice_pgp)
.setChecked(true);
break; break;
default: default:
popup.getMenu().findItem(R.id.encryption_choice_none).setChecked(true); popup.getMenu().findItem(R.id.encryption_choice_none)
.setChecked(true);
break; break;
} }
popup.show(); popup.show();
@ -396,7 +403,8 @@ public class ConversationActivity extends XmppActivity {
FragmentTransaction transaction = getFragmentManager() FragmentTransaction transaction = getFragmentManager()
.beginTransaction(); .beginTransaction();
transaction.replace(R.id.selected_conversation, selectedFragment,"conversation"); transaction.replace(R.id.selected_conversation, selectedFragment,
"conversation");
transaction.commit(); transaction.commit();
return selectedFragment; return selectedFragment;
} }
@ -415,12 +423,13 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
this.useSubject = preferences.getBoolean("use_subject_in_muc", true); this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (this.xmppConnectionServiceBound) { if (this.xmppConnectionServiceBound) {
this.onBackendConnected(); this.onBackendConnected();
} }
if (conversationList.size()>=1) { if (conversationList.size() >= 1) {
onConvChanged.onConversationListChanged(); onConvChanged.onConversationListChanged();
} }
} }
@ -436,18 +445,20 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
void onBackendConnected() { void onBackendConnected() {
this.registerListener(); this.registerListener();
if (conversationList.size()==0) { if (conversationList.size() == 0) {
updateConversationList(); updateConversationList();
} }
if ((getIntent().getAction()!=null)&&(getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { if ((getIntent().getAction() != null)
&& (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) {
if (getIntent().getType().equals( if (getIntent().getType().equals(
ConversationActivity.VIEW_CONVERSATION)) { ConversationActivity.VIEW_CONVERSATION)) {
handledViewIntent = true; handledViewIntent = true;
String convToView = (String) getIntent().getExtras().get(CONVERSATION); String convToView = (String) getIntent().getExtras().get(
CONVERSATION);
for(int i = 0; i < conversationList.size(); ++i) { for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) { if (conversationList.get(i).getUuid().equals(convToView)) {
selectedConversation = conversationList.get(i); selectedConversation = conversationList.get(i);
} }
@ -461,48 +472,108 @@ public class ConversationActivity extends XmppActivity {
startActivity(new Intent(this, ManageAccountActivity.class)); startActivity(new Intent(this, ManageAccountActivity.class));
finish(); finish();
} else if (conversationList.size() <= 0) { } else if (conversationList.size() <= 0) {
//add no history // add no history
startActivity(new Intent(this, ContactsActivity.class)); startActivity(new Intent(this, ContactsActivity.class));
finish(); finish();
} else { } else {
spl.openPane(); spl.openPane();
//find currently loaded fragment // find currently loaded fragment
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
if (selectedFragment!=null) { .findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.onBackendConnected(); selectedFragment.onBackendConnected();
} else { } else {
selectedConversation = conversationList.get(0); selectedConversation = conversationList.get(0);
swapConversationFragment(); swapConversationFragment();
} }
ExceptionHelper.checkForCrash(this,this.xmppConnectionService); ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
} }
} }
} }
public void registerListener() { public void registerListener() {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.setOnConversationListChangedListener(this.onConvChanged); xmppConnectionService
.setOnConversationListChangedListener(this.onConvChanged);
} }
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_DECRYPT_PGP) { if (requestCode == REQUEST_DECRYPT_PGP) {
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
if (selectedFragment!=null) { .findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.hidePgpPassphraseBox(); selectedFragment.hidePgpPassphraseBox();
} }
} else if (requestCode == ATTACH_FILE) { } else if (requestCode == ATTACH_FILE) {
xmppConnectionService.attachImageToConversation(getSelectedConversation(), data.getData()); Conversation conversation = getSelectedConversation();
String presence = conversation.getNextPresence();
xmppConnectionService.attachImageToConversation(conversation, presence, data.getData());
} }
} }
} }
public void updateConversationList() { public void updateConversationList() {
conversationList.clear(); conversationList.clear();
conversationList.addAll(xmppConnectionService conversationList.addAll(xmppConnectionService.getConversations());
.getConversations());
listView.invalidateViews(); listView.invalidateViews();
} }
public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
Contact contact = conversation.getContact();
if (contact==null) {
showAddToRosterDialog(conversation);
listener.onPresenceSelected(false,null);
} else {
Hashtable<String, Integer> presences = contact.getPresences();
if (presences.size() == 0) {
listener.onPresenceSelected(false, null);
} else if (presences.size() == 1) {
String presence = (String) presences.keySet().toArray()[0];
conversation.setNextPresence(presence);
listener.onPresenceSelected(true, presence);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose Presence");
final String[] presencesArray = new String[presences.size()];
presences.keySet().toArray(presencesArray);
builder.setItems(presencesArray,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String presence = presencesArray[which];
conversation.setNextPresence(presence);
listener.onPresenceSelected(true,presence);
}
});
builder.create().show();
}
}
}
private void showAddToRosterDialog(final Conversation conversation) {
String jid = conversation.getContactJid();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(jid);
builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String jid = conversation.getContactJid();
Account account = getSelectedConversation().getAccount();
String name = jid.split("@")[0];
Contact contact = new Contact(account, name, jid, null);
xmppConnectionService.createContact(contact);
}
});
builder.create().show();
}
} }

View File

@ -0,0 +1,5 @@
package eu.siacs.conversations.ui;
public interface OnPresenceSelected {
public void onPresenceSelected(boolean success, String presence);
}

View File

@ -19,6 +19,11 @@ public class JingleConnection {
private JingleConnectionManager mJingleConnectionManager; private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService; private XmppConnectionService mXmppConnectionService;
public static final int STATUS_INITIATED = 0;
public static final int STATUS_ACCEPTED = 1;
public static final int STATUS_FAILED = 99;
private int status = -1;
private Message message; private Message message;
private String sessionId; private String sessionId;
private Account account; private Account account;
@ -30,7 +35,9 @@ public class JingleConnection {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
Log.d("xmppService",packet.toString()); if (packet.getType() == IqPacket.TYPE_ERROR) {
status = STATUS_FAILED;
}
} }
}; };
@ -44,6 +51,21 @@ public class JingleConnection {
return this.sessionId; return this.sessionId;
} }
public String getAccountJid() {
return this.account.getJid();
}
public String getCounterPart() {
return this.message.getCounterpart();
}
public void deliverPacket(JinglePacket packet) {
Log.d("xmppService","packet arrived in connection");
if (packet.isAction("")) {
}
}
public void init(Message message) { public void init(Message message) {
this.message = message; this.message = message;
this.account = message.getConversation().getAccount(); this.account = message.getConversation().getAccount();
@ -78,13 +100,14 @@ public class JingleConnection {
packet.setContent(content); packet.setContent(content);
Log.d("xmppService",packet.toString()); Log.d("xmppService",packet.toString());
account.getXmppConnection().sendIqPacket(packet, this.responseListener); account.getXmppConnection().sendIqPacket(packet, this.responseListener);
this.status = STATUS_INITIATED;
} }
} }
private JinglePacket bootstrapPacket() { private JinglePacket bootstrapPacket() {
JinglePacket packet = new JinglePacket(); JinglePacket packet = new JinglePacket();
packet.setFrom(account.getFullJid()); packet.setFrom(account.getFullJid());
packet.setTo(this.message.getCounterpart()+"/Gajim"); //fixme, not right in all cases; packet.setTo(this.message.getCounterpart()); //fixme, not right in all cases;
packet.setSessionId(this.sessionId); packet.setSessionId(this.sessionId);
return packet; return packet;
} }

View File

@ -20,7 +20,8 @@ public class JingleConnectionManager {
private XmppConnectionService xmppConnectionService; private XmppConnectionService xmppConnectionService;
private List<JingleConnection> connections = new ArrayList<JingleConnection>(); //make concurrent private List<JingleConnection> connections = new ArrayList<JingleConnection>(); // make
// concurrent
private ConcurrentHashMap<String, Element> primaryCanditates = new ConcurrentHashMap<String, Element>(); private ConcurrentHashMap<String, Element> primaryCanditates = new ConcurrentHashMap<String, Element>();
@ -31,19 +32,34 @@ public class JingleConnectionManager {
} }
public void deliverPacket(Account account, JinglePacket packet) { public void deliverPacket(Account account, JinglePacket packet) {
String id = generateInternalId(account.getJid(), packet.getFrom(), packet.getSessionId()); for (JingleConnection connection : connections) {
if (connection.getAccountJid().equals(account.getJid()) && connection
.getSessionId().equals(packet.getSessionId()) && connection
.getCounterPart().equals(packet.getFrom())) {
connection.deliverPacket(packet);
return;
}
}
Log.d("xmppService","delivering packet failed "+packet.toString());
} }
public JingleConnection createNewConnection(Message message) { public JingleConnection createNewConnection(Message message) {
Account account = message.getConversation().getAccount(); Account account = message.getConversation().getAccount();
JingleConnection connection = new JingleConnection(this); JingleConnection connection = new JingleConnection(this);
String id = generateInternalId(account.getJid(), message.getCounterpart(), connection.getSessionId());
connection.init(message); connection.init(message);
connections.add(connection);
return connection; return connection;
} }
private String generateInternalId(String account, String counterpart, String sid) { public JingleConnection createNewConnection(JinglePacket packet) {
return account+"#"+counterpart+"#"+sid; JingleConnection connection = new JingleConnection(this);
connections.add(connection);
return connection;
}
private String generateInternalId(String account, String counterpart,
String sid) {
return account + "#" + counterpart + "#" + sid;
} }
@ -51,30 +67,47 @@ public class JingleConnectionManager {
return this.xmppConnectionService; return this.xmppConnectionService;
} }
public void getPrimaryCanditate(Account account, final OnPrimaryCanditateFound listener) { public void getPrimaryCanditate(Account account,
final OnPrimaryCanditateFound listener) {
if (!this.primaryCanditates.containsKey(account.getJid())) { if (!this.primaryCanditates.containsKey(account.getJid())) {
String xmlns = "http://jabber.org/protocol/bytestreams"; String xmlns = "http://jabber.org/protocol/bytestreams";
String proxy = account.getXmppConnection().findDiscoItemByFeature(xmlns); final String proxy = account.getXmppConnection()
if (proxy!=null) { .findDiscoItemByFeature(xmlns);
if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET); IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
iq.setTo(proxy); iq.setTo(proxy);
iq.query(xmlns); iq.query(xmlns);
account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() { account.getXmppConnection().sendIqPacket(iq,
new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account,
Element streamhost = packet.query().findChild("streamhost","http://jabber.org/protocol/bytestreams"); IqPacket packet) {
if (streamhost!=null) { Element streamhost = packet
Log.d("xmppService","streamhost found "+streamhost.toString()); .query()
.findChild("streamhost",
"http://jabber.org/protocol/bytestreams");
if (streamhost != null) {
Log.d("xmppService", "streamhost found "
+ streamhost.toString());
Element canditate = new Element("canditate"); Element canditate = new Element("canditate");
canditate.setAttribute("cid",nextRandomId()); canditate.setAttribute("cid",
canditate.setAttribute("host", streamhost.getAttribute("host")); nextRandomId());
canditate.setAttribute("port",streamhost.getAttribute("port")); canditate.setAttribute("host",
streamhost.getAttribute("host"));
canditate.setAttribute("port",
streamhost.getAttribute("port"));
canditate.setAttribute("type", "proxy"); canditate.setAttribute("type", "proxy");
primaryCanditates.put(account.getJid(), canditate); canditate.setAttribute("jid", proxy);
listener.onPrimaryCanditateFound(true, canditate); canditate
.setAttribute("priority", "655360");
primaryCanditates.put(account.getJid(),
canditate);
listener.onPrimaryCanditateFound(true,
canditate);
} else { } else {
listener.onPrimaryCanditateFound(false, null); listener.onPrimaryCanditateFound(false,
null);
} }
} }
}); });
@ -83,7 +116,8 @@ public class JingleConnectionManager {
} }
} else { } else {
listener.onPrimaryCanditateFound(true, this.primaryCanditates.get(account.getJid())); listener.onPrimaryCanditateFound(true,
this.primaryCanditates.get(account.getJid()));
} }
} }

View File

@ -70,7 +70,15 @@ public class JinglePacket extends IqPacket {
this.jingle.setAttribute("action", action); this.jingle.setAttribute("action", action);
} }
public String getAction() {
return this.jingle.getAttribute("action");
}
public void setInitiator(String initiator) { public void setInitiator(String initiator) {
this.jingle.setAttribute("initiator", initiator); this.jingle.setAttribute("initiator", initiator);
} }
public boolean isAction(String action) {
return action.equalsIgnoreCase(this.getAction());
}
} }