pushing bookmarks back to server
This commit is contained in:
parent
6031af8606
commit
2ebd92b7a7
|
@ -268,4 +268,5 @@
|
||||||
<string name="conference_address_example">room@conference.example.com</string>
|
<string name="conference_address_example">room@conference.example.com</string>
|
||||||
<string name="save_as_bookmark">Save as bookmark</string>
|
<string name="save_as_bookmark">Save as bookmark</string>
|
||||||
<string name="delete_bookmark">Delete bookmark</string>
|
<string name="delete_bookmark">Delete bookmark</string>
|
||||||
|
<string name="bookmark_already_exists">This bookmark already exists</string>
|
||||||
</resources>
|
</resources>
|
|
@ -309,4 +309,13 @@ public class Account extends AbstractEntity{
|
||||||
public List<Bookmark> getBookmarks() {
|
public List<Bookmark> getBookmarks() {
|
||||||
return this.bookmarks;
|
return this.bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasBookmarkFor(String conferenceJid) {
|
||||||
|
for(Bookmark bmark : this.bookmarks) {
|
||||||
|
if (bmark.getJid().equals(conferenceJid)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ public class Bookmark implements ListItem {
|
||||||
private boolean autojoin;
|
private boolean autojoin;
|
||||||
private Conversation mJoinedConversation;
|
private Conversation mJoinedConversation;
|
||||||
|
|
||||||
public Bookmark(Account account) {
|
public Bookmark(Account account, String jid) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
this.jid = jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bookmark parse(Element element, Account account) {
|
public static Bookmark parse(Element element, Account account) {
|
||||||
Bookmark bookmark = new Bookmark(account);
|
Bookmark bookmark = new Bookmark(account,element.getAttribute("jid"));
|
||||||
bookmark.setJid(element.getAttribute("jid"));
|
|
||||||
bookmark.setName(element.getAttribute("name"));
|
bookmark.setName(element.getAttribute("name"));
|
||||||
String autojoin = element.getAttribute("autojoin");
|
String autojoin = element.getAttribute("autojoin");
|
||||||
if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) {
|
if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) {
|
||||||
|
@ -45,10 +45,6 @@ public class Bookmark implements ListItem {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJid(String jid) {
|
|
||||||
this.jid = jid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNick(String nick) {
|
public void setNick(String nick) {
|
||||||
this.nick = nick;
|
this.nick = nick;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +56,8 @@ public class Bookmark implements ListItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
if (this.mJoinedConversation!=null) {
|
if (this.mJoinedConversation!=null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
|
||||||
return this.mJoinedConversation.getName(true);
|
return this.mJoinedConversation.getMucOptions().getSubject();
|
||||||
} else if (name!=null) {
|
} else if (name!=null) {
|
||||||
return name;
|
return name;
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,4 +105,21 @@ public class Bookmark implements ListItem {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -390,4 +390,8 @@ public class Conversation extends AbstractEntity {
|
||||||
this.bookmark.setConversation(null);
|
this.bookmark.setConversation(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bookmark getBookmark() {
|
||||||
|
return this.bookmark;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,6 +702,16 @@ public class XmppConnectionService extends Service {
|
||||||
sendIqPacket(account, iqPacket, callback);
|
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() {
|
private void mergePhoneContactsWithRoster() {
|
||||||
PhoneHelper.loadPhoneContacts(getApplicationContext(),
|
PhoneHelper.loadPhoneContacts(getApplicationContext(),
|
||||||
|
@ -840,6 +850,11 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void archiveConversation(Conversation conversation) {
|
public void archiveConversation(Conversation conversation) {
|
||||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||||
|
Bookmark bookmark = conversation.getBookmark();
|
||||||
|
if (bookmark!=null && bookmark.autojoin()) {
|
||||||
|
bookmark.setAutojoin(false);
|
||||||
|
pushBookmarks(bookmark.getAccount());
|
||||||
|
}
|
||||||
leaveMuc(conversation);
|
leaveMuc(conversation);
|
||||||
} else {
|
} else {
|
||||||
conversation.endOtrIfNeeded();
|
conversation.endOtrIfNeeded();
|
||||||
|
@ -1005,10 +1020,10 @@ public class XmppConnectionService extends Service {
|
||||||
+ "/" + conversation.getMucOptions().getNick());
|
+ "/" + conversation.getMucOptions().getNick());
|
||||||
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
||||||
packet.setAttribute("type", "unavailable");
|
packet.setAttribute("type", "unavailable");
|
||||||
Log.d(LOGTAG, "send leaving muc " + packet);
|
|
||||||
sendPresencePacket(conversation.getAccount(),packet);
|
sendPresencePacket(conversation.getAccount(),packet);
|
||||||
conversation.getMucOptions().setOffline();
|
conversation.getMucOptions().setOffline();
|
||||||
conversation.deregisterWithBookmark();
|
conversation.deregisterWithBookmark();
|
||||||
|
Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(Account account, boolean force) {
|
public void disconnect(Account account, boolean force) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
@ -222,6 +223,10 @@ public class StartConversation extends XmppActivity {
|
||||||
Bookmark bookmark = (Bookmark) conferences.get(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);
|
conversation.setBookmark(bookmark);
|
||||||
|
if (!bookmark.autojoin()) {
|
||||||
|
bookmark.setAutojoin(true);
|
||||||
|
xmppConnectionService.pushBookmarks(bookmark.getAccount());
|
||||||
|
}
|
||||||
switchToConversation(conversation);
|
switchToConversation(conversation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,6 +242,15 @@ public class StartConversation extends XmppActivity {
|
||||||
xmppConnectionService.deleteContactOnServer(contact);
|
xmppConnectionService.deleteContactOnServer(contact);
|
||||||
filter(mSearchEditText.getText().toString());
|
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() {
|
protected void showCreateContactDialog() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
@ -293,6 +307,7 @@ public class StartConversation extends XmppActivity {
|
||||||
jid.setAdapter(new KnownHostsAdapter(this,
|
jid.setAdapter(new KnownHostsAdapter(this,
|
||||||
android.R.layout.simple_list_item_1, mKnownConferenceHosts));
|
android.R.layout.simple_list_item_1, mKnownConferenceHosts));
|
||||||
populateAccountSpinner(spinner);
|
populateAccountSpinner(spinner);
|
||||||
|
final CheckBox bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
|
||||||
builder.setView(dialogView);
|
builder.setView(dialogView);
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
builder.setPositiveButton(R.string.join, null);
|
builder.setPositiveButton(R.string.join, null);
|
||||||
|
@ -309,10 +324,26 @@ public class StartConversation extends XmppActivity {
|
||||||
String conferenceJid = jid.getText().toString();
|
String conferenceJid = jid.getText().toString();
|
||||||
Account account = xmppConnectionService
|
Account account = xmppConnectionService
|
||||||
.findAccountByJid(accountJid);
|
.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,
|
.findOrCreateConversation(account,
|
||||||
conferenceJid, true);
|
conferenceJid, true);
|
||||||
switchToConversation(conversation);
|
switchToConversation(conversation);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
jid.setError(getString(R.string.invalid_jid));
|
jid.setError(getString(R.string.invalid_jid));
|
||||||
}
|
}
|
||||||
|
@ -508,6 +539,8 @@ public class StartConversation extends XmppActivity {
|
||||||
case R.id.context_join_conference:
|
case R.id.context_join_conference:
|
||||||
activity.openConversationForBookmark();
|
activity.openConversationForBookmark();
|
||||||
break;
|
break;
|
||||||
|
case R.id.context_delete_conference:
|
||||||
|
activity.deleteConference();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue