aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/eu/siacs/conversations/entities/Bookmark.java6
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java42
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java2
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java45
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java9
-rw-r--r--src/eu/siacs/conversations/ui/MucDetailsActivity.java4
-rw-r--r--src/eu/siacs/conversations/ui/StartConversation.java115
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java6
9 files changed, 152 insertions, 80 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 10a3f0e2..5aa7afe1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -37,7 +37,8 @@
<string name="participant">Participant</string>
<string name="visitor">Visitor</string>
<string name="enter_new_name">Enter a new name:</string>
- <string name="remove_contact_text">Do you want to delete %s from your roster? The conversation associated with this account will not be removed.</string>
+ <string name="remove_contact_text">Would you like to remove %s from your roster? The conversation associated with this contact will not be removed.</string>
+ <string name="remove_bookmark_text">Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed.</string>
<string name="untrusted_cert_hint">The server %s presented you with an untrusted, possible self signed, certificate.</string>
<string name="account_info">Server Info</string>
<string name="register_account">Register new account on server</string>
diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java
index c4e151cb..38c03410 100644
--- a/src/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/eu/siacs/conversations/entities/Bookmark.java
@@ -122,4 +122,10 @@ public class Bookmark implements ListItem {
}
return element;
}
+
+ public void unregisterConversation() {
+ if (this.mJoinedConversation != null) {
+ this.mJoinedConversation.deregisterWithBookmark();
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 0f8e3565..3c5190de 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -87,6 +87,7 @@ public class MucOptions {
private boolean aboutToRename = false;
private User self = new User();
private String subject = null;
+ private String nick;
public MucOptions(Account account) {
this.account = account;
@@ -123,7 +124,7 @@ public class MucOptions {
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
user.setName(name);
- if (name.equals(getNick())) {
+ if (name.equals(getJoinNick())) {
this.isOnline = true;
this.error = 0;
self = user;
@@ -145,7 +146,7 @@ public class MucOptions {
}
}
} else if (type.equals("unavailable")) {
- if (name.equals(getNick())) {
+ if (name.equals(self.getName())) {
Element item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
String nick = item.getAttribute("nick");
if (nick!=null) {
@@ -153,7 +154,6 @@ public class MucOptions {
if (renameListener!=null) {
renameListener.onRename(true);
}
- this.setNick(nick);
}
}
deleteUser(packet.getAttribute("from").split("/")[1]);
@@ -165,6 +165,7 @@ public class MucOptions {
renameListener.onRename(false);
}
aboutToRename = false;
+ this.setJoinNick(getActualNick());
} else {
this.error = ERROR_NICK_IN_USE;
}
@@ -177,22 +178,33 @@ public class MucOptions {
return this.users;
}
- public String getNick() {
- String[] split = conversation.getContactJid().split("/");
- if (split.length == 2) {
- return split[1];
+ public String getProposedNick() {
+ String[] mucParts = conversation.getContactJid().split("/");
+ if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) {
+ return conversation.getBookmark().getNick();
} else {
- if (conversation.getAccount()!=null) {
- return conversation.getAccount().getUsername();
+ if (mucParts.length == 2) {
+ return mucParts[1];
} else {
- return null;
+ return account.getUsername();
}
}
}
- public void setNick(String nick) {
- String jid = conversation.getContactJid().split("/")[0]+"/"+nick;
- conversation.setContactJid(jid);
+ public String getJoinNick() {
+ return this.nick;
+ }
+
+ public String getActualNick() {
+ if (this.self.getName()!=null) {
+ return this.self.getName();
+ } else {
+ return this.getProposedNick();
+ }
+ }
+
+ public void setJoinNick(String nick) {
+ this.nick = nick;
}
public void setConversation(Conversation conversation) {
@@ -268,4 +280,8 @@ public class MucOptions {
}
return true;
}
+
+ public String getJoinJid() {
+ return this.conversation.getContactJid().split("/")[0]+"/"+this.getJoinNick();
+ }
} \ No newline at end of file
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index 1673fbf0..d4e1e08d 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -121,7 +121,7 @@ public class MessageParser extends AbstractParser implements
return null;
}
String counterPart = fromParts[1];
- if (counterPart.equals(conversation.getMucOptions().getNick())) {
+ if (counterPart.equals(conversation.getMucOptions().getActualNick())) {
if (mXmppConnectionService.markMessage(conversation,
packet.getId(), Message.STATUS_SEND)) {
return null;
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index c43a34b7..abcb1f97 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -691,6 +691,7 @@ public class XmppConnectionService extends Service {
if (bookmark.autojoin()) {
conversation = findOrCreateConversation(account, bookmark.getJid(), true);
conversation.setBookmark(bookmark);
+ joinMuc(conversation);
}
}
}
@@ -840,10 +841,6 @@ public class XmppConnectionService extends Service {
this.databaseBackend.createConversation(conversation);
}
this.conversations.add(conversation);
- if ((account.getStatus() == Account.STATUS_ONLINE)
- && (conversation.getMode() == Conversation.MODE_MULTI)) {
- joinMuc(conversation);
- }
updateConversationUi();
return conversation;
}
@@ -933,19 +930,12 @@ public class XmppConnectionService extends Service {
}
public void joinMuc(Conversation conversation) {
+ Log.d(LOGTAG,"joining conversation "+conversation.getContactJid());
Account account = conversation.getAccount();
- String[] mucParts = conversation.getContactJid().split("/");
- String muc;
- String nick;
- if (mucParts.length == 2) {
- muc = mucParts[0];
- nick = mucParts[1];
- } else {
- muc = mucParts[0];
- nick = account.getUsername();
- }
+ String nick = conversation.getMucOptions().getProposedNick();
+ conversation.getMucOptions().setJoinNick(nick);
PresencePacket packet = new PresencePacket();
- packet.setAttribute("to", muc + "/" + nick);
+ packet.setAttribute("to",conversation.getMucOptions().getJoinJid());
Element x = new Element("x");
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
String sig = account.getPgpSignature();
@@ -974,6 +964,7 @@ public class XmppConnectionService extends Service {
public void renameInMuc(final Conversation conversation, final String nick) {
final MucOptions options = conversation.getMucOptions();
+ options.setJoinNick(nick);
if (options.online()) {
Account account = conversation.getAccount();
options.setOnRenameListener(new OnRenameListener() {
@@ -984,17 +975,19 @@ public class XmppConnectionService extends Service {
renameListener.onRename(success);
}
if (success) {
- String jid = conversation.getContactJid().split("/")[0]
- + "/" + nick;
- conversation.setContactJid(jid);
+ conversation.setContactJid(conversation.getMucOptions().getJoinJid());
databaseBackend.updateConversation(conversation);
+ Bookmark bookmark = conversation.getBookmark();
+ if (bookmark!=null) {
+ bookmark.setNick(nick);
+ pushBookmarks(bookmark.getAccount());
+ }
}
}
});
options.flagAboutToRename();
PresencePacket packet = new PresencePacket();
- packet.setAttribute("to",
- conversation.getContactJid().split("/")[0] + "/" + nick);
+ packet.setAttribute("to",options.getJoinJid());
packet.setAttribute("from", conversation.getAccount().getFullJid());
String sig = account.getPgpSignature();
@@ -1004,11 +997,14 @@ public class XmppConnectionService extends Service {
}
sendPresencePacket(account,packet);
} else {
- String jid = conversation.getContactJid().split("/")[0] + "/"
- + nick;
- conversation.setContactJid(jid);
+ conversation.setContactJid(options.getJoinJid());
databaseBackend.updateConversation(conversation);
if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
+ Bookmark bookmark = conversation.getBookmark();
+ if (bookmark!=null) {
+ bookmark.setNick(nick);
+ pushBookmarks(bookmark.getAccount());
+ }
joinMuc(conversation);
}
}
@@ -1016,8 +1012,7 @@ public class XmppConnectionService extends Service {
public void leaveMuc(Conversation conversation) {
PresencePacket packet = new PresencePacket();
- packet.setAttribute("to", conversation.getContactJid().split("/")[0]
- + "/" + conversation.getMucOptions().getNick());
+ packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
packet.setAttribute("from", conversation.getAccount().getFullJid());
packet.setAttribute("type", "unavailable");
sendPresencePacket(conversation.getAccount(),packet);
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 01bab773..a21246af 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -183,6 +183,15 @@ public class ConversationFragment extends Fragment {
final View view = inflater.inflate(R.layout.fragment_conversation,
container, false);
chatMsg = (EditText) view.findViewById(R.id.textinput);
+ chatMsg.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ if (activity.getSlidingPaneLayout().isSlideable()) {
+ activity.getSlidingPaneLayout().closePane();
+ }
+ }
+ });
ImageButton sendButton = (ImageButton) view
.findViewById(R.id.textSendButton);
diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java
index 8226e381..a81e49d6 100644
--- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java
@@ -48,7 +48,7 @@ public class MucDetailsActivity extends XmppActivity {
public void onClick(View arg0) {
MucOptions options = conversation.getMucOptions();
String nick = mYourNick.getText().toString();
- if (!options.getNick().equals(nick)) {
+ if (!options.getActualNick().equals(nick)) {
xmppConnectionService.renameInMuc(conversation, nick);
finish();
}
@@ -149,7 +149,7 @@ public class MucDetailsActivity extends XmppActivity {
mSubject.setText(conversation.getMucOptions().getSubject());
setTitle(conversation.getName(useSubject));
mFullJid.setText(conversation.getContactJid().split("/")[0]);
- mYourNick.setText(conversation.getMucOptions().getNick());
+ mYourNick.setText(conversation.getMucOptions().getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (conversation.getMucOptions().online()) {
mMoreDetails.setVisibility(View.VISIBLE);
diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java
index c9166c39..f23eb420 100644
--- a/src/eu/siacs/conversations/ui/StartConversation.java
+++ b/src/eu/siacs/conversations/ui/StartConversation.java
@@ -12,6 +12,8 @@ import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
@@ -43,7 +45,6 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.utils.KnownHostsAdapter;
-import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.Validator;
public class StartConversation extends XmppActivity {
@@ -65,7 +66,7 @@ public class StartConversation extends XmppActivity {
private List<String> mKnownConferenceHosts;
private EditText mSearchEditText;
-
+
public int conference_context_id;
public int contact_context_id;
@@ -178,14 +179,15 @@ public class StartConversation extends XmppActivity {
mConferenceAdapter = new ListItemAdapter(conferences);
mConferenceListFragment.setListAdapter(mConferenceAdapter);
mConferenceListFragment.setContextMenu(R.menu.conference_context);
- mConferenceListFragment.setOnListItemClickListener(new OnItemClickListener() {
+ mConferenceListFragment
+ .setOnListItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int position, long arg3) {
- openConversationForBookmark(position);
- }
- });
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1,
+ int position, long arg3) {
+ openConversationForBookmark(position);
+ }
+ });
mContactsAdapter = new ListItemAdapter(contacts);
mContactsListFragment.setListAdapter(mContactsAdapter);
@@ -209,20 +211,25 @@ public class StartConversation extends XmppActivity {
contact.getJid(), false);
switchToConversation(conversation);
}
-
+
protected void openConversationForContact() {
int position = contact_context_id;
openConversationForContact(position);
}
-
+
protected void openConversationForBookmark() {
openConversationForBookmark(conference_context_id);
}
-
+
protected void openConversationForBookmark(int position) {
Bookmark bookmark = (Bookmark) conferences.get(position);
- Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), bookmark.getJid(), true);
+ Conversation conversation = xmppConnectionService
+ .findOrCreateConversation(bookmark.getAccount(),
+ bookmark.getJid(), true);
conversation.setBookmark(bookmark);
+ if (!conversation.getMucOptions().online()) {
+ xmppConnectionService.joinMuc(conversation);
+ }
if (!bookmark.autojoin()) {
bookmark.setAutojoin(true);
xmppConnectionService.pushBookmarks(bookmark.getAccount());
@@ -238,18 +245,48 @@ public class StartConversation extends XmppActivity {
protected void deleteContact() {
int position = contact_context_id;
- Contact contact = (Contact) contacts.get(position);
- xmppConnectionService.deleteContactOnServer(contact);
- filter(mSearchEditText.getText().toString());
+ final Contact contact = (Contact) contacts.get(position);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setTitle(R.string.action_delete_contact);
+ builder.setMessage(
+ getString(R.string.remove_contact_text,
+ contact.getJid()));
+ builder.setPositiveButton(R.string.delete,new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ xmppConnectionService.deleteContactOnServer(contact);
+ filter(mSearchEditText.getText().toString());
+ }
+ });
+ builder.create().show();
+
}
-
+
protected void deleteConference() {
- int position = contact_context_id;
- Bookmark bookmark = (Bookmark) conferences.get(position);
- Account account = bookmark.getAccount();
- account.getBookmarks().remove(bookmark);
- xmppConnectionService.pushBookmarks(account);
- filter(mSearchEditText.getText().toString());
+ int position = conference_context_id;
+ final Bookmark bookmark = (Bookmark) conferences.get(position);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setTitle(R.string.delete_bookmark);
+ builder.setMessage(
+ getString(R.string.remove_bookmark_text,
+ bookmark.getJid()));
+ builder.setPositiveButton(R.string.delete,new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ bookmark.unregisterConversation();
+ Account account = bookmark.getAccount();
+ account.getBookmarks().remove(bookmark);
+ xmppConnectionService.pushBookmarks(account);
+ filter(mSearchEditText.getText().toString());
+ }
+ });
+ builder.create().show();
+
}
protected void showCreateContactDialog() {
@@ -307,7 +344,8 @@ public class StartConversation extends XmppActivity {
jid.setAdapter(new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1, mKnownConferenceHosts));
populateAccountSpinner(spinner);
- final CheckBox bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
+ final CheckBox bookmarkCheckBox = (CheckBox) dialogView
+ .findViewById(R.id.bookmark);
builder.setView(dialogView);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.join, null);
@@ -328,20 +366,28 @@ public class StartConversation extends XmppActivity {
if (account.hasBookmarkFor(conferenceJid)) {
jid.setError(getString(R.string.bookmark_already_exists));
} else {
- Bookmark bookmark = new Bookmark(account, conferenceJid);
+ Bookmark bookmark = new Bookmark(account,
+ conferenceJid);
bookmark.setAutojoin(true);
account.getBookmarks().add(bookmark);
- xmppConnectionService.pushBookmarks(account);
+ xmppConnectionService
+ .pushBookmarks(account);
Conversation conversation = xmppConnectionService
.findOrCreateConversation(account,
conferenceJid, true);
conversation.setBookmark(bookmark);
- switchToConversation(conversation);
+ if (!conversation.getMucOptions().online()) {
+ xmppConnectionService.joinMuc(conversation);
+ }
+ switchToConversation(conversation);
}
} else {
Conversation conversation = xmppConnectionService
- .findOrCreateConversation(account,
- conferenceJid, true);
+ .findOrCreateConversation(account,
+ conferenceJid, true);
+ if (!conversation.getMucOptions().online()) {
+ xmppConnectionService.joinMuc(conversation);
+ }
switchToConversation(conversation);
}
} else {
@@ -416,7 +462,7 @@ public class StartConversation extends XmppActivity {
this.mKnownConferenceHosts = xmppConnectionService
.getKnownConferenceHosts();
}
-
+
protected void filter(String needle) {
this.filterContacts(needle);
this.filterConferences(needle);
@@ -436,12 +482,12 @@ public class StartConversation extends XmppActivity {
Collections.sort(this.contacts);
mContactsAdapter.notifyDataSetChanged();
}
-
+
protected void filterConferences(String needle) {
this.conferences.clear();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.STATUS_DISABLED) {
- for(Bookmark bookmark : account.getBookmarks()) {
+ for (Bookmark bookmark : account.getBookmarks()) {
if (bookmark.match(needle)) {
this.conferences.add(bookmark);
}
@@ -486,7 +532,7 @@ public class StartConversation extends XmppActivity {
public static class MyListFragment extends ListFragment {
private AdapterView.OnItemClickListener mOnItemClickListener;
private int mResContextMenu;
-
+
public void setContextMenu(int res) {
this.mResContextMenu = res;
}
@@ -513,8 +559,7 @@ public class StartConversation extends XmppActivity {
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
StartConversation activity = (StartConversation) getActivity();
- activity.getMenuInflater().inflate(mResContextMenu,
- menu);
+ activity.getMenuInflater().inflate(mResContextMenu, menu);
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
if (mResContextMenu == R.menu.conference_context) {
activity.conference_context_id = acmi.position;
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index ede43830..4e902817 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -216,7 +216,7 @@ public class UIHelper {
bgColor, fgColor);
}
String[] names = new String[members.size() + 1];
- names[0] = conversation.getMucOptions().getNick();
+ names[0] = conversation.getMucOptions().getActualNick();
for (int i = 0; i < members.size(); ++i) {
names[i + 1] = members.get(i).getName();
}
@@ -343,7 +343,7 @@ public class UIHelper {
if ((currentCon != null)
&& (currentCon.getMode() == Conversation.MODE_MULTI)
&& (!alwaysNotify)) {
- String nick = currentCon.getMucOptions().getNick();
+ String nick = currentCon.getMucOptions().getActualNick();
Pattern highlight = generateNickHighlightPattern(nick);
Matcher m = highlight.matcher(currentCon.getLatestMessage()
.getBody());
@@ -463,7 +463,7 @@ public class UIHelper {
private static boolean wasHighlighted(Conversation conversation) {
List<Message> messages = conversation.getMessages();
- String nick = conversation.getMucOptions().getNick();
+ String nick = conversation.getMucOptions().getActualNick();
Pattern highlight = generateNickHighlightPattern(nick);
for (int i = messages.size() - 1; i >= 0; --i) {
if (messages.get(i).isRead()) {