MUC: set the password from bookmarks.

This commit is contained in:
Michael 2014-09-07 14:06:23 +02:00
parent d9990e6cd8
commit ecd613dcdd
4 changed files with 59 additions and 3 deletions

View File

@ -13,7 +13,9 @@ public class Bookmark implements ListItem {
private String jid; private String jid;
private String nick; private String nick;
private String name; private String name;
private String password;
private boolean autojoin; private boolean autojoin;
private boolean providePassword;
private Conversation mJoinedConversation; private Conversation mJoinedConversation;
public Bookmark(Account account, String jid) { public Bookmark(Account account, String jid) {
@ -35,6 +37,11 @@ public class Bookmark implements ListItem {
if (nick != null) { if (nick != null) {
bookmark.setNick(nick.getContent()); bookmark.setNick(nick.getContent());
} }
Element password = element.findChild("password");
if (password != null) {
bookmark.setPassword(password.getContent());
bookmark.setProvidePassword(true);
}
return bookmark; return bookmark;
} }
@ -50,6 +57,14 @@ public class Bookmark implements ListItem {
this.nick = nick; this.nick = nick;
} }
public void setPassword(String password) {
this.password = password;
}
private void setProvidePassword(boolean providePassword) {
this.providePassword = providePassword;
}
@Override @Override
public int compareTo(ListItem another) { public int compareTo(ListItem another) {
return this.getDisplayName().compareToIgnoreCase( return this.getDisplayName().compareToIgnoreCase(
@ -81,6 +96,14 @@ public class Bookmark implements ListItem {
return autojoin; return autojoin;
} }
public String getPassword() {
return this.password;
}
public boolean isProvidePassword() {
return this.providePassword;
}
public boolean match(String needle) { public boolean match(String needle) {
return needle == null return needle == null
|| getJid().contains(needle.toLowerCase(Locale.US)) || getJid().contains(needle.toLowerCase(Locale.US))
@ -125,6 +148,9 @@ public class Bookmark implements ListItem {
if (this.nick != null) { if (this.nick != null) {
element.addChild("nick").setContent(this.nick); element.addChild("nick").setContent(this.nick);
} }
if (this.password != null && isProvidePassword()) {
element.addChild("password").setContent(this.password);
}
return element; return element;
} }

View File

@ -108,6 +108,7 @@ public class MucOptions {
private String subject = null; private String subject = null;
private String joinnick; private String joinnick;
private String password = null; private String password = null;
private boolean passwordChanged = false;
public MucOptions(Account account) { public MucOptions(Account account) {
this.account = account; this.account = account;
@ -157,6 +158,10 @@ public class MucOptions {
} }
aboutToRename = false; aboutToRename = false;
} }
if (conversation.getBookmark() != null &&
conversation.getBookmark().isProvidePassword()) {
this.passwordChanged = false;
}
} else { } else {
addUser(user); addUser(user);
} }
@ -189,6 +194,10 @@ public class MucOptions {
this.error = ERROR_NICK_IN_USE; this.error = ERROR_NICK_IN_USE;
} }
} else if (error.hasChild("not-authorized")) { } else if (error.hasChild("not-authorized")) {
if (conversation.getBookmark() != null &&
conversation.getBookmark().isProvidePassword()) {
this.passwordChanged = true;
}
this.error = ERROR_PASSWORD_REQUIRED; this.error = ERROR_PASSWORD_REQUIRED;
} }
} }
@ -314,10 +323,25 @@ public class MucOptions {
} }
public String getPassword() { public String getPassword() {
if (conversation.getBookmark() != null &&
conversation.getBookmark().getPassword() != null) {
return conversation.getBookmark().getPassword();
} else {
return this.password; return this.password;
} }
}
public void setPassword(String password) { public void setPassword(String password) {
if (conversation.getBookmark() != null &&
conversation.getBookmark().isProvidePassword()) {
conversation.getBookmark().setPassword(password);
} else {
this.password = password; this.password = password;
} }
} }
public boolean isPasswordChanged() {
return this.passwordChanged;
}
}

View File

@ -1,7 +1,6 @@
package eu.siacs.conversations.parser; package eu.siacs.conversations.parser;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
import net.java.otr4j.session.Session; import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;

View File

@ -1099,6 +1099,13 @@ public class XmppConnectionService extends Service {
public void providePasswordForMuc(Conversation conversation, String password) { public void providePasswordForMuc(Conversation conversation, String password) {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
conversation.getMucOptions().setPassword(password); conversation.getMucOptions().setPassword(password);
if (conversation.getBookmark() != null &&
conversation.getMucOptions().isPasswordChanged()) {
if (!conversation.getBookmark().autojoin()) {
conversation.getBookmark().setAutojoin(true);
}
pushBookmarks(conversation.getAccount());
}
joinMuc(conversation); joinMuc(conversation);
} }
} }