aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-06 00:33:52 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-06 00:33:52 +0200
commitb788b84c31bc53feb659e1af4dcaad98396c2de7 (patch)
tree700da6bfedd14b4d3ab622471f44917bb16e626c /src/eu/siacs/conversations/entities
parent6b3097ee27ff256afc22b93efec45d84caa2f53d (diff)
refactored muc bookmark to extend element. keep all elements the server or other clients added before
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/Bookmark.java115
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java11
2 files changed, 54 insertions, 72 deletions
diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java
index 14f010e79..722fb6d98 100644
--- a/src/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/eu/siacs/conversations/entities/Bookmark.java
@@ -7,46 +7,35 @@ import android.graphics.Bitmap;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
-public class Bookmark implements ListItem {
+public class Bookmark extends Element implements ListItem {
private Account account;
- 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) {
+ super("conference");
+ this.setAttribute("jid", jid);
+ this.account = account;
+ }
+
+ private Bookmark(Account account) {
+ super("conference");
this.account = account;
- this.jid = jid;
}
public static Bookmark parse(Element element, Account account) {
- 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"))) {
- bookmark.setAutojoin(true);
- } else {
- bookmark.setAutojoin(false);
- }
- Element nick = element.findChild("nick");
- if (nick != null) {
- bookmark.setNick(nick.getContent());
- }
- Element password = element.findChild("password");
- if (password != null) {
- bookmark.setPassword(password.getContent());
- bookmark.setProvidePassword(true);
- }
+ Bookmark bookmark = new Bookmark(account);
+ bookmark.setAttributes(element.getAttributes());
+ bookmark.setChildren(element.getChildren());
return bookmark;
}
public void setAutojoin(boolean autojoin) {
- this.autojoin = autojoin;
+ if (autojoin) {
+ this.setAttribute("autojoin", "true");
+ } else {
+ this.setAttribute("autojoin", "false");
+ }
}
public void setName(String name) {
@@ -54,15 +43,18 @@ public class Bookmark implements ListItem {
}
public void setNick(String nick) {
- this.nick = nick;
+ Element element = this.findChild("nick");
+ if (element == null) {
+ element = this.addChild("nick");
+ }
+ element.setContent(nick);
}
public void setPassword(String password) {
- this.password = password;
- }
-
- private void setProvidePassword(boolean providePassword) {
- this.providePassword = providePassword;
+ Element element = this.findChild("password");
+ if (element != null) {
+ element.setContent(password);
+ }
}
@Override
@@ -76,32 +68,45 @@ public class Bookmark implements ListItem {
if (this.mJoinedConversation != null
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
return this.mJoinedConversation.getMucOptions().getSubject();
- } else if (name != null) {
- return name;
+ } else if (getName() != null) {
+ return getName();
} else {
- return this.jid.split("@")[0];
+ return this.getJid().split("@")[0];
}
}
@Override
public String getJid() {
- return this.jid.toLowerCase(Locale.US);
+ String jid = this.getAttribute("jid");
+ if (jid != null) {
+ return jid.toLowerCase(Locale.US);
+ } else {
+ return null;
+ }
}
public String getNick() {
- return this.nick;
+ Element nick = this.findChild("nick");
+ if (nick != null) {
+ return nick.getContent();
+ } else {
+ return null;
+ }
}
public boolean autojoin() {
- return autojoin;
+ String autojoin = this.getAttribute("autojoin");
+ return (autojoin != null && (autojoin.equalsIgnoreCase("true") || autojoin
+ .equalsIgnoreCase("1")));
}
public String getPassword() {
- return this.password;
- }
-
- public boolean isProvidePassword() {
- return this.providePassword;
+ Element password = this.findChild("password");
+ if (password != null) {
+ return password.getContent();
+ } else {
+ return null;
+ }
}
public boolean match(String needle) {
@@ -131,27 +136,7 @@ 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);
- }
- if (this.password != null && isProvidePassword()) {
- element.addChild("password").setContent(this.password);
- }
- return element;
+ return this.getAttribute("name");
}
public void unregisterConversation() {
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 595d9058a..a9d568486 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -165,8 +165,7 @@ public class MucOptions {
}
aboutToRename = false;
}
- if (conversation.getBookmark() != null
- && conversation.getBookmark().isProvidePassword()) {
+ if (conversation.getBookmark() != null) {
this.passwordChanged = false;
}
} else {
@@ -213,8 +212,7 @@ public class MucOptions {
this.error = ERROR_NICK_IN_USE;
}
} else if (error.hasChild("not-authorized")) {
- if (conversation.getBookmark() != null
- && conversation.getBookmark().isProvidePassword()) {
+ if (conversation.getBookmark() != null) {
this.passwordChanged = true;
}
this.error = ERROR_PASSWORD_REQUIRED;
@@ -357,8 +355,7 @@ public class MucOptions {
}
public void setPassword(String password) {
- if (conversation.getBookmark() != null
- && conversation.getBookmark().isProvidePassword()) {
+ if (conversation.getBookmark() != null) {
conversation.getBookmark().setPassword(password);
} else {
this.password = password;
@@ -367,7 +364,7 @@ public class MucOptions {
.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
}
- public boolean isPasswordChanged() {
+ public boolean isPasswordChanged2() {
return this.passwordChanged;
}