diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-09-07 14:50:09 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-09-07 14:50:09 +0200 |
commit | 04665b59c8b96341ac050399aaf0654e2e4e3132 (patch) | |
tree | 5a09a1dc8093355fde000286f6c20ebeae713dd1 /src/eu/siacs | |
parent | d9990e6cd8bb4f2d9bc5696019f757db8a732b1f (diff) | |
parent | ecd613dcdd4288b52fea893192c75f3e527436ea (diff) |
Merge pull request #424 from betheg/bookmark_password
MUC: set the password from bookmarks.
Diffstat (limited to 'src/eu/siacs')
4 files changed, 59 insertions, 3 deletions
diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java index 596cbe01..14f010e7 100644 --- a/src/eu/siacs/conversations/entities/Bookmark.java +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -13,7 +13,9 @@ public class Bookmark implements ListItem { private String jid; private String nick; private String name; + private String password; private boolean autojoin; + private boolean providePassword; private Conversation mJoinedConversation; public Bookmark(Account account, String jid) { @@ -35,6 +37,11 @@ public class Bookmark implements ListItem { if (nick != null) { bookmark.setNick(nick.getContent()); } + Element password = element.findChild("password"); + if (password != null) { + bookmark.setPassword(password.getContent()); + bookmark.setProvidePassword(true); + } return bookmark; } @@ -50,6 +57,14 @@ public class Bookmark implements ListItem { this.nick = nick; } + public void setPassword(String password) { + this.password = password; + } + + private void setProvidePassword(boolean providePassword) { + this.providePassword = providePassword; + } + @Override public int compareTo(ListItem another) { return this.getDisplayName().compareToIgnoreCase( @@ -81,6 +96,14 @@ public class Bookmark implements ListItem { return autojoin; } + public String getPassword() { + return this.password; + } + + public boolean isProvidePassword() { + return this.providePassword; + } + public boolean match(String needle) { return needle == null || getJid().contains(needle.toLowerCase(Locale.US)) @@ -125,6 +148,9 @@ public class Bookmark implements ListItem { if (this.nick != null) { element.addChild("nick").setContent(this.nick); } + if (this.password != null && isProvidePassword()) { + element.addChild("password").setContent(this.password); + } return element; } diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 72fbeeab..3988eae0 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -108,6 +108,7 @@ public class MucOptions { private String subject = null; private String joinnick; private String password = null; + private boolean passwordChanged = false; public MucOptions(Account account) { this.account = account; @@ -157,6 +158,10 @@ public class MucOptions { } aboutToRename = false; } + if (conversation.getBookmark() != null && + conversation.getBookmark().isProvidePassword()) { + this.passwordChanged = false; + } } else { addUser(user); } @@ -189,6 +194,10 @@ public class MucOptions { this.error = ERROR_NICK_IN_USE; } } else if (error.hasChild("not-authorized")) { + if (conversation.getBookmark() != null && + conversation.getBookmark().isProvidePassword()) { + this.passwordChanged = true; + } this.error = ERROR_PASSWORD_REQUIRED; } } @@ -314,10 +323,25 @@ public class MucOptions { } public String getPassword() { - return this.password; + if (conversation.getBookmark() != null && + conversation.getBookmark().getPassword() != null) { + return conversation.getBookmark().getPassword(); + } else { + return this.password; + } } public void setPassword(String password) { - this.password = password; + if (conversation.getBookmark() != null && + conversation.getBookmark().isProvidePassword()) { + conversation.getBookmark().setPassword(password); + } else { + this.password = password; + } + } + + public boolean isPasswordChanged() { + return this.passwordChanged; } + }
\ 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 ca029e9d..fa5e0a59 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -1,7 +1,6 @@ package eu.siacs.conversations.parser; import android.os.SystemClock; -import android.util.Log; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; import eu.siacs.conversations.Config; diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index da7ffb4d..2b2616e2 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1099,6 +1099,13 @@ public class XmppConnectionService extends Service { public void providePasswordForMuc(Conversation conversation, String password) { if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.getMucOptions().setPassword(password); + if (conversation.getBookmark() != null && + conversation.getMucOptions().isPasswordChanged()) { + if (!conversation.getBookmark().autojoin()) { + conversation.getBookmark().setAutojoin(true); + } + pushBookmarks(conversation.getAccount()); + } joinMuc(conversation); } } |