diff options
author | Michael <betheg@bitcloner.org> | 2014-09-07 14:06:23 +0200 |
---|---|---|
committer | Michael <betheg@bitcloner.org> | 2014-09-07 14:06:23 +0200 |
commit | ecd613dcdd4288b52fea893192c75f3e527436ea (patch) | |
tree | 5a09a1dc8093355fde000286f6c20ebeae713dd1 /src/eu/siacs/conversations | |
parent | d9990e6cd8bb4f2d9bc5696019f757db8a732b1f (diff) |
MUC: set the password from bookmarks.
Diffstat (limited to 'src/eu/siacs/conversations')
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 596cbe01b..14f010e79 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 72fbeeabb..3988eae0c 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 ca029e9d9..fa5e0a59e 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 da7ffb4dd..2b2616e28 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); } } |