diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-07-14 11:47:42 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-07-14 11:47:42 +0200 |
commit | e2f886d121826df2a97d9f71bc7feab9f6dd52c2 (patch) | |
tree | d9ede20b319a262479e319d00afc881519da360a /src/eu/siacs/conversations/entities | |
parent | 876a076e129ae7f2eb7cf7f7e8b2b46c2cb549be (diff) |
fetch bookmarks from server
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r-- | src/eu/siacs/conversations/entities/Account.java | 12 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Bookmark.java | 94 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 6 |
3 files changed, 112 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index a73d49f91..20abddcd0 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -1,6 +1,8 @@ package eu.siacs.conversations.entities; import java.security.interfaces.DSAPublicKey; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import net.java.otr4j.crypto.OtrCryptoEngineImpl; @@ -67,6 +69,8 @@ public class Account extends AbstractEntity{ private String otrFingerprint; private Roster roster = null; + + private List<Bookmark> bookmarks = new ArrayList<Bookmark>(); public Account() { this.uuid = "0"; @@ -297,4 +301,12 @@ public class Account extends AbstractEntity{ } return this.roster; } + + public void setBookmarks(List<Bookmark> bookmarks) { + this.bookmarks = bookmarks; + } + + public List<Bookmark> getBookmarks() { + return this.bookmarks; + } } diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java new file mode 100644 index 000000000..1b97c5730 --- /dev/null +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -0,0 +1,94 @@ +package eu.siacs.conversations.entities; + +import java.util.Locale; + +import eu.siacs.conversations.xml.Element; + +public class Bookmark implements ListItem { + + private Account account; + private String jid; + private String nick; + private String displayName; + private boolean autojoin; + + public Bookmark(Account account) { + this.account = account; + } + + public static Bookmark parse(Element element, Account account) { + Bookmark bookmark = new Bookmark(account); + bookmark.setJid(element.getAttribute("jid")); + bookmark.setDisplayName(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()); + } + return bookmark; + } + + public void setAutojoin(boolean autojoin) { + this.autojoin = autojoin; + } + + public void setDisplayName(String name) { + this.displayName = name; + } + + public void setJid(String jid) { + this.jid = jid; + } + + public void setNick(String nick) { + this.nick = nick; + } + + @Override + public int compareTo(ListItem another) { + return this.getDisplayName().compareToIgnoreCase(another.getDisplayName()); + } + + @Override + public String getDisplayName() { + if (displayName!=null) { + return displayName; + } else { + return this.jid.split("@")[0]; + } + } + + @Override + public String getJid() { + return this.jid.toLowerCase(Locale.US); + } + + public String getNick() { + return this.nick; + } + + public boolean autojoin() { + return autojoin; + } + + @Override + public String getProfilePhoto() { + return null; + } + + public boolean match(String needle) { + return needle == null + || getJid().contains(needle.toLowerCase(Locale.US)) + || getDisplayName().toLowerCase(Locale.US) + .contains(needle.toLowerCase(Locale.US)); + } + + public Account getAccount() { + return this.account; + } +} diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 23ab382f8..fbd87f3f6 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -64,6 +64,8 @@ public class Conversation extends AbstractEntity { private boolean otrSessionNeedsStarting = false; + private Bookmark bookmark; + public Conversation(String name, Account account, String contactJid, int mode) { this(java.util.UUID.randomUUID().toString(), name, null, account @@ -375,4 +377,8 @@ public class Conversation extends AbstractEntity { public byte[] getSymmetricKey() { return this.symmetricKey; } + + public void setBookmark(Bookmark bookmark) { + this.bookmark = bookmark; + } } |