diff options
Diffstat (limited to '')
5 files changed, 86 insertions, 12 deletions
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index 20abddcd0..ac62cf7b6 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -309,4 +309,13 @@ public class Account extends AbstractEntity{ public List<Bookmark> getBookmarks() { return this.bookmarks; } + + public boolean hasBookmarkFor(String conferenceJid) { + for(Bookmark bmark : this.bookmarks) { + if (bmark.getJid().equals(conferenceJid)) { + return true; + } + } + return false; + } } diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java index 6c1d7258f..c4e151cb3 100644 --- a/src/eu/siacs/conversations/entities/Bookmark.java +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -16,13 +16,13 @@ public class Bookmark implements ListItem { private boolean autojoin; private Conversation mJoinedConversation; - public Bookmark(Account account) { + public Bookmark(Account account, String jid) { this.account = account; + this.jid = jid; } public static Bookmark parse(Element element, Account account) { - Bookmark bookmark = new Bookmark(account); - bookmark.setJid(element.getAttribute("jid")); + Bookmark bookmark = new Bookmark(account,element.getAttribute("jid")); bookmark.setName(element.getAttribute("name")); String autojoin = element.getAttribute("autojoin"); if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) { @@ -45,10 +45,6 @@ public class Bookmark implements ListItem { this.name = name; } - public void setJid(String jid) { - this.jid = jid; - } - public void setNick(String nick) { this.nick = nick; } @@ -60,8 +56,8 @@ public class Bookmark implements ListItem { @Override public String getDisplayName() { - if (this.mJoinedConversation!=null) { - return this.mJoinedConversation.getName(true); + if (this.mJoinedConversation!=null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) { + return this.mJoinedConversation.getMucOptions().getSubject(); } else if (name!=null) { return name; } else { @@ -109,4 +105,21 @@ public class Bookmark implements ListItem { public String getName() { return name; } + + public Element toElement() { + Element element = new Element("conference"); + element.setAttribute("jid", this.getJid()); + if (this.getName() != null) { + element.setAttribute("name", this.getName()); + } + if (this.autojoin) { + element.setAttribute("autojoin", "true"); + } else { + element.setAttribute("autojoin", "false"); + } + if (this.nick != null) { + element.addChild("nick").setContent(this.nick); + } + return element; + } } diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 8e2c17843..70752adc2 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -390,4 +390,8 @@ public class Conversation extends AbstractEntity { this.bookmark.setConversation(null); } } + + public Bookmark getBookmark() { + return this.bookmark; + } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index aa62b8a1a..c43a34b78 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -702,6 +702,16 @@ public class XmppConnectionService extends Service { sendIqPacket(account, iqPacket, callback); } + + public void pushBookmarks(Account account) { + IqPacket iqPacket = new IqPacket(IqPacket.TYPE_SET); + Element query = iqPacket.query("jabber:iq:private"); + Element storage = query.addChild("storage", "storage:bookmarks"); + for(Bookmark bookmark : account.getBookmarks()) { + storage.addChild(bookmark.toElement()); + } + sendIqPacket(account, iqPacket,null); + } private void mergePhoneContactsWithRoster() { PhoneHelper.loadPhoneContacts(getApplicationContext(), @@ -840,6 +850,11 @@ public class XmppConnectionService extends Service { public void archiveConversation(Conversation conversation) { if (conversation.getMode() == Conversation.MODE_MULTI) { + Bookmark bookmark = conversation.getBookmark(); + if (bookmark!=null && bookmark.autojoin()) { + bookmark.setAutojoin(false); + pushBookmarks(bookmark.getAccount()); + } leaveMuc(conversation); } else { conversation.endOtrIfNeeded(); @@ -1005,10 +1020,10 @@ public class XmppConnectionService extends Service { + "/" + conversation.getMucOptions().getNick()); packet.setAttribute("from", conversation.getAccount().getFullJid()); packet.setAttribute("type", "unavailable"); - Log.d(LOGTAG, "send leaving muc " + packet); sendPresencePacket(conversation.getAccount(),packet); conversation.getMucOptions().setOffline(); conversation.deregisterWithBookmark(); + Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid()); } public void disconnect(Account account, boolean force) { diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index e11868582..c9166c39f 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -30,6 +30,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; @@ -222,6 +223,10 @@ public class StartConversation extends XmppActivity { Bookmark bookmark = (Bookmark) conferences.get(position); Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), bookmark.getJid(), true); conversation.setBookmark(bookmark); + if (!bookmark.autojoin()) { + bookmark.setAutojoin(true); + xmppConnectionService.pushBookmarks(bookmark.getAccount()); + } switchToConversation(conversation); } @@ -237,6 +242,15 @@ public class StartConversation extends XmppActivity { xmppConnectionService.deleteContactOnServer(contact); filter(mSearchEditText.getText().toString()); } + + 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()); + } protected void showCreateContactDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -293,6 +307,7 @@ 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); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.join, null); @@ -309,10 +324,26 @@ public class StartConversation extends XmppActivity { String conferenceJid = jid.getText().toString(); Account account = xmppConnectionService .findAccountByJid(accountJid); - Conversation conversation = xmppConnectionService + if (bookmarkCheckBox.isChecked()) { + if (account.hasBookmarkFor(conferenceJid)) { + jid.setError(getString(R.string.bookmark_already_exists)); + } else { + Bookmark bookmark = new Bookmark(account, conferenceJid); + bookmark.setAutojoin(true); + account.getBookmarks().add(bookmark); + xmppConnectionService.pushBookmarks(account); + Conversation conversation = xmppConnectionService + .findOrCreateConversation(account, + conferenceJid, true); + conversation.setBookmark(bookmark); + switchToConversation(conversation); + } + } else { + Conversation conversation = xmppConnectionService .findOrCreateConversation(account, conferenceJid, true); - switchToConversation(conversation); + switchToConversation(conversation); + } } else { jid.setError(getString(R.string.invalid_jid)); } @@ -508,6 +539,8 @@ public class StartConversation extends XmppActivity { case R.id.context_join_conference: activity.openConversationForBookmark(); break; + case R.id.context_delete_conference: + activity.deleteConference(); } return true; } |