aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/Account.java21
-rw-r--r--src/eu/siacs/conversations/entities/Bookmark.java125
-rw-r--r--src/eu/siacs/conversations/entities/Contact.java58
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java34
-rw-r--r--src/eu/siacs/conversations/entities/ListItem.java10
5 files changed, 212 insertions, 36 deletions
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java
index a73d49f9..ac62cf7b 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,21 @@ public class Account extends AbstractEntity{
}
return this.roster;
}
+
+ public void setBookmarks(List<Bookmark> bookmarks) {
+ this.bookmarks = bookmarks;
+ }
+
+ public List<Bookmark> getBookmarks() {
+ return this.bookmarks;
+ }
+
+ public boolean hasBookmarkFor(String conferenceJid) {
+ for(Bookmark bmark : this.bookmarks) {
+ if (bmark.getJid().equals(conferenceJid)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java
new file mode 100644
index 00000000..c4e151cb
--- /dev/null
+++ b/src/eu/siacs/conversations/entities/Bookmark.java
@@ -0,0 +1,125 @@
+package eu.siacs.conversations.entities;
+
+import java.util.Locale;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import eu.siacs.conversations.utils.UIHelper;
+import eu.siacs.conversations.xml.Element;
+
+public class Bookmark implements ListItem {
+
+ private Account account;
+ private String jid;
+ private String nick;
+ private String name;
+ private boolean autojoin;
+ private Conversation mJoinedConversation;
+
+ public Bookmark(Account account, String jid) {
+ 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());
+ }
+ return bookmark;
+ }
+
+ public void setAutojoin(boolean autojoin) {
+ this.autojoin = autojoin;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ 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 (this.mJoinedConversation!=null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
+ return this.mJoinedConversation.getMucOptions().getSubject();
+ } else if (name!=null) {
+ return name;
+ } 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;
+ }
+
+ 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;
+ }
+
+ @Override
+ public Bitmap getImage(int dpSize, Context context) {
+ if (this.mJoinedConversation==null) {
+ return UIHelper.getContactPicture(getDisplayName(), dpSize, context, false);
+ } else {
+ return UIHelper.getContactPicture(this.mJoinedConversation, dpSize, context, false);
+ }
+ }
+
+ public void setConversation(Conversation conversation) {
+ this.mJoinedConversation = conversation;
+ }
+
+ 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);
+ }
+ return element;
+ }
+}
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java
index 50d7af8b..8f8e38a5 100644
--- a/src/eu/siacs/conversations/entities/Contact.java
+++ b/src/eu/siacs/conversations/entities/Contact.java
@@ -8,11 +8,14 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
import android.content.ContentValues;
+import android.content.Context;
import android.database.Cursor;
+import android.graphics.Bitmap;
-public class Contact {
+public class Contact implements ListItem {
public static final String TABLENAME = "contacts";
public static final String SYSTEMNAME = "systemname";
@@ -37,7 +40,7 @@ public class Contact {
protected Account account;
protected boolean inRoster = true;
-
+
public Lastseen lastseen = new Lastseen();
public Contact(String account, String systemName, String serverName,
@@ -83,8 +86,10 @@ public class Contact {
}
public boolean match(String needle) {
- return (jid.toLowerCase().contains(needle.toLowerCase()) || (getDisplayName()
- .toLowerCase().contains(needle.toLowerCase())));
+ return needle == null
+ || jid.contains(needle.toLowerCase())
+ || getDisplayName().toLowerCase()
+ .contains(needle.toLowerCase());
}
public ContentValues getContentValues() {
@@ -127,27 +132,7 @@ public class Contact {
public Account getAccount() {
return this.account;
}
-
- public boolean couldBeMuc() {
- String[] split = this.getJid().split("@");
- if (split.length != 2) {
- return false;
- } else {
- String[] domainParts = split[1].split("\\.");
- if (domainParts.length < 3) {
- return false;
- } else {
- return (domainParts[0].equals("conf")
- || domainParts[0].equals("conference")
- || domainParts[0].equals("room")
- || domainParts[0].equals("muc")
- || domainParts[0].equals("chat")
- || domainParts[0].equals("sala")
- || domainParts[0].equals("salas"));
- }
- }
- }
-
+
public Presences getPresences() {
return this.presences;
}
@@ -270,9 +255,11 @@ public class Contact {
} else if (subscription.equals("from")) {
this.resetOption(Contact.Options.TO);
this.setOption(Contact.Options.FROM);
+ this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else if (subscription.equals("both")) {
this.setOption(Contact.Options.TO);
this.setOption(Contact.Options.FROM);
+ this.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else if (subscription.equals("none")) {
this.resetOption(Contact.Options.FROM);
this.resetOption(Contact.Options.TO);
@@ -308,9 +295,28 @@ public class Contact {
public static final int DIRTY_PUSH = 6;
public static final int DIRTY_DELETE = 7;
}
-
+
public class Lastseen {
public long time = 0;
public String presence = null;
}
+
+ @Override
+ public int compareTo(ListItem another) {
+ return this.getDisplayName().compareToIgnoreCase(another.getDisplayName());
+ }
+
+ public String getServer() {
+ String[] split = getJid().split("@");
+ if (split.length >= 2) {
+ return split[1];
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Bitmap getImage(int dpSize, Context context) {
+ return UIHelper.getContactPicture(this, dpSize, context, false);
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index c207a5c9..70752adc 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -4,8 +4,6 @@ import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList;
import java.util.List;
-import eu.siacs.conversations.services.XmppConnectionService;
-
import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException;
@@ -66,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
@@ -117,14 +117,11 @@ public class Conversation extends AbstractEntity {
this.messages.get(i).markRead();
}
}
-
- public void markRead(XmppConnectionService service) {
- markRead();
- if (service.confirmMessages() && this.latestMarkableMessageId != null) {
- service.sendConfirmMessage(getAccount(), getContactJid(),
- this.latestMarkableMessageId);
- this.latestMarkableMessageId = null;
- }
+
+ public String popLatestMarkableMessageId() {
+ String id = this.latestMarkableMessageId;
+ this.latestMarkableMessageId = null;
+ return id;
}
public Message getLatestMessage() {
@@ -147,6 +144,8 @@ public class Conversation extends AbstractEntity {
if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null)
&& useSubject) {
return getMucOptions().getSubject();
+ } else if (getMode() == MODE_MULTI && bookmark!=null && bookmark.getName() != null) {
+ return bookmark.getName();
} else {
return this.getContact().getDisplayName();
}
@@ -380,4 +379,19 @@ public class Conversation extends AbstractEntity {
public byte[] getSymmetricKey() {
return this.symmetricKey;
}
+
+ public void setBookmark(Bookmark bookmark) {
+ this.bookmark = bookmark;
+ this.bookmark.setConversation(this);
+ }
+
+ public void deregisterWithBookmark() {
+ if (this.bookmark != null) {
+ this.bookmark.setConversation(null);
+ }
+ }
+
+ public Bookmark getBookmark() {
+ return this.bookmark;
+ }
}
diff --git a/src/eu/siacs/conversations/entities/ListItem.java b/src/eu/siacs/conversations/entities/ListItem.java
new file mode 100644
index 00000000..c89c85d9
--- /dev/null
+++ b/src/eu/siacs/conversations/entities/ListItem.java
@@ -0,0 +1,10 @@
+package eu.siacs.conversations.entities;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+
+public interface ListItem extends Comparable<ListItem> {
+ public String getDisplayName();
+ public String getJid();
+ public Bitmap getImage(int dpSize, Context context);
+}